A background apt process locks /var/lib/dpkg/lock and causes apt
commands to fail. Therefore check if apt is locked before running
apt.
Errors:
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource
temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg), is
another process using
Change-Id: I3ced3711b26ebe9ecf5654c70d23f44e905c1f4c
Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
# Retry installing package 5 times if necessary
for i in {0..5}
do
# 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"
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"