#!/bin/bash # author Antonio Amorim Antonio.Amorim@paipix.org # GNU public license # # Creates a PAIPIX bootable pen drive from the iso file # The pen drive must be the only removable device inserted and mounted # The script will look into the current directory and in the /home/user/Desktop # for a single iso file. # All files are copied and grub is intalled in the pen drive # echo "" # Make sure only root can run our script if [[ $EUID -ne 0 ]]; then echo "This script must be run as root" 1>&2 exit 1 fi echo "Looking for iso in current directory." ISO=`find . -maxdepth 1 -name \*.iso` if [ ! -f "$ISO" ] then echo "Looking for iso in /home/$SUDO_USER/Desktop directory." ISO=`find /home/$SUDO_USER/Desktop/ -maxdepth 1 -name \*.iso` if [ ! -f "$ISO" ] then echo "" echo "There is no .iso file in the Current and /home/$SUDO_USER/Desktop directories" echo " or there are more than one iso file in the directory." echo " Please correct." exit 1 fi fi echo "Using $ISO as paipix iso file." echo "" if [ "`grep -c 'uhelper=hal' /etc/mtab`" != "1" ] then echo "There is no USB pen currently mounted." echo "Or there are several removable devices connected. Please correct." echo "Insert the pen again (use open in a new window when the pop-up appears)." exit 1 fi PEN="`grep 'uhelper=hal' /etc/mtab| cut -f2 -d ' ' `" DEVICE="`grep $PEN /etc/mtab| cut -f1 -d ' ' `" echo "" echo "Using $PEN as pen mounted directory" echo "" echo 'Do you want to proceed with the installation? (Yes/No)' read a if [ "$a" != "Yes" ] && [ "$a" != "yes" ] && [ "$a" != "Y" ] && [ "$a" != "y" ] then echo "Aborting" exit 1 fi echo "" echo "Starting rsynk. It may take a long time." echo "" mkdir -p /media/paipix-iso mount $ISO /media/paipix-iso -o loop rsync --delete --modify-window=1 -rtuv /media/paipix-iso/ $PEN umount /media/paipix-iso rmdir /media/paipix-iso mkdir -p $PEN/boot/grub cp -f /usr/lib/grub/x86_64-pc/stage1 $PEN/boot/grub cp -f /usr/lib/grub/x86_64-pc/stage2 $PEN/boot/grub rm -f $PEN/boot/grub/fat_stage1_5 echo "" echo "Installing grub." echo "" grub-mkdevicemap -m $PEN/paipix-pen-devicemap DRIVE="`grub-probe -m $PEN/paipix-pen-devicemap -d $DEVICE -t drive| cut -c2,3,4`" echo "Now performing the installation on DEVICE $DEVICE DRIVE $DRIVE" /usr/sbin/grub --batch --device-map=$PEN/paipix-pen-devicemap <