Notes to Self

Alex Sokolsky's Notes on Computers and Programming

apt-get / dpkg

List Packages Installed

apt list --installed

Identify the Package That Owns the File

dpkg -S /bin/ls

Waiting on the apt/dpkg locks

apt-wait.sh:

#!/usr/bin/env bash
#
# Wait for all known dpkg locks
#
function apt_wait () {
  while sudo fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do
    echo "Waiting on /var/lib/dpkg/lock..."
    sleep 1
  done
  while sudo fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1 ; do
    echo "Waiting on /var/lib/dpkg/lock-frontend..."
    sleep 1
  done
  while sudo fuser /var/lib/apt/lists/lock >/dev/null 2>&1 ; do
    echo "Waiting on /var/lib/apt/lists/lock..."
    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
      echo "Waiting on /var/log/unattended-upgrades/unattended-upgrades.log..."
      sleep 1
    done
  fi
  # FIXME: wait for /var/cache/apt/archives/lock
  # /var/cache/apt/archives/lock
}
#
# to avoid "Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 5475 (unattended-upgr)"
#
apt_wait

Specify lock timeout on the command line

APT_GET_OPTIONS="-o DPkg::Lock::Timeout=60"
sudo apt-get "${APT_GET_OPTIONS}" install -y _package_