Skip to content

Instantly share code, notes, and snippets.

@jikamens
Last active March 5, 2022 17:11
Show Gist options
  • Save jikamens/354d7692f7f07a51e1c0b63c5b0380b7 to your computer and use it in GitHub Desktop.
Save jikamens/354d7692f7f07a51e1c0b63c5b0380b7 to your computer and use it in GitHub Desktop.
#!/usr/bin/bash -e
# Pick the first updatable package that isn't held, and list what was
# updated.
trap "rm /tmp/*.$$" EXIT
cp /var/log/dpkg.log /tmp/dpkg.log.$$
apt-mark showhold | awk -F: '{print $1}' |sort -u > /tmp/held.$$
apt list --upgradable 2>/dev/null | awk -F/ 'NR>1 {print $1}' | sort -u > \
/tmp/upgradable.$$
package="$(comm -23 /tmp/upgradable.$$ /tmp/held.$$)"
if [ ! "$package" ]; then
echo "There are no unheld packages to update." 1>&2
exit 1
fi
apt-get install $package
echo
diff /tmp/dpkg.log.$$ /var/log/dpkg | grep ' upgrade '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment