From 4f1eec818029df209ef275752cff36d6dfbb1c16 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Wed, 29 Mar 2017 00:10:30 +0200 Subject: [PATCH] Avoid undefined variables in activation script --- modules/activation-init.sh | 11 ++++++++--- modules/home-environment.nix | 4 ++-- modules/systemd.nix | 10 +++++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/modules/activation-init.sh b/modules/activation-init.sh index 5ac5fdfe2..a7011b9c2 100755 --- a/modules/activation-init.sh +++ b/modules/activation-init.sh @@ -47,10 +47,15 @@ else fi $VERBOSE_ECHO "Activation variables:" -$VERBOSE_ECHO " oldGenNum=$oldGenNum" -$VERBOSE_ECHO " newGenNum=$newGenNum" -$VERBOSE_ECHO " oldGenPath=$oldGenPath" +if [[ -v oldGenNum ]] ; then + $VERBOSE_ECHO " oldGenNum=$oldGenNum" + $VERBOSE_ECHO " oldGenPath=$oldGenPath" +else + $VERBOSE_ECHO " oldGenNum undefined (first run?)" + $VERBOSE_ECHO " oldGenPath undefined (first run?)" +fi $VERBOSE_ECHO " newGenPath=$newGenPath" +$VERBOSE_ECHO " newGenNum=$newGenNum" $VERBOSE_ECHO " newGenProfilePath=$newGenProfilePath" $VERBOSE_ECHO " newGenGcPath=$newGenGcPath" $VERBOSE_ECHO " genProfilePath=$genProfilePath" diff --git a/modules/home-environment.nix b/modules/home-environment.nix index cef70541a..8c3c462e9 100644 --- a/modules/home-environment.nix +++ b/modules/home-environment.nix @@ -281,7 +281,7 @@ in } function cleanOldGen() { - if [[ -z "$oldGenPath" ]] ; then + if [[ ! -v oldGenPath ]] ; then return fi @@ -294,7 +294,7 @@ in | xargs -0 bash ${cleanup} "$newGenFiles" "$oldGenFiles" } - if [[ "$oldGenPath" != "$newGenPath" ]] ; then + if [[ ! -v oldGenPath || "$oldGenPath" != "$newGenPath" ]] ; then $DRY_RUN_CMD ln -Tsf $VERBOSE_ARG "$newGenPath" "$newGenProfilePath" $DRY_RUN_CMD ln -Tsf $VERBOSE_ARG "$newGenProfilePath" "$genProfilePath" $DRY_RUN_CMD ln -Tsf $VERBOSE_ARG "$newGenPath" "$newGenGcPath" diff --git a/modules/systemd.nix b/modules/systemd.nix index 57c819e01..293b32df1 100644 --- a/modules/systemd.nix +++ b/modules/systemd.nix @@ -74,17 +74,21 @@ in local workDir workDir="$(mktemp -d)" - local oldUserServicePath="$oldGenPath/home-files/.config/systemd/user" + if [[ -v oldGenPath ]] ; then + local oldUserServicePath="$oldGenPath/home-files/.config/systemd/user" + fi + local newUserServicePath="$newGenPath/home-files/.config/systemd/user" local oldServiceFiles="$workDir/old-files" local newServiceFiles="$workDir/new-files" local servicesDiffFile="$workDir/diff-files" - if [[ ! -d "$oldUserServicePath" && ! -d "$newUserServicePath" ]]; then + if [[ ! (-v oldUserServicePath && -d "$oldUserServicePath") \ + && ! -d "$newUserServicePath" ]]; then return fi - if [[ ! -d "$oldUserServicePath" ]]; then + if [[ ! (-v oldUserServicePath && -d "$oldUserServicePath") ]]; then touch "$oldServiceFiles" else find "$oldUserServicePath" \