Use stricter Bash settings in activation script

For example, with these settings Bash will complain if uninitialized
variables are used. Some code has been improved to run cleanly with
these settings.
This commit is contained in:
Robert Helgesson 2017-03-25 21:48:17 +01:00
parent 207c349825
commit fea693ba16
No known key found for this signature in database
GPG key ID: C3DB11069E65DC86
4 changed files with 8 additions and 7 deletions

View file

@ -40,7 +40,7 @@ function doBuild() {
extraArgs="$extraArgs -I $p" extraArgs="$extraArgs -I $p"
done done
if [[ $VERBOSE ]]; then if [[ -v VERBOSE ]]; then
extraArgs="$extraArgs --show-trace" extraArgs="$extraArgs --show-trace"
fi fi

View file

@ -30,20 +30,20 @@ setupVars
echo "Starting home manager activation" echo "Starting home manager activation"
if [[ $VERBOSE ]]; then if [[ -v VERBOSE ]]; then
export VERBOSE_ECHO=echo export VERBOSE_ECHO=echo
export VERBOSE_ARG="--verbose" export VERBOSE_ARG="--verbose"
else else
export VERBOSE_ECHO=true export VERBOSE_ECHO=true
unset VERBOSE_ARG export VERBOSE_ARG=""
fi fi
if [[ $DRY_RUN ]] ; then if [[ -v DRY_RUN ]] ; then
$VERBOSE_ECHO "This is a dry run" $VERBOSE_ECHO "This is a dry run"
export DRY_RUN_CMD=echo export DRY_RUN_CMD=echo
else else
$VERBOSE_ECHO "This is a live run" $VERBOSE_ECHO "This is a live run"
unset DRY_RUN_CMD export DRY_RUN_CMD=""
fi fi
$VERBOSE_ECHO "Activation variables:" $VERBOSE_ECHO "Activation variables:"

View file

@ -328,7 +328,8 @@ in
sf = pkgs.writeText "activation-script" '' sf = pkgs.writeText "activation-script" ''
#!${pkgs.stdenv.shell} #!${pkgs.stdenv.shell}
set -e set -eu
set -o pipefail
${builtins.readFile ./activation-init.sh} ${builtins.readFile ./activation-init.sh}

View file

@ -184,7 +184,7 @@ in
in in
# The dconf service needs to be installed and prepared. # The dconf service needs to be installed and prepared.
stringAfter [ "installPackages" ] '' stringAfter [ "installPackages" ] ''
if [[ $DRY_RUN ]]; then if [[ -v DRY_RUN ]]; then
echo ${pkgs.gnome3.dconf}/bin/dconf load ${dconfPath} "<" ${sf} echo ${pkgs.gnome3.dconf}/bin/dconf load ${dconfPath} "<" ${sf}
else else
${pkgs.gnome3.dconf}/bin/dconf load ${dconfPath} < ${sf} ${pkgs.gnome3.dconf}/bin/dconf load ${dconfPath} < ${sf}