diff options
Diffstat (limited to 'mk/install/shell')
-rw-r--r-- | mk/install/shell | 188 |
1 files changed, 188 insertions, 0 deletions
diff --git a/mk/install/shell b/mk/install/shell new file mode 100644 index 00000000000..6991cc2e900 --- /dev/null +++ b/mk/install/shell @@ -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."$$" + fi + done + case "$printed_header" in + yes) ${ECHO} "" + ${ECHO} "===========================================================================" + ;; + esac; } + ;; + +CHECK-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} "The following lines can be added to $shelldb:" + ${ECHO} "" + ;; + esac + ${ECHO} " $shell" + fi + done + case "$printed_header" in + yes) ${ECHO} "" + ${ECHO} "===========================================================================" + exit 1 + ;; + esac; } + ${TEST} $? -eq 0 || exitcode=1 + ;; + +CHECK-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} "The following lines can be removed from $shelldb:" + ${ECHO} "" + ;; + esac + ${ECHO} " $shell" + fi + done + case "$printed_header" in + yes) ${ECHO} "" + ${ECHO} "===========================================================================" + exit 1 + ;; + esac; } + ${TEST} $? -eq 0 || exitcode=1 + ;; + +*) + ${ECHO} "Usage: ./+SHELL ADD|REMOVE [metadatadir]" + ${ECHO} " ./+SHELL CHECK-ADD|CHECK-REMOVE [metadatadir]" + ;; +esac +exit $exitcode |