Skip to content

Instantly share code, notes, and snippets.

@peci1
Created January 7, 2019 12:54
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peci1/2d7859857fdad73ee8443f5ecd5ee5a3 to your computer and use it in GitHub Desktop.
Save peci1/2d7859857fdad73ee8443f5ecd5ee5a3 to your computer and use it in GitHub Desktop.
Revert all packages from non-PPA versions to their latest PPA version.
#!/usr/bin/env bash
# BSD 3-clause license, copyright Martin Pecka @ 2019
# This script outputs a command that will revert all packages from non-PPA versions to their latest PPA version.
# This may be handy i.e. for finding packages for which you installed a newer version from a .deb file, or after
# incompletely removing a PPA.
export LC_ALL=C
command=""
for p in `dpkg-query --showformat='${Package} ' -W`; do
if [[ $(apt-cache policy $p | grep -Pzo "\*\*\* [^\n]+\s+100") ]]; then
versions=$(apt-cache policy $p | tr "\n" "\r" | grep -Po '(?<=\r )[ *]{3} [^\r]+ [0-9]+\r\s+[0-9]+' | sed 's/ [0-9]\+\r\s\+\([0-9]\+\)/ \1/g' | tr "\r" "\n")
installable_versions=$(echo "${versions}" | grep -v " 100$")
version_to_install=$(echo "${installable_versions}" | head -n1 | grep -Po "\s+\K.*(?= [0-9]+$)")
if [[ ! -z "${version_to_install}" ]]; then
echo "${p}=${version_to_install}"
command="${command} ${p}=${version_to_install}"
else
echo "${p}: no PPA version"
fi
fi;
done
echo "To revert packages to their latest PPA version, call the following command as root. Please, carefully go through the list of changes apt-get will present to you!"
echo "apt-get install ${command}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment