wait for dpkg locks
authorIan Kelling <iank@fsf.org>
Mon, 28 May 2018 22:45:15 +0000 (18:45 -0400)
committerIan Kelling <iank@fsf.org>
Mon, 28 May 2018 22:45:15 +0000 (18:45 -0400)
src/package-manager-abstractions

index 6d433d249b0858f94032bfb4c23e5308ed4add9b..f70bf1d01772d3d403c4a6f45d38d40f45429681 100644 (file)
@@ -65,14 +65,7 @@ elif command -v apt-get &>/dev/null; then
         if dpkg -s -- "$@" &>/dev/null; then
             return 0
         fi
-        pupdate
-        local s; [[ $EUID != 0 ]] && s=sudo
-        $s apt-get -y install --purge --auto-remove "$@"
-    }
-    pi() {
-        if dpkg -s -- "$@" &>/dev/null; then
-            return 0
-        fi
+        while fuser /var/lib/dpkg/lock &>/dev/null; do sleep 1; done
         pupdate
         local s; [[ $EUID != 0 ]] && s=sudo
         $s $PI_PREFIX apt-get -y install --purge --auto-remove "$@"
@@ -82,6 +75,7 @@ elif command -v apt-get &>/dev/null; then
         if dpkg -s -- "$@" &>/dev/null; then
             return 0
         fi
+        while fuser /var/lib/dpkg/lock &>/dev/null; do sleep 1; done
         pupdate
         local s; [[ $EUID != 0 ]] && s=sudo
         local f=/usr/sbin/policy-rc.d
@@ -109,11 +103,13 @@ EOF
     }
     pu() {
         local s; [[ $EUID != 0 ]] && s=sudo
+        while fuser /var/lib/dpkg/lock &>/dev/null; do sleep 1; done
         $s apt-get -y remove --purge --auto-remove  "$@"
         # seems slightly redundant, but it removes more stuff sometimes.
         $s apt-get -y autoremove
     }
     pup() { # upgrade
+        while fuser /var/lib/dpkg/lock &>/dev/null; do sleep 1; done
         pupdate
         local s; [[ $EUID != 0 ]] && s=sudo
         $s apt-get -y dist-upgrade --purge --auto-remove "$@"