Skip to content

Instantly share code, notes, and snippets.

@farhaven
Created August 30, 2011 15:24
Show Gist options
  • Save farhaven/1181155 to your computer and use it in GitHub Desktop.
Save farhaven/1181155 to your computer and use it in GitHub Desktop.
#!/bin/ksh
T=`mktemp -d`
cd "$T"
pkg_info -m | cut -d' ' -f1 > pkg_manual
if [ "`whoami`" != "root" ]; then
echo "You're not root, so I'll just list the packages that would be removed."
else
echo "These packages will be removed:"
fi
pkg_info -a | cut -d' ' -f1 | grep -v -F -f pkg_manual | while read p; do
d=`pkg_info -R $p | wc -l | tr -d '[[:space:]]'`
if [ "$d" == "0" ]; then
echo "$p" >> pkg_to_delete
else
echo "$p" >> pkg_to_save
fi
done
if [ ! -f pkg_to_delete ]; then
cd ~
rm -r "$T"
echo "No packages to remove."
exit 1
fi
cat pkg_to_delete
if [ "`whoami`" != "root" ]; then
cd ~
rm -r "$T"
exit 0
fi
echo "Press return to remove these packages, ^C to abort."
read
while read p; do
pkg_delete -vi $p
done < pkg_to_delete
cd ~
rm -r "$T"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment