Date: Sun, 26 Sep 1999 01:52:36 +0200 (CEST) From: Oliver Fromme <olli@dorifer.heim3.tu-clausthal.de> To: freebsd-hackers@FreeBSD.ORG Subject: Re: A new package fetching utility, pkg_get Message-ID: <199909252352.BAA26437@dorifer.heim3.tu-clausthal.de>
next in thread | raw e-mail | index | archive | help
While we're talking about making package handling easier for
newbies, I'd like to present two simple shell scripts that I
wrote quite some time ago. Yeah, I know I could send-pr this,
but I'm not sure if they're really worth it (if someone thinks
they are, then I'll send-pr them).
The first one is "pkg_ls" and it simply lists packages that
are installed. If no arguments are given, it lists all of
them, otherwise the arguments are (abbreviated) package names
to list. For example, "pkg_ls lynx" will list your installed
lynx package, without you having to know which version it is.
You can do this with pkg_info | grep, but remember we're
talking about making things easier for newbies. ;-)
The second script is called "pkg_rm"; it can be used to delete
packages like pkg_delete, but you can use arguments in the same
way as for pkg_ls above (i.e. "pkg_rm lynx"). Think of it like
pkg_info | grep | pkg_delete.
It might more sense to implement these features in pkg_info and
pkg_delete, resprectively, but I don't have the time to do that
(and these scripts work fine, so I have no incentive to bother
with the C sources of pkg_{info,delete}).
------------------ begin file pkg_ls ------------------
#!/bin/sh -
PL_EXITCODE=0
Usage()
{
echo ""
echo "Usage: `basename $0` [<pkgname ...>]" >&2
echo "Where <pkgname> is one or more package names which may" >&2
echo "be abbreviated." >&2
echo ""
exit 1
}
if OPTS=`getopt 'h?' "$@"`; then
:
else
Usage
fi
set -- $OPTS
while :; do
case "$1" in
--) shift; break;;
-*) Usage;;
*) break;;
esac
shift
done
if [ $# -lt 1 ]; then
set -- .
fi
while [ $# -gt 0 ]; do
PKGS=`pkg_info -aI 2>/dev/null | grep "^$1"`
if [ -z "$PKGS" ]; then
echo "*** No package matching \"$1\" found!" >&2
echo ""
PL_EXITCODE=1
else
echo "$PKGS" >&2
fi
shift
done
exit $PL_EXITCODE
------------------ end file pkg_ls ------------------
------------------ begin file pkg_rm ------------------
#!/bin/sh -
PR_FLAGS=""
PR_EXITCODE=0
Usage()
{
echo ""
echo "Usage: `basename $0` [-fln] <pkgname ...>" >&2
echo "Where <pkgname> is one or more package names which may" >&2
echo "be abbreviated, as long as they're unique. If multiple" >&2
echo "packages match, they are listed (but none is removed)." >&2
echo " -f Force removal, ignoring dependencies." >&2
echo " -l Only list packages (do not remove)." >&2
echo " -n Print what would be done (do not remove)." >&2
echo ""
exit 1
}
if OPTS=`getopt 'lnfh?' "$@"`; then
:
else
Usage
fi
set -- $OPTS
while :; do
case "$1" in
-f) PR_FLAGS="-f";;
-n) PR_NOTREALLY=1;;
-l) PR_LIST=1;;
--) shift; break;;
-*) Usage;;
*) break;;
esac
shift
done
if [ $# -lt 1 ]; then
Usage
fi
while [ $# -gt 0 ]; do
PKGS=`pkg_info -aI 2>/dev/null | grep "^$1"`
if [ -z "$PKGS" ]; then
echo "*** No package matching \"$1\" found!" >&2
echo ""
PR_EXITCODE=1
elif [ `echo "$PKGS" | wc -l` -eq 1 ]; then
PKG=`echo "$PKGS" | cut -f1 -d" "`
if [ "$PR_LIST" = 1 ]; then
echo "$PKGS"
elif [ "$PR_NOTREALLY" = 1 ]; then
echo pkg_delete $PR_FLAGS $PKG
else
echo "Removing $PKGS ..."
pkg_delete $PR_FLAGS $PKG
fi
else
echo "*** Multiple packages match \"$1\":" >&2
echo "$PKGS" >&2
echo ""
PR_EXITCODE=1
fi
shift
done
exit $PR_EXITCODE
------------------ end file pkg_rm ------------------
Regards
Oliver
--
Oliver Fromme, Leibnizstr. 18/61, 38678 Clausthal, Germany
(Info: finger userinfo:olli@dorifer.heim3.tu-clausthal.de)
"In jedem Stück Kohle wartet ein Diamant auf seine Geburt"
(Terry Pratchett)
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199909252352.BAA26437>
