From 738f5d476482b1536f95cc889e193d53ba7ed661 Mon Sep 17 00:00:00 2001 From: hwdsl2 Date: Sun, 13 May 2018 00:56:29 -0500 Subject: [PATCH] Improve check for apt/dpkg lock --- vpnsetup.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/vpnsetup.sh b/vpnsetup.sh index a30f596..27198fa 100755 --- a/vpnsetup.sh +++ b/vpnsetup.sh @@ -134,17 +134,19 @@ bigecho "VPN setup in progress... Please be patient." mkdir -p /opt/src cd /opt/src || exiterr "Cannot enter /opt/src." -bigecho "Populating apt-get cache..." - -# Wait up to 60s for apt/dpkg lock count=0 -while fuser /var/lib/apt/lists/lock /var/lib/dpkg/lock >/dev/null 2>&1; do - [ "$count" -ge "20" ] && exiterr "Cannot get apt/dpkg lock." +while fuser /var/lib/apt/lists/lock /var/lib/dpkg/lock >/dev/null 2>&1 \ + || lsof /var/lib/apt/lists/lock >/dev/null 2>&1 \ + || lsof /var/lib/dpkg/lock >/dev/null 2>&1; do + [ "$count" = "0" ] && bigecho "Waiting for apt to be available..." + [ "$count" -ge "60" ] && exiterr "Could not get apt/dpkg lock." count=$((count+1)) printf '%s' '.' sleep 3 done +bigecho "Populating apt-get cache..." + export DEBIAN_FRONTEND=noninteractive apt-get -yq update || exiterr "'apt-get update' failed."