From 2c762899de062300958017d0ba905d5ea995e9f5 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 3 Mar 2017 11:28:35 +0100 Subject: [PATCH 1/3] Add loop to wait if package manager is blocked externally --- automated install/basic-install.sh | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 219b08cb..878ac319 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -59,7 +59,7 @@ distro_check() { if command -v apt-get &> /dev/null; then #Debian Family ############################################# - PKG_MANAGER="apt-get" + PKG_MANAGER="test_dpkg_lock; apt-get" UPDATE_PKG_CACHE="${PKG_MANAGER} update" PKG_INSTALL=(${PKG_MANAGER} --yes --no-install-recommends install) # grep -c will return 1 retVal on 0 matches, block this throwing the set -e with an OR TRUE @@ -87,6 +87,32 @@ if command -v apt-get &> /dev/null; then LIGHTTPD_CFG="lighttpd.conf.debian" DNSMASQ_USER="dnsmasq" + test_dpkg_lock() { + i=0 + while fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do + echo -en "\r::: Waiting for package manager to finish" + j=0 + while [ $j -lt 6 ]; do + if [ $j -lt $i ]; then + echo -n "." + else + echo -n " " + fi + ((j=j+1)) + done + sleep 0.5 + if [ $i -lt 6 ]; then + ((i=i+1)) + else + i=0 + fi + done + # Add final newline only if we entered the loop at least once + if [ $j -gt 0 ]; then + echo "" + fi + } + elif command -v rpm &> /dev/null; then # Fedora Family if command -v dnf &> /dev/null; then From a535ca9db4504dc75c57097fec57b123d6b2ce90 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 3 Mar 2017 11:35:44 +0100 Subject: [PATCH 2/3] Some tweaks to the new dpkg lock detector --- automated install/basic-install.sh | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 878ac319..19e23c16 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -90,27 +90,12 @@ if command -v apt-get &> /dev/null; then test_dpkg_lock() { i=0 while fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do - echo -en "\r::: Waiting for package manager to finish" - j=0 - while [ $j -lt 6 ]; do - if [ $j -lt $i ]; then - echo -n "." - else - echo -n " " - fi - ((j=j+1)) - done sleep 0.5 - if [ $i -lt 6 ]; then - ((i=i+1)) - else - i=0 - fi + ((i=i+1)) done - # Add final newline only if we entered the loop at least once - if [ $j -gt 0 ]; then - echo "" - fi + # Always return success, since we only return if there is no + # lock (anymore) + return 0 } elif command -v rpm &> /dev/null; then @@ -764,7 +749,7 @@ update_package_cache() { echo ":::" echo -n "::: Updating local cache of available packages..." - if eval ${UPDATE_PKG_CACHE} &> /dev/null; then + if eval "${UPDATE_PKG_CACHE}" &> /dev/null; then echo " done!" else echo -n "\n!!! ERROR - Unable to update package cache. Please try \"${UPDATE_PKG_CACHE}\"" From 95023569803115e9cf913c0878b018f91c0a7429 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 3 Mar 2017 11:52:49 +0100 Subject: [PATCH 3/3] Move test_dpkg_lock to initial UPDATE_PKG_CACHE. There was unpredictable interference with debconf-apt-progress --- automated install/basic-install.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 19e23c16..57c49233 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -59,8 +59,8 @@ distro_check() { if command -v apt-get &> /dev/null; then #Debian Family ############################################# - PKG_MANAGER="test_dpkg_lock; apt-get" - UPDATE_PKG_CACHE="${PKG_MANAGER} update" + PKG_MANAGER="apt-get" + UPDATE_PKG_CACHE="test_dpkg_lock; ${PKG_MANAGER} update" PKG_INSTALL=(${PKG_MANAGER} --yes --no-install-recommends install) # grep -c will return 1 retVal on 0 matches, block this throwing the set -e with an OR TRUE PKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true" @@ -799,6 +799,7 @@ install_dependent_packages() { fi done if [[ ${#installArray[@]} -gt 0 ]]; then + test_dpkg_lock debconf-apt-progress -- "${PKG_INSTALL[@]}" "${installArray[@]}" return fi