summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjlam <jlam@pkgsrc.org>2005-02-02 10:33:01 +0000
committerjlam <jlam@pkgsrc.org>2005-02-02 10:33:01 +0000
commitdb299f9a8bdf4e5edf59914e745ab7b0a17efbac (patch)
treeab08f08dabf71690f616e6ae12223d4151ac4b31
parent8207e021bb7d24a6db35e223748fe1bd7290b290 (diff)
downloadpkgsrc-db299f9a8bdf4e5edf59914e745ab7b0a17efbac.tar.gz
Next round of install script cleanup -- we now create +FILES,
+RCD_SCRIPTS, and +PERMS subscripts to handle copying config files and rc.d scripts, and setting special permissions on files. The +FILES and +RCD_SCRIPTS are basically identical except for different embedded packets of data, and they feature reference-counting for the files in case multiple packages share the same config file. Garbage-collect unused functions and definitions in the install scripts now that the subscripts are self-contained.
-rw-r--r--mk/bsd.pkg.install.mk120
-rw-r--r--mk/install/deinstall137
-rw-r--r--mk/install/files276
-rw-r--r--mk/install/header52
-rw-r--r--mk/install/install219
-rw-r--r--mk/install/perms78
6 files changed, 533 insertions, 349 deletions
diff --git a/mk/bsd.pkg.install.mk b/mk/bsd.pkg.install.mk
index 5770f5ec164..cc97d040315 100644
--- a/mk/bsd.pkg.install.mk
+++ b/mk/bsd.pkg.install.mk
@@ -1,4 +1,4 @@
-# $NetBSD: bsd.pkg.install.mk,v 1.78 2005/01/28 19:06:07 jlam Exp $
+# $NetBSD: bsd.pkg.install.mk,v 1.79 2005/02/02 10:33:01 jlam Exp $
#
# This Makefile fragment is included by bsd.pkg.mk to use the common
# INSTALL/DEINSTALL scripts. To use this Makefile fragment, simply:
@@ -173,7 +173,37 @@ ${INSTALL_USERGROUP_FILE}: ../../mk/install/usergroup
#
SPECIAL_PERMS?= # empty
SETUID_ROOT_PERMS?= ${ROOT_USER} ${ROOT_GROUP} 4711
-FILES_SUBST+= SPECIAL_PERMS=${SPECIAL_PERMS:Q}
+
+INSTALL_PERMS_FILE= ${WRKDIR}/.install-perms
+INSTALL_UNPACK_TMPL+= ${INSTALL_PERMS_FILE}
+
+${INSTALL_PERMS_FILE}: ../../mk/install/perms
+ ${_PKG_SILENT}${_PKG_DEBUG}{ \
+ ${ECHO} "# start of install-perms"; \
+ ${ECHO} "#"; \
+ ${ECHO} "# Generate a +PERMS script that sets the special"; \
+ ${ECHO} "# permissions on files and directories used by the"; \
+ ${ECHO} "# package."; \
+ ${ECHO} "#"; \
+ ${ECHO} "case \$${STAGE} in"; \
+ ${ECHO} "PRE-INSTALL)"; \
+ ${ECHO} " \$${CAT} > ./+PERMS << 'EOF_PERMS'"; \
+ ${SED} ${FILES_SUBST_SED} ../../mk/install/perms; \
+ ${ECHO} ""; \
+ eval set -- ${SPECIAL_PERMS} ; \
+ while ${TEST} $$# -gt 0; do \
+ file="$$1"; owner="$$2"; group="$$3"; mode="$$4"; \
+ shift; shift; shift; shift; \
+ ${ECHO} "# PERMS: $$file $$mode $$owner $$group"; \
+ done; \
+ ${ECHO} "EOF_PERMS"; \
+ ${ECHO} " \$${CHMOD} +x ./+PERMS"; \
+ ${ECHO} " ;;"; \
+ ${ECHO} "esac"; \
+ ${ECHO} ""; \
+ ${ECHO} "# end of install-perms"; \
+ } > ${.TARGET}.tmp; \
+ ${MV} -f ${.TARGET}.tmp ${.TARGET}
# CONF_FILES are pairs of example and true config files, used much like
# MLINKS in the base system. At post-install time, if the true config
@@ -211,20 +241,86 @@ PKG_FAIL_REASON+= \
"bsd.pkg.install.mk: RCD_SCRIPTS_EXAMPLEDIR can't be an absolute path."
.endif
RCD_SCRIPTS_SHELL?= ${SH}
-FILES_SUBST+= CONF_FILES=${CONF_FILES:Q}
-FILES_SUBST+= CONF_FILES_MODE=${CONF_FILES_MODE}
-FILES_SUBST+= CONF_FILES_PERMS=${CONF_FILES_PERMS:Q}
-FILES_SUBST+= SUPPORT_FILES=${SUPPORT_FILES:Q}
-FILES_SUBST+= SUPPORT_FILES_MODE=${SUPPORT_FILES_MODE}
-FILES_SUBST+= SUPPORT_FILES_PERMS=${SUPPORT_FILES_PERMS:Q}
-FILES_SUBST+= RCD_SCRIPTS=${RCD_SCRIPTS:Q}
-FILES_SUBST+= RCD_SCRIPTS_MODE=${RCD_SCRIPTS_MODE}
-FILES_SUBST+= RCD_SCRIPTS_DIR=${RCD_SCRIPTS_DIR}
-FILES_SUBST+= RCD_SCRIPTS_EXAMPLEDIR=${RCD_SCRIPTS_EXAMPLEDIR}
FILES_SUBST+= RCD_SCRIPTS_SHELL=${RCD_SCRIPTS_SHELL}
MESSAGE_SUBST+= RCD_SCRIPTS_DIR=${RCD_SCRIPTS_DIR}
MESSAGE_SUBST+= RCD_SCRIPTS_EXAMPLEDIR=${RCD_SCRIPTS_EXAMPLEDIR}
+INSTALL_FILES_FILE= ${WRKDIR}/.install-files
+INSTALL_UNPACK_TMPL+= ${INSTALL_FILES_FILE}
+
+${INSTALL_FILES_FILE}: ../../mk/install/files
+ ${_PKG_SILENT}${_PKG_DEBUG}{ \
+ ${ECHO} "# start of install-files"; \
+ ${ECHO} "#"; \
+ ${ECHO} "# Generate a +FILES script that reference counts config"; \
+ ${ECHO} "# files that are required for the proper functioning"; \
+ ${ECHO} "# of the package."; \
+ ${ECHO} "#"; \
+ ${ECHO} "case \$${STAGE} in"; \
+ ${ECHO} "PRE-INSTALL)"; \
+ ${ECHO} " \$${CAT} > ./+FILES << 'EOF_FILES'"; \
+ ${SED} ${FILES_SUBST_SED} ../../mk/install/files; \
+ ${ECHO} ""; \
+ eval set -- ${CONF_FILES} ; \
+ while ${TEST} $$# -gt 0; do \
+ egfile="$$1"; file="$$2"; \
+ shift; shift; \
+ ${ECHO} "# FILE: $$file c $$egfile ${CONF_FILES_MODE}"; \
+ done; \
+ eval set -- ${SUPPORT_FILES} ; \
+ while ${TEST} $$# -gt 0; do \
+ egfile="$$1"; file="$$2"; \
+ shift; shift; \
+ ${ECHO} "# FILE: $$file c $$egfile ${SUPPORT_FILES_MODE}"; \
+ done; \
+ eval set -- ${CONF_FILES_PERMS} ${SUPPORT_FILES_PERMS} ; \
+ while ${TEST} $$# -gt 0; do \
+ egfile="$$1"; file="$$2"; \
+ owner="$$3"; group="$$4"; mode="$$5"; \
+ shift; shift; shift; shift; shift; \
+ ${ECHO} "# FILE: $$file c $$egfile $$mode $$owner $$group"; \
+ done; \
+ ${ECHO} "EOF_FILES"; \
+ ${ECHO} " \$${CHMOD} +x ./+FILES"; \
+ ${ECHO} " ;;"; \
+ ${ECHO} "esac"; \
+ ${ECHO} ""; \
+ ${ECHO} "# end of install-files"; \
+ } > ${.TARGET}.tmp; \
+ ${MV} -f ${.TARGET}.tmp ${.TARGET}
+
+INSTALL_RCD_SCRIPTS_FILE= ${WRKDIR}/.install-rcd-scripts
+INSTALL_UNPACK_TMPL+= ${INSTALL_RCD_SCRIPTS_FILE}
+
+${INSTALL_RCD_SCRIPTS_FILE}: ../../mk/install/files
+ ${_PKG_SILENT}${_PKG_DEBUG}{ \
+ ${ECHO} "# start of install-rcd-scripts"; \
+ ${ECHO} "#"; \
+ ${ECHO} "# Generate a +RCD_SCRIPTS script that reference counts config"; \
+ ${ECHO} "# files that are required for the proper functioning"; \
+ ${ECHO} "# of the package."; \
+ ${ECHO} "#"; \
+ ${ECHO} "case \$${STAGE} in"; \
+ ${ECHO} "PRE-INSTALL)"; \
+ ${ECHO} " \$${CAT} > ./+RCD_SCRIPTS << 'EOF_RCD_SCRIPTS'"; \
+ ${SED} ${FILES_SUBST_SED} ../../mk/install/files; \
+ ${ECHO} ""; \
+ eval set -- ${RCD_SCRIPTS} ; \
+ while ${TEST} $$# -gt 0; do \
+ script="$$1"; shift; \
+ file="${RCD_SCRIPTS_DIR}/$$script"; \
+ egfile="${PREFIX}/${RCD_SCRIPTS_EXAMPLEDIR}/$$script"; \
+ ${ECHO} "# FILE: $$file c $$egfile ${RCD_SCRIPTS_MODE}"; \
+ done; \
+ ${ECHO} "EOF_RCD_SCRIPTS"; \
+ ${ECHO} " \$${CHMOD} +x ./+RCD_SCRIPTS"; \
+ ${ECHO} " ;;"; \
+ ${ECHO} "esac"; \
+ ${ECHO} ""; \
+ ${ECHO} "# end of install-rcd-scripts"; \
+ } > ${.TARGET}.tmp; \
+ ${MV} -f ${.TARGET}.tmp ${.TARGET}
+
# OWN_DIRS contains a list of directories for this package that should be
# created and should attempt to be destroyed by the INSTALL/DEINSTALL
# scripts. MAKE_DIRS is used the same way, but the package admin
diff --git a/mk/install/deinstall b/mk/install/deinstall
index ebef22dd6de..1c9c4bd626d 100644
--- a/mk/install/deinstall
+++ b/mk/install/deinstall
@@ -1,50 +1,24 @@
# start of deinstall
#
-# $NetBSD: deinstall,v 1.31 2005/01/28 07:37:55 jlam Exp $
-
-eval set -- ${CONF_FILES} ${SUPPORT_FILES}
-while [ $# -gt 0 ]; do
- samplefile="$1"; file="$2"
- shift; shift
- ALL_FILES="${ALL_FILES} \"${samplefile}\" \"${file}\""
- VIEW_FILES="${VIEW_FILES} \"${file}\""
-done
-if [ "${_PKG_RCD_SCRIPTS}" = "YES" ]; then
- eval set -- ${RCD_SCRIPTS}
- for script; do
- samplefile="${PKG_PREFIX}/${RCD_SCRIPTS_EXAMPLEDIR}/${script}"
- file="${RCD_SCRIPTS_DIR}/${script}"
- shift
- ALL_FILES="${ALL_FILES} \"${samplefile}\" \"${file}\""
- done
-fi
-eval set -- ${CONF_FILES_PERMS} ${SUPPORT_FILES_PERMS}
-while [ $# -gt 0 ]; do
- samplefile="$1"; file="$2"; owner="$3"; group="$4"; mode="$5"
- shift; shift; shift; shift; shift
- ALL_FILES="${ALL_FILES} \"${samplefile}\" \"${file}\""
- VIEW_FILES="${VIEW_FILES} \"${file}\""
-done
+# $NetBSD: deinstall,v 1.32 2005/02/02 10:33:01 jlam Exp $
case ${STAGE} in
VIEW-DEINSTALL)
- if [ "${_PKG_CONFIG}" = "YES" -a -n "${VIEW_FILES}" ]; then
- if [ -n "${PKG_SYSCONFDEPOTBASE}" ]; then
+ case ${_PKG_CONFIG} in
+ YES)
+ case ${PKG_SYSCONFDEPOTBASE} in
+ "")
+ ${TEST} -x ./+FILES &&
+ ./+FILES VIEW-REMOVE ${PREFIX} ${PKG_PREFIX}
+ ;;
+ *)
${SETENV} PLIST_IGNORE_FILES="${CONF_IGNORE_FILES}" \
${LINKFARM} -D -t ${PKG_SYSCONFVIEWBASE} -d ${PKG_SYSCONFDEPOTBASE} ${PKGNAME}
${RMDIR} -p ${PKG_SYSCONFVIEWBASE} 2>/dev/null || ${TRUE}
- else
- eval set -- ${VIEW_FILES}
- for file; do
- link=`${ECHO} ${file} | ${SED} "s,^${PREFIX}/,${PKG_PREFIX}/,"`
- dir=`${DIRNAME} ${link}`
- if [ -h "${link}" ]; then
- ${RM} -f ${link}
- ${RMDIR} -p ${dir} 2>/dev/null || ${TRUE}
- fi
- done
- fi
- fi
+ ;;
+ esac
+ ;;
+ esac
if [ -n "${PKG_SHELL}" -a "${PKG_REGISTER_SHELLS}" = "YES" ]; then
${ECHO} "===> Updating /etc/shells"
${CP} /etc/shells /etc/shells.pkgsrc."$$"
@@ -57,34 +31,17 @@ DEINSTALL)
# Remove configuration files if they don't differ from the default
# config file.
#
- if [ "${_PKG_CONFIG}" = "YES" ]; then
- eval set -- ${ALL_FILES}
- while [ $# -gt 0 ]; do
- samplefile="$1"; file="$2"
- shift; shift
-
- if [ ! "${file}" -ef "${samplefile}" -a \
- -f "${file}" -a -f "${samplefile}" ]; then
- if ${CMP} -s "${file}" "${samplefile}"; then
- ${RM} -f "${file}"
- fi
- fi
- done
- fi
+ case ${_PKG_CONFIG} in
+ YES) ${TEST} -x ./+FILES &&
+ ./+FILES REMOVE ${PKG_METADATA_DIR} ;;
+ esac
+ case ${_PKG_CONFIG}${_PKG_RCD_SCRIPTS} in
+ YESYES) ${TEST} -x ./+RCD_SCRIPTS &&
+ ./+RCD_SCRIPTS REMOVE ${PKG_METADATA_DIR} ;;
+ esac
;;
POST-DEINSTALL)
- modified_files=''
- eval set -- ${ALL_FILES}
- while [ $# -gt 0 ]; do
- samplefile="$1"; file="$2"
- shift; shift
-
- if [ -f "${file}" ]; then
- modified_files="${modified_files} \"${file}\""
- fi
- done
-
if [ "${PKG_INSTALLATION_TYPE}" = "pkgviews" -a \
"${_PKG_CONFIG}" = "YES" -a -n "${CONF_DEPENDS}" ]; then
if [ -h ${PKG_SYSCONFDIR} ]; then
@@ -92,44 +49,28 @@ POST-DEINSTALL)
fi
${RMDIR} -p `${DIRNAME} ${PKG_SYSCONFDIR}` 2>/dev/null || ${TRUE}
fi
-
+ #
+ # Remove empty directories and unused users/groups.
+ #
case ${_PKG_CONFIG} in
- YES) ${TEST} -x ./+DIRS && ./+DIRS REMOVE ${PKG_METADATA_DIR} ;;
+ YES) ${TEST} -x ./+DIRS &&
+ ./+DIRS REMOVE ${PKG_METADATA_DIR} ;;
esac
case ${_PKG_CREATE_USERGROUP} in
- YES) ${TEST} -x ./+USERGROUP && ./+USERGROUP REMOVE ${PKG_METADATA_DIR} ;;
+ YES) ${TEST} -x ./+USERGROUP &&
+ ./+USERGROUP REMOVE ${PKG_METADATA_DIR} ;;
esac
-
- if [ -n "${modified_files}" ]; then
- ${CAT} << EOF
-===========================================================================
-If you won't be using ${PKGNAME} any longer, you may want to remove
-EOF
- if [ -n "${modified_files}" ]; then
- ${CAT} << EOF
-
- * the following files:
-
-EOF
- eval set -- ${modified_files}
- for file; do
- ${ECHO} " ${file}"
- done
- fi
- if [ -n "${RCD_SCRIPTS}" ]; then
- ${CAT} << EOF
-
-You may also want to remove any settings in rc.conf that you may have
-made in order to use ${PKGNAME}.
-EOF
- fi
- ${CAT} << EOF
-===========================================================================
-EOF
- fi
-
- ${TEST} -x ./+USERGROUP && ./+USERGROUP CHECK-REMOVE ${PKG_METADATA_DIR}
- ${TEST} -x ./+DIRS && ./+DIRS CHECK-REMOVE ${PKG_METADATA_DIR}
+ #
+ # Check for any existing bits after we're finished de-installing.
+ #
+ ${TEST} -x ./+USERGROUP &&
+ ./+USERGROUP CHECK-REMOVE ${PKG_METADATA_DIR}
+ ${TEST} -x ./+FILES &&
+ ./+FILES CHECK-REMOVE ${PKG_METADATA_DIR}
+ ${TEST} -x ./+RCD_SCRIPTS &&
+ ./+RCD_SCRIPTS CHECK-REMOVE ${PKG_METADATA_DIR}
+ ${TEST} -x ./+DIRS &&
+ ./+DIRS CHECK-REMOVE ${PKG_METADATA_DIR}
;;
esac
diff --git a/mk/install/files b/mk/install/files
new file mode 100644
index 00000000000..548f1ed84b5
--- /dev/null
+++ b/mk/install/files
@@ -0,0 +1,276 @@
+#!@SH@
+#
+# $NetBSD: files,v 1.1 2005/02/02 10:33:01 jlam Exp $
+#
+# +FILES - reference-counted configuration file management script
+#
+# Usage: ./+FILES ADD|REMOVE [metadatadir]
+# ./+FILES VIEW-REMOVE depotdir viewdir
+# ./+FILES CHECK-ADD|CHECK-REMOVE [metadatadir]
+#
+# This script supports two actions, ADD and REMOVE, that will add or
+# remove the configuration files needed by the package associated with
+# <metadatadir>. The CHECK-ADD action will check whether any files
+# needed by the package are missing, and print an informative message
+# noting those files. The CHECK-REMOVE action will check whether
+# any files needed by the package still exist, and print an informative
+# message noting those files. The CHECK-ADD and CHECK-REMOVE actions
+# return non-zero if they detect either missing or existing files,
+# respectively. The VIEW-REMOVE action will remove from <viewdir> the
+# links to the configuration files in <depotdir>.
+#
+# Lines starting with "# FILE: " are data read by this script that
+# name the files that this package requires to exist to function
+# correctly, along with the locations of the example files, e.g.
+#
+# # FILE: /etc/bar.conf c /example/bar.conf
+# # FILE: /etc/baz/conf c /example/baz.conf 0600 foo-user foo-group
+#
+# The second field in each FILE entry is a set of flags with the following
+# meaning:
+#
+# c file is copied into place
+#
+CAT="@CAT@"
+CP="@CP@"
+CHGRP="@CHGRP@"
+CHMOD="@CHMOD@"
+CHOWN="@CHOWN@"
+CMP="@CMP@"
+ECHO="@ECHO@"
+GREP="@GREP@"
+MKDIR="@MKDIR@"
+MV="@MV@"
+PWD_CMD="@PWD_CMD@"
+RM="@RM@"
+RMDIR="@RMDIR@"
+SED="@SED@"
+SORT="@SORT@"
+TEST="@TEST@"
+TRUE="@TRUE@"
+
+SELF=$0
+ACTION=$1
+
+case ${ACTION} in
+VIEW-REMOVE)
+ DEPOTDIR="$2"
+ VIEWDIR="$3"
+ ${TEST} -n "${DEPOTDIR}" -a -n "${VIEWDIR}" || exit 0
+ ;;
+*)
+ PKG_METADATA_DIR="${2-`${PWD_CMD}`}"
+ : ${PKGNAME=${PKG_METADATA_DIR##*/}}
+ : ${PKG_DBDIR=${PKG_METADATA_DIR%/*}}
+ : ${PKG_REFCOUNT_DBDIR=${PKG_DBDIR}.refcount}
+ PKG_REFCOUNT_FILES_DBDIR="${PKG_REFCOUNT_DBDIR}/files"
+ ;;
+esac
+
+exitcode=0
+case $ACTION in
+ADD)
+ ${SED} -n "/^\# FILE: /{s/^\# FILE: //;p;}" ${SELF} | ${SORT} -u |
+ { while read file f_flags f_eg f_mode f_user f_group; do
+ case $file in
+ ""|[!/]*) continue ;;
+ esac
+ case $f_flags in
+ *c*) ;;
+ *) continue ;;
+ esac
+
+ shadow_dir="${PKG_REFCOUNT_FILES_DBDIR}$file"
+ perms="$shadow_dir/+PERMISSIONS"
+ preexist="$shadow_dir/+PREEXISTING"
+ token="$shadow_dir/${PKGNAME}"
+ if ${TEST} ! -d "$shadow_dir"; then
+ ${MKDIR} $shadow_dir
+ ${TEST} -f "$file" &&
+ ${ECHO} "${PKGNAME}" > $preexist
+ fi
+ if ${TEST} -f "$token" && \
+ ${GREP} "^${PKG_METADATA_DIR}$" $token >/dev/null; then
+ :
+ else
+ ${ECHO} "${PKG_METADATA_DIR}" >> $token
+ fi
+
+ case $f_mode$f_user$f_group in
+ "") ;;
+ *) ${ECHO} "$f_mode $f_user $f_group" > $perms ;;
+ esac
+ if ${TEST} ! -f "$file" -a ! -f "$f_eg"; then
+ :
+ else
+ case "$printed_header" in
+ yes) ;;
+ *) printed_header=yes
+ ${ECHO} "==========================================================================="
+ ${ECHO} "Installing files needed by ${PKGNAME}:"
+ ;;
+ esac
+ if ${TEST} -f "$file"; then
+ ${ECHO} ""
+ ${ECHO} " $file already exists."
+ elif ${TEST} -f "$f_eg"; then
+ ${ECHO} ""
+ ${ECHO} " $file"
+ ${ECHO} " [$f_eg]"
+ ${CP} $f_eg $file
+ case $f_mode in
+ "") ;;
+ *) ${CHMOD} $f_mode $file ;;
+ esac
+ case $f_user in
+ "") ;;
+ *) ${CHOWN} $f_user $file ;;
+ esac
+ case $f_group in
+ "") ;;
+ *) ${CHGRP} $f_group $file ;;
+ esac
+ fi
+ fi
+ done
+ case "$printed_header" in
+ yes) ${ECHO} ""
+ ${ECHO} "==========================================================================="
+ ;;
+ esac; }
+ ;;
+
+REMOVE)
+ ${SED} -n "/^\# FILE: /{s/^\# FILE: //;p;}" ${SELF} | ${SORT} -ru |
+ while read file f_flags f_eg f_mode f_user f_group; do
+ case $file in
+ ""|[!/]*) continue ;;
+ esac
+ case $f_flags in
+ *c*) ;;
+ *) continue ;;
+ esac
+ shadow_dir="${PKG_REFCOUNT_FILES_DBDIR}$file"
+ perms="$shadow_dir/+PERMISSIONS"
+ preexist="$shadow_dir/+PREEXISTING"
+ token="$shadow_dir/${PKGNAME}"
+ tokentmp="$token.tmp.$$"
+ if ${TEST} -f "$token" && \
+ ${GREP} "^${PKG_METADATA_DIR}$" $token >/dev/null; then
+ ${CAT} "$token" | ${GREP} -v "^${PKG_METADATA_DIR}$" > $tokentmp
+ case `${CAT} $tokentmp | ${SED} -n "$="` in
+ "")
+ if ${TEST} -f "$preexist"; then
+ :
+ elif ${TEST} -f "$file" -a -f "$f_eg" -a \
+ ! "$file" -ef "$f_eg" && \
+ ${CMP} -s "$file" "$f_eg"; then
+ ${RM} -f "$file"
+ fi
+ ${RM} -f $perms $preexist $token $token.tmp.*
+ ${RMDIR} -p $shadow_dir 2>/dev/null || ${TRUE}
+ ;;
+ *)
+ ${MV} -f $tokentmp $token
+ ;;
+ esac
+ fi
+ done
+ ;;
+
+VIEW-REMOVE)
+ ${SED} -n "/^\# FILE: /{s/^\# FILE: //;p;}" ${SELF} | ${SORT} -ru |
+ while read file f_flags f_eg f_mode f_user f_group; do
+ case $file in
+ ${DEPOTDIR}/*) ;;
+ *) continue ;;
+ esac
+ link="${VIEWDIR}/${file#${DEPOTDIR}/}"
+ dir="${link%[^/]*}"
+ if ${TEST} -h "$link"; then
+ ${RM} -f $link
+ ${RMDIR} -p $dir 2>/dev/null || ${TRUE}
+ fi
+ done
+ ;;
+
+CHECK-ADD)
+ ${SED} -n "/^\# FILE: /{s/^\# FILE: //;p;}" ${SELF} | ${SORT} -ru |
+ { while read file f_flags f_eg f_mode f_user f_group; do
+ case $file in
+ ""|[!/]*) continue ;;
+ *) ${TEST} -f "$file" && continue ;;
+ esac
+ case $f_flags in
+ *c*) ;;
+ *) continue ;;
+ esac
+ case "$printed_header" in
+ yes) ;;
+ *) printed_header=yes
+ ${ECHO} "==========================================================================="
+ ${ECHO} "The following files should be created for ${PKGNAME}:"
+ ;;
+ esac
+ ${ECHO} ""
+ case $f_mode/$f_user/$f_group in
+ //)
+ ${ECHO} " $file"
+ ;;
+ [!/]*//)
+ ${ECHO} " $file (m=$f_mode)"
+ ;;
+ [!/]*/[!/]*/)
+ ${ECHO} " $file (o=$f_user, m=$f_mode)"
+ ;;
+ [!/]*/[!/]*/[!/]*)
+ ${ECHO} " $file (o=$f_user, g=$f_group, m=$f_mode)"
+ ;;
+ esac
+ ${TEST} -f "$f_eg" && ${ECHO} " [$f_eg]"
+ done
+ case "$printed_header" in
+ yes) ${ECHO} ""
+ ${ECHO} "==========================================================================="
+ exit 1
+ ;;
+ esac; }
+ ${TEST} $? -eq 0 || exitcode=1
+ ;;
+
+CHECK-REMOVE)
+ ${SED} -n "/^\# FILE: /{s/^\# FILE: //;p;}" ${SELF} | ${SORT} -ru |
+ { while read file f_flags f_eg f_mode f_user f_group; do
+ case $file in
+ ""|[!/]*) continue ;;
+ *) ${TEST} -f "$file" || continue ;;
+ esac
+ shadow_dir="${PKG_REFCOUNT_FILES_DBDIR}$file"
+ ${TEST} -d "$shadow_dir" && continue # refcount isn't zero
+ case "$printed_header" in
+ yes) ;;
+ *) printed_header=yes
+ ${ECHO} "==========================================================================="
+ ${ECHO} "The following file are no longer being used by ${PKGNAME},"
+ ${ECHO} "and they can be removed if no other packages are using them:"
+ ${ECHO} ""
+ ;;
+ esac
+ ${ECHO} " $file"
+ done
+ case "$printed_header" in
+ yes) ${ECHO} ""
+ ${ECHO} "==========================================================================="
+ exit 1
+ ;;
+ esac; }
+ ${TEST} $? -eq 0 || exitcode=1
+ ;;
+
+*)
+ ${ECHO} "Usage: ./+FILES ADD|REMOVE [metadatadir]"
+ ${ECHO} " ./+FILES VIEW-REMOVE depotdir viewdir"
+ ${ECHO} " ./+FILES CHECK-ADD|CHECK-REMOVE [metadatadir]"
+ ;;
+esac
+exit $exitcode
diff --git a/mk/install/header b/mk/install/header
index d2812955ee0..12cf1600253 100644
--- a/mk/install/header
+++ b/mk/install/header
@@ -2,7 +2,7 @@
#
# start of header
#
-# $NetBSD: header,v 1.31 2005/01/31 18:41:08 jlam Exp $
+# $NetBSD: header,v 1.32 2005/02/02 10:33:01 jlam Exp $
PKGNAME=$1
STAGE=$2
@@ -60,17 +60,6 @@ ${LOCALBASE}/*) VIEW="${PKG_PREFIX#${LOCALBASE}/}" ;;
*) VIEW="" ;;
esac
-SPECIAL_PERMS="@SPECIAL_PERMS@"
-
-CONF_FILES="@CONF_FILES@"
-CONF_FILES_MODE="@CONF_FILES_MODE@"
-CONF_FILES_PERMS="@CONF_FILES_PERMS@"
-SUPPORT_FILES="@SUPPORT_FILES@"
-SUPPORT_FILES_PERMS="@SUPPORT_FILES_PERMS@"
-RCD_SCRIPTS="@RCD_SCRIPTS@"
-RCD_SCRIPTS_DIR="@RCD_SCRIPTS_DIR@"
-RCD_SCRIPTS_EXAMPLEDIR="@RCD_SCRIPTS_EXAMPLEDIR@"
-
PKG_SYSCONFBASE="@PKG_SYSCONFBASE@"
PKG_SYSCONFDEPOTBASE="@PKG_SYSCONFDEPOTBASE@"
PKG_SYSCONFBASEDIR="@PKG_SYSCONFBASEDIR@"
@@ -85,9 +74,6 @@ esac
PKG_REGISTER_SHELLS="@PKG_REGISTER_SHELLS@"
PKG_SHELL="@PKG_SHELL@"
-ALL_FILES=
-VIEW_FILES=
-
CONF_IGNORE_FILES="*[~#] *.OLD *.orig *,v .pkgsrc */.pkgsrc"
PKG_INSTALLATION_TYPE="@PKG_INSTALLATION_TYPE@"
@@ -119,40 +105,4 @@ case "${PKG_RCD_SCRIPTS:-@PKG_RCD_SCRIPTS@}" in
;;
esac
-msginit()
-{
- _msgn=0
- _msgempty=1
-
-}
-
-msgempty()
-{
- if [ $_msgempty -gt 0 ]; then
- ${TRUE}
- else
- ${FALSE}
- fi
-}
-
-msgadd()
-{
- eval _msg$_msgn=\"$1\"
- _msgn=`${EXPR} $_msgn + 1`
- _msgempty=0
-}
-
-msgprint()
-{
- i=0
- while [ $i -lt $_msgn ]; do
- eval _msg=_msg$i
- eval ${ECHO} "\$$_msg" | ${SED} \
- -e "s,^###, ," \
- -e "s,^##, ," \
- -e "s,^#, ,"
- i=`${EXPR} $i + 1`
- done
-}
-
# end of header
diff --git a/mk/install/install b/mk/install/install
index 7ab2557bd08..ca17e8a3f2e 100644
--- a/mk/install/install
+++ b/mk/install/install
@@ -1,6 +1,6 @@
# start of install
#
-# $NetBSD: install,v 1.35 2005/01/28 07:37:55 jlam Exp $
+# $NetBSD: install,v 1.36 2005/02/02 10:33:01 jlam Exp $
case ${STAGE} in
PRE-INSTALL)
@@ -9,9 +9,11 @@ PRE-INSTALL)
# installation of the package.
#
case ${_PKG_CREATE_USERGROUP} in
- YES) ${TEST} -x ./+USERGROUP && ./+USERGROUP ADD ${PKG_METADATA_DIR} ;;
+ YES) ${TEST} -x ./+USERGROUP &&
+ ./+USERGROUP ADD ${PKG_METADATA_DIR} ;;
esac
- if ${TEST} -x ./+USERGROUP && ./+USERGROUP CHECK-ADD ${PKG_METADATA_DIR}; then
+ if ${TEST} -x ./+USERGROUP &&
+ ./+USERGROUP CHECK-ADD ${PKG_METADATA_DIR}; then
:
else
exit 1
@@ -34,191 +36,37 @@ PRE-INSTALL)
fi
fi
case ${_PKG_CONFIG} in
- YES) ${TEST} -x ./+DIRS && ./+DIRS ADD ${PKG_METADATA_DIR} ;;
+ YES) ${TEST} -x ./+DIRS &&
+ ./+DIRS ADD ${PKG_METADATA_DIR} ;;
esac
;;
POST-INSTALL)
#
- # Note any missing package directories.
+ # Copy configuration/support files into place.
#
- ${TEST} -x ./+DIRS && ./+DIRS CHECK-ADD ${PKG_METADATA_DIR}
-
- msginit
- if [ "${_PKG_CONFIG}" = "YES" ]; then
- if [ -n "${CONF_FILES}" -o \
- -n "${CONF_FILES_PERMS}" -o \
- -n "${SUPPORT_FILES}" -o \
- -n "${SUPPORT_FILES_PERMS}" ] || \
- [ "${_PKG_RCD_SCRIPTS}" = "YES" -a \
- -n "${RCD_SCRIPTS}" ]; then
- ${CAT} << EOF
-
-===> Installing configuration/support files for ${PKGNAME}
-
-EOF
- fi
- fi
- _print_file_header=1
- eval set -- ${CONF_FILES}
- while [ $# -gt 0 ]; do
- samplefile="$1"; file="$2"
- shift; shift
-
- if [ "${_PKG_CONFIG}" = "NO" ]; then
- if [ ${_print_file_header} -gt 0 ]; then
- _print_file_header=0
- msgadd ""
- msgadd "The following files should be created for ${PKGNAME}:"
- msgadd ""
- fi
- msgadd "#${file} (m=@CONF_FILES_MODE@)"
- elif [ -f "${file}" ]; then
- if [ ! "${file}" -ef "${samplefile}" ]; then
- ${ECHO} " ${file} already exists, example file is"
- ${ECHO} " ${samplefile}"
- fi
- else
- if [ -f "${samplefile}" ]; then
- ${ECHO} " ${file}"
- ${CP} "${samplefile}" "${file}"
- ${CHMOD} @CONF_FILES_MODE@ "${file}"
- fi
- fi
- done
- eval set -- ${SUPPORT_FILES}
- while [ $# -gt 0 ]; do
- samplefile="$1"; file="$2"
- shift; shift
-
- if [ "${_PKG_CONFIG}" = "NO" ]; then
- if [ ${_print_file_header} -gt 0 ]; then
- _print_file_header=0
- msgadd ""
- msgadd "The following files should be created for ${PKGNAME}:"
- msgadd ""
- fi
- msgadd "#${file} (m=@SUPPORT_FILES_MODE@)"
- elif [ -f "${file}" ]; then
- if [ ! "${file}" -ef "${samplefile}" ]; then
- ${ECHO} " ${file} already exists, example file is"
- ${ECHO} " ${samplefile}"
- fi
- else
- if [ -f "${samplefile}" ]; then
- ${ECHO} " ${file}"
- ${CP} "${samplefile}" "${file}"
- ${CHMOD} @SUPPORT_FILES_MODE@ "${file}"
- fi
- fi
- done
- eval set -- ${CONF_FILES_PERMS} ${SUPPORT_FILES_PERMS}
- while [ $# -gt 0 ]; do
- samplefile="$1"; file="$2"
- owner="$3"; group="$4"; mode="$5"
- shift; shift; shift; shift; shift
-
- if [ "${_PKG_CONFIG}" = "NO" ]; then
- if [ ${_print_file_header} -gt 0 ]; then
- _print_file_header=0
- msgadd ""
- msgadd "The following files should be created for ${PKGNAME}:"
- msgadd ""
- fi
- msgadd "#${file} (o=${owner}, g=${group}, m=${mode})"
- elif [ -f ${file} ]; then
- if [ ! "${file}" -ef "${samplefile}" ]; then
- ${ECHO} " ${file} already exists, example file is"
- ${ECHO} " ${samplefile}"
- fi
- else
- if [ -f "${samplefile}" ]; then
- ${ECHO} " ${file}"
- ${CP} "${samplefile}" "${file}"
- ${CHOWN} "${owner}" "${file}"
- ${CHGRP} "${group}" "${file}"
- ${CHMOD} ${mode} "${file}"
- fi
- fi
- done
- eval set -- ${RCD_SCRIPTS}
- for script; do
- samplefile="${PKG_PREFIX}/${RCD_SCRIPTS_EXAMPLEDIR}/${script}"
- file="${RCD_SCRIPTS_DIR}/${script}"
-
- if [ "${_PKG_CONFIG}" = "NO" -o \
- "${_PKG_RCD_SCRIPTS}" = "NO" ]; then
- if [ ${_print_file_header} -gt 0 ]; then
- _print_file_header=0
- msgadd ""
- msgadd "The following files should be created for ${PKGNAME}:"
- msgadd ""
- fi
- msgadd "#${file} (m=@RCD_SCRIPTS_MODE@)"
- elif [ -f "${file}" ]; then
- if [ ! "${file}" -ef "${samplefile}" ]; then
- ${ECHO} " ${file} already exists, example file is"
- ${ECHO} " ${samplefile}"
- fi
- else
- if [ -f "${samplefile}" ]; then
- ${ECHO} " ${file}"
- ${CP} "${samplefile}" "${file}"
- ${CHMOD} @RCD_SCRIPTS_MODE@ "${file}"
- fi
- fi
- done
- _print_special_header=1
- eval set -- ${SPECIAL_PERMS}
- while [ $# -gt 0 ]; do
- file="$1"; owner="$2"; group="$3"; mode="$4"
- shift; shift; shift; shift
-
- if [ ${_print_special_header} -gt 0 ]; then
- _print_special_header=0
- msgadd ""
- msgadd "The following files and directories have special permissions:"
- msgadd ""
- fi
- msgadd "#${file} (o=${owner}, g=${group}, m=${mode})"
- ${CHOWN} "${owner}" "${file}"
- ${CHGRP} "${group}" "${file}"
- ${CHMOD} ${mode} "${file}"
- done
- if ! msgempty; then
- ${ECHO} "==========================================================================="
- msgprint
- ${ECHO} ""
- ${ECHO} "==========================================================================="
- fi
- if [ "${_PKG_CONFIG}" = "YES" ]; then
- if [ -n "${CONF_FILES}" -o -n "${CONF_FILES_PERMS}" ]; then
- ${CAT} << EOF
-
-===========================================================================
-You may wish to customize the following files for ${PKGNAME}:
-
-EOF
- eval set -- ${CONF_FILES}
- while [ $# -gt 0 ]; do
- samplefile="$1"; file="$2"
- shift; shift
-
- ${ECHO} " ${file}"
- done
- eval set -- ${CONF_FILES_PERMS}
- while [ $# -gt 0 ]; do
- samplefile="$1"; file="$2"
- owner="$3"; group="$4"; mode="$5"
- shift; shift; shift; shift; shift
+ case ${_PKG_CONFIG} in
+ YES) ${TEST} -x ./+FILES &&
+ ./+FILES ADD ${PKG_METADATA_DIR} ;;
+ esac
+ case ${_PKG_CONFIG}${_PKG_RCD_SCRIPTS} in
+ YESYES) ${TEST} -x ./+RCD_SCRIPTS &&
+ ./+RCD_SCRIPTS ADD ${PKG_METADATA_DIR} ;;
+ esac
+ #
+ # Set special permissions on any files/directories that need them.
+ #
+ ${TEST} -x ./+PERMS &&
+ ./+PERMS ${PKG_METADATA_DIR}
- ${ECHO} " ${file}"
- done
- ${CAT} << EOF
-===========================================================================
-EOF
- fi
- fi
+ # Check for any missing bits after we're finished installing.
+ #
+ ${TEST} -x ./+DIRS &&
+ ./+DIRS CHECK-ADD ${PKG_METADATA_DIR}
+ ${TEST} -x ./+FILES &&
+ ./+FILES CHECK-ADD ${PKG_METADATA_DIR}
+ ${TEST} -x ./+RCD_SCRIPTS &&
+ ./+RCD_SCRIPTS CHECK-ADD ${PKG_METADATA_DIR}
;;
VIEW-INSTALL)
@@ -234,13 +82,8 @@ VIEW-INSTALL)
# package config files to the proper view.
#
if [ "${_PKG_CONFIG}" = "YES" -a -n "${PKG_SYSCONFDEPOTBASE}" ]; then
- if [ -n "${CONF_FILES}" -o \
- -n "${CONF_FILES_PERMS}" -o \
- -n "${SUPPORT_FILES}" -o \
- -n "${SUPPORT_FILES_PERMS}" ]; then
- ${SETENV} PLIST_IGNORE_FILES="${CONF_IGNORE_FILES}" \
- ${LINKFARM} -t ${PKG_SYSCONFVIEWBASE} -d ${PKG_SYSCONFDEPOTBASE} ${PKGNAME}
- fi
+ ${SETENV} PLIST_IGNORE_FILES="${CONF_IGNORE_FILES}" \
+ ${LINKFARM} -t ${PKG_SYSCONFVIEWBASE} -d ${PKG_SYSCONFDEPOTBASE} ${PKGNAME}
fi
;;
esac
diff --git a/mk/install/perms b/mk/install/perms
new file mode 100644
index 00000000000..9035709fdb2
--- /dev/null
+++ b/mk/install/perms
@@ -0,0 +1,78 @@
+#!@SH@
+#
+# $NetBSD: perms,v 1.1 2005/02/02 10:33:01 jlam Exp $
+#
+# +PERMS - special file and directory permissions management script
+#
+# Usage: ./+PERMS [metadatadir]
+#
+# This script sets special permissions on files and directories needed
+# by the package associated with <metadatadir>.
+#
+# Lines starting with "# PERMS: " are data read by this script that
+# name the files and directories required to have special permissions
+# in order for this package to function correctly.
+#
+# # PERMS: /usr/pkg/bin/lppasswd 4711 lp sys
+# # PERMS: /usr/pkg/etc/pwd.db 0600
+#
+CHGRP="@CHGRP@"
+CHMOD="@CHMOD@"
+CHOWN="@CHOWN@"
+ECHO="@ECHO@"
+PWD_CMD="@PWD_CMD@"
+SED="@SED@"
+SORT="@SORT@"
+TEST="@TEST@"
+
+SELF=$0
+PKG_METADATA_DIR="${1-`${PWD_CMD}`}"
+: ${PKGNAME=${PKG_METADATA_DIR##*/}}
+
+${SED} -n "/^\# PERMS: /{s/^\# PERMS: //;p;}" ${SELF} | ${SORT} -u |
+{ while read file f_mode f_user f_group; do
+ case $file in
+ ""|[!/]*) continue ;;
+ *) ${TEST} -f "$file" || continue ;;
+ esac
+ case "$printed_header" in
+ yes) ;;
+ *) printed_header=yes
+ ${ECHO} "==========================================================================="
+ ${ECHO} "The following files and directories needed by ${PKGNAME}"
+ ${ECHO} "have special permissions:"
+ ${ECHO} ""
+ ;;
+ esac
+ case $f_mode/$f_user/$f_group in
+ //)
+ ${ECHO} " $file"
+ ;;
+ [!/]*//)
+ ${ECHO} " $file (m=$f_mode)"
+ ;;
+ [!/]*/[!/]*/)
+ ${ECHO} " $file (o=$f_user, m=$f_mode)"
+ ;;
+ [!/]*/[!/]*/[!/]*)
+ ${ECHO} " $file (o=$f_user, g=$f_group, m=$f_mode)"
+ ;;
+ esac
+ case $f_mode in
+ "") ;;
+ *) ${CHMOD} $f_mode $file ;;
+ esac
+ case $f_user in
+ "") ;;
+ *) ${CHOWN} $f_user $file ;;
+ esac
+ case $f_group in
+ "") ;;
+ *) ${CHGRP} $f_group $file ;;
+ esac
+done
+case "$printed_header" in
+yes) ${ECHO} ""
+ ${ECHO} "==========================================================================="
+ ;;
+esac; }