Skip to content

Instantly share code, notes, and snippets.

@JayDoubleu
Forked from tedivm/apt_wait.sh
Created March 31, 2022 10:34
Show Gist options
  • Save JayDoubleu/6ccf7a2896ea693fb6b8b761abd5757f to your computer and use it in GitHub Desktop.
Save JayDoubleu/6ccf7a2896ea693fb6b8b761abd5757f 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