+DPKG_LOCK="/var/lib/dpkg/lock-frontend"
+
+# Wait for other apt process to finish by checking the dpkg lock file.
+try=0
+while sudo lsof ${DPKG_LOCK} > /dev/null 2>&1 ; do
+ echo "DPKG file locked: ${DPKG_LOCK}."
+ echo " Waiting for another pkg instalaltion process to finish ..."
+ sleep 10
+ if [[ ${try} -gt 60 ]] ; then
+ echo "ERROR: Max number of re-tries reached, exiting..."
+ exit 1
+ fi
+ try=$((try + 1))
+done