Additional fixes for dpkg lock issues 17/5117/3
authorRudy Grigar <rgrigar@linuxfoundation.org>
Tue, 14 Feb 2017 00:57:31 +0000 (16:57 -0800)
committerRudy Grigar <rgrigar@linuxfoundation.org>
Tue, 14 Feb 2017 04:00:39 +0000 (20:00 -0800)
This adds a wrapper around apt-get to loop until the lock is available
for dpkg operations.

Change-Id: I85d3b1f1e6992a046d021a192997f307c7ca4785
Signed-off-by: Rudy Grigar <rgrigar@linuxfoundation.org>
packer/provision/baseline.sh

index d97f0e2..625728a 100644 (file)
@@ -115,6 +115,31 @@ Dpkg::Options {
 
 EOF
 
+    # Wrap apt-get to wait for the lock to become available for operation
+    # http://askubuntu.com/questions/132059/how-to-make-a-package-manager-wait-if-another-instance-of-apt-is-running
+    cat <<EOF >> /usr/local/bin/apt-get
+#!/bin/bash
+
+i=0
+tput sc
+while fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do
+    case $(($i % 4)) in
+        0 ) j="-" ;;
+        1 ) j="\\" ;;
+        2 ) j="|" ;;
+        3 ) j="/" ;;
+    esac
+    tput rc
+    echo -en "\r[$j] Waiting for other software managers to finish..."
+    sleep 0.5
+    ((i=i+1))
+done
+
+/usr/bin/apt-get "$@"
+
+EOF
+    chmod +x /usr/local/bin/apt-get
+
     echo "---> Updating operating system"
     apt-get update
     apt-get upgrade