pkg_clean helps to delete Lola packages.

A package is said to be Lola only if:

1. It's unneeded by other packages.
2. It's unwanted by the root user.

If a package that was deleted needed _now_ Lola packages, pkg_clean
will also help deleting them. This is usual when a package uses
libraries unneeded by other packages. Each run request a list of
unneeded packages to pkg_info -t. After each iteration of unwanted
packages of that list, pkg_info -t is called again, and the whole
process starts again. So it's usual to see a run that goes: A-Z, then
M, A, X, B, etc., where each letter is the first letter of a package
name.

pkg_clean asks the user if he/she wants to delete each Lola package.
For example:

--

Delete amsn-0.97.2p1? (l, n, YES): [n]

l:
list package files

n:
don't delete the package, add it to the exception list instead

YES:
delete the package

--

pkg_clean writes its exception list to /etc/pkg_clean.conf. If the
name of the utility is changed, so will change the name of this file.

The exception list can be cleared by calling: pkg_clean -c. This also
starts pkg_clean in interactive mode.

The exception list won't be useful if a package is updated, since it
has the package name, including its version. I haven't added a feature
to be able to treat an updated package just as an non-updated package,
so pkg_clean will ask for each package-1.0, package-1.0p0,
package-1.0p1. This is mainly because packages-specs(7) does not rule
out the possibility that a version from upstream can't match
p[[:digit:]]+$.

--

Please feel free to report any bug, or request any feature. Any
comment of the shell script itself is well received. Even if I could
manage to write it, doesn't hurt to know whenever something could be
written in a better way. Better if any change would me it eligible to
be part of base :P

--

In case you remember, this are the previous versions of the tool:

http://article.gmane.org/gmane.os.openbsd.misc/105917
http://article.gmane.org/gmane.os.openbsd.misc/105964
http://article.gmane.org/gmane.os.openbsd.misc/106012

None of them is now supported.

--

#!/bin/sh

# Copyright 2006, 2007, 2008, 2009 Andris Delfino <adelf...@gmail.com>

# 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.

util_name="${0##*/}"
conf_pathname="/etc/${util_name}.conf"

clean_conf=0
show_usage=0

while getopts ':c' ch; do
        case "${ch}" in
                (c)
                        clean_conf=1
                ;;
                (*)
                        show_usage=1

                        break
                        # NOTREACHED
                ;;
        esac
done

if [ "${show_usage}" -eq 1 ]; then
        printf 'usage: %s [-ch]\n' "${util_name}" >&2

        exit 1
fi

if ! [ `id -u` -eq 0 ]; then
        printf '%s must be run as root\n' "${util_name}" >&2

        exit 2
fi

if ! [ -e "${conf_pathname}" ] || [ "${clean_conf}" -eq 1 ]; then
        printf '' > "${conf_pathname}"
fi

while true; do
        # Note: this does't work flawlessly, some ports are identified by
their version (autoconf, python)
        # packages=`pkg_info -At | cut -d ' ' -f 1 | sed 's/-[^-]\{1,\}$//' |
grep -f "${conf_pathname}" -vx`

        # Note: this doesn't work flawlessly either, since package updates
will render the exception list useless
        packages=`pkg_info -At | cut -d ' ' -f 1 | grep -f "${conf_pathname}" 
-vx`

        if [ -z "${packages}" ]; then
                printf '%s: no unwanted packages to delete\n' "${util_name}" >&2

                break
        fi

        for package in $packages; do
                while true; do
                        printf 'Delete %s? (l, n, YES): [n] ' "${package}" >&2

                        read

                        case "${REPLY}" in
                                (l)
                                        pkg_info -Lq "${package}" | less
                                ;;
                                (n | '')
                                        printf '%s\n' "${package}" >> 
"${conf_pathname}"

                                        break
                                ;;
                                (YES)
                                        pkg_delete -ix "${package}"

                                        break
                                ;;
                                (*)
                                        # NOTREACHED
                                ;;
                        esac
                done
        done
done

exit 0

--

Greetings.



Poscript: Lola is my dog's name. Didn't find any correct term, sorry.

Reply via email to