pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/pkg_alternatives Update to 1.2:



details:   https://anonhg.NetBSD.org/pkgsrc/rev/c697bd6363bf
branches:  trunk
changeset: 488403:c697bd6363bf
user:      jmmv <jmmv%pkgsrc.org@localhost>
date:      Sun Jan 30 12:35:22 2005 +0000

description:
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.

diffstat:

 pkgtools/pkg_alternatives/Makefile                  |   9 +-
 pkgtools/pkg_alternatives/PLIST                     |   4 +-
 pkgtools/pkg_alternatives/files/filter.conf         |  19 ++++
 pkgtools/pkg_alternatives/files/pkg_alternatives.8  |  84 ++++++++++++++++++++-
 pkgtools/pkg_alternatives/files/pkg_alternatives.sh |  57 +++++++++++++-
 5 files changed, 164 insertions(+), 9 deletions(-)

diffs (truncated from 304 to 300 lines):

diff -r 76b36eb5c9a3 -r c697bd6363bf pkgtools/pkg_alternatives/Makefile
--- a/pkgtools/pkg_alternatives/Makefile        Sun Jan 30 11:21:49 2005 +0000
+++ b/pkgtools/pkg_alternatives/Makefile        Sun Jan 30 12:35:22 2005 +0000
@@ -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 @@
 
 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+=            ${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 @@
        ${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 @@
        ${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"
diff -r 76b36eb5c9a3 -r c697bd6363bf pkgtools/pkg_alternatives/PLIST
--- a/pkgtools/pkg_alternatives/PLIST   Sun Jan 30 11:21:49 2005 +0000
+++ b/pkgtools/pkg_alternatives/PLIST   Sun Jan 30 12:35:22 2005 +0000
@@ -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
diff -r 76b36eb5c9a3 -r c697bd6363bf pkgtools/pkg_alternatives/files/filter.conf
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/pkg_alternatives/files/filter.conf       Sun Jan 30 12:35:22 2005 +0000
@@ -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 -r 76b36eb5c9a3 -r c697bd6363bf pkgtools/pkg_alternatives/files/pkg_alternatives.8
--- a/pkgtools/pkg_alternatives/files/pkg_alternatives.8        Sun Jan 30 11:21:49 2005 +0000
+++ b/pkgtools/pkg_alternatives/files/pkg_alternatives.8        Sun Jan 30 12:35:22 2005 +0000
@@ -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@localhost>
@@ -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 @@
 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 @@
 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 -r 76b36eb5c9a3 -r c697bd6363bf pkgtools/pkg_alternatives/files/pkg_alternatives.sh
--- a/pkgtools/pkg_alternatives/files/pkg_alternatives.sh       Sun Jan 30 11:21:49 2005 +0000
+++ b/pkgtools/pkg_alternatives/files/pkg_alternatives.sh       Sun Jan 30 12:35:22 2005 +0000
@@ -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@localhost>
@@ -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_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_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 @@
     alt=${1}; shift
     args=${*}
 
+    filter ${wbase} || return
+
     wabs=${Prefix}/${wbase}
     manpage=$(get_manpage ${wbase})
     dbconf=${Db_Dir}/${wbase}
@@ -415,6 +421,49 @@
 
 # -------------------------------------------------------------------------
 
+# 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
+}
+
+# -------------------------------------------------------------------------



Home | Main Index | Thread Index | Old Index