From ad4b235667aaa8ee1ced783295b1735dc965f4b0 Mon Sep 17 00:00:00 2001 From: Botspot <54716352+Botspot@users.noreply.github.com> Date: Sat, 2 Sep 2023 15:41:30 -0500 Subject: [PATCH] install_packages: add basic 5-time retry for Other Apt Update --- api | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/api b/api index d6716db86f..b2efd68e09 100755 --- a/api +++ b/api @@ -518,19 +518,6 @@ Package: $package_name" > ~/$package_name/DEBIAN/control echo "$package_name is already installed and no changes would be made. Skipping..." else - #Before apt update, check if local repo still exists - if [ "$using_local_packages" == 1 ] && [ ! -f /tmp/pi-apps-local-packages/Packages ];then - error "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." - fi - - #run an apt update - apt_update "${apt_flags[@]}" || exit 1 - - #After apt update, check again if local repo still exists - if [ "$using_local_packages" == 1 ] && [ ! -f /tmp/pi-apps-local-packages/Packages ];then - error "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." - fi - #Build .deb file for the dummy package local output="$(dpkg-deb --build ~/$package_name 2>&1)" if [ $? != 0 ] || [ ! -f ~/$package_name.deb ];then @@ -539,12 +526,32 @@ Package: $package_name" > ~/$package_name/DEBIAN/control error "install_packages(): failed to create dummy deb ${package_name}!" fi - #install dummy deb - status "Installing the $package_name package..." + #Before apt update, check if local repo still exists + if [ "$using_local_packages" == 1 ] && [ ! -f /tmp/pi-apps-local-packages/Packages ];then + error "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." + fi - apt_lock_wait - local output="$(sudo -E apt install -fy --no-install-recommends --allow-downgrades "${apt_flags[@]}" ~/$package_name.deb 2>&1 | less_apt | tee /dev/stderr)" - status "Apt finished." + local i=0 + while [ $i -le 5 ];do #retry loop ; run apt update and apt install again if apt's records of the local repo goes missing + #run an apt update + apt_update "${apt_flags[@]}" || exit 1 + + #install dummy deb + status "Installing the $package_name package..." + + apt_lock_wait + local output="$(sudo -E apt install -fy --no-install-recommends --allow-downgrades "${apt_flags[@]}" ~/$package_name.deb 2>&1 | less_apt | tee /dev/stderr)" + status "Apt finished." + + if [ "$using_local_packages" == 1 ] && [ ! -f /var/lib/apt/lists/_tmp_pi-apps-local-packages_._Packages ];then + #another apt update process deleted apt's knowledge of the pi-apps local repo. Warn the user and try again, up to 5 tries. + i=$((i+1)) + warning "Local packages failed to install because another apt update process erased apt's knowledge of the pi-apps local repository.\nTrying again... (attempt $i of 5)" + else + #apt may have succeeded or failed, but exit retry loop for Other Apt Update + break + fi + done errors="$(echo "$output" | grep '^[(E)|(Err]:')" if [ ! -z "$errors" ];then