Skip to content

Commit

Permalink
api: check apt exitcode for unexpected value
Browse files Browse the repository at this point in the history
  • Loading branch information
Botspot authored and theofficialgman committed Aug 24, 2024
1 parent 3ae76e0 commit 1449b2c
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions api
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -687,12 +690,14 @@ 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 -e "\e[91mFailed to install the packages!\e[39m"
echo -e "APT reported these errors:\n\e[91m$errors\e[39m"
echo "$output"

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 "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."
Expand Down

0 comments on commit 1449b2c

Please sign in to comment.