Last active
August 29, 2015 14:07
-
-
Save wieczorek1990/cb9f29203c7cb80e1489 to your computer and use it in GitHub Desktop.
apt-get manually installed packages history
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
#!/bin/bash | |
# This will list all manually installed packages without: dependencies, uninstalled packages, packages installed during system installation. | |
unopts() { | |
echo "`cat`" | sed -r 's/ --[^ ]+//g;s/ -[^ ]+//g' | |
} | |
list() { | |
cat '/var/log/apt/history.log' | | |
grep --color=never -v '\-o APT::Status-Fd=4 \-o APT::Keep-Fds::=5 \-o APT::Keep-Fds::=6' | | |
egrep --color=never "Commandline: apt-get.* ${1}" | | |
sed -r "s/Commandline: apt-get//;s/ ${1}//" | | |
unopts | | |
tr ' ' '\n' | | |
sed '/^$/d' | |
} | |
hapt() { | |
tmp=`mktemp -d` | |
installed="${tmp}/installed" | |
deleted="${tmp}/deleted" | |
dpkg="${tmp}/dpkg" | |
list 'install' > "$installed" | |
list '(remove|purge|autoremove)' > "$deleted" | |
dpkg --get-selections | | |
grep -v 'deinstall' | | |
cut -f 1 > "$dpkg" | |
while read package | |
do | |
sed -i "0,/${package}/{//d;}" "$installed" | |
done < "$deleted" | |
while read package | |
do | |
if [ -z "`grep --color=never "^${package}$" "$dpkg"`" ] | |
then | |
sed -i "0,/${package}/{//d;}" "$installed" | |
fi | |
done < "$installed" | |
cat "$installed" | |
rm -r "$tmp" | |
} | |
hapt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment