Created
August 6, 2020 05:01
-
-
Save riskiwah/197f19643518b99ab092e9d305409cb9 to your computer and use it in GitHub Desktop.
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
#!/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 | |
#Thanks to this https://askubuntu.com/questions/674976/check-for-and-remove-unused-ppas |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment