diff --git a/modules/lib-bash/activation-init.sh b/modules/lib-bash/activation-init.sh index b5472504c..5cdb66e59 100755 --- a/modules/lib-bash/activation-init.sh +++ b/modules/lib-bash/activation-init.sh @@ -11,27 +11,38 @@ function setupVars() { | sort -rn \ | head -1) - if [[ -n "$greatestGenNum" ]] ; then + if [[ -n $greatestGenNum ]] ; then oldGenNum=$greatestGenNum newGenNum=$((oldGenNum + 1)) else newGenNum=1 fi - if [[ -e "$gcPath/current-home" ]] ; then + if [[ -e $gcPath/current-home ]] ; then oldGenPath="$(readlink -e "$gcPath/current-home")" fi + $VERBOSE_ECHO "Sanity checking oldGenNum and oldGenPath" + if [[ -v oldGenNum && ! -v oldGenPath + || ! -v oldGenNum && -v oldGenPath ]]; then + errorEcho "Invalid profile number and GC root values! These must be" + errorEcho "either both empty or both set but are now set to" + errorEcho " '${oldGenNum:-}' and '${oldGenPath:-}'" + errorEcho "If you don't mind losing previous profile generations then" + errorEcho "the easiest solution is probably to run" + errorEcho " rm $profilesPath/home-manager*" + errorEcho " rm $gcPath/current-home" + errorEcho "and trying home-manager switch again. Good luck!" + exit 1 + fi + + genProfilePath="$profilesPath/home-manager" newGenPath="@GENERATION_DIR@"; newGenProfilePath="$profilesPath/home-manager-$newGenNum-link" newGenGcPath="$gcPath/current-home" } -setupVars - -echo "Starting home manager activation" - if [[ -v VERBOSE ]]; then export VERBOSE_ECHO=echo export VERBOSE_ARG="--verbose" @@ -40,6 +51,10 @@ else export VERBOSE_ARG="" fi +echo "Starting home manager activation" + +setupVars + if [[ -v DRY_RUN ]] ; then echo "This is a dry run" export DRY_RUN_CMD=echo