From 4c4291d40daf4eb235faf89c7832f6c389607ce8 Mon Sep 17 00:00:00 2001 From: Adam Spragg Date: Wed, 16 Mar 2022 15:05:09 +0000 Subject: Exit scripts early if there's nothing to do --- adu-download | 14 +++++++------- adu-upgrade | 7 +++++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/adu-download b/adu-download index dcc215e..ba021f7 100755 --- a/adu-download +++ b/adu-download @@ -26,13 +26,13 @@ UPDATE_SYMLINK="/system-update" UPDATE_TARGET="${SBINDIR}/adu-upgrade" apt-get -qq update -apt-get -qq upgrade -d - -#apt-get -qq autoclean upgrades=$(apt -qq list --upgradeable 2>/dev/null | wc -l) - -if [ $upgrades -gt 0 ]; then - ln -s -- "${UPDATE_TARGET}" "${UPDATE_SYMLINK}" 2>/dev/null || true - echo "$upgrades updates available" +if [ "$upgrades" -eq 0 ]; then + exit 0 fi + +apt-get -qq upgrade -d + +ln -s -- "${UPDATE_TARGET}" "${UPDATE_SYMLINK}" 2>/dev/null || true +echo "$upgrades updates available" diff --git a/adu-upgrade b/adu-upgrade index d12b57f..81f6e90 100755 --- a/adu-upgrade +++ b/adu-upgrade @@ -34,6 +34,13 @@ fi # the update script to avoid reboot loops in case the update fails." rm -f -- "${UPDATE_SYMLINK}" +upgrades=$(apt -qq list --upgradeable 2>/dev/null | wc -l) +if [ "$upgrades" -eq 0 ]; then + echo "Nothing to do? Rebooting..." + systemctl reboot + exit 0 +fi + # Do the update apt-get upgrade -y --no-download --ignore-missing -- cgit v1.2.1