diff --git a/api b/api index 2c5218d672a..232ef0ffefe 100755 --- a/api +++ b/api @@ -371,8 +371,9 @@ apt_update() { #run an apt update with error-checking and minimal output apt_lock_wait status "Running \e[7msudo apt update\e[27m..." - output="$(sudo -E apt update --allow-releaseinfo-change "$@" 2>&1 | less_apt | tee /dev/stderr)" - exitcode=$? + set -o pipefail + local output="$(sudo -E apt update --allow-releaseinfo-change "$@" 2>&1 | less_apt | tee /dev/stderr)" + local exitcode=$? status "apt update complete." #inform user about autoremovable packages @@ -388,7 +389,7 @@ apt_update() { #run an apt update with error-checking and minimal output fi #exit on apt error - errors="$(echo "$output" | grep '^[(E)|(Err]:')" + local errors="$(echo "$output" | grep '^[(E)|(Err]:')" if [ $exitcode != 0 ] || [ ! -z "$errors" ];then echo -e "\e[91mFailed to run \e[4msudo apt update\e[0m\e[39m!" echo -e "APT reported these errors:\n\e[91m$errors\e[39m" @@ -674,7 +675,9 @@ Package: $package_name" > /tmp/$package_name/DEBIAN/control status "Installing the $package_name package..." apt_lock_wait + set -o pipefail local output="$(sudo -E apt install -fy --no-install-recommends --allow-downgrades "${apt_flags[@]}" /tmp/$package_name.deb 2>&1 | less_apt | tee /dev/stderr)" + local exitcode=$? status "Apt finished." if [ "$using_local_packages" == 1 ] && [ ! -f /var/lib/apt/lists/_tmp_pi-apps-local-packages_._Packages ] && [ $i != 5 ];then @@ -687,12 +690,13 @@ Package: $package_name" > /tmp/$package_name/DEBIAN/control fi done - errors="$(echo "$output" | grep '^[(E)|(Err]:')" - if [ ! -z "$errors" ];then + local errors="$(echo "$output" | grep '^[(E)|(Err]:')" + if [ -z "$errors" ] && [ "$exitcode" != 0 ]; then + echo "User error: Apt exited with a failed exitcode ($exitcode) and no error (E/Err) output. This could indicate system corruption (eg: storage corruption or unstable overclocking)." + exit 1 + elif [ ! -z "$errors" ];then echo -e "\e[91mFailed to install the packages!\e[39m" - echo -e "APT reported these errors:\n\e[91m$errors\e[39m" - echo "$output" - + echo -e "The APT reported these errors:\n\e[91m$errors\e[39m" #some error reports seem to indicate that package URLs aren't being properly downloaded. This output aims to solve the mystery. if [ "$using_local_packages" == 1 ] && [ ! -f /tmp/pi-apps-local-packages/Packages ];then echo "User error: Uh-oh, the /tmp/pi-apps-local-packages folder went missing while installing packages.\nThis usually happens if you try to install several apps at the same time in multiple terminals."