Skip to content

Instantly share code, notes, and snippets.

@wieczorek1990
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wieczorek1990/cb9f29203c7cb80e1489 to your computer and use it in GitHub Desktop.
Save wieczorek1990/cb9f29203c7cb80e1489 to your computer and use it in GitHub Desktop.
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