Nov 082013
 

I was adding some new features on PiParted recently and needed a simple file browser for my PiParted script. I couldn’t find anything online for this sort of thing, so I built my own file browser of sorts.

Using whiptail and the output of ls (which isn’t recommended but I’ll get around to posting an updated version of this script sometime), I managed to get a simple file browser to allow a user to pick a file.
I’ll paste bits and pieces of the code to explain it, and then paste the whole function at the end of this post.

This starts off with an if statement to check to see whether a path has been passed to the script. If it hasn’t it will start the listing off at /, Otherwise it will start at the path it had been passed.

function Filebrowser() {
if [ -z $1 ]; then
imgpath=$(ls -lhp / | awk -F ' ' ' { print $9 " " $5 } ')
else
imgpath=$(ls -lhp "/$1" | awk -F ' ' ' { print $9 " " $5 } ')
fi

Next, still checking to see whether it was passed a path, it will show a back button if it was passed a path.

if [ -z $1 ]; then
pathselect=$(whiptail --menu "Select Image File" 40 50 30 --cancel-button Cancel --ok-button Select $imgpath 3>&1 1>&2 2>&3)
else
pathselect=$(whiptail --menu "Select Image File" 40 50 30 --cancel-button Cancel --ok-button Select ../ BACK $imgpath 3>&1 1>&2 2>&3)
fi

Next, it checks the return value to make sure it was 0 to signify the user didn’t press cancel
After that, it checks the path the user selected to see if it was a directory, if it is then it re-runs the function and passes a path
Otherwise it will determine whether the file selected is the file type that is required, and if it is show that it is about to perform an action. If it’s not the type required, present an error to the user.

RET=$?
if [ $RET -eq 0 ]; then
if [[ -d "/$1$pathselect" ]]; then
Filebrowser "/$1$pathselect"
elif [[ -f "/$1$pathselect" ]]; then
fileout=`file "$1$pathselect"
filename=`readlink -m $1$pathselect`
if [[ $fileout =~ x86\ boot\ sector$ ]]; then
whiptail --yesno --title "! WARNING !" "About to try and automatically resize $filename. Are you sure ?" 10 50
### This bit of the code would be what you want to do after the user has selected the right type of file.
if [ $? -ne 0 ]; then
Filebrowser
fi
else
whiptail --msgbox --title "! ERROR ! ERROR ! ERROR ! " "Selected file is not an image file." 8 44
Filebrowser
fi

And lastly, check to make sure the path that was passed to the script is valid. At the moment, I don’t imagine this script would handle spaces well so you may see this error message when processing directories with spaces in their names.

else
echo pathselect $1$pathselect
whiptail --title "! ERROR !" --msgbox "Error setting path to image file." 8 44
unset base
unset imgpath
Filebrowser
fi
exit 0

And, as promised, the whole code in one big block

Filebrowser() {
if [ -z $1 ]; then
imgpath=$(ls -lhp / | awk -F ' ' ' { print $9 " " $5 } ')
else
imgpath=$(ls -lhp "/$1" | awk -F ' ' ' { print $9 " " $5 } ')
fi
if [ -z $1 ]; then
pathselect=$(whiptail --menu "Select Image File" 40 50 30 --cancel-button Cancel --ok-button Select $imgpath 3>&1 1>&2 2>&3)
else
pathselect=$(whiptail --menu "Select Image File" 40 50 30 --cancel-button Cancel --ok-button Select ../ BACK $imgpath 3>&1 1>&2 2>&3)
fi
RET=$?
if [ $RET -eq 1 ]; then
## This is the section where you control what happens when the user hits Cancel
AdvancedMenu
exit 0
elif [ $RET -eq 0 ]; then
if [[ -d "/$1$pathselect" ]]; then
Filebrowser "/$1$pathselect"
elif [[ -f "/$1$pathselect" ]]; then
## Do your thing here, this is just a stub of the code I had to do what I wanted the script to do.
fileout=`file "$1$pathselect"`
filename=`readlink -m $1$pathselect`
if [[ $fileout =~ x86\ boot\ sector$ ]]; then
whiptail --yesno --title "! WARNING !" "About to try and automatically resize $filename. Are you sure ?" 10 50
if [ $? -ne 0 ]; then
Filebrowser
fi
else
whiptail --msgbox --title "! ERROR ! ERROR ! ERROR ! " "Selected file is not an image file." 8 44
Filebrowser
fi
else
echo pathselect $1$pathselect
whiptail --title "! ERROR !" --msgbox "Error setting path to image file." 8 44
unset base
unset imgpath
Filebrowser
fi
exit 0
fi
}

Share
Jun 202013
 

I recently decided to create a LiveCD to simplify downloading and flashing Raspberry Pi images.

I started off with the GParted ISO as that is already a small distribution, plus it has everything I needed for the PiParted distribution.
GParted comes in ISO form, so the first thing we need to do is mount the ISO file to get all the files that out of it. You’ll need to be root to mount the ISO file, or use sudo.

# mkdir -p ~/isodistro/iso
# mount -o loop gparted-live-0.16.1-1-i486.iso /mnt/iso
# cp -r /mnt/iso/* ~/isodistro/iso

You should see the following files inside

EFI EFI-imgs GParted-Live-Version GPL isolinux live syslinux utils

Inside the live directory, you will see these files

filesystem.packages filesystem.squashfs initrd.img memtest vmlinuz

The one we want is filesystem.squashfs, this file is what contains the main filesystem of the distribution.

As you can probably deduce from the file extension, this file is a squash fs file system. Which means that we can easily unsquash it.

# mkdir ~/isodistro/fs
# cp ~/isodistro/iso/live/filesystem.squashfs ~/isodistro/fs/
# cd ~/isodistro/fs
# unsquashfs filesystem.squashfs

This will create the squashfs-root directory within the fs directory, and if we have a look in there…

# ls squashfs-root/
bin dev etc home initrd.img lib media mnt opt proc root run sbin selinux srv sys tmp usr var vmlinuz

Tada ! We have the root filesystem of GParted.
The startup scripts are located within etc/gparted-live/gparted-live.d if you want to modify those.
Once the modifications have been made, you will need to pack it all back up, and repack the files into the ISO file.

mksquashfs ~/isodistro/fs/squashfs-root/* ~/isodistro/fs/filesystem.squashfs -comp xz
mv ~/isodistro/fs/filesystem.squashfs ~/isodistro/iso/live/
mkisofs -o youriso.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -J -R -V youriso-live ~/isodistro/iso

That will create the ISO file for you, and hopefully you should be able to boot your newly customised GParted distribution !

Share
Apr 242013
 

Another update to PiParted

Fixed up non-appearing SD Cards
Also added a backup option, at the moment it can only backup ~4GB SD Cards as it reads it to ram for now. Your computer will also need at least 4 GB of ram to backup the SD Card.

Grab it here !

SHA1 Hash – 2fa25e4f9e9260a3612129a1b0291fca3e3fd628 PiParted-0.04.iso

Comments / feedback would be very welcome !

Share
Apr 192013
 

Just finished up with PiParted v0.03

Changes –
No longer needs 4 gigs of ram as it will uncompress and image on the fly.
Tested it on a laptop with 1.5 gigs of ram and it worked ok.

Installing from SD Card –
Works with both zip and .gz file, haven’t tested properly with .tar.gz but should still work

Also checks SHA1 hash when downloaded from the Pi site.

Incremental update really.
Download it from here
SHA1 Hash –
f91e53df56aec6cc7d1b27041e0750b0f4763bfd PiParted-0.03.iso

Share
Apr 082013
 

After some tweaking, I have improved PiParted.
Please note this is a very early testing version, so some things may break or not work properly.

Download it here !

New features –
Flash OS from zip file on SD Card:
If the SD card only has one partition, and there is one zip file on that partition, the script will use that to flash an OS on.

Reset SD Card:
This will format an SD Card back to defaults, i.e. one vfat partition.

dd will now show it’s status when it’s flashing a SD card.

I’m looking for testers, so if anyone tries this out, please give me some feedback, either on this post or in the forum thread @ http://www.raspberrypi.org/phpBB3/viewtopic.php?f=63&t=39160

Share