I changed a couple of things:
a) Now there's a license notice (template from
/usr/src/share/misc/license.template). Nothing important, just to be
sure.
b) All packages which you didn't want to delete are saved to a file,
so you will not have to answer "n" in future runs (to check the full
list of packages just do: "sudo rm /etc/pkg_check.conf").
c) If, in a run, packages were deleted, a new run is suggested,
because maybe there are packages which were *only* used by those
packages.
Again, feedback is useful :)
#!/bin/ksh
# Copyright (c) 2006 AndrC)s Delfino <[EMAIL PROTECTED]>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
function move_cursor_up {
tput up dl 0
}
function check_for_packages {
for package in $( ls "/var/db/pkg" ); {
echo "Checking for $package"
if ! { test -a "/var/db/pkg/$package/+REQUIRED_BY" || {
package_name=$( echo "$package" | sed "s/-[^-]\{1,\}$//" ); grep -qs
"$package_name" "/etc/pkg_check.conf"; } } then
move_cursor_up
echo -n "No package depends on $package, would you like to
delete it? YES/n "
while true; do
read answer
case $answer in
YES )
sudo pkg_delete "$package"
let "deleted_packages = 1"
break
;;
n )
echo "$package_name" >>
"/etc/pkg_check.conf"
break
;;
* )
echo -n 'YES/n '
;;
esac
done
else
move_cursor_up
fi
}
}
while true; do
check_for_packages
if ! let "deleted_packages"; then
break
fi
let "deleted_packages = 0"
echo -n "\nIt's possible that there are packages which were only used
by any of the deleted ones, would you like to run pkg_check again? y/n
"
while true; do
read answer
case $answer in
y )
echo
break
;;
n )
break 2
;;
* )
echo -n 'y/n '
;;
esac
done
done