[Nix-dev] Does anyone mind my replacing the fail in stage-1 by

Marc Weber marco-oweber at gmx.de
Tue Jul 15 16:40:09 CEST 2008


targetRoot=/mnt/root
fail() {
    # If starting stage 2 failed, start an interactive shell.
    echo "error while running Stage 1" 
    echo "Stage 1 should mount the root partition containing the nix store on \`$targetRoot'";
    echo 
    echo "stage 2 is \$stage2Init $stage2Init"
    echo "I'll launch an interactive shell you should exit with to"
    echo " - status 0: continue"
    echo "             (type exit or press ctrl-d)"
    echo " - status 2: finally switch to interactive shell (exec @staticShell) "
    echo "             (type exit 2)"
    export $stage2Init
    # no longer using exec here, so after resuming we'll have this shell as 
    @staticShell@;
    case $? in
      0) echo "resuming ..";;
      2) echo "switching to final interactive shell using exec .."; exec @staticShell@;;
      *) echo "got exit status $? from interactive shell, quiting." 
         echo "you'll have to reboot"; exit;;
    esac
}
trap 'fail' ERR; # if we were using bash we could even show the malicious command using  "$BASH_COMMAND"

new features:
* resuming
* docuemntation (what should be mounted where here)

It has been:
fail() {
    # If starting stage 2 failed, start an interactive shell.
    echo "Stage 2 failed, starting emergency shell..."
    echo "(Stage 1 init script is $stage2Init)"
    exec @staticShell@
}

Marc Weber



More information about the nix-dev mailing list