From 288932d607e1162041a63444bad6954b6ab4efdc Mon Sep 17 00:00:00 2001 From: buanet Date: Mon, 20 Feb 2023 18:01:33 +0100 Subject: [PATCH] fix error handling --- debian/scripts/iobroker_startup.sh | 14 +------------- debian/scripts/setup_packages.sh | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/debian/scripts/iobroker_startup.sh b/debian/scripts/iobroker_startup.sh index 588b0d6..f3b139e 100644 --- a/debian/scripts/iobroker_startup.sh +++ b/debian/scripts/iobroker_startup.sh @@ -135,19 +135,7 @@ if [[ -f /opt/.first_run ]]; then if [[ "$offlinemode" = "true" ]]; then echo "OFFLINE_MODE is \"true\". Skipping Linux package updates on first run." else - echo -n "Updating Linux packages on first run... " - set +e - bash /opt/scripts/setup_packages.sh -update > /opt/scripts/setup_packages.log 2>&1 - return=$? - set -e - if [[ "$return" -ne 0 ]]; then - echo "Failed." - echo "For more details see \"/opt/scripts/setup_packages.log\"." - echo "Make sure the container has internet access to get the latest package updates." - echo "This has no impact to the setup process. The script will continue." - else - echo 'Done.' - fi + bash /opt/scripts/setup_packages.sh -update fi echo ' ' # Installing packages from ENV diff --git a/debian/scripts/setup_packages.sh b/debian/scripts/setup_packages.sh index 776af9e..48fcd66 100644 --- a/debian/scripts/setup_packages.sh +++ b/debian/scripts/setup_packages.sh @@ -10,7 +10,7 @@ then for i in $packages; do if [ "$(dpkg-query -W -f='${Status}' "$i" 2>/dev/null | grep -c "ok installed")" -eq 0 ]; then - echo -n "$i is not installed. Installing..." + echo -n "$i is not installed. Installing... " DEBIAN_FRONTEND=noninteractive apt-get -q -y install "$i" >> /opt/scripts/setup_packages.log 2>&1 return=$? if [[ "$return" -ne 0 ]]; then @@ -24,10 +24,20 @@ then echo "$i is already installed." fi done -elif [ "$1" == "-update" ] -then - apt-get -q update - apt-get -q -y upgrade +elif [ "$1" == "-update" ]; then + echo -n "Updating Linux packages on first run... " + apt-get -q update >> /opt/scripts/setup_packages.log 2>&1 + return=$? + apt-get -q -y upgrade >> /opt/scripts/setup_packages.log 2>&1 + return1=$? + if [[ "$return" -ne 0 || "$return1" -ne 0 ]]; then + echo "Failed." + echo "For more details see \"/opt/scripts/setup_packages.log\"." + echo "Make sure the container has internet access to get the latest package updates." + echo "This has no impact to the setup process. The script will continue." + else + echo 'Done.' + fi else echo "No paramerter found!" exit 1