Created
September 4, 2020 06:53
-
-
Save sfpprxy/8507a49a522fc7ac224e08746c7908e9 to your computer and use it in GitHub Desktop.
auto remove unused PPAs
This file contains 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" | |
# Sanitize entry line by removing stuff between square brackets | |
ENTRY=$(echo "$ENTRY" | sed 's/\[.*\] //') | |
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 |
This file contains 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
chmod +x ./checkPPAs.sh | |
./checkPPAs.sh --delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment