diff --git a/README.md b/README.md index 02109ea..3f5603c 100644 --- a/README.md +++ b/README.md @@ -274,6 +274,8 @@ The following table is giving a list of error code with explanation: | 11 | Bad function call | | 12 | Error copying files | | 13 | Bad target file system | +| 14 | Impossible to chroot | +| 15 | Bad target filesystem/installation | | 50..100 | Error in module execution | | 126 | Command exists but not executable | | 127 | Command not found | diff --git a/init.sh b/init.sh index 2ad0370..7f5d7f8 100755 --- a/init.sh +++ b/init.sh @@ -116,6 +116,10 @@ fi # -- Cannot be a function ends here # ------------------------------------------------------------------------------ +if [[ -n $CHROOT_PATH && -z $CHROOT_DONE ]]; then + chroot_bootstrap $@ +fi + load_autoconf load_configuration diff --git a/lib/zzz_main_fct.sh b/lib/zzz_main_fct.sh index 02a55cc..8b9a173 100644 --- a/lib/zzz_main_fct.sh +++ b/lib/zzz_main_fct.sh @@ -139,6 +139,36 @@ read_commandline() export -f read_commandline +# ------------------------------------------------------------------------------ +# If chrooted, we need to bootstrap to a new copy of our directory tree +chroot_bootstrap() +{ + if [[ ! -d $CHROOT_PATH ]]; then + prnt E "The path given to chroot don't exists." + die 14 + fi + 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 bootstrap_items="conf lib modules repo bash.rc init.sh" + if [[ $RESUME == true ]]; then + bootstrap_items="$bootstrap_items $STAGE_FILE" + fi + + prnt I "Préparation du changement de racine." + cp -av $bootstrap_items $tmpdir + + prnt I "Changement de racine et démarrage d'un fork d'init.sh..." + chroot $CHROOT_PATH /bin/bash -c 'CHROOT_DONE=true; $tmpdir/init.sh $@' + + prnt I "Retours au système hote et nettoyage." + rm -rf $tmpdir + exit 0 +} + # ------------------------------------------------------------------------------ # Automatically load system specific configuration if file exist in the # following order: