function echoout { echo "[OBI] $@" echo "$@" >> "${HOME}"/obi-installer.log } function mklub { ## Find the path that OBI is installed to... ## if it is from the Debian package it will be /usr/share/OBI/ if [ -f "/home/$USER/mkpxpy" ] then dpath="/home/$USER" elif [ -f "$PWD/mkpxpy" ] then dpath="$PWD" elif [ -f "${HOME}/mkpxpy" ] then dpath="${HOME}" elif [ -f "/usr/share/OBI/mkpxpy" ] then dpath="/usr/share/OBI" else echo "Script not found. Change directory!" fi # variables LC_ALL=C LANG=C swapping=true # system and partitions system="$1" tarball="$2" rootpart="$3" swappart="$4" ##Save these variables to the logfile for examination later echoout "$system" echoout "$tarball" echoout "$rootpart" echoout "$swappart" ## check if swap partition exists... if not... NO swap if [ -z "$swappart" ] then swapping=false fi # Unmount the partition if it is mounted MOUNTIE=$(mount |grep /mnt) if [ ! -z "${MOUNTIE}" ] then umount /mnt fi # make file system mkfs.ext4 "$rootpart" sync # mount what will be the root partition mount "$rootpart" /mnt if [ $? != 0 ] then echoout "mount of what should become the root partition failed: $rootpart" exit fi # copy the files # check for tarballs if [ -d "/tarballs" ] then tarpath="/tarballs" elif [ -d "${HOME}/tarballs" ] then tarpath="${HOME}/tarballs" elif [ -d "${PWD}/tarballs" ] then tarpath="${PWD}/tarballs" else tarpath="${PWD}" echo "Error finding the tarball path" fi startdir="$dpath" cd /mnt #df . ## see if the tarball has the fullpath listed in selected, or not... if [ "$tarball" == "$(basename "$tarball")" ] then trbll="$tarpath/$tarball" else trbll="$tarball" fi ## check if there is gz or xz.... if not FAIL if [ "$tarball" != "${tarball/.gz}" ] then echoout "pv $trbll | tar -xz" pv "$trbll" | tar -xz elif [ "$tarball" != "${tarball/.xz}" ] then echoout "pv $trbll | tar -xJ" pv "$trbll" | tar -xJ else read -p "only gzip and xz compression implemented" exit fi echoout "the tarball $tarball is expanded, syncing the drive ..." sync cd "$startdir" # match the UUIDs to the fstab in the tarball and activate the swap c=0;for i in $(grep ^UUID /mnt/etc/fstab|grep ext4|sed -e s/\ .*// -e 's/UUID=//'); do echo $i;c=$(($c+1));done;echo $c if [ $c -ne 1 ] then echoout "There are $c ext4 partitions in /mnt/etc/fstab, should be 1" exit fi c=0;for i in $(grep ^UUID /mnt/etc/fstab|grep swap|sed -e s/\ .*// -e 's/UUID=//'); do echo $i;c=$(($c+1));done;echo $c if $swapping then if [ $c -ne 1 ] then echoout "There are $c swap partitions in /mnt/etc/fstab, should be 1" exit fi suidblkid=$(blkid -c /dev/null|grep "$swappart"|grep 'TYPE="swap"') if [ $? -eq 0 ] then echoout "Use existing swap partition $swappart - keep its UUID" swapoff "$swappart" else echoout "Make $swappart a swap partition - and get new UUID" mkswap "$swappart" fi swapuid=$(grep ^UUID /mnt/etc/fstab|grep swap|sed -e s/\ .*// -e 's/UUID=//') swapUUID=$(blkid -c /dev/null "$swappart"|sed -e 's/.*UUID="//' -e 's/".*//') fi rootuid=$(grep ^UUID /mnt/etc/fstab|grep ext4|sed -e s/\ .*// -e 's/UUID=//') rootUUID=$(blkid -c /dev/null "$rootpart"|sed -e 's/.*UUID="//' -e 's/".*//') if [ -f /mnt/etc/fstab ] # moved to before fstab0 is used then mv /mnt/etc/fstab /mnt/etc/fstab0 else echoout "MISSING /mnt/etc/fstab" fi if $swapping then sed s/"$swapuid"/"$swapUUID"/ /mnt/etc/fstab0 > /mnt/etc/fstab1 else grep ^UUID /mnt/etc/fstab0|grep swap if [ $? -eq 0 ] then swapline=$(grep ^UUID /mnt/etc/fstab0|grep swap) sed s/"$swapline"/"#$swapline"/ /mnt/etc/fstab0 > /mnt/etc/fstab1 else cp /mnt/etc/fstab0 /mnt/etc/fstab1 fi fi if [ -f /mnt/boot/grub/grub.cfg ] then mv /mnt/boot/grub/grub.cfg /mnt/boot/grub/grub.cfg0 sed s/"$rootuid"/"$rootUUID"/ /mnt/boot/grub/grub.cfg0 > /mnt/boot/grub/grub.cfg rm /mnt/boot/grub/grub.cfg0 else echoout "MISSING /mnt/boot/grub/grub.cfg" fi if [ -f /mnt/etc/grub.d/40_custom ] then mv /mnt/etc/grub.d/40_custom /mnt/etc/grub.d/40_custom0 sed s/"$rootuid"/"$rootUUID"/ /mnt/etc/grub.d/40_custom0 > /mnt/etc/grub.d/40_custom rm /mnt/etc/grub.d/40_custom0 chmod ugo+x /mnt/etc/grub.d/40_custom else echoout "MISSING /mnt/etc/grub.d/40_custom" fi if [ -f /mnt/etc/fstab1 ] then sed s/"$rootuid"/"$rootUUID"/ /mnt/etc/fstab1 > /mnt/etc/fstab rm /mnt/etc/fstab{0,1} else echoout "MISSING /mnt/etc/fstab1" fi # label=${system//\ /_} labelfix tune2fs -L "$label" "$rootpart" # tune2fs -U "$rootuid" "$rootpart" # mkswap -U "$swapuid" "$swappart" df -h /mnt if $swapping then swapon "$swappart" -p 3 swapon -s fi blkid -c /dev/null # install the bootloader target="${rootpart:0:8}" /bin/echo -n "Bootloader: " "$dpath"/grub-installer "$target" sync user-config umount "$rootpart" #/bin/echo -n "File checking with " #e2fsck -f "$rootpart" # finish echoout "The installation of $system to $device has finished" dialog --title "Reboot Now?" --clear \ --yesno "Do you want to reboot into $system" 10 30 case $? in 0) clear echoout "Rebooting Now" reboot ;; 1) echoout "Not rebooting.";; esac }