Skip to content

Instantly share code, notes, and snippets.

@HariSekhon
Forked from tedivm/apt_wait.sh
Created June 7, 2020 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HariSekhon/e76faad3255d6269f34c6ee65bf3a29e to your computer and use it in GitHub Desktop.
Save HariSekhon/e76faad3255d6269f34c6ee65bf3a29e to your computer and use it in GitHub Desktop.
A BASH function to wait for `apt` to finish and release all locks.
#!/usr/bin/env bash
apt_wait () {
while sudo fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do
sleep 1
done
while sudo fuser /var/lib/apt/lists/lock >/dev/null 2>&1 ; do
sleep 1
done
if [ -f /var/log/unattended-upgrades/unattended-upgrades.log ]; then
while sudo fuser /var/log/unattended-upgrades/unattended-upgrades.log >/dev/null 2>&1 ; do
sleep 1
done
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment