From 020b8fe34c159d1d5f427bcd44d82c07c811ba3f Mon Sep 17 00:00:00 2001 From: Patrik Lundin Date: Wed, 12 Oct 2022 16:26:20 +0200 Subject: [PATCH] Enable "set -e" again Good idea to fail when unexpected things go wrong. Additional fixes added to the script to not stop where we can expect a non-zero return code. Requested by @fredrikt who also reviewed the patch before going in, thanks! --- .../overlay/etc/cosmos/apt/bootstrap-cosmos.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/global/overlay/etc/cosmos/apt/bootstrap-cosmos.sh b/global/overlay/etc/cosmos/apt/bootstrap-cosmos.sh index d3c4b80..1426904 100755 --- a/global/overlay/etc/cosmos/apt/bootstrap-cosmos.sh +++ b/global/overlay/etc/cosmos/apt/bootstrap-cosmos.sh @@ -1,7 +1,6 @@ #!/bin/sh -#set -e -# not all breakage is un-recoverable... +set -e cmd_hostname="$1" if test -z "$cmd_hostname"; then @@ -32,7 +31,9 @@ export DEBIAN_FRONTEND='noninteractive' apt-get -y update apt-get -y upgrade for pkg in rsync git git-core wget gpg; do - apt-get -y install $pkg + # script is running with "set -e", use "|| true" to allow packages to not + # exist without stopping the script + apt-get -y install $pkg || true done dpkg -i cosmos_1.5-1_all.deb @@ -40,8 +41,10 @@ if ! test -d /var/cache/cosmos/repo; then cosmos clone "$cmd_repo" fi -# re-run cosmos at reboot until it succeeds - use bash -l to get working proxy settings -grep -v "^exit 0" /etc/rc.local > /etc/rc.local.new +# Re-run cosmos at reboot until it succeeds - use bash -l to get working proxy settings. +# It is possible the file does not exist or contains no matching lines, +# both cases are OK +grep -v "^exit 0" /etc/rc.local > /etc/rc.local.new || true (echo "" echo "test -f /etc/run-cosmos-at-boot && (bash -l cosmos -v update; bash -l cosmos -v apply && rm /etc/run-cosmos-at-boot)" echo "" @@ -52,8 +55,7 @@ mv -f /etc/rc.local.new /etc/rc.local touch /etc/run-cosmos-at-boot # If this cloud-config is set, it will interfere with our changes to /etc/hosts -grep -q 'manage_etc_hosts: true' /etc/cloud/cloud.cfg -if [ ${?} -eq 0 ]; then +if [ -f /etc/cloud/cloud.cfg ]; then sed -i 's/manage_etc_hosts: true/manage_etc_hosts: false/g' /etc/cloud/cloud.cfg fi