improved code quality, few bug fixes
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#!/bin/bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Chroot system functions
|
||||
# This file is part of the init.sh project
|
||||
@@ -13,36 +14,36 @@
|
||||
# If chrooted, we need to bootstrap to a new copy of our directory tree
|
||||
chroot_bootstrap()
|
||||
{
|
||||
if [[ ! -d $CHROOT_PATH ]]; then
|
||||
if [[ ! -d "$CHROOT_PATH" ]]; then
|
||||
prnt E "The path given to chroot don't exists."
|
||||
die 14
|
||||
fi
|
||||
if [[ ! -d $CHROOT_PATH/tmp ]]; then
|
||||
if [[ ! -d "$CHROOT_PATH/tmp" ]]; then
|
||||
prnt E "The target filesystem doesn't seems to be a valid installation."
|
||||
die 15
|
||||
fi
|
||||
|
||||
local tmpdir=$(mktemp -d $CHROOT_PATH/tmp/init.sh-XXXX)
|
||||
local tmpdir=$(mktemp -d "$CHROOT_PATH/tmp/init.sh-XXXX")
|
||||
local bootstrap_items="conf lib modules repo bash.rc init.sh prepost.d"
|
||||
if [[ $RESUME == true ]]; then
|
||||
bootstrap_items="$bootstrap_items $STAGE_FILE"
|
||||
fi
|
||||
|
||||
prnt I "Preparing root change."
|
||||
cp -av $bootstrap_items $tmpdir
|
||||
cp -av $bootstrap_items "$tmpdir"
|
||||
|
||||
prnt I "Changing root and starting a fork of init.sh..."
|
||||
# on the following line, true allows to correctly exit in case of error since
|
||||
# errors are managed by the chrooted environment
|
||||
chroot $CHROOT_PATH /bin/bash -c 'CHROOT_DONE=true; $tmpdir/init.sh $@' || true
|
||||
chroot "$CHROOT_PATH" /bin/bash -c 'CHROOT_DONE=true; "$tmpdir/init.sh" "$@"' || true
|
||||
|
||||
# If stage file still exists we copy it to be able to resume later
|
||||
if [[ -e $tmpdir/$(basename $STAGE_FILE) ]]; then
|
||||
cp $tmpdir/$(basename $STAGE_FILE) $STAGE_FILE
|
||||
if [[ -e "$tmpdir/$(basename "$STAGE_FILE")" ]]; then
|
||||
cp "$tmpdir/$(basename "$STAGE_FILE")" "$STAGE_FILE"
|
||||
fi
|
||||
|
||||
prnt I "Back to host system and clean up."
|
||||
rm -rf $tmpdir
|
||||
rm -rf "$tmpdir"
|
||||
}
|
||||
|
||||
# EOF
|
||||
|
||||
Reference in New Issue
Block a user