diff options
Diffstat (limited to 'pkgtools/pkg_alternatives/files')
-rw-r--r-- | pkgtools/pkg_alternatives/files/filter.conf | 19 | ||||
-rw-r--r-- | pkgtools/pkg_alternatives/files/pkg_alternatives.8 | 84 | ||||
-rw-r--r-- | pkgtools/pkg_alternatives/files/pkg_alternatives.sh | 57 |
3 files changed, 154 insertions, 6 deletions
diff --git a/pkgtools/pkg_alternatives/files/filter.conf b/pkgtools/pkg_alternatives/files/filter.conf new file mode 100644 index 00000000000..235abda23ea --- /dev/null +++ b/pkgtools/pkg_alternatives/files/filter.conf @@ -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 .* diff --git a/pkgtools/pkg_alternatives/files/pkg_alternatives.8 b/pkgtools/pkg_alternatives/files/pkg_alternatives.8 index 1b9e8fa0f2c..98ba5b3cfb0 100644 --- a/pkgtools/pkg_alternatives/files/pkg_alternatives.8 +++ b/pkgtools/pkg_alternatives/files/pkg_alternatives.8 @@ -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 diff --git a/pkgtools/pkg_alternatives/files/pkg_alternatives.sh b/pkgtools/pkg_alternatives/files/pkg_alternatives.sh index 1a88257428c..998bccf47fd 100644 --- a/pkgtools/pkg_alternatives/files/pkg_alternatives.sh +++ b/pkgtools/pkg_alternatives/files/pkg_alternatives.sh @@ -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 |