diff options
author | jlam <jlam> | 2001-11-19 16:18:44 +0000 |
---|---|---|
committer | jlam <jlam> | 2001-11-19 16:18:44 +0000 |
commit | e740603fc9e2110613fe030c8dabf0543d664a81 (patch) | |
tree | a60637d6a03f36964a4f6c39dd848d88feaed3f4 | |
parent | 7cdb3f64df39d4ce2d4dd4f5327759a4f19517cf (diff) | |
download | pkgsrc-e740603fc9e2110613fe030c8dabf0543d664a81.tar.gz |
Common INSTALL/DEINSTALL scripts and Makefile magic to automatically perform
many of the tasks that need to be done when package is installed or
deinstalled:
* creating user/group for the package,
* creating and removing directories with special permissions and
ownership,
* copying config files to their final locations, and removing them
at deinstall time if they don't differ from the example ones,
* reminding the package admin of files he may want to customize or
of files/directories he may want to remove.
-rw-r--r-- | mk/bsd.pkg.install.mk | 189 | ||||
-rw-r--r-- | mk/install/deinstall | 153 | ||||
-rw-r--r-- | mk/install/footer | 7 | ||||
-rw-r--r-- | mk/install/header | 51 | ||||
-rw-r--r-- | mk/install/install | 177 |
5 files changed, 577 insertions, 0 deletions
diff --git a/mk/bsd.pkg.install.mk b/mk/bsd.pkg.install.mk new file mode 100644 index 00000000000..25289261703 --- /dev/null +++ b/mk/bsd.pkg.install.mk @@ -0,0 +1,189 @@ +# $NetBSD: bsd.pkg.install.mk,v 1.1 2001/11/19 16:18:44 jlam Exp $ +# +# This Makefile fragment is included by package Makefiles to use the common +# INSTALL/DEINSTALL scripts. To use this Makefile fragment, simply: +# +# (1) Set the variables to customize the install scripts to the package, and +# (2) Include this Makefile fragment in the package Makefile. +# +# NOTE: This file must be included _before_ bsd.pkg.mk. + +.if !defined(BSD_PKG_INSTALL_MK) +BSD_PKG_INSTALL_MK= 1 + +DEINSTALL_FILE= ${WRKDIR}/.DEINSTALL +INSTALL_FILE= ${WRKDIR}/.INSTALL + +# These are the template scripts for the INSTALL/DEINSTALL scripts. Packages +# may do additional work in the INSTALL/DEINSTALL scripts by overriding the +# variables DEINSTALL_EXTRA_TMPL and INSTALL_EXTRA_TMPL to point to +# additional script fragments. These bits are included after the main +# install/deinstall script fragments. Packages may also override the +# variables DEINSTALL_TMPL and INSTALL_TMPL to completely customize the +# install/deinstall logic. +# +_HEADER_TMPL?= ${.CURDIR}/../../mk/install/header +DEINSTALL_EXTRA_TMPL?= # empty +DEINSTALL_TMPL?= ${.CURDIR}/../../mk/install/deinstall +INSTALL_TMPL?= ${.CURDIR}/../../mk/install/install +INSTALL_EXTRA_TMPL?= # empty +_FOOTER_TMPL?= ${.CURDIR}/../../mk/install/footer + +# DEINSTALL_TEMPLATES and INSTALL_TEMPLATES are the default list of source +# files that are concatenated to form the DEINSTALL/INSTALL scripts. +# +DEINSTALL_TEMPLATES= ${_HEADER_TMPL} +DEINSTALL_TEMPLATES+= ${DEINSTALL_EXTRA_TMPL} +DEINSTALL_TEMPLATES+= ${DEINSTALL_TMPL} +DEINSTALL_TEMPLATES+= ${_FOOTER_TMPL} +INSTALL_TEMPLATES= ${_HEADER_TMPL} +INSTALL_TEMPLATES+= ${INSTALL_TMPL} +INSTALL_TEMPLATES+= ${INSTALL_EXTRA_TMPL} +INSTALL_TEMPLATES+= ${_FOOTER_TMPL} + +# These are the list of source files that are concatenated to form the +# INSTALL/DEINSTALL scripts. +# +DEINSTALL_SRC?= ${DEINSTALL_TEMPLATES} +INSTALL_SRC?= ${INSTALL_TEMPLATES} + +FILES_SUBST+= PREFIX=${PREFIX} +FILES_SUBST+= LOCALBASE=${LOCALBASE} +FILES_SUBST+= X11BASE=${X11BASE} +FILES_SUBST+= CONFDIR=${CONFDIR} + +# PKG_USER and PKG_GROUP are the user and group that need to be created +# before this package is installed. +# +# PKG_USERID and PKG_GROUPID are the numeric IDs used in creating the user +# and group. If they're blank, then the default values chosen by the +# system is used. +# +# PKG_USER_DESCR is the description of the user to add to the system. It +# defaults to "foo user" for package "foo". +# +# PKG_USER_HOME is the home directory of the user to add to the system. It +# defaults to "/". +# +# PKG_USER_SHELL is the login shell for the user. For system security +# purposes, it defaults to "${NOLOGIN}". +# +PKG_USER?= # empty +PKG_USERID?= # empty +PKG_USER_DESCR?= ${PKGBASE} user +PKG_USER_HOME?= / +PKG_USER_SHELL?= ${NOLOGIN} +PKG_GROUP?= # empty +PKG_GROUPID?= # empty +FILES_SUBST+= PKG_USER=${PKG_USER} +FILES_SUBST+= PKG_USERID=${PKG_USERID} +FILES_SUBST+= PKG_USER_DESCR=${PKG_USER_DESCR:Q} +FILES_SUBST+= PKG_USER_HOME=${PKG_USER_HOME} +FILES_SUBST+= PKG_USER_SHELL=${PKG_USER_SHELL} +FILES_SUBST+= PKG_GROUP=${PKG_GROUP} +FILES_SUBST+= PKG_GROUPID=${PKG_GROUPID} + +.if !empty(PKG_USER) +USE_USERADD= YES +.endif +.if !empty(PKG_GROUP) +USE_USERGROUP= YES +.endif + +# 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 +# file doesn't exist, then the example one is copied into place. At +# deinstall time, the true one is removed if it doesn't differ from the +# example one. SUPPORT_FILES is used the same way, but the package +# admin isn't prompted to customize the file at post-install time. +# +# CONF_FILES_MODE and SUPPORT_FILES_MODE are the file permissions for the +# files in CONF_FILES and SUPPORT_FILES, respectively. +# +# CONF_FILES_PERMS are lists that look like: +# example_file config_file user group mode +# and works like CONF_FILES, except the config files are owned by +# user:group have mode permissions. +# +# RCD_SCRIPTS works like CONF_FILES but deals with rc.d startup scripts. The +# scripts are copied with ${RCD_SCRIPTS_MODE} permissions. +# +CONF_FILES?= # empty +CONF_FILES_MODE?= 0644 +CONF_FILES_PERMS?= # empty +SUPPORT_FILES?= # empty +SUPPORT_FILES_MODE?= 0644 +RCD_SCRIPTS?= # empty +RCD_SCRIPTS_MODE?= 0755 +FILES_SUBST+= CONF_FILES=${CONF_FILES:Q} +FILES_SUBST+= CONF_FILES_MODE=${CONF_FILES_MODE} +FILES_SUBST+= SUPPORT_FILES=${SUPPORT_FILES:Q} +FILES_SUBST+= SUPPORT_FILES_MODE=${SUPPORT_FILES_MODE} +FILES_SUBST+= CONF_FILES_PERMS=${CONF_FILES_PERMS:Q} +FILES_SUBST+= RCD_SCRIPTS=${RCD_SCRIPTS:Q} +FILES_SUBST+= RCD_SCRIPTS_MODE=${RCD_SCRIPTS_MODE} + +# 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 +# isn't prompted to remove the directory at post-deinstall time if it +# isn't empty. For convenience, ${CONFDIR} and /etc/rc.d are +# automatically added to MAKE_DIRS. +# +# OWN_DIRS_PERMS contains a list of "directory owner group mode" sublists +# representing directories for this package that should be +# created/destroyed by the INSTALL/DEINSTALL scripts. MAKE_DIRS_PERMS +# is used the same way but the package admin isn't prompted to remove +# the directory at post-deinstall time if it isn't empty. +# +MAKE_DIRS?= # empty +MAKE_DIRS_PERMS?= # empty +_MAKE_DIRS= ${CONFDIR} /etc/rc.d ${MAKE_DIRS} +OWN_DIRS?= # empty +OWN_DIRS_PERMS?= # empty +FILES_SUBST+= MAKE_DIRS=${_MAKE_DIRS:Q} +FILES_SUBST+= MAKE_DIRS_PERMS=${MAKE_DIRS_PERMS:Q} +FILES_SUBST+= OWN_DIRS=${OWN_DIRS:Q} +FILES_SUBST+= OWN_DIRS_PERMS=${OWN_DIRS_PERMS:Q} + +# Substitute for various programs used in the DEINSTALL/INSTALL scripts. +FILES_SUBST+= AWK=${AWK:Q} +FILES_SUBST+= BASENAME=${BASENAME:Q} +FILES_SUBST+= CAT=${CAT:Q} +FILES_SUBST+= CHGRP=${CHGRP:Q} +FILES_SUBST+= CHMOD=${CHMOD:Q} +FILES_SUBST+= CHOWN=${CHOWN:Q} +FILES_SUBST+= CMP=${CMP:Q} +FILES_SUBST+= CP=${CP:Q} +FILES_SUBST+= DIRNAME=${DIRNAME:Q} +FILES_SUBST+= ECHO=${ECHO:Q} +FILES_SUBST+= EGREP=${EGREP:Q} +FILES_SUBST+= FALSE=${FALSE:Q} +FILES_SUBST+= GROUPADD=${GROUPADD:Q} +FILES_SUBST+= ID=${ID:Q} +FILES_SUBST+= LN=${LN:Q} +FILES_SUBST+= MKDIR=${MKDIR:Q} +FILES_SUBST+= MV=${MV:Q} +FILES_SUBST+= RM=${RM:Q} +FILES_SUBST+= RMDIR=${RMDIR:Q} +FILES_SUBST+= SED=${SED:Q} +FILES_SUBST+= SH=${SH:Q} +FILES_SUBST+= SORT=${SORT:Q} +FILES_SUBST+= TOUCH=${TOUCH:Q} +FILES_SUBST+= TR=${TR:Q} +FILES_SUBST+= TRUE=${TRUE:Q} +FILES_SUBST+= USERADD=${USERADD:Q} + +FILES_SUBST_SED= ${FILES_SUBST:S/=/@!/:S/$/!g/:S/^/ -e s!@/} + +pre-install: install-scripts + +install-scripts: + ${_PKG_SILENT}${_PKG_DEBUG}${CAT} ${DEINSTALL_SRC} | \ + ${SED} ${FILES_SUBST_SED} > ${DEINSTALL_FILE} + ${_PKG_SILENT}${_PKG_DEBUG}${CHMOD} +x ${DEINSTALL_FILE} + ${_PKG_SILENT}${_PKG_DEBUG}${CAT} ${INSTALL_SRC} | \ + ${SED} ${FILES_SUBST_SED} > ${INSTALL_FILE} + ${_PKG_SILENT}${_PKG_DEBUG}${CHMOD} +x ${INSTALL_FILE} + +.endif # BSD_PKG_INSTALL_MK diff --git a/mk/install/deinstall b/mk/install/deinstall new file mode 100644 index 00000000000..41512fe9628 --- /dev/null +++ b/mk/install/deinstall @@ -0,0 +1,153 @@ +# start of deinstall +# +# $NetBSD: deinstall,v 1.1 2001/11/19 16:18:44 jlam Exp $ + +ALL_FILES="${CONF_FILES} ${SUPPORT_FILES} ${RCD_SCRIPTS}" +set -- ${CONF_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}" +done + +ALL_MAKE_DIRS="${MAKE_DIRS}" +set -- ${MAKE_DIRS_PERMS} +while [ $# -gt 0 ] +do + dir="$1"; owner="$2"; group="$3"; mode="$4" + shift; shift; shift; shift + ALL_MAKE_DIRS="${ALL_MAKE_DIRS} ${dir}" +done +ALL_DIRS="${ALL_MAKE_DIRS} ${OWN_DIRS}" +set -- ${OWN_DIRS_PERMS} +while [ $# -gt 0 ] +do + dir="$1"; owner="$2"; group="$3"; mode="$4" + shift; shift; shift; shift + ALL_DIRS="${ALL_DIRS} ${dir}" +done +ALL_DIRS=` \ + ${ECHO} ${ALL_DIRS} | \ + ${SED} "s,[ ][ ]*, ,g" | \ + ${TR} ' ' "\012" | \ + ${SORT} -r \ +` + +case ${STAGE} in +DEINSTALL) + # Remove configuration files if they don't differ from the default + # config file. + # + set -- ${ALL_FILES} + while [ $# -gt 0 ] + do + samplefile="$1"; file="$2" + shift; shift + + if [ "${file}" != "${samplefile}" -a \ + -f ${file} -a -f ${samplefile} ] + then + if ${CMP} -s ${file} ${samplefile} + then + ${RM} -f ${file} + fi + fi + done + ;; + +POST-DEINSTALL) + modified_files='' + set -- ${ALL_FILES} + while [ $# -gt 0 ] + do + samplefile="$1"; file="$2" + shift; shift + + if [ -f ${file} ] + then + modified_files="${modified_files} ${file}" + fi + done + + existing_dirs='' + set -- ${ALL_DIRS} + while [ $# -gt 0 ] + do + dir=$1; shift + is_make_dir=0 + for make_dir in __dummy ${ALL_MAKE_DIRS} + do + if [ "${make_dir}" != "__dummy" -a \ + "${dir}" = "${make_dir}" ] + then + is_make_dir=1 + break + fi + done + + ${RMDIR} -p ${dir} 2>/dev/null || ${TRUE} + if [ ${is_make_dir} -eq 0 -a -d ${dir} ] + then + existing_dirs="${existing_dirs} ${dir}" + fi + done + + if [ -n "${PKG_USER}" -o -n "${PKG_GROUP}" -o \ + -n "${modified_files}" -o -n "${existing_dirs}" ] + then + ${CAT} << EOF +=========================================================================== +If you won't be using ${PKGNAME} any longer, you may want to remove +EOF + if [ -n "${PKG_USER}" ] + then + ${CAT} << EOF + + * the \`${PKG_USER}' user +EOF + fi + if [ -n "${PKG_GROUP}" ] + then + ${CAT} << EOF + + * the \`${PKG_GROUP}' group +EOF + fi + if [ -n "${modified_files}" ] + then + ${CAT} << EOF + + * the following files: + +EOF + for file in ${modified_files} + do + ${ECHO} " ${file}" + done + fi + if [ -n "${existing_dirs}" ] + then + ${CAT} << EOF + + * the following directories: + +EOF + for dir in ${existing_dirs} + do + ${ECHO} " ${dir}" + done + fi + ${CAT} << EOF +=========================================================================== +EOF + fi + ;; + +*) + ${ECHO} "Unexpected argument: ${STAGE}" + exit 1 + ;; +esac + +# end of deinstall diff --git a/mk/install/footer b/mk/install/footer new file mode 100644 index 00000000000..44719cce24c --- /dev/null +++ b/mk/install/footer @@ -0,0 +1,7 @@ +# start of footer +# +# $NetBSD: footer,v 1.1 2001/11/19 16:18:44 jlam Exp $ + +exit 0 + +# end of footer diff --git a/mk/install/header b/mk/install/header new file mode 100644 index 00000000000..8e6278f2356 --- /dev/null +++ b/mk/install/header @@ -0,0 +1,51 @@ +#!@SH@ +# +# start of header +# +# $NetBSD: header,v 1.1 2001/11/19 16:18:44 jlam Exp $ + +PKGNAME=$1 +STAGE=$2 + +AWK="@AWK@" +BASENAME="@BASENAME@" +CAT="@CAT@" +CHGRP="@CHGRP@" +CHMOD="@CHMOD@" +CHOWN="@CHOWN@" +CMP="@CMP@" +CP="@CP@" +DIRNAME="@DIRNAME@" +ECHO="@ECHO@" +EGREP="@EGREP@" +FALSE="@FALSE@" +GROUPADD="@GROUPADD@" +ID="@ID@" +LN="@LN@" +MKDIR="@MKDIR@" +MV="@MV@" +RM="@RM@" +RMDIR="@RMDIR@" +SED="@SED@" +SORT="@SORT@" +TOUCH="@TOUCH@" +TR="@TR@" +TRUE="@TRUE@" +USERADD="@USERADD@" + +PKG_USER="@PKG_USER@" +PKG_GROUP="@PKG_GROUP@" +PKG_GROUP="@PKG_GROUP@" +PKG_GROUPID="@PKG_GROUPID@" + +CONF_FILES="@CONF_FILES@" +CONF_FILES_PERMS="@CONF_FILES_PERMS@" +SUPPORT_FILES="@SUPPORT_FILES@" +RCD_SCRIPTS="@RCD_SCRIPTS@" + +MAKE_DIRS="@MAKE_DIRS@" +MAKE_DIRS_PERMS="@MAKE_DIRS_PERMS@" +OWN_DIRS="@OWN_DIRS@" +OWN_DIRS_PERMS="@OWN_DIRS_PERMS@" + +# end of header diff --git a/mk/install/install b/mk/install/install new file mode 100644 index 00000000000..9344ee3915a --- /dev/null +++ b/mk/install/install @@ -0,0 +1,177 @@ +# start of install +# +# $NetBSD: install,v 1.1 2001/11/19 16:18:44 jlam Exp $ + +case ${STAGE} in +PRE-INSTALL) + if [ -n "${PKG_GROUP}" ] + then + # We need to check that ${PKG_GROUP} exists before adding the + # user. Do it with chgrp to be able to use NIS. + # + ${TOUCH} /tmp/grouptest.$$ + ${CHGRP} ${PKG_GROUP} /tmp/grouptest.$$ >/dev/null 2>&1 + if [ $? -eq 0 ] + then + ${ECHO} "Group '${PKG_GROUP}' already exists." + else + groupid_option= + if [ -n "${PKG_GROUPID}" ] + then + groupid_option="-g ${PKG_GROUPID}" + fi + ${ECHO} "Creating '${PKG_GROUP}' group..." + ${GROUPADD} ${groupid_option} ${PKG_GROUP} + ${ECHO} "Done." + fi + ${RM} -f /tmp/grouptest.$$ + fi + + if [ -n "${PKG_USER}" -a -n "${PKG_GROUP}" ] + then + # Use `id' to be able to use NIS. + ${ID} ${PKG_USER} >/dev/null 2>&1 + if [ $? -eq 0 ] + then + ${ECHO} "User '${PKG_USER}' already exists." + else + userid_option= + if [ -n "${PKG_USERID}" ] + then + userid_option="-u ${PKG_USERID}" + fi + ${ECHO} "Creating '${PKG_USER}' user..." + ${USERADD} -c "@PKG_USER_DESCR@" \ + ${userid_option} \ + -g ${PKG_GROUP} \ + -d @PKG_USER_HOME@ \ + -s @PKG_USER_SHELL@ \ + ${PKG_USER} + ${ECHO} "Done." + fi + fi + ;; + +POST-INSTALL) + # Create package directories. + set -- ${MAKE_DIRS} ${OWN_DIRS} + for dir + do + ${MKDIR} ${dir} + done + set -- ${MAKE_DIRS_PERMS} ${OWN_DIRS_PERMS} + while [ $# -gt 0 ] + do + dir="$1"; owner="$2"; group="$3"; mode="$4" + shift; shift; shift; shift + ${MKDIR} ${dir} + ${CHOWN} ${owner} ${dir} + ${CHGRP} ${group} ${dir} + ${CHMOD} ${mode} ${dir} + done + + if [ -n "${CONF_FILES}" -o -n "${CONF_FILES_PERMS}" -o \ + -n "${SUPPORT_FILES}" ] + then + ${ECHO} "Installing configuration files:" + fi + set -- ${CONF_FILES} + while [ $# -gt 0 ] + do + samplefile="$1"; file="$2" + shift; shift + + if [ -f ${file} ] + then + ${ECHO} " ${file} already exists" + else + ${ECHO} " ${file}" + ${CP} ${samplefile} ${file} + ${CHMOD} @CONF_FILES_MODE@ ${file} + fi + done + set -- ${CONF_FILES_PERMS} + while [ $# -gt 0 ] + do + samplefile="$1"; file="$2"; owner="$3"; group="$4"; mode="$5" + shift; shift; shift; shift; shift + + if [ -f ${file} ] + then + ${ECHO} " ${file} already exists" + else + ${ECHO} " ${file}" + ${CP} ${samplefile} ${file} + ${CHOWN} ${owner} ${file} + ${CHGRP} ${group} ${file} + ${CHMOD} ${mode} ${file} + fi + done + set -- ${SUPPORT_FILES} + while [ $# -gt 0 ] + do + samplefile="$1"; file="$2" + shift; shift + + if [ -f ${file} ] + then + ${ECHO} " ${file} already exists" + else + ${ECHO} " ${file}" + ${CP} ${samplefile} ${file} + ${CHMOD} @SUPPORT_FILES_MODE@ ${file} + fi + done + set -- ${RCD_SCRIPTS} + while [ $# -gt 0 ] + do + samplefile="$1"; file="$2" + shift; shift + + if [ -f ${file} ] + then + ${ECHO} " ${file} already exists" + else + ${ECHO} " ${file}" + ${CP} ${samplefile} ${file} + ${CHMOD} @RCD_SCRIPTS_MODE@ ${file} + fi + done + + if [ -n "${CONF_FILES}" -o -n "${CONF_FILES_PERMS}" ] + then + ${CAT} << EOF + +=========================================================================== +You may wish to customize the following files: + +EOF + set -- ${CONF_FILES} + while [ $# -gt 0 ] + do + samplefile="$1"; file="$2" + shift; shift + + ${ECHO} " ${file}" + done + set -- ${CONF_FILES_PERMS} + while [ $# -gt 0 ] + do + samplefile="$1"; file="$2"; owner="$3"; group="$4"; mode="$5" + shift; shift; shift; shift; shift + + ${ECHO} " ${file}" + done + ${CAT} << EOF +=========================================================================== +EOF + fi + ;; + +*) + ${ECHO} "Unexpected argument: ${STAGE}" + exit 1 + ;; +esac + +# end of install |