# Retry installing package 5 times if necessary
for i in {0..5}
do
+
+ # Wait for any background apt processes to finish before running apt
+ while pgrep apt > /dev/null; do sleep 1; done
+
echo "$i: Installing $pkg"
if [ "$(dpkg-query -W -f='${Status}' "$pkg" 2>/dev/null | grep -c "ok installed")" -eq 0 ]; then
apt-cache policy "$pkg"