Skip to content

Instantly share code, notes, and snippets.

@JayDoubleu
Created July 24, 2023 12:16
Show Gist options
  • Save JayDoubleu/1a02ea9b7acf2312d8a7ce7b312262c2 to your computer and use it in GitHub Desktop.
Save JayDoubleu/1a02ea9b7acf2312d8a7ce7b312262c2 to your computer and use it in GitHub Desktop.
apt-get lock function
apt_wait() {
# Check if dpkg or apt-get lock is held by another process
locks=(/var/lib/dpkg/lock /var/lib/apt/lists/lock)
for lock in "${locks[@]}"; do
echo "Waiting for lock on $lock..."
while fuser "$lock" >/dev/null 2>&1; do
sleep 1
echo -n "."
done
echo
done
# Check if unattended-upgrades log is locked
if [ -f /var/log/unattended-upgrades/unattended-upgrades.log ]; then
echo "Waiting for lock on unattended-upgrades.log..."
while fuser /var/log/unattended-upgrades/unattended-upgrades.log >/dev/null 2>&1; do
sleep 1
echo -n "."
done
echo
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment