pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc * Separate out the shell registration into a separatel...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/1c067e099cd0
branches:  trunk
changeset: 497520:1c067e099cd0
user:      jlam <jlam%pkgsrc.org@localhost>
date:      Fri Jul 29 18:32:17 2005 +0000

description:
* Separate out the shell registration into a separately unpacked script
  +SHELL.

* Turn PKG_REGISTER_SHELLS into a variable that can be set in the shell
  environment so that admins can make a choice when installing from
  binary packages.

* PKG_SHELL is now a list of paths, and if the path is relative, then it
  is taken to be relative to ${PREFIX}.  Convert packages that set
  PKG_SHELL to take advantage of this new feature by changing the full
  paths to the shells into relative paths.

diffstat:

 mk/install/bsd.pkginstall.mk    |   52 ++++++++--
 mk/install/deinstall            |   17 ++-
 mk/install/header               |   14 ++-
 mk/install/install              |   18 ++-
 mk/install/shell                |  188 ++++++++++++++++++++++++++++++++++++++++
 shells/ast-ksh/Makefile.common  |    4 +-
 shells/bash/Makefile            |    4 +-
 shells/bash2/Makefile           |    4 +-
 shells/es/Makefile              |    4 +-
 shells/esh/Makefile             |    4 +-
 shells/osh/Makefile             |    4 +-
 shells/pdksh/Makefile           |    4 +-
 shells/perlsh/Makefile          |    4 +-
 shells/posh/Makefile            |    4 +-
 shells/rc/Makefile              |    4 +-
 shells/rssh/Makefile            |    4 +-
 shells/scponly/Makefile         |    4 +-
 shells/scsh/Makefile            |    4 +-
 shells/standalone-tcsh/Makefile |    4 +-
 shells/tcsh/Makefile            |    4 +-
 shells/xsh/Makefile             |    4 +-
 shells/zsh/Makefile.common      |    4 +-
 shells/zsh3/Makefile            |    4 +-
 23 files changed, 294 insertions(+), 67 deletions(-)

diffs (truncated from 700 to 300 lines):

diff -r 7d3f4924d474 -r 1c067e099cd0 mk/install/bsd.pkginstall.mk
--- a/mk/install/bsd.pkginstall.mk      Fri Jul 29 17:34:16 2005 +0000
+++ b/mk/install/bsd.pkginstall.mk      Fri Jul 29 18:32:17 2005 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: bsd.pkginstall.mk,v 1.3 2005/07/27 04:55:43 jlam Exp $
+# $NetBSD: bsd.pkginstall.mk,v 1.4 2005/07/29 18:32:18 jlam Exp $
 #
 # This Makefile fragment is included by bsd.pkg.mk to use the common
 # INSTALL/DEINSTALL scripts.  To use this Makefile fragment, simply:
@@ -399,6 +399,42 @@
        ) > ${.TARGET}.tmp;                                             \
        ${MV} -f ${.TARGET}.tmp ${.TARGET}
 
+# PKG_SHELL contains the pathname of the shell that should be added or
+#      removed from the shell database, /etc/shells.  If the pathname
+#      is relative, then it is taken to be relative to ${PREFIX}.
+#
+PKG_SHELL?=            # empty
+
+INSTALL_SHELL_FILE=    ${WRKDIR}/.install-shell
+INSTALL_UNPACK_TMPL+=  ${INSTALL_SHELL_FILE}
+
+${INSTALL_SHELL_FILE}: ../../mk/install/shell
+       ${_PKG_SILENT}${_PKG_DEBUG}(                                    \
+       eval set -- ${PKG_SHELL} ;                                      \
+       ${TEST} $$# -gt 0 || exit 0;                                    \
+       ${ECHO} "# start of install-shell";                             \
+       ${ECHO} "#";                                                    \
+       ${ECHO} "# Generate a +SHELL script that handles shell registration."; \
+       ${ECHO} "#";                                                    \
+       ${ECHO} "case \$${STAGE} in";                                   \
+       ${ECHO} "PRE-INSTALL|UNPACK)";                                  \
+       ${ECHO} "       \$${CAT} > ./+SHELL << 'EOF_SHELL'";            \
+       ${SED} ${FILES_SUBST_SED} ../../mk/install/shell;               \
+       ${ECHO} "";                                                     \
+       eval set -- ${PKG_SHELL} ;                                      \
+       while ${TEST} $$# -gt 0; do                                     \
+               i="$$1"; shift;                                         \
+               ${ECHO} "# SHELL: $$i";                                 \
+       done;                                                           \
+       ${ECHO} "EOF_SHELL";                                            \
+       ${ECHO} "       \$${CHMOD} +x ./+SHELL";                        \
+       ${ECHO} "       ;;";                                            \
+       ${ECHO} "esac";                                                 \
+       ${ECHO} "";                                                     \
+       ${ECHO} "# end of install-shell";                               \
+       ) > ${.TARGET}.tmp;                                             \
+       ${MV} -f ${.TARGET}.tmp ${.TARGET}
+
 # PKG_CREATE_USERGROUP indicates whether the INSTALL script should
 #      automatically add any needed users/groups to the system using
 #      useradd/groupadd.  It is either YES or NO and defaults to YES.
@@ -413,26 +449,20 @@
 #      to ${RCD_SCRIPTS_DIR}.  It is either YES or NO and defaults to
 #      NO.  This variable only takes effect if ${PKG_CONFIG} == "YES".
 #
+# PKG_REGISTER_SHELLS indicates whether to automatically register shells
+#      in /etc/shells.  It is either YES or NO and defaults to YES.
+#
 # These values merely set the defaults for INSTALL/DEINSTALL scripts, but
 # they may be overridden by resetting them in the environment.
 #
 PKG_CREATE_USERGROUP?= YES
 PKG_CONFIG?=           YES
 PKG_RCD_SCRIPTS?=      NO
+PKG_REGISTER_SHELLS?=  YES
 FILES_SUBST+=          PKG_CREATE_USERGROUP=${PKG_CREATE_USERGROUP}
 FILES_SUBST+=          PKG_CONFIG=${PKG_CONFIG}
 FILES_SUBST+=          PKG_RCD_SCRIPTS=${PKG_RCD_SCRIPTS}
-
-# PKG_REGISTER_SHELLS indicates whether to automatically register shells
-#      in /etc/shells.  It is either YES or NO and defaults to YES.
-#
-# PKG_SHELL contains the full pathname of the shell being installed.
-#
-
-PKG_REGISTER_SHELLS?=  YES
-PKG_SHELL?=            # empty
 FILES_SUBST+=          PKG_REGISTER_SHELLS=${PKG_REGISTER_SHELLS}
-FILES_SUBST+=          PKG_SHELL=${PKG_SHELL:Q}
 
 # Substitute for various programs used in the DEINSTALL/INSTALL scripts and
 # in the rc.d scripts.
diff -r 7d3f4924d474 -r 1c067e099cd0 mk/install/deinstall
--- a/mk/install/deinstall      Fri Jul 29 17:34:16 2005 +0000
+++ b/mk/install/deinstall      Fri Jul 29 18:32:17 2005 +0000
@@ -1,7 +1,7 @@
 # -*- sh -*-
 # start of deinstall
 #
-# $NetBSD: deinstall,v 1.34 2005/07/27 16:18:54 jlam Exp $
+# $NetBSD: deinstall,v 1.35 2005/07/29 18:32:18 jlam Exp $
 
 case ${STAGE} in
 VIEW-DEINSTALL)
@@ -20,12 +20,15 @@
                esac
                ;;
        esac
-       if [ -n "${PKG_SHELL}" -a "${PKG_REGISTER_SHELLS}" = "YES" ]; then
-               ${ECHO} "===> Updating /etc/shells"
-               ${CP} /etc/shells /etc/shells.pkgsrc."$$"
-               (${GREP} -v "^${PKG_SHELL}" /etc/shells.pkgsrc."$$" || ${TRUE}) > /etc/shells
-               ${RM} /etc/shells.pkgsrc."$$"
-       fi
+       #
+       # Remove shells from /etc/shells.
+       #
+       case ${_PKG_REGISTER_SHELLS} in
+       YES)    ${TEST} ! -x ./+SHELL ||
+                       ./+SHELL REMOVE ${PKG_METADATA_DIR} ;;
+       esac
+       ${TEST} ! -x ./+SHELL ||
+               ./+SHELL CHECK-REMOVE ${PKG_METADATA_DIR}
        ;;
 
 DEINSTALL)
diff -r 7d3f4924d474 -r 1c067e099cd0 mk/install/header
--- a/mk/install/header Fri Jul 29 17:34:16 2005 +0000
+++ b/mk/install/header Fri Jul 29 18:32:17 2005 +0000
@@ -2,7 +2,7 @@
 #
 # start of header
 #
-# $NetBSD: header,v 1.32 2005/02/02 10:33:01 jlam Exp $
+# $NetBSD: header,v 1.33 2005/07/29 18:32:18 jlam Exp $
 
 PKGNAME=$1
 STAGE=$2
@@ -71,9 +71,6 @@
 *)     PKG_SYSCONFVIEWBASE="${PKG_SYSCONFBASE}/${VIEW}" ;;
 esac
 
-PKG_REGISTER_SHELLS="@PKG_REGISTER_SHELLS@"
-PKG_SHELL="@PKG_SHELL@"
-
 CONF_IGNORE_FILES="*[~#] *.OLD *.orig *,v .pkgsrc */.pkgsrc"
 
 PKG_INSTALLATION_TYPE="@PKG_INSTALLATION_TYPE@"
@@ -105,4 +102,13 @@
        ;;
 esac
 
+case "${PKG_REGISTER_SHELLS:-@PKG_REGISTER_SHELLS@}" in
+[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
+       _PKG_REGISTER_SHELLS=YES
+       ;;
+[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
+       _PKG_REGISTER_SHELLS=NO
+       ;;
+esac
+
 # end of header
diff -r 7d3f4924d474 -r 1c067e099cd0 mk/install/install
--- a/mk/install/install        Fri Jul 29 17:34:16 2005 +0000
+++ b/mk/install/install        Fri Jul 29 18:32:17 2005 +0000
@@ -1,7 +1,7 @@
 # -*- sh -*-
 # start of install
 #
-# $NetBSD: install,v 1.39 2005/07/27 16:18:54 jlam Exp $
+# $NetBSD: install,v 1.40 2005/07/29 18:32:18 jlam Exp $
 
 case ${STAGE} in
 PRE-INSTALL)
@@ -71,14 +71,16 @@
        ;;
 
 VIEW-INSTALL)
-       if [ -n "${PKG_SHELL}" -a "${PKG_REGISTER_SHELLS}" = "YES" ]; then
-               ${ECHO} "===> Updating /etc/shells"
-               ${TOUCH} /etc/shells
-               ${CP} /etc/shells /etc/shells.pkgsrc."$$"
-               (${GREP} -v "^${PKG_SHELL}" /etc/shells.pkgsrc."$$" || ${TRUE}; ${ECHO} ${PKG_SHELL}) > /etc/shells
-               ${RM} /etc/shells.pkgsrc."$$"
-       fi
+       #
+       # Register shells in /etc/shells.
        #
+       case ${_PKG_REGISTER_SHELLS} in
+       YES)    ${TEST} ! -x ./+SHELL ||
+                       ./+SHELL ADD ${PKG_METADATA_DIR} ;;
+       esac
+       ${TEST} ! -x ./+SHELL ||
+               ./+SHELL CHECK-ADD ${PKG_METADATA_DIR}
+
        # If ${PKG_SYSCONFBASE} points outside of ${PREFIX}, then add the
        # package config files to the proper view.
        #
diff -r 7d3f4924d474 -r 1c067e099cd0 mk/install/shell
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/mk/install/shell  Fri Jul 29 18:32:17 2005 +0000
@@ -0,0 +1,188 @@
+#!@SH@
+#
+# $NetBSD: shell,v 1.1 2005/07/29 18:32:18 jlam Exp $
+#
+# +SHELL - shell registration script
+#
+# Usage: ./+SHELL ADD|REMOVE [metadatadir]
+#        ./+SHELL CHECK-ADD|CHECK-REMOVE [metadatadir]
+#
+# This script supports two actions, ADD and REMOVE, that will add or
+# remove shell paths from the shell database in /etc/shells.  The
+# CHECK-ADD action will check whether shell paths provided by the
+# package are missing from the shell database, and print an informative
+# message noting those shell paths.  The CHECK-REMOVE action will check
+# whether shell paths provided by the package are still present in the
+# shell database, and print an informative message noting those shell
+# paths.  The CHECK-ADD and CHECK-REMOVE actions return non-zero if
+# they detect either missing or existing paths, respectively.
+#
+# Lines starting with "# SHELL: " are data read by this script that
+# name the shell paths that should be added or removed from the shell
+# database.  If the path is relative, then it is taken to be relative
+# to ${PKG_PREFIX}.
+#
+#      # SHELL: bin/pdksh
+#
+CAT="@CAT@"
+CP="@CP@"
+ECHO="@ECHO@"
+GREP="@GREP@"
+PWD_CMD="@PWD_CMD@"
+RM="@RM@"
+SED="@SED@"
+SORT="@SORT@"
+TEST="@TEST@"
+TOUCH="@TOUCH@"
+
+SELF=$0
+ACTION=$1
+
+PKG_METADATA_DIR="${2-`${PWD_CMD}`}"
+: ${PKG_PREFIX=@PREFIX@}
+: ${PKGNAME=${PKG_METADATA_DIR##*/}}
+
+exitcode=0
+case $ACTION in
+ADD)
+       ${SED} -n "/^\# SHELL: /{s/^\# SHELL: //;p;}" ${SELF} | ${SORT} -u |
+       { while read shell; do
+               case $shell in
+               /*)     continue ;;
+               *)      shell="${PKG_PREFIX}/$shell" ;;
+               esac
+               ${TEST} -f "$shell" || continue
+
+               shelldb="/etc/shells"
+               if ${TEST} -f "$shelldb" && \
+                  ${GREP} "^$shell" $shelldb >/dev/null; then
+                       :
+               else
+                       case "$printed_header" in
+                       yes)    ;;
+                       *)      printed_header=yes
+                               ${ECHO} "==========================================================================="
+                               ${ECHO} "Adding shells from ${PKGNAME} to $shelldb:"
+                               ${ECHO} ""
+                               ;;
+                       esac
+                       ${ECHO} "       $shell"
+                       ${TOUCH} $shelldb
+                       ${CP} $shelldb $shelldb.pkgsrc."$$"
+                       { ${CAT} $shelldb.pkgsrc."$$"; ${ECHO} "$shell"; } > $shelldb
+                       ${RM} $shelldb.pkgsrc."$$"
+               fi
+       done
+       case "$printed_header" in
+       yes)    ${ECHO} ""
+               ${ECHO} "==========================================================================="
+               ;;
+       esac; }
+       ;;
+
+REMOVE)
+       ${SED} -n "/^\# SHELL: /{s/^\# SHELL: //;p;}" ${SELF} | ${SORT} -u |
+       { while read shell; do
+               case $shell in
+               /*)     continue ;;
+               *)      shell="${PKG_PREFIX}/$shell" ;;
+               esac
+               ${TEST} -f "$shell" || continue
+
+               shelldb="/etc/shells"
+               if ${TEST} -f "$shelldb" && \
+                  ${GREP} "^$shell" $shelldb >/dev/null; then
+                       case "$printed_header" in
+                       yes)    ;;
+                       *)      printed_header=yes
+                               ${ECHO} "==========================================================================="
+                               ${ECHO} "Removing shells from ${PKGNAME} to $shelldb:"
+                               ${ECHO} ""
+                               ;;
+                       esac
+                       ${ECHO} "       $shell"
+                       ${TOUCH} $shelldb
+                       ${CP} $shelldb $shelldb.pkgsrc."$$"
+                       { ${GREP} -v "^$shell" $shelldb.pkgsrc."$$" || ${TRUE}; } > $shelldb
+                       ${RM} $shelldb.pkgsrc."$$"



Home | Main Index | Thread Index | Old Index