Update to 1.2:
- Add support to explicitly select which wrappers are wanted on a system and which ones are not. This is done through a configuration file that defines a filter with a set of actions and regular expressions (example file included). - Add an examples section to the manual page with solutions for some FAQs.
This commit is contained in:
parent
0b59fa78ea
commit
2f6fe82ae2
5 changed files with 164 additions and 9 deletions
|
@ -1,7 +1,7 @@
|
|||
# $NetBSD: Makefile,v 1.2 2005/01/25 16:27:37 jmmv Exp $
|
||||
# $NetBSD: Makefile,v 1.3 2005/01/30 12:35:22 jmmv Exp $
|
||||
#
|
||||
|
||||
DISTNAME= pkg_alternatives-1.1
|
||||
DISTNAME= pkg_alternatives-1.2
|
||||
CATEGORIES= pkgtools
|
||||
MASTER_SITES= # empty
|
||||
DISTFILES= # empty
|
||||
|
@ -20,6 +20,7 @@ WRKSRC= ${WRKDIR}
|
|||
|
||||
DATADIR= ${PREFIX}/share/pkg_alternatives
|
||||
DBDIR= ${PREFIX}/libdata/pkg_alternatives
|
||||
EGDIR= ${PREFIX}/share/examples/pkg_alternatives
|
||||
|
||||
DEINSTALL_EXTRA_TMPL+= ${.CURDIR}/DEINSTALL
|
||||
INSTALL_EXTRA_TMPL+= ${.CURDIR}/INSTALL
|
||||
|
@ -29,6 +30,7 @@ MAKE_DIRS= ${DBDIR}
|
|||
MAKE_DIRS+= ${PKG_SYSCONFDIR}
|
||||
|
||||
PKG_SYSCONFSUBDIR= pkg_alternatives
|
||||
CONF_FILES= ${EGDIR}/filter.conf ${PKG_SYSCONFDIR}/filter.conf
|
||||
|
||||
SUBST_CLASSES+= vars
|
||||
SUBST_STAGE.vars= do-configure
|
||||
|
@ -49,6 +51,7 @@ do-extract:
|
|||
${CP} ${FILESDIR}/pkg_alternatives.8 ${WRKSRC}
|
||||
${CP} ${FILESDIR}/wrapper.sh ${WRKSRC}
|
||||
${CP} ${FILESDIR}/wrapper.man ${WRKSRC}
|
||||
${CP} ${FILESDIR}/filter.conf ${WRKSRC}
|
||||
|
||||
do-install:
|
||||
${INSTALL_SCRIPT} ${WRKSRC}/pkg_alternatives.sh \
|
||||
|
@ -57,5 +60,7 @@ do-install:
|
|||
${INSTALL_DATA_DIR} ${DATADIR}
|
||||
${INSTALL_DATA} ${WRKSRC}/wrapper.sh ${DATADIR}/
|
||||
${INSTALL_DATA} ${WRKSRC}/wrapper.man ${DATADIR}/
|
||||
${INSTALL_DATA_DIR} ${EGDIR}
|
||||
${INSTALL_DATA} ${WRKSRC}/filter.conf ${EGDIR}/
|
||||
|
||||
.include "../../mk/bsd.pkg.mk"
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
@comment $NetBSD: PLIST,v 1.1.1.1 2005/01/25 13:00:46 jmmv Exp $
|
||||
@comment $NetBSD: PLIST,v 1.2 2005/01/30 12:35:22 jmmv Exp $
|
||||
man/man8/pkg_alternatives.8
|
||||
share/examples/pkg_alternatives/filter.conf
|
||||
share/pkg_alternatives/wrapper.man
|
||||
share/pkg_alternatives/wrapper.sh
|
||||
sbin/pkg_alternatives
|
||||
@dirrm share/pkg_alternatives
|
||||
@dirrm share/examples/pkg_alternatives
|
||||
|
|
19
pkgtools/pkg_alternatives/files/filter.conf
Normal file
19
pkgtools/pkg_alternatives/files/filter.conf
Normal file
|
@ -0,0 +1,19 @@
|
|||
# $NetBSD: filter.conf,v 1.1 2005/01/30 12:35:22 jmmv Exp $
|
||||
#
|
||||
# pkg_alternatives - filter.conf
|
||||
# See pkg_alternatives(8) for information about the format of this file.
|
||||
#
|
||||
# !!! AFTER EDITING THIS FILE YOU MUST RUN 'pkg_alternatives rebuild' !!!
|
||||
#
|
||||
|
||||
# Allow the python wrapper to be created.
|
||||
#accept ^bin/python$
|
||||
|
||||
# Ignore the vi related wrappers, as we want to keep the vi utility from the
|
||||
# base system.
|
||||
#ignore ^bin/ex$
|
||||
#ignore ^bin/vi$
|
||||
#ignore ^bin/view$
|
||||
|
||||
# At last, accept anything else.
|
||||
#accept .*
|
|
@ -1,4 +1,4 @@
|
|||
.\" $NetBSD: pkg_alternatives.8,v 1.4 2005/01/28 12:59:57 wiz Exp $
|
||||
.\" $NetBSD: pkg_alternatives.8,v 1.5 2005/01/30 12:35:22 jmmv Exp $
|
||||
.\"
|
||||
.\" pkg_alternatives - Generic wrappers for programs with similar interfaces
|
||||
.\" Copyright (c) 2005 Julio M. Merino Vidal <jmmv@NetBSD.org>
|
||||
|
@ -27,7 +27,7 @@
|
|||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd January 25, 2005
|
||||
.Dd January 30, 2005
|
||||
.Dt PKG_ALTERNATIVES 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
@ -277,6 +277,34 @@ If there are no more alternatives available, the wrapper is removed.
|
|||
This action should not be used directly; packages providing alternatives
|
||||
will take care to execute it at deinstallation time.
|
||||
.El
|
||||
.Ss Filtering wrappers
|
||||
.Nm
|
||||
lets you choose which wrappers you want on your system and which ones should
|
||||
simply be ignored.
|
||||
This is accomplished by a filter matched against every wrapper, which is
|
||||
defined in the
|
||||
.Pa @CONFDIR@/filter.conf
|
||||
file.
|
||||
.Pp
|
||||
A filter is composed of multiple entries.
|
||||
Each entry contains an action and a regular expression, separated by a
|
||||
.Em single space .
|
||||
The action can be either
|
||||
.Dq accept
|
||||
or
|
||||
.Dq ignore .
|
||||
The former specifies that, if the regular expression is matched against a
|
||||
wrapper name, processing should stop and the wrapper should be created.
|
||||
The later is exactly the opposite: if the name matches the expression, the
|
||||
wrapper is ignored and processing stops.
|
||||
.Pp
|
||||
Please note that, after modifying the filter configuration file, the
|
||||
wrappers database
|
||||
.Em must be rebuilt
|
||||
using the
|
||||
.Dq rebuild
|
||||
action.
|
||||
Otherwise your changes will take no effect.
|
||||
.Sh ENVIRONMENT
|
||||
.Bl -tag -width PKG_DBDIR
|
||||
.It Ev PKG_DBDIR
|
||||
|
@ -290,12 +318,64 @@ Defaults to
|
|||
User-specific configuration directory.
|
||||
.It Pa @CONFDIR@/
|
||||
System-wide configuration directory.
|
||||
.It Pa @CONFDIR@/filter.conf
|
||||
Wrapper filter.
|
||||
.It Pa @DATADIR@/
|
||||
System-wide configuration database.
|
||||
.El
|
||||
.Sh DIAGNOSTICS
|
||||
.Nm
|
||||
exists 0 on success and 1 if an error occurred.
|
||||
.Sh EXAMPLES
|
||||
.Ss Managing wrapper groups
|
||||
The following command tells all Vim related wrappers (which include
|
||||
.Xr ex 1 ,
|
||||
.Xr vi 1
|
||||
and
|
||||
.Xr view 1 )
|
||||
to always prefer Vim in favour of any other program:
|
||||
.Bd -literal -offset indent
|
||||
# pkg_alternatives manual vim
|
||||
.Ed
|
||||
.Pp
|
||||
And the following command reverts the previous change, configuring the
|
||||
affected wrappers to use whichever alternative is available:
|
||||
.Bd -literal -offset indent
|
||||
# pkg_alternatives auto vim
|
||||
.Ed
|
||||
.Ss Managing individual wrappers
|
||||
Suppose that you want to use Sun's Java 1.5 by default for all Java-related
|
||||
wrappers, except for
|
||||
.Xr appletviewer 1 ,
|
||||
because you want to use Kaffe in that case.
|
||||
The following commands do this, by first selecting Sun's Java 1.5 and later
|
||||
overriding the exact wrapper to refer to Kaffe:
|
||||
.Bd -literal -offset indent
|
||||
# pkg_alternatives manual sun-jre15
|
||||
# pkg_alternatives manual sun-jdk15
|
||||
# pkg_alternatives -w manual bin/appletviewer \\
|
||||
/usr/pkg/bin/kaffe-appletviewer
|
||||
.Ed
|
||||
.Ss Applying filters
|
||||
Let us consider a very typical situation: you have just installed a Python
|
||||
interpreter and you want the
|
||||
.Pa bin/python
|
||||
wrapper to be created, but you do not want to pollute your system with any
|
||||
other wrapper (such as those coming from Vim).
|
||||
You can achieve this by using a filter that first accepts the Python wrapper
|
||||
and then ignores everything else.
|
||||
The following lines could be added to
|
||||
.Pa @CONFDIR@/filter.conf
|
||||
to achieve this:
|
||||
.Bd -literal -offset indent
|
||||
accept ^bin/python$
|
||||
ignore .*
|
||||
.Ed
|
||||
.Pp
|
||||
Don't forget to run the following command after doing the above changes:
|
||||
.Bd -literal -offset indent
|
||||
# pkg_alternatives rebuild
|
||||
.Ed
|
||||
.Sh SEE ALSO
|
||||
.Xr pkg_add 1 ,
|
||||
.Xr pkg_delete 1
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!@SH@
|
||||
#
|
||||
# $NetBSD: pkg_alternatives.sh,v 1.3 2005/01/25 16:47:20 jmmv Exp $
|
||||
# $NetBSD: pkg_alternatives.sh,v 1.4 2005/01/30 12:35:22 jmmv Exp $
|
||||
#
|
||||
# pkg_alternatives - Generic wrappers for programs with similar interfaces
|
||||
# Copyright (c) 2005 Julio M. Merino Vidal <jmmv@NetBSD.org>
|
||||
|
@ -34,6 +34,8 @@
|
|||
Conf_Dir=@CONFDIR@@PREFIX@
|
||||
Data_Dir=@DATADIR@
|
||||
Db_Dir=@DBDIR@@PREFIX@
|
||||
Filter=
|
||||
Filter_Read=no
|
||||
Prefix=@PREFIX@
|
||||
Prog_Name=${0##*/}
|
||||
Verbose=yes
|
||||
|
@ -93,6 +95,8 @@ action_auto_wrapper() {
|
|||
action_destroy_package() {
|
||||
validate_args list ${#} -eq 0
|
||||
|
||||
[ -d ${Db_Dir} ] || return 0
|
||||
|
||||
wrappers=$(cd ${Db_Dir} ; find . -type f)
|
||||
|
||||
for w in ${wrappers}; do
|
||||
|
@ -190,13 +194,13 @@ action_manual_wrapper() {
|
|||
|
||||
# action_rebuild_package
|
||||
#
|
||||
# Rebuilds the alternatives database from the package database.
|
||||
# Rebuilds the alternatives database from the package database and also
|
||||
# reinstalls the wrappers (so that filter.conf takes effect).
|
||||
#
|
||||
action_rebuild_package() {
|
||||
validate_args list ${#} -eq 0
|
||||
|
||||
info "removing contents of \`@DBDIR@'"
|
||||
rm -rf @DBDIR@/* 2>/dev/null
|
||||
action_destroy_package
|
||||
info "looking for alternatives in \`${PKG_DBDIR}'"
|
||||
for d in ${PKG_DBDIR}/*; do
|
||||
if [ -f ${d}/+ALTERNATIVES ]; then
|
||||
|
@ -249,6 +253,8 @@ action_register_wrapper() {
|
|||
alt=${1}; shift
|
||||
args=${*}
|
||||
|
||||
filter ${wbase} || return
|
||||
|
||||
wabs=${Prefix}/${wbase}
|
||||
manpage=$(get_manpage ${wbase})
|
||||
dbconf=${Db_Dir}/${wbase}
|
||||
|
@ -415,6 +421,49 @@ err() {
|
|||
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
# filter wrapper
|
||||
#
|
||||
# Reads the configuration filter from CONFDIR/filter.conf and, for the
|
||||
# given wrapper, returns whether it is accepted or ignored.
|
||||
#
|
||||
filter() {
|
||||
[ ! -f @CONFDIR@/filter.conf ] && return 0
|
||||
|
||||
if [ ${Filter_Read} = no ]; then
|
||||
Filter=$(cat @CONFDIR@/filter.conf | grep -v '^#' | tr ' ' '¬')
|
||||
Filter_Read=yes
|
||||
fi
|
||||
|
||||
[ -z "${Filter}" ] && return 0
|
||||
|
||||
for f in ${Filter}; do
|
||||
what=$(echo ${f} | cut -d '¬' -f 1)
|
||||
case ${what} in
|
||||
accept)
|
||||
name=$(echo ${f} | cut -d '¬' -f 2- | tr '¬' ' ')
|
||||
if echo ${1} | grep "${name}" >/dev/null; then
|
||||
info "filter accepts \`${1}'"
|
||||
return 0
|
||||
fi
|
||||
;;
|
||||
ignore)
|
||||
name=$(echo ${f} | cut -d '¬' -f 2- | tr '¬' ' ')
|
||||
if echo ${1} | grep "${name}" >/dev/null; then
|
||||
info "filter ignores \`${1}'"
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
warn "unknown filter type \`${what}'; ignoring"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
# get_my_config
|
||||
#
|
||||
# Prints the configuration directory for the current user. If root, this
|
||||
|
|
Loading…
Reference in a new issue