Skip to content

Instantly share code, notes, and snippets.

@pandeykartikey
Created August 4, 2017 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pandeykartikey/6721bfddd27284213ef3e7b1a0ac8da6 to your computer and use it in GitHub Desktop.
Save pandeykartikey/6721bfddd27284213ef3e7b1a0ac8da6 to your computer and use it in GitHub Desktop.
Script to remove unused ppa. (Its a copied script from askubuntu https://askubuntu.com/questions/674976/check-for-and-remove-unused-ppas)
#!/usr/bin/env bash
for f in /etc/apt/sources.list.d/*.list; do
grep -Po "(?<=^deb\s).*?(?=#|$)" "$f" | while read -r ENTRY ; do
echo "ENTRY: $ENTRY"
HOST=$(cut -d/ -f3 <<< "$ENTRY")
if [ "ppa.launchpad.net" = "$HOST" ]; then
USER=$(cut -d/ -f4 <<< "$ENTRY")
PPA=$(cut -d/ -f5 <<< "$ENTRY")
packageCount=$(awk '$1=="Package:" {if (a[$2]++ == 0) {system("dpkg -l "$2)}}' /var/lib/apt/lists/*"$USER"*"$PPA"*Packages 2>/dev/null | awk '/^ii/' | wc -l)
echo "PPA: ppa:$USER/$PPA"
echo "FILENAME: $f"
echo "$packageCount package(s) installed"
if [ "$packageCount" -eq 0 ] && [ "$1" == "--delete" ]; then
sudo rm "$f" && echo "$f deleted"
fi
echo
else
USER=$(cut -d/ -f3 <<< "$ENTRY")
PPA=$(cut -d/ -f4 <<< "$ENTRY")
packageCount=$(awk '$1=="Package:" {if (a[$2]++ == 0) {system("dpkg -l "$2)}}' /var/lib/apt/lists/*"$USER"*Packages 2>/dev/null | awk '/^ii/' | wc -l)
echo "REPOSITORY: $USER/$PPA"
echo "FILENAME: $f"
echo "$packageCount package(s) installed"
if [ "$packageCount" -eq 0 ] && [ "$1" == "--delete" ]; then
sudo rm "$f" && echo "$f deleted"
fi
echo
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment