Created
April 24, 2017 09:24
-
-
Save ubuntuvibes/0e184045d78d9da5fad7f2d6fe88558c to your computer and use it in GitHub Desktop.
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
# source: https://askubuntu.com/a/675109 | |
# Without a parameter, the script lists some infos. | |
# With --delete, the list files will be removed, if no packages are installed. | |
#!/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