Skip to content

Instantly share code, notes, and snippets.

@wieczorek1990
Last active Aug 29, 2015
Embed
What would you like to do?
apt-get manually installed packages history
#!/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