+#!/bin/bash
+first_parameter=$1
+
+drop_to_init_bash(){
+ echo -e "\\033[1;31mERROR: Live Boot Failed: $1\\033[0m"
+ echo -e "\\033[1mDropping you to an almost useless bash shell.\\033[0m"
+ exec /bin/bash --login
+}
+
+corrupt_failure_check(){
+ if [[ $1 == "yes" ]] ; then
+ echo -e "\\033[1;31m!CRITICAL ERROR!\\033[0m"
+ drop_to_init_bash "Data is corrupted/missing, Media is bad/damaged, or an unsupported kernel is being used"
+ fi
+}
+
+missing_file_warning(){
+ echo -e "\\033[0;33mWarning: Unable to $1 '\\033[0;01m$2\\033[0;33m', it could not be found.\\033[0m"
+ sleep 2
+}
+
+do_unsquash(){
+ local d=$float_path$boot_dir$system_dir$sq_path
+ local exists=no
+
+ if [[ ! -f $d$2.$1 ]] ; then
+ if [[ $3 != "silent_on_missing" ]] ; then
+ echo -e "\\033[1;31mERROR: Could not find '\\033[0;01m${d}${2}.${1}\\033[1;31m'\\033[0m"
+ fi
+
+ return 1;
+ fi
+
+ echo -e -n "Unsquashing $2: "
+
+ if [[ -d $2 ]] ; then
+ exists=yes
+ unsquashfs -n $d$2.$1 &>/dev/null &&
+ mv --progress squashfs-root/* $2 &&
+ rmdir -p squashfs-root
+ else
+ unsquashfs -n $d$2.$1 &>/dev/null &&
+ mv --progress squashfs-root $2
+ fi
+
+ if [[ $? != 0 ]] ; then
+ if [[ -e squashfs-root ]] ; then
+ rm -Rf squashfs-root
+ fi
+
+ if [[ $exists == "no" && -d $2 ]] ; then
+ rm -Rf $2
+ fi
+
+ echo -e "\\033[1;31mFailure\\033[0m"
+ return 1
+ fi
+
+ echo -e "\\033[1mDone\\033[0m"
+}
+
+copy_squash_files(){
+ local d=$float_path$boot_dir$system_dir$sq_path
+ local l=$float_path$boot_dir$live_dir
+
+ cp --progress ${d}{bin,lib,sbin}.sfs $l || failure="yes"
+
+ if [[ $failure == "no" && $without_share == "" && $share_device == "" ]] ; then
+ cp --progress ${d}share.sfs $l || failure="yes"
+ fi
+
+ if [[ $failure == "no" ]] ; then
+ if [[ -f ${d}firmware.sfs ]] ; then
+ cp --progress ${d}firmware.sfs $l || failure="yes"
+ else
+ missing_file_warning copy ${d}firmware.sfs
+ fi
+ fi
+
+ if [[ $failure == "no" && -f ${d}$current_kernel.modules ]] ; then
+ if [[ -f ${d}$current_kernel.modules ]] ; then
+ cp --progress ${d}$current_kernel.modules $l || failure="yes"
+ else
+ missing_file_warning copy ${d}$current_kernel.modules
+ fi
+ fi
+
+ if [[ $failure == "no" && $with_toolchain != "" && $toolchain_device == "" ]] ; then
+ if [[ -f ${d}toolchain.sfs ]] ; then
+ cp --progress ${d}toolchain.sfs $l || failure="yes"
+ else
+ missing_file_warning copy ${d}toolchain.sfs
+ fi
+ fi
+
+ if [[ $failure == "no" && $with_documentation != "" && $documentation_device == "" ]] ; then
+ if [[ -f ${d}documentation.sfs ]] ; then
+ cp --progress ${d}documentation.sfs $l || failure="yes"
+ else
+ missing_file_warning copy ${d}documentation.sfs
+ fi
+ fi
+
+ if [[ $failure == "no" && $with_package != "" && $package_device == "" ]] ; then
+ if [[ -f ${d}package.sfs ]] ; then
+ cp --progress ${d}package.sfs $l || failure="yes"
+ else
+ missing_file_warning copy ${d}package.sfs
+ fi
+ fi
+
+ if [[ $failure == "no" && $with_perl != "" && $perl_device == "" ]] ; then
+ if [[ -f ${d}perl.sfs ]] ; then
+ cp --progress ${d}perl.sfs $l || failure="yes"
+ else
+ missing_file_warning copy ${d}perl.sfs
+ fi
+ fi
+
+ if [[ $failure == "no" && $with_python != "" && $python_device == "" ]] ; then
+ if [[ -f ${d}python.sfs ]] ; then
+ cp --progress ${d}python.sfs $l || failure="yes"
+ else
+ missing_file_warning copy ${d}python.sfs
+ fi
+ fi
+}
+
+do_dynamic_files(){
+ local d=$float_path$boot_dir$system_dir$sq_path
+ local l=$float_path$boot_dir$live_dir
+
+ do_unsquash sfs $1 || failure="yes"
+
+ if [[ $failure == "yes" ]] ; then
+ failure="no"
+
+ if [[ -f $d$1.sfs ]] ; then
+ mkdir -p $1
+ cp --progress $d$1.sfs $l &&
+ mount -o loop $l$1.sfs $1 || failure="yes"
+
+ corrupt_failure_check $failure
+ else
+ echo -e "\\033[0;33mWarning: Unable to find '\\033[0;01m$1.sfs\\033[0;33m' in '\\033[0;01m${d}\\033[0;33m'.\\033[0m"
+ sleep 1
+ fi
+ fi
+}
+
+mount_floating_root(){
+ if [[ $filesystem_limit == "" || $(echo $filesystem_limit | grep -s -o "^\<[[:digit:]]") == "" ]] ; then
+ mount -t tmpfs -o gid=d_root,mode=2751 live_system $float_path || drop_to_init_bash "Unable to mount the floating root filesystem"
+ else
+ mount -t tmpfs -o size=$filesystem_limit,gid=d_root,mode=2751 live_system $float_path || drop_to_init_bash "Unable to mount the floating root filesystem"
+ fi
+}
+
+create_basic_root_directories(){
+ local d=$float_path
+
+ mkdir -p ${d}{$boot_dir/{$live_dir,$system_dir},dev,mnt,proc,sys}
+ mkdir -p ${d}dev/pts
+
+ chmod o-r ${d}{mnt,proc,dev,boot,sys}
+ chmod o+x ${d}$boot_dir{,/$live_dir,/$system_dir}
+ chgrp d_root ${d}
+ chgrp d_boot ${d}$boot_dir{,/$live_dir,/$system_dir}
+ chgrp d_device ${d}dev
+ chgrp k_system ${d}sys
+ chgrp k_process ${d}proc
+ chgrp d_mount ${d}mnt
+ chmod -t ${d}
+ chmod g+s ${d}mnt ${d}$boot_dir{,/$live_dir,/$system_dir}
+}
+
+create_additional_root_directories(){
+ local d=$float_path
+ local i=
+
+ if [[ ! -e ${d}var ]] ; then
+ mkdir -p ${d}var
+ chgrp d_variable ${d}var
+ chmod u+rwx,g+rxs-w,o+x-rw ${d}var
+ fi
+
+ if [[ ! -e ${d}var/log ]] ; then
+ mkdir -p ${d}var/log
+ chgrp d_log ${d}var/log
+ chmod u+rwx,g+rxs-w,o+x-rw ${d}var/log
+ fi
+
+ if [[ ! -e ${d}var/run ]] ; then
+ mkdir -p ${d}var/run
+ chgrp d_run ${d}var/run
+ chmod u+rwx,g+rxs-w,o+x-rw ${d}var/run
+ fi
+
+ if [[ ! -d ${d}tmp ]] ; then
+ mkdir -p ${d}tmp &&
+ chgrp d_temporary ${d}tmp &&
+ chmod u+rwx,g+rwx,o-rwx ${d}tmp &&
+ chmod +t ${d}tmp ||
+ failure="yes"
+
+ if [[ $failure == "yes" ]] ; then
+ echo -e "\\033[1;31mERROR: Failed to create the '\\033[0;01m${d}tmp\\033[1;31m' directory\\033[0m"
+ fi
+ fi
+}
+
+# All of the boot time parameters available are here
+boot_string=$(/bin/grep -s -o "\<root=[[:alnum:][:punct:]]*\>" /proc/cmdline | sed -e 's|\<root=||')
+init_string=$(/bin/grep -s -o "\<init=[[:alnum:][:punct:]]*\>" /proc/cmdline | sed -e 's|\<init=||')
+filesystem_limit=$(/bin/grep -s -o "\<filesystemlimit=[[:digit:]]*[[:alpha:]]*\>" /proc/cmdline | sed -e 's|\<filesystemlimit=||')
+with_toolchain=$(/bin/grep -s -o "\<toolchain=yes\>" /proc/cmdline)
+with_documentation=$(/bin/grep -s -o "\<documentation=yes\>" /proc/cmdline)
+with_python=$(/bin/grep -s -o "\<python=yes\>" /proc/cmdline)
+with_perl=$(/bin/grep -s -o "\<perl=yes\>" /proc/cmdline)
+with_package=$(/bin/grep -s -o "\<package=yes\>" /proc/cmdline)
+without_share=$(/bin/grep -s -o "\<share=no\>" /proc/cmdline)
+current_kernel=$(/bin/uname -r)
+doing_squash=$(/bin/grep -s -o "\<squashboot=[[:alnum:][:punct:]]*\>" /proc/cmdline | sed -e 's|\<squashboot=||')
+doing_squish=$(/bin/grep -s -o "\<squishboot=[[:alnum:][:punct:]]*\>" /proc/cmdline | sed -e 's|\<squishboot=||')
+doing_install=$(/bin/grep -s -o "\<install=[[:alnum:][:punct:]]*\>" /proc/cmdline | sed -e 's|\<install=||')
+subroot_string=$(/bin/grep -s -o "\<subroot=[[:alnum:][:punct:]]*\>" /proc/cmdline | sed -e 's|\<subroot=||')
+sq_path=$(/bin/grep -s -o "\<squashpath=[[:alnum:][:punct:]]*" /proc/cmdline | sed -e 's|\<squashpath=||')
+live_dir="live/"
+live_undir="../"
+boot_dir="boot/"
+boot_undir="../"
+system_dir="system/"
+system_undir="../"
+rootfs_path="/mnt/"
+float_path="/this/"
+system_symlinks=
+
+home_device=
+etc_device=
+share_device=
+var_device=
+tmp_device=
+package_device=
+perl_device=
+python_device=
+documentation_device=
+toolchain_device=
+
+install_files=
+
+if [[ $doing_squash == "" && $doing_squish == "" ]] ; then
+ sq_command="invalid"
+elif [[ $doing_squash != "" && $doing_squash != "device" && $doing_squash != "memory" && $doing_squash != "extract" ]] ; then
+ sq_command="invalid"
+elif [[ $doing_squish != "" && $doing_squish != "device" && $doing_squish != "memory" && $doing_squish != "extract" ]] ; then
+ sq_command="invalid"
+fi
+
+if [[ $sq_command == "invalid" ]] ; then
+ drop_to_init_bash "No valid squashboot= nor squishboot= parameter was passed, valid choices are: device, memory, or extract"
+fi
+
+if [[ $doing_install != "" ]] ; then
+ if [[ $doing_install != "kiwi" ]] ; then
+ if [[ $(echo $doing_install | grep -s '^/.*') != "" ]] ; then
+ install_files=$doing_install
+ else
+ drop_to_init_bash "Only '\\033[0;01mkiwi\\033[1;31m' or path based installation mode is supported at this time, try install=kiwi or install=/directory/to/squash/files"
+ fi
+ else
+ install_files="/boot/live"
+ fi
+fi
+
+if [[ $subroot_string != "" ]] ; then
+ subroot_string=$(echo $subroot_string | sed -e 's|^/*||' -e 's|/*$|/|')
+fi
+
+if [[ $init_string == "" ]] ; then
+ init_string="/bin/pre_init"
+fi
+
+if [[ $doing_squash != "" ]] ; then
+ doing_squish=
+ sq_command=$doing_squash
+else
+ doing_squash=
+ sq_command=$doing_squish
+fi
+
+if [[ $sq_path == "" ]] ; then
+ sq_path="boot/live/"
+else
+ sq_path=$(echo ${sq_path} | sed -e 's|/*$|/|')
+fi
+
+if [[ -d ${float_path}home ]] ; then
+ home_device=mounted
+fi
+
+if [[ -d ${float_path}etc ]] ; then
+ etc_device=mounted
+fi
+
+if [[ -d ${float_path}share ]] ; then
+ share_device=mounted
+fi
+
+if [[ -d ${float_path}var ]] ; then
+ var_device=mounted
+fi
+
+if [[ -d ${float_path}tmp ]] ; then
+ tmp_device=mounted
+fi
+
+if [[ -d ${float_path}package ]] ; then
+ package_device=mounted
+fi
+
+if [[ -d ${float_path}perl ]] ; then
+ perl_device=mounted
+fi
+
+if [[ -d ${float_path}python ]] ; then
+ python_device=mounted
+fi
+
+if [[ -d ${float_path}toolchain ]] ; then
+ toolchain_device=mounted
+fi
+
+if [[ -d ${float_path}documentation ]] ; then
+ documentation_device=mounted
+fi
+
+# prepend the subroot path
+if [[ $subroot_string != "" ]] ; then
+ sq_path=$subroot_string$sq_path
+fi
+
+# Begin loading
+echo -e -n "\\033[1;32mNow Loading the "
+if [[ $doing_squash != "" ]] ; then
+ echo -n "Squashed"
+else
+ echo -n "Squished"
+fi
+echo -e " Filesystems\\033[0m"
+
+mount_floating_root
+
+# Now mount the boot device and directories
+mount_init $float_path $rootfs_path
+
+if [[ $? -ne 0 ]] ; then
+ drop_to_init_bash "Cannot boot: Unable to mount the root device: \\033[0;01m${boot_string}\\033[1;31m"
+fi
+
+create_basic_root_directories
+
+mount -n --move $rootfs_path $float_path$boot_dir$system_dir
+
+if [[ $? -ne 0 ]] ; then
+ drop_to_init_bash "Failed to move mount from '\\033[0;01m$rootfs_path\\033[1;31m' to '\\033[0;01m$float_path$boot_dir$system_dir\\033[1;31m'"
+fi
+
+failure="no"
+cd $float_path
+
+# prepare installation files
+if [[ $install_files != "" ]] ; then
+ mkdir -p ${float_path}installation/device &&
+ chgrp e_public ${float_path}installation{,/device} &&
+ chmod o-rx ${float_path}installation{,/device}
+
+ if [[ $? -ne 0 ]] ; then
+ echo -e "\\033[0;33mWarning: Failed to create or modify the installation directory '\\033[0;01m${float_path}installation/device\\033[0;33m'\\033[0m"
+ sleep 0.5
+ fi
+
+ mount -n $boot_string ${float_path}installation/device &> /dev/null
+ if [[ $? -ne 0 ]] ; then
+ echo -e "\\033[0;33mWarning: Failed to mount drive '\\033[0;01m${boot_string}\\033[0;33m' to installation directory '\\033[0;01m${float_path}installation/device\\033[0;33m'\\033[0m"
+ sleep 0.5
+ else
+ ln -s device$install_files ${float_path}installation/live
+ fi
+fi
+
+# Extract the following files & directories (or perform mounts)
+if [[ $failure == "no" && $doing_squash != "" ]] ; then
+ if [[ $etc_device == "" ]] ; then
+ do_dynamic_files etc || failure=yes
+ fi
+
+ if [[ $failure == "no" && $home_device == "" ]] ; then
+ do_dynamic_files home || failure=yes
+ fi
+
+ if [[ $failure == "yes" ]] ; then
+ drop_to_init_bash "Failed to extract squash files"
+ fi
+fi
+
+# Copy the devices
+if [[ ! -e ${float_path}dev/console ]] ; then
+ cp -pR /dev/console ${float_path}dev/
+fi
+
+# Mount the rest of the squashed files
+if [[ $sq_command == "extract" && $failure == "no" ]] ; then
+ echo -e "\\033[0;32mExtracting System Into Memory\\033[0m"
+
+ do_unsquash sfs bin &&
+ do_unsquash sfs lib &&
+ do_unsquash sfs sbin ||
+ failure="yes"
+
+ if [[ $failure == "no" && $without_share == "" && $share_device == "" ]] ; then
+ do_unsquash sfs share || failure="yes"
+ fi
+
+ # extract firmware & modules for currently running kernel, which are not critical
+ if [[ $failure == "no" ]] ; then
+ do_unsquash sfs firmware silent_on_missing
+
+ if [[ ! -d modules ]] ; then
+ mkdir -p modules
+ fi
+
+ cd modules/
+ do_unsquash modules $current_kernel silent_on_missing
+ cd ..
+ fi
+
+ if [[ $failure == "no" && $with_toolchain != "" && $toolchain_device == "" ]] ; then
+ if [[ -f $float_path$boot_dir$system_dir${sq_path}toolchain.sfs ]] ; then
+ do_unsquash sfs toolchain || failure="yes"
+ else
+ missing_file_warning unsquash $float_path$boot_dir$system_dir${sq_path}toolchain.sfs
+ fi
+ fi
+
+ if [[ $failure == "no" && $with_documentation != "" && $documentation_device == "" ]] ; then
+ if [[ -f $float_path$boot_dir${system_dir}documentation.sfs ]] ; then
+ do_unsquash sfs documentation || failure="yes"
+ else
+ missing_file_warning unsquash $float_path$boot_dir${system_dir}documentation.sfs
+ fi
+ fi
+
+ if [[ $failure == "no" && $with_package != "" && $package_device == "" ]] ; then
+ if [[ -f $float_path$boot_dir$system_dir${sq_path}package.sfs ]] ; then
+ do_unsquash sfs package || failure="yes"
+ else
+ missing_file_warning unsquash $float_path$boot_dir$system_dir${sq_path}package.sfs
+ fi
+ fi
+
+ if [[ $failure == "no" && $with_perl != "" && $perl_device == "" ]] ; then
+ if [[ -f $float_path$boot_dir$system_dir${sq_path}perl.sfs ]] ; then
+ do_unsquash sfs perl || failure="yes"
+ else
+ missing_file_warning unsquash $float_path$boot_dir$system_dir${sq_path}perl.sfs
+ fi
+ fi
+
+ if [[ $failure == "no" && $with_python != "" && $python_device == "" ]] ; then
+ if [[ -f $float_path$boot_dir$system_dir${sq_path}python.sfs ]] ; then
+ do_unsquash sfs python || failure="yes"
+ else
+ missing_file_warning unsquash $float_path$boot_dir$system_dir${sq_path}python.sfs
+ fi
+ fi
+
+ if [[ $failure == "yes" ]] ; then
+ echo -e "\\033[1;31mERROR: Failed to Extract the Filesystem into Memory\\033[0m"
+ echo -e "\\033[1mAttempting Compressed Memory Filesystem Load.\\033[0m"
+
+ rm -Rf bin lib sbin firmware modules
+
+ if [[ $share_device == "" ]] ; then
+ rm -Rf share
+ fi
+
+ if [[ $toolchain_device == "" ]] ; then
+ rm -Rf toolchain
+ fi
+
+ if [[ $documentation_device == "" ]] ; then
+ rm -Rf documentation
+ fi
+
+ if [[ $package_device == "" ]] ; then
+ rm -Rf package
+ fi
+
+ if [[ $perl_device == "" ]] ; then
+ rm -Rf perl
+ fi
+
+ if [[ $python_device == "" ]] ; then
+ rm -Rf python
+ fi
+
+ sq_command="memory"
+ sleep 3
+ fi
+fi
+
+if [[ $sq_command == "memory" ]] ; then
+ failure="no"
+
+ echo -e "\\033[0;32mCopying Squash System Data Into Memory\\033[0m"
+ copy_squash_files
+
+ if [[ $failure == "yes" ]] ; then
+ echo -e "\\033[1;31mERROR: Failed to Load the Compressed Filesystem into Memory\\033[0m"
+ echo -e "\\033[1mAttempting Device Filesystem Load.\\033[0m"
+
+ rm -f $float_path$boot_dir${live_dir}{bin,lib,sbin,share,firmware,toolchain,documentation,package,perl,python}.sfs
+ rm -f $float_path$boot_dir$live_dir$current_kernel.modules
+
+ sq_command="device"
+
+ sleep 3
+ fi
+fi
+
+if [[ $sq_command == "device" ]] ; then
+ failure="no"
+
+ cd $float_path$boot_dir$system_dir$sq_path || failure="yes"
+
+ if [[ $failure == "no" ]] ; then
+ for i in * ; do
+ ln -sf ../$system_dir$sq_path$i $float_path$boot_dir$live_dir$i &&
+ system_symlinks="$system_symlinks$i " || failure="yes"
+ done
+
+ cd $float_path
+ fi
+fi
+
+if [[ $failure == "no" && ( $sq_command == "memory" || $sq_command == "device" ) ]] ; then
+ mkdir -p bin lib sbin &&
+ mount -o loop $float_path$boot_dir${live_dir}bin.sfs bin &&
+ mount -o loop $float_path$boot_dir${live_dir}lib.sfs lib &&
+ mount -o loop $float_path$boot_dir${live_dir}sbin.sfs sbin ||
+ failure="yes"
+
+ if [[ $failure == "no" && $without_share == "" && $share_device == "" ]] ; then
+ mkdir -p share &&
+ mount -o loop $float_path$boot_dir${live_dir}share.sfs share || failure="yes"
+ fi
+
+ if [[ $failure == "no" && -f $float_path$boot_dir${live_dir}firmware.sfs ]] ; then
+ mkdir -p firmware &&
+ mount -o loop $float_path$boot_dir${live_dir}firmware.sfs firmware || failure="yes"
+ fi
+
+ if [[ $failure == "no" && -f $float_path$boot_dir$live_dir$current_kernel.modules ]] ; then
+ mkdir -p modules/$current_kernel &&
+ mount -o loop $float_path$boot_dir$live_dir$current_kernel.modules modules/$current_kernel || failure="yes"
+ fi
+
+ if [[ $failure == "no" && $with_toolchain != "" && $toolchain_device == "" ]] ; then
+ if [[ -f $float_path$boot_dir${live_dir}toolchain.sfs ]] ; then
+ mkdir -p toolchain &&
+ mount -o loop $float_path$boot_dir${live_dir}toolchain.sfs toolchain || failure="yes"
+ else
+ missing_file_warning mount $float_path$boot_dir${live_dir}toolchain.sfs
+ fi
+ fi
+
+ if [[ $failure == "no" && $with_documentation != "" && $documentation_device == "" ]] ; then
+ if [[ -f $float_path$boot_dir${live_dir}documentation.sfs ]] ; then
+ mkdir -p documentation &&
+ mount -o loop $float_path$boot_dir${live_dir}documentation.sfs documentation || failure="yes"
+ else
+ missing_file_warning mount $float_path$boot_dir${live_dir}documentation.sfs
+ fi
+ fi
+
+ if [[ $failure == "no" && $with_package != "" && $package_device == "" ]] ; then
+ if [[ -f $float_path$boot_dir${live_dir}package.sfs ]] ; then
+ mkdir -p package &&
+ mount -o loop $float_path$boot_dir${live_dir}package.sfs package || failure="yes"
+ else
+ missing_file_warning mount $float_path$boot_dir${live_dir}package.sfs
+ fi
+ fi
+
+ if [[ $failure == "no" && $with_perl != "" && $perl_device == "" ]] ; then
+ if [[ -f $float_path$boot_dir${live_dir}perl.sfs ]] ; then
+ mkdir -p perl &&
+ mount -o loop $float_path$boot_dir${live_dir}perl.sfs perl || failure="yes"
+ else
+ missing_file_warning mount $float_path$boot_dir${live_dir}perl.sfs
+ fi
+ fi
+
+ if [[ $failure == "no" && $with_python != "" && $python_device == "" ]] ; then
+ if [[ -f $float_path$boot_dir${live_dir}python.sfs ]] ; then
+ mkdir -p documentation &&
+ mount -o loop $float_path$boot_dir${live_dir}python.sfs python || failure="yes"
+ else
+ missing_file_warning mount $float_path$boot_dir${live_dir}python.sfs
+ fi
+ fi
+
+ if [[ $failure == "yes" ]] ; then
+ echo -e "\\033[1;31mERROR: Failed to mount the squashed filesystems\\033[0m"
+
+ for i in bin lib sbin share firmware toolchain documentation package perl python; do
+ if [[ $(mount -l | grep -s -o "^.* on $float_path$boot_dir$live_dir$i ") ]] ; then
+ umount -l $i
+ fi
+ done
+
+ if [[ $(mount -l | grep -s -o "^.* on $float_path$boot_dir${live_dir}modules/$current_kernel ") ]] ; then
+ umount -l modules/$current_kernel
+ fi
+
+ sleep 3
+ fi
+fi
+
+if [[ $failure == "no" && $doing_squish != "" ]] ; then
+ cd $float_path$boot_dir$system_dir$subroot_string || failure="yes"
+
+ if [[ $failure == "no" ]] ; then
+ for i in * ; do
+ if [[ ! -e $float_path$i ]] ; then
+ ln -sf $boot_dir$system_dir$subroot_string$i $float_path$i &&
+ system_symlinks="$system_symlinks$i " || failure="yes"
+ fi
+ done
+
+ cd $float_path
+ else
+ echo -e "\\033[1;31mERROR: Failed to change to the path '\\033[0;01m$float_path$boot_dir$system_dir$subroot_string\\033[1;31m'\\033[0m"
+ fi
+fi
+
+if [[ $failure == "no" ]] ; then
+ create_additional_root_directories
+
+ if [[ $squash_boot != "" ]] ; then
+ umount -l $float_path$boot_dir$system_dir
+ fi
+fi
+
+corrupt_failure_check $failure
+
+if [[ $system_symlinks == "" ]] ; then
+ umount -l $float_path$boot_dir$system_dir
+fi
+
+# make sure /proc is not mounted prior to chroot & pivot_root
+umount -n /proc
+
+# Now attempt to switch to the new system
+echo -e -n "\\033[1;32mNow Switching to the "
+if [[ $doing_squash != "" ]] ; then
+ echo -n "Squash"
+else
+ echo -n "Squish"
+fi
+echo -e " System\\033[0m"
+
+cd $float_path
+
+pivot_root . tmp/ || drop_to_init_bash "Failed to pivot root to the live system"
+cd /
+umount -l -n /tmp
+
+if [[ ! -e dev/console ]] ; then
+ echo -e "\\033[1;31mERROR: Failed to find console device at dev/console\\033[0m"
+ echo -e "\\033[1mDropping to system shell.\\033[0m"
+ exec /bin/bash
+fi
+
+if [[ ! -e $init_string ]] ; then
+ drop_to_init_bash "Could not find init binary: \\033[0;01m${init_string}\\033[1;31m"
+fi
+
+if [[ ! -e bin/bash ]] ; then
+ drop_to_init_bash "Could not find bash binary: \\033[0;01mbin/bash\\033[1;31m"
+fi
+
+exec chroot . /bin/bash -c "exec $init_string" < dev/console > dev/console 2>&1