Created
July 24, 2023 12:16
-
-
Save JayDoubleu/1a02ea9b7acf2312d8a7ce7b312262c2 to your computer and use it in GitHub Desktop.
apt-get lock function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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