diff options
author | jlam <jlam@pkgsrc.org> | 2006-05-21 23:50:15 +0000 |
---|---|---|
committer | jlam <jlam@pkgsrc.org> | 2006-05-21 23:50:15 +0000 |
commit | 143b5f7d148dfa538bb18fb22a3bd3755f6f8c80 (patch) | |
tree | 0c523987180f677a1b6f7605da0f810de5df2349 /mk/pkginstall | |
parent | 7bd087ae6e04e7c2d1c5e1ee2dcfedae70f0e0a2 (diff) | |
download | pkgsrc-143b5f7d148dfa538bb18fb22a3bd3755f6f8c80.tar.gz |
Move mk/install to mk/pkginstall to better reflect the contents (the
pkginstall framework).
Diffstat (limited to 'mk/pkginstall')
-rw-r--r-- | mk/pkginstall/bsd.pkginstall.mk | 1017 | ||||
-rw-r--r-- | mk/pkginstall/deinstall | 73 | ||||
-rw-r--r-- | mk/pkginstall/deinstall-pre | 15 | ||||
-rw-r--r-- | mk/pkginstall/dirs | 374 | ||||
-rw-r--r-- | mk/pkginstall/files | 459 | ||||
-rw-r--r-- | mk/pkginstall/fonts | 101 | ||||
-rw-r--r-- | mk/pkginstall/footer | 4 | ||||
-rw-r--r-- | mk/pkginstall/header | 86 | ||||
-rw-r--r-- | mk/pkginstall/info-files | 136 | ||||
-rw-r--r-- | mk/pkginstall/install | 97 | ||||
-rw-r--r-- | mk/pkginstall/install-post | 15 | ||||
-rw-r--r-- | mk/pkginstall/perms | 96 | ||||
-rw-r--r-- | mk/pkginstall/shell | 233 | ||||
-rw-r--r-- | mk/pkginstall/usergroup | 382 | ||||
-rwxr-xr-x | mk/pkginstall/usergroup-check | 126 | ||||
-rw-r--r-- | mk/pkginstall/usergroupfuncs | 148 | ||||
-rw-r--r-- | mk/pkginstall/usergroupfuncs.DragonFly | 142 | ||||
-rw-r--r-- | mk/pkginstall/usergroupfuncs.FreeBSD | 142 |
18 files changed, 3646 insertions, 0 deletions
diff --git a/mk/pkginstall/bsd.pkginstall.mk b/mk/pkginstall/bsd.pkginstall.mk new file mode 100644 index 00000000000..22182d62087 --- /dev/null +++ b/mk/pkginstall/bsd.pkginstall.mk @@ -0,0 +1,1017 @@ +# $NetBSD: bsd.pkginstall.mk,v 1.1 2006/05/21 23:50:15 jlam Exp $ +# +# This Makefile fragment is included by bsd.pkg.mk and implements the +# common INSTALL/DEINSTALL scripts framework. To use the pkginstall +# framework, simply set the relevant variables to customize the install +# scripts to the package. +# + +# The Solaris /bin/sh does not know the ${foo#bar} shell substitution. +# This shell function serves a similar purpose, but is specialized on +# stripping ${PREFIX}/ from a pathname. +_FUNC_STRIP_PREFIX= \ + strip_prefix() { \ + ${AWK} 'END { \ + plen = length(prefix); \ + if (substr(s, 1, plen) == prefix) { \ + s = substr(s, 1 + plen, length(s) - plen); \ + } \ + print s; \ + }' s="$$1" prefix=${PREFIX:Q}/ /dev/null; \ + } + +# This is a command that exits with a zero status if the given file +# is zero-length. +# +_ZERO_FILESIZE_P= ${AWK} 'END { exit NR ? 1 : 0; }' + +_PKGINSTALL_DIR= ${WRKDIR}/.pkginstall + +# 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_TEMPLATE and INSTALL_TEMPLATE to +# point to additional script fragments. These bits are included after +# the main install/deinstall script fragments. +# +_HEADER_TMPL?= ${.CURDIR}/../../mk/pkginstall/header +HEADER_TEMPLATE?= # empty +.if exists(${PKGDIR}/HEADER) && \ + empty(HEADER_TEMPLATE:M${PKGDIR}/HEADER) +HEADER_TEMPLATE+= ${PKGDIR}/HEADER +.endif +_DEINSTALL_PRE_TMPL?= ${.CURDIR}/../../mk/pkginstall/deinstall-pre +DEINSTALL_TEMPLATE?= # empty +.if exists(${PKGDIR}/DEINSTALL) && \ + empty(DEINSTALL_TEMPLATE:M${PKGDIR}/DEINSTALL) +DEINSTALL_TEMPLATE+= ${PKGDIR}/DEINSTALL +.endif +_DEINSTALL_TMPL?= ${.CURDIR}/../../mk/pkginstall/deinstall +_INSTALL_UNPACK_TMPL?= # empty +_INSTALL_TMPL?= ${.CURDIR}/../../mk/pkginstall/install +INSTALL_TEMPLATE?= # empty +.if exists(${PKGDIR}/INSTALL) && \ + empty(INSTALL_TEMPLATE:M${PKGDIR}/INSTALL) +INSTALL_TEMPLATE+= ${PKGDIR}/INSTALL +.endif +_INSTALL_POST_TMPL?= ${.CURDIR}/../../mk/pkginstall/install-post +_INSTALL_DATA_TMPL?= # empty +_FOOTER_TMPL?= ${.CURDIR}/../../mk/pkginstall/footer + +# _DEINSTALL_TEMPLATES and _INSTALL_TEMPLATES are the list of source +# files that are concatenated to form the DEINSTALL/INSTALL +# scripts. +# +# _DEINSTALL_TEMPLATES_DFLT and _INSTALL_TEMPLATES_DFLT are the list of +# template files minus any user-supplied templates. +# +_DEINSTALL_TEMPLATES= ${_HEADER_TMPL} ${HEADER_TEMPLATE} \ + ${_DEINSTALL_PRE_TMPL} \ + ${DEINSTALL_TEMPLATE} \ + ${_DEINSTALL_TMPL} \ + ${_FOOTER_TMPL} +_INSTALL_TEMPLATES= ${_HEADER_TMPL} ${HEADER_TEMPLATE} \ + ${_INSTALL_UNPACK_TMPL} \ + ${_INSTALL_TMPL} \ + ${INSTALL_TEMPLATE} \ + ${_INSTALL_POST_TMPL} \ + ${_FOOTER_TMPL} \ + ${_INSTALL_DATA_TMPL} \ + +_DEINSTALL_TEMPLATES_DFLT= ${_HEADER_TMPL} \ + ${_DEINSTALL_PRE_TMPL} \ + ${_DEINSTALL_TMPL} \ + ${_FOOTER_TMPL} +_INSTALL_TEMPLATES_DFLT= ${_HEADER_TMPL} \ + ${_INSTALL_TMPL} \ + ${_INSTALL_POST_TMPL} \ + ${_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 lists what to substitute in DEINSTALL/INSTALL scripts and in +# rc.d scripts. +# +FILES_SUBST+= PREFIX=${PREFIX:Q} +FILES_SUBST+= LOCALBASE=${LOCALBASE:Q} +FILES_SUBST+= X11BASE=${X11BASE:Q} +FILES_SUBST+= DEPOTBASE=${DEPOTBASE:Q} +FILES_SUBST+= VARBASE=${VARBASE:Q} +FILES_SUBST+= PKG_SYSCONFBASE=${PKG_SYSCONFBASE:Q} +FILES_SUBST+= PKG_SYSCONFDEPOTBASE=${PKG_SYSCONFDEPOTBASE:Q} +FILES_SUBST+= PKG_SYSCONFBASEDIR=${PKG_SYSCONFBASEDIR:Q} +FILES_SUBST+= PKG_SYSCONFDIR=${PKG_SYSCONFDIR:Q} +FILES_SUBST+= CONF_DEPENDS=${CONF_DEPENDS:C/:.*//:Q} +FILES_SUBST+= PKGBASE=${PKGBASE:Q} +FILES_SUBST+= PKG_INSTALLATION_TYPE=${PKG_INSTALLATION_TYPE:Q} + +# PKG_USERS represents the users to create for the package. It is a +# space-separated list of elements of the form +# +# user:group +# +# The following variables are optional and specify further details of +# the user accounts listed in PKG_USERS: +# +# PKG_UID.<user> is the hardcoded numeric UID for <user>. +# PKG_GECOS.<user> is <user>'s description, as well as contact info. +# PKG_HOME.<user> is the home directory for <user>. +# PKG_SHELL.<user> is the login shell for <user>. +# +# +# PKG_GROUPS represents the groups to create for the package. It is a +# space-separated list of elements of the form +# +# group +# +# The following variables are optional and specify further details of +# the user accounts listed in PKG_GROUPS: +# +# PKG_GID.<group> is the hardcoded numeric GID for <group>. +# +# For example: +# +# PKG_GROUPS+= mail +# PKG_USERS+= courier:mail +# +# PKG_GECOS.courier= Courier authlib and mail user +# +# USERGROUP_PHASE is set to the phase just before which users and +# groups need to be created. Valid values are "configure" and +# "build". If not defined, then by default users and groups +# are created prior to installation by the pre-install-script +# target. If this is defined, then the numeric UIDs and GIDs +# of users and groups required by this package are hardcoded +# into the +INSTALL script. +# +PKG_GROUPS?= # empty +PKG_USERS?= # empty +_PKG_USER_HOME?= /nonexistent +_PKG_USER_SHELL?= ${NOLOGIN} +FILES_SUBST+= PKG_USER_HOME=${_PKG_USER_HOME:Q} +FILES_SUBST+= PKG_USER_SHELL=${_PKG_USER_SHELL:Q} + +# Interix is very special in that users are groups cannot have the +# same name. Interix.mk tries to work around this by overriding +# some specific package defaults. If we get here and there's still a +# conflict, add a breakage indicator to make sure the package won't +# compile without changing something. +# +.if !empty(OPSYS:MInterix) +. for user in ${PKG_USERS:C/\\\\//g:C/:.*//} +. if !empty(PKG_GROUPS:M${user}) +PKG_FAIL_REASON+= "User and group '${user}' cannot have the same name on Interix" +. endif +. endfor +.endif + +.if !empty(PKG_USERS) || !empty(PKG_GROUPS) +DEPENDS+= ${_USER_DEPENDS} +.endif + +_INSTALL_USERGROUP_FILE= ${_PKGINSTALL_DIR}/usergroup +.if exists(../../mk/pkginstall/usergroupfuncs.${OPSYS}) +_INSTALL_USERGROUPFUNCS_FILE?= ../../mk/pkginstall/usergroupfuncs.${OPSYS} +.else +_INSTALL_USERGROUPFUNCS_FILE?= ../../mk/pkginstall/usergroupfuncs +.endif +_INSTALL_USERGROUP_DATAFILE= ${_PKGINSTALL_DIR}/usergroup-data +_INSTALL_UNPACK_TMPL+= ${_INSTALL_USERGROUP_FILE} +_INSTALL_DATA_TMPL+= ${_INSTALL_USERGROUP_DATAFILE} + +.for _group_ in ${PKG_GROUPS} +. if defined(USERGROUP_PHASE) +# Determine the numeric GID of each group. +USE_TOOLS+= perl +PKG_GID.${_group_}_cmd= \ + if ${TEST} ! -x ${PERL5}; then ${ECHO} ""; exit 0; fi; \ + ${PERL5} -le 'print scalar getgrnam shift' ${_group_} +PKG_GID.${_group_}?= ${PKG_GID.${_group_}_cmd:sh:M*} +. endif +_PKG_GROUPS+= ${_group_}:${PKG_GID.${_group_}} +.endfor + +.for _entry_ in ${PKG_USERS} +. if defined(USERGROUP_PHASE) +# Determine the numeric UID of each user. +USE_TOOLS+= perl +PKG_UID.${_entry_:C/\:.*//}_cmd= \ + if ${TEST} ! -x ${PERL5}; then ${ECHO} ""; exit 0; fi; \ + ${PERL5} -le 'print scalar getpwnam shift' ${_entry_:C/\:.*//} +PKG_UID.${_entry_:C/\:.*//}?= ${PKG_UID.${_entry_:C/\:.*//}_cmd:sh:M*} +. endif +_PKG_USERS+= ${_user_::=${_entry_:C/\:.*//}}${_entry_}:${PKG_UID.${_user_}}:${PKG_GECOS.${_user_}:Q}:${PKG_HOME.${_user_}:Q}:${PKG_SHELL.${_user_}:Q} +.endfor + +${_INSTALL_USERGROUP_DATAFILE}: + ${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${.TARGET:H} + ${_PKG_SILENT}${_PKG_DEBUG}${RM} -f ${.TARGET} ${.TARGET}.tmp + ${_PKG_SILENT}${_PKG_DEBUG}${TOUCH} ${TOUCH_ARGS} ${.TARGET}.tmp + ${_PKG_SILENT}${_PKG_DEBUG} \ + set -- dummy ${_PKG_GROUPS:C/\:*$//}; shift; \ + exec 1>>${.TARGET}.tmp; \ + while ${TEST} $$# -gt 0; do \ + i="$$1"; shift; \ + ${ECHO} "# GROUP: $$i"; \ + done + ${_PKG_SILENT}${_PKG_DEBUG} \ + set -- dummy ${_PKG_USERS:C/\:*$//}; shift; \ + exec 1>>${.TARGET}.tmp; \ + while ${TEST} $$# -gt 0; do \ + i="$$1"; shift; \ + ${ECHO} "# USER: $$i"; \ + done + ${_PKG_SILENT}${_PKG_DEBUG}${MV} -f ${.TARGET}.tmp ${.TARGET} + +${_INSTALL_USERGROUP_FILE}: ${_INSTALL_USERGROUP_DATAFILE} +${_INSTALL_USERGROUP_FILE}: \ + ../../mk/pkginstall/usergroup \ + ${INSTALL_USERGROUPFUNCS_FILE} + ${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${.TARGET:H} + ${_PKG_SILENT}${_PKG_DEBUG} \ + ${SED} -e "/^# platform-specific adduser\/addgroup functions/r${_INSTALL_USERGROUPFUNCS_FILE}" ../../mk/pkginstall/usergroup | \ + ${SED} ${FILES_SUBST_SED} > ${.TARGET} + ${_PKG_SILENT}${_PKG_DEBUG} \ + if ${_ZERO_FILESIZE_P} ${_INSTALL_USERGROUP_DATAFILE}; then \ + ${RM} -f ${.TARGET}; \ + ${TOUCH} ${TOUCH_ARGS} ${.TARGET}; \ + fi + +_INSTALL_USERGROUP_UNPACKER= ${_PKGINSTALL_DIR}/usergroup-unpack + +${_INSTALL_USERGROUP_UNPACKER}: \ + ${_INSTALL_USERGROUP_FILE} \ + ${_INSTALL_USERGROUP_DATAFILE} + ${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${.TARGET:H} + ${_PKG_SILENT}${_PKG_DEBUG} \ + exec 1>${.TARGET}.tmp; \ + ${ECHO} "#!${SH}"; \ + ${ECHO} ""; \ + ${ECHO} "CAT="${CAT:Q}; \ + ${ECHO} "CHMOD="${CHMOD:Q}; \ + ${ECHO} "SED="${SED:Q}; \ + ${ECHO} ""; \ + ${ECHO} "SELF=\$$0"; \ + ${ECHO} "STAGE=UNPACK"; \ + ${ECHO} ""; \ + ${CAT} ${_INSTALL_USERGROUP_FILE} \ + ${_INSTALL_USERGROUP_DATAFILE} + ${_PKG_SILENT}${_PKG_DEBUG}${MV} -f ${.TARGET}.tmp ${.TARGET} + ${_PKG_SILENT}${_PKG_DEBUG}${CHMOD} +x ${.TARGET} + +.if defined(USERGROUP_PHASE) +. if !empty(USERGROUP_PHASE:M*configure) +pre-configure: do-su-create-usergroup +. elif !empty(USERGROUP_PHASE:M*build) +pre-build: do-su-create-usergroup +. endif +.endif + +_INSTALL_USERGROUP_CHECK= \ + ${SETENV} PERL5=${PERL5:Q} \ + ${SH} ${PKGSRCDIR}/mk/pkginstall/usergroup-check + +.PHONY: do-su-create-usergroup +do-su-create-usergroup: + @${ECHO_MSG} "${_PKGSRC_IN}> Requiring users and groups for ${PKGNAME}" + ${_PKG_SILENT}${_PKG_DEBUG} \ + if ${_INSTALL_USERGROUP_CHECK} -g ${_PKG_GROUPS:C/\:*$//} && \ + ${_INSTALL_USERGROUP_CHECK} -u ${_PKG_USERS:C/\:*$//}; then \ + exit 0; \ + fi; \ + realtarget="create-usergroup"; \ + action="create-usergroup"; \ + ${_SU_TARGET} + +.PHONY: create-usergroup +create-usergroup: ${_INSTALL_USERGROUP_UNPACKER} + ${_PKG_SILENT}${_PKG_DEBUG} \ + cd ${_PKGINSTALL_DIR} && \ + ${SH} ${_INSTALL_USERGROUP_UNPACKER}; \ + exitcode=1; \ + if ${TEST} -f ./+USERGROUP && \ + ./+USERGROUP ADD ${_PKG_DBDIR}/${PKGNAME} && \ + ./+USERGROUP CHECK-ADD ${_PKG_DBDIR}/${PKGNAME}; then \ + exitcode=0; \ + fi; \ + ${RM} -f ${_INSTALL_USERGROUP_FILE:Q} \ + ${_INSTALL_USERGROUP_DATAFILE:Q} \ + ${_INSTALL_USERGROUP_UNPACKER:Q} \ + ./+USERGROUP; \ + exit $$exitcode + +# SPECIAL_PERMS are lists that look like: +# file user group mode +# At post-install time, file (it may be a directory) is changed to be +# owned by user:group with mode permissions. If a file pathname +# is relative, then it is taken to be relative to ${PREFIX}. +# +# SPECIAL_PERMS should be used primarily to change permissions of files or +# directories listed in the PLIST. This may be used to make certain files +# set-uid or to change the ownership or a directory. +# +# SETUID_ROOT_PERMS is a convenience definition to note an executable is +# meant to be setuid-root, and should be used as follows: +# +# SPECIAL_PERMS+= /path/to/suidroot ${SETUID_ROOT_PERMS} +# +SPECIAL_PERMS?= # empty +SETUID_ROOT_PERMS?= ${ROOT_USER} ${ROOT_GROUP} 4711 + +_INSTALL_PERMS_FILE= ${_PKGINSTALL_DIR}/perms +_INSTALL_PERMS_DATAFILE= ${_PKGINSTALL_DIR}/perms-data +_INSTALL_UNPACK_TMPL+= ${_INSTALL_PERMS_FILE} +_INSTALL_DATA_TMPL+= ${_INSTALL_PERMS_DATAFILE} + +${_INSTALL_PERMS_DATAFILE}: + ${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${.TARGET:H} + ${_PKG_SILENT}${_PKG_DEBUG}${RM} -f ${.TARGET} ${.TARGET}.tmp + ${_PKG_SILENT}${_PKG_DEBUG}${TOUCH} ${TOUCH_ARGS} ${.TARGET}.tmp + ${_PKG_SILENT}${_PKG_DEBUG}${_FUNC_STRIP_PREFIX}; \ + set -- dummy ${SPECIAL_PERMS}; shift; \ + exec 1>>${.TARGET}.tmp; \ + while ${TEST} $$# -gt 0; do \ + file="$$1"; owner="$$2"; group="$$3"; mode="$$4"; \ + shift; shift; shift; shift; \ + file=`strip_prefix "$$file"`; \ + ${ECHO} "# PERMS: $$file $$mode $$owner $$group"; \ + done + ${_PKG_SILENT}${_PKG_DEBUG}${MV} -f ${.TARGET}.tmp ${.TARGET} + +${_INSTALL_PERMS_FILE}: ${_INSTALL_PERMS_DATAFILE} +${_INSTALL_PERMS_FILE}: ../../mk/pkginstall/perms + ${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${.TARGET:H} + ${_PKG_SILENT}${_PKG_DEBUG} \ + ${SED} ${FILES_SUBST_SED} ../../mk/pkginstall/perms > ${.TARGET} + ${_PKG_SILENT}${_PKG_DEBUG} \ + if ${_ZERO_FILESIZE_P} ${_INSTALL_PERMS_DATAFILE}; then \ + ${RM} -f ${.TARGET}; \ + ${TOUCH} ${TOUCH_ARGS} ${.TARGET}; \ + fi + +# 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. REQD_FILES is the same as CONF_FILES but the value +# of PKG_CONFIG is ignored; however, all files listed in REQD_FILES +# should be under ${PREFIX}. +# +# CONF_FILES_MODE and REQD_FILES_MODE are the file permissions for the +# files in CONF_FILES and REQD_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. REQD_FILES_PERMS is the same +# as CONF_FILES_PERMS but the value of PKG_CONFIG is ignored; +# however, all files listed in REQD_FILES_PERMS should be under +# ${PREFIX}. +# +# RCD_SCRIPTS works lists the basenames of the rc.d scripts. They are +# expected to be found in ${PREFIX}/share/examples/rc.d, and +# the scripts will be copied into ${RCD_SCRIPTS_DIR} with +# ${RCD_SCRIPTS_MODE} permissions. +# +# If any file pathnames are relative, then they are taken to be relative +# to ${PREFIX}. +# +CONF_FILES?= # empty +CONF_FILES_MODE?= 0644 +CONF_FILES_PERMS?= # empty +RCD_SCRIPTS?= # empty +RCD_SCRIPTS_MODE?= 0755 +RCD_SCRIPTS_EXAMPLEDIR= share/examples/rc.d +RCD_SCRIPTS_SHELL?= ${SH} +FILES_SUBST+= RCD_SCRIPTS_SHELL=${RCD_SCRIPTS_SHELL:Q} +MESSAGE_SUBST+= RCD_SCRIPTS_DIR=${RCD_SCRIPTS_DIR} +MESSAGE_SUBST+= RCD_SCRIPTS_EXAMPLEDIR=${RCD_SCRIPTS_EXAMPLEDIR} + +_INSTALL_FILES_FILE= ${_PKGINSTALL_DIR}/files +_INSTALL_FILES_DATAFILE= ${_PKGINSTALL_DIR}/files-data +_INSTALL_UNPACK_TMPL+= ${_INSTALL_FILES_FILE} +_INSTALL_DATA_TMPL+= ${_INSTALL_FILES_DATAFILE} + +${_INSTALL_FILES_DATAFILE}: + ${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${.TARGET:H} + ${_PKG_SILENT}${_PKG_DEBUG}${RM} -f ${.TARGET} ${.TARGET}.tmp + ${_PKG_SILENT}${_PKG_DEBUG}${TOUCH} ${TOUCH_ARGS} ${.TARGET}.tmp + ${_PKG_SILENT}${_PKG_DEBUG}${_FUNC_STRIP_PREFIX}; \ + set -- dummy ${RCD_SCRIPTS}; shift; \ + exec 1>>${.TARGET}.tmp; \ + while ${TEST} $$# -gt 0; do \ + script="$$1"; shift; \ + file="${RCD_SCRIPTS_DIR:S/^${PREFIX}\///}/$$script"; \ + egfile="${RCD_SCRIPTS_EXAMPLEDIR}/$$script"; \ + ${ECHO} "# FILE: $$file cr $$egfile ${RCD_SCRIPTS_MODE}"; \ + done + ${_PKG_SILENT}${_PKG_DEBUG}${_FUNC_STRIP_PREFIX}; \ + set -- dummy ${CONF_FILES}; shift; \ + exec 1>>${.TARGET}.tmp; \ + while ${TEST} $$# -gt 0; do \ + egfile="$$1"; file="$$2"; \ + shift; shift; \ + egfile=`strip_prefix "$$egfile"`; \ + file=`strip_prefix "$$file"`; \ + ${ECHO} "# FILE: $$file c $$egfile ${CONF_FILES_MODE}"; \ + done + ${_PKG_SILENT}${_PKG_DEBUG}${_FUNC_STRIP_PREFIX}; \ + set -- dummy ${REQD_FILES}; shift; \ + exec 1>>${.TARGET}.tmp; \ + while ${TEST} $$# -gt 0; do \ + egfile="$$1"; file="$$2"; \ + shift; shift; \ + egfile=`strip_prefix "$$egfile"`; \ + file=`strip_prefix "$$file"`; \ + ${ECHO} "# FILE: $$file cf $$egfile ${REQD_FILES_MODE}"; \ + done + ${_PKG_SILENT}${_PKG_DEBUG}${_FUNC_STRIP_PREFIX}; \ + set -- dummy ${CONF_FILES_PERMS}; shift; \ + exec 1>>${.TARGET}.tmp; \ + while ${TEST} $$# -gt 0; do \ + egfile="$$1"; file="$$2"; \ + owner="$$3"; group="$$4"; mode="$$5"; \ + shift; shift; shift; shift; shift; \ + egfile=`strip_prefix "$$egfile"`; \ + file=`strip_prefix "$$file"`; \ + ${ECHO} "# FILE: $$file c $$egfile $$mode $$owner $$group"; \ + done + ${_PKG_SILENT}${_PKG_DEBUG}${_FUNC_STRIP_PREFIX}; \ + set -- dummy ${REQD_FILES_PERMS}; shift; \ + exec 1>>${.TARGET}.tmp; \ + while ${TEST} $$# -gt 0; do \ + egfile="$$1"; file="$$2"; \ + owner="$$3"; group="$$4"; mode="$$5"; \ + shift; shift; shift; shift; shift; \ + egfile=`strip_prefix "$$egfile"`; \ + file=`strip_prefix "$$file"`; \ + ${ECHO} "# FILE: $$file cf $$egfile $$mode $$owner $$group"; \ + done + ${_PKG_SILENT}${_PKG_DEBUG}${MV} -f ${.TARGET}.tmp ${.TARGET} + +${_INSTALL_FILES_FILE}: ${_INSTALL_FILES_DATAFILE} +${_INSTALL_FILES_FILE}: ../../mk/pkginstall/files + ${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${.TARGET:H} + ${_PKG_SILENT}${_PKG_DEBUG} \ + ${SED} ${FILES_SUBST_SED} ../../mk/pkginstall/files > ${.TARGET} + ${_PKG_SILENT}${_PKG_DEBUG} \ + if ${_ZERO_FILESIZE_P} ${_INSTALL_FILES_DATAFILE}; then \ + ${RM} -f ${.TARGET}; \ + ${TOUCH} ${TOUCH_ARGS} ${.TARGET}; \ + fi + +# 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. REQD_DIRS is like MAKE_DIRS but the value of PKG_CONFIG +# is ignored; however, all directories listed in REQD_DIRS should +# be under ${PREFIX}. +# +# 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. +# REQD_DIRS_PERMS is like MAKE_DIRS but the value of PKG_CONFIG is +# ignored; however, all directories listed in REQD_DIRS should be +# under ${PREFIX}. +# +# If any directory pathnames are relative, then they are taken to be +# relative to ${PREFIX}. +# +MAKE_DIRS?= # empty +MAKE_DIRS_PERMS?= # empty +REQD_DIRS?= # empty +REQD_DIRS_PERMS?= # empty +OWN_DIRS?= # empty +OWN_DIRS_PERMS?= # empty + +_INSTALL_DIRS_FILE= ${_PKGINSTALL_DIR}/dirs +_INSTALL_DIRS_DATAFILE= ${_PKGINSTALL_DIR}/dirs-data +_INSTALL_UNPACK_TMPL+= ${_INSTALL_DIRS_FILE} +_INSTALL_DATA_TMPL+= ${_INSTALL_DIRS_DATAFILE} + +${_INSTALL_DIRS_DATAFILE}: + ${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${.TARGET:H} + ${_PKG_SILENT}${_PKG_DEBUG}${RM} -f ${.TARGET} ${.TARGET}.tmp + ${_PKG_SILENT}${_PKG_DEBUG}${TOUCH} ${TOUCH_ARGS} ${.TARGET}.tmp + ${_PKG_SILENT}${_PKG_DEBUG}${_FUNC_STRIP_PREFIX}; \ + exec 1>>${.TARGET}.tmp; \ + case ${PKG_SYSCONFSUBDIR:M*:Q}${CONF_FILES:M*:Q}${CONF_FILES_PERMS:M*:Q}"" in \ + "") ;; \ + *) case ${PKG_SYSCONFSUBDIR:M*:Q}"" in \ + "") ${ECHO} "# DIR: ${PKG_SYSCONFDIR:S/${PREFIX}\///} m" ;; \ + *) set -- dummy ${PKG_SYSCONFDIR} ${PKG_SYSCONFDIR_PERMS}; shift; \ + while ${TEST} $$# -gt 0; do \ + dir="$$1"; owner="$$2"; \ + group="$$3"; mode="$$4"; \ + shift; shift; shift; shift; \ + dir=`strip_prefix "$$dir"`; \ + ${ECHO} "# DIR: $$dir m $$mode $$owner $$group"; \ + done; \ + ;; \ + esac; \ + ;; \ + esac + ${_PKG_SILENT}${_PKG_DEBUG} \ + exec 1>>${.TARGET}.tmp; \ + case ${RCD_SCRIPTS:M*:Q}"" in \ + "") ;; \ + *) ${ECHO} "# DIR: ${RCD_SCRIPTS_DIR:S/${PREFIX}\///} m" ;; \ + esac + ${_PKG_SILENT}${_PKG_DEBUG}${_FUNC_STRIP_PREFIX}; \ + set -- dummy ${MAKE_DIRS}; shift; \ + exec 1>>${.TARGET}.tmp; \ + while ${TEST} $$# -gt 0; do \ + dir="$$1"; shift; \ + dir=`strip_prefix "$$dir"`; \ + ${ECHO} "# DIR: $$dir m"; \ + done + ${_PKG_SILENT}${_PKG_DEBUG}${_FUNC_STRIP_PREFIX}; \ + set -- dummy ${REQD_DIRS}; shift; \ + exec 1>>${.TARGET}.tmp; \ + while ${TEST} $$# -gt 0; do \ + dir="$$1"; shift; \ + dir=`strip_prefix "$$dir"`; \ + ${ECHO} "# DIR: $$dir fm"; \ + done + ${_PKG_SILENT}${_PKG_DEBUG}${_FUNC_STRIP_PREFIX}; \ + set -- dummy ${OWN_DIRS}; shift; \ + exec 1>>${.TARGET}.tmp; \ + while ${TEST} $$# -gt 0; do \ + dir="$$1"; shift; \ + dir=`strip_prefix "$$dir"`; \ + ${ECHO} "# DIR: $$dir mo"; \ + done + ${_PKG_SILENT}${_PKG_DEBUG}${_FUNC_STRIP_PREFIX}; \ + set -- dummy ${MAKE_DIRS_PERMS}; shift; \ + exec 1>>${.TARGET}.tmp; \ + while ${TEST} $$# -gt 0; do \ + dir="$$1"; owner="$$2"; group="$$3"; mode="$$4"; \ + shift; shift; shift; shift; \ + dir=`strip_prefix "$$dir"`; \ + ${ECHO} "# DIR: $$dir m $$mode $$owner $$group"; \ + done + ${_PKG_SILENT}${_PKG_DEBUG}${_FUNC_STRIP_PREFIX}; \ + set -- dummy ${REQD_DIRS_PERMS}; shift; \ + exec 1>>${.TARGET}.tmp; \ + while ${TEST} $$# -gt 0; do \ + dir="$$1"; owner="$$2"; group="$$3"; mode="$$4"; \ + shift; shift; shift; shift; \ + dir=`strip_prefix "$$dir"`; \ + ${ECHO} "# DIR: $$dir fm $$mode $$owner $$group"; \ + done + ${_PKG_SILENT}${_PKG_DEBUG}${_FUNC_STRIP_PREFIX}; \ + set -- dummy ${OWN_DIRS_PERMS}; shift; \ + exec 1>>${.TARGET}.tmp; \ + while ${TEST} $$# -gt 0; do \ + dir="$$1"; owner="$$2"; group="$$3"; mode="$$4"; \ + shift; shift; shift; shift; \ + dir=`strip_prefix "$$dir"`; \ + ${ECHO} "# DIR: $$dir mo $$mode $$owner $$group"; \ + done + ${_PKG_SILENT}${_PKG_DEBUG}${MV} -f ${.TARGET}.tmp ${.TARGET} + +${_INSTALL_DIRS_FILE}: ${_INSTALL_DIRS_DATAFILE} +${_INSTALL_DIRS_FILE}: ../../mk/pkginstall/dirs + ${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${.TARGET:H} + ${_PKG_SILENT}${_PKG_DEBUG} \ + ${SED} ${FILES_SUBST_SED} ../../mk/pkginstall/dirs > ${.TARGET} + ${_PKG_SILENT}${_PKG_DEBUG} \ + if ${_ZERO_FILESIZE_P} ${_INSTALL_DIRS_DATAFILE}; then \ + ${RM} -f ${.TARGET}; \ + ${TOUCH} ${TOUCH_ARGS} ${.TARGET}; \ + fi + +# INFO_DIR, if defined, specifies the directory path containing the "dir" +# index file that should be updated. If the pathname is relative, +# then it is taken to be relative to ${PREFIX}. This shouldn't +# be needed unless "dir" is not in the same directory as the +# installed info files. +# +_INSTALL_INFO_FILES_FILE= ${_PKGINSTALL_DIR}/info-files +_INSTALL_INFO_FILES_DATAFILE= ${_PKGINSTALL_DIR}/info-files-data +_INSTALL_UNPACK_TMPL+= ${_INSTALL_INFO_FILES_FILE} +_INSTALL_DATA_TMPL+= ${_INSTALL_INFO_FILES_DATAFILE} + +.if defined(INFO_FILES) +USE_TOOLS+= install-info:run +FILES_SUBST+= INSTALL_INFO=${INSTALL_INFO:Q} +.endif + +${_INSTALL_INFO_FILES_DATAFILE}: + ${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${.TARGET:H} + ${_PKG_SILENT}${_PKG_DEBUG}${RM} -f ${.TARGET} + ${_PKG_SILENT}${_PKG_DEBUG}${TOUCH} ${TOUCH_ARGS} ${.TARGET} + +${_INSTALL_INFO_FILES_FILE}: ${_INSTALL_INFO_FILES_DATAFILE} +${_INSTALL_INFO_FILES_FILE}: ../../mk/pkginstall/info-files + ${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${.TARGET:H} + ${_PKG_SILENT}${_PKG_DEBUG} \ + ${SED} ${FILES_SUBST_SED} ../../mk/pkginstall/info-files > ${.TARGET} +.if !defined(INFO_FILES) + ${_PKG_SILENT}${_PKG_DEBUG} \ + if ${_ZERO_FILESIZE_P} ${_INSTALL_INFO_FILES_DATAFILE}; then \ + ${RM} -f ${.TARGET}; \ + ${TOUCH} ${TOUCH_ARGS} ${.TARGET}; \ + fi +.endif + +.PHONY: install-script-data-info-files +install-script-data: install-script-data-info-files +install-script-data-info-files: +.if defined(INFO_FILES) + ${_PKG_SILENT}${_PKG_DEBUG}${_FUNC_STRIP_PREFIX}; \ + if ${TEST} -x ${INSTALL_FILE}; then \ + ${INFO_FILES_cmd} | \ + while read file; do \ + infodir=${INFO_DIR:Q}; \ + infodir=`strip_prefix "$$infodir"`; \ + case "$$infodir" in \ + "") ${ECHO} "# INFO: $$file" \ + >> ${INSTALL_FILE} ;; \ + *) ${ECHO} "# INFO: $$file $$infodir" \ + >> ${INSTALL_FILE} ;; \ + esac; \ + done; \ + cd ${PKG_DB_TMPDIR} && ${SETENV} ${INSTALL_SCRIPTS_ENV} \ + ${_PKG_DEBUG_SCRIPT} ${INSTALL_FILE} ${PKGNAME} \ + UNPACK +INFO_FILES; \ + fi +.endif + +# PKG_SHELL contains the pathname of the shell that should be added or +# removed from the shell database, /etc/shells. If a pathname +# is relative, then it is taken to be relative to ${PREFIX}. +# +PKG_SHELL?= # empty + +_INSTALL_SHELL_FILE= ${_PKGINSTALL_DIR}/shell +_INSTALL_SHELL_DATAFILE= ${_PKGINSTALL_DIR}/shell-data +_INSTALL_UNPACK_TMPL+= ${_INSTALL_SHELL_FILE} +_INSTALL_DATA_TMPL+= ${_INSTALL_SHELL_DATAFILE} + +${_INSTALL_SHELL_DATAFILE}: + ${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${.TARGET:H} + ${_PKG_SILENT}${_PKG_DEBUG}${RM} -f ${.TARGET} ${.TARGET}.tmp + ${_PKG_SILENT}${_PKG_DEBUG}${TOUCH} ${TOUCH_ARGS} ${.TARGET}.tmp + ${_PKG_SILENT}${_PKG_DEBUG}${_FUNC_STRIP_PREFIX}; \ + set -- dummy ${PKG_SHELL}; shift; \ + exec 1>>${.TARGET}.tmp; \ + while ${TEST} $$# -gt 0; do \ + shell="$$1"; shift; \ + shell=`strip_prefix "$$shell"`; \ + ${ECHO} "# SHELL: $$shell"; \ + done + ${_PKG_SILENT}${_PKG_DEBUG}${MV} -f ${.TARGET}.tmp ${.TARGET} + +${_INSTALL_SHELL_FILE}: ${_INSTALL_SHELL_DATAFILE} +${_INSTALL_SHELL_FILE}: ../../mk/pkginstall/shell + ${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${.TARGET:H} + ${_PKG_SILENT}${_PKG_DEBUG} \ + ${SED} ${FILES_SUBST_SED} ../../mk/pkginstall/shell > ${.TARGET} + ${_PKG_SILENT}${_PKG_DEBUG} \ + if ${_ZERO_FILESIZE_P} ${_INSTALL_SHELL_DATAFILE}; then \ + ${RM} -f ${.TARGET}; \ + ${TOUCH} ${TOUCH_ARGS} ${.TARGET}; \ + fi + +# FONTS_DIRS.<type> are lists of directories in which the font databases +# are updated. If this is non-empty, then the appropriate tools is +# used to update the fonts database for the font type. The supported +# types are: +# +# ttf TrueType fonts +# type1 Type1 fonts +# x11 Generic X fonts, e.g. PCF, SNF, BDF, etc. +# +FONTS_DIRS.ttf?= # empty +FONTS_DIRS.type1?= # empty +FONTS_DIRS.x11?= # empty + +_INSTALL_FONTS_FILE= ${_PKGINSTALL_DIR}/fonts +_INSTALL_FONTS_DATAFILE= ${_PKGINSTALL_DIR}/fonts-data +_INSTALL_UNPACK_TMPL+= ${_INSTALL_FONTS_FILE} +_INSTALL_DATA_TMPL+= ${_INSTALL_FONTS_DATAFILE} + +# Directories with TTF and Type1 fonts also need to run mkfontdir, so +# list them as "x11" font directories as well. +# +.if !empty(FONTS_DIRS.ttf:M*) +USE_TOOLS+= ttmkfdir:run +FILES_SUBST+= TTMKFDIR=${TOOLS_PATH.ttmkfdir:Q} +FONTS_DIRS.x11+= ${FONTS_DIRS.ttf} +.endif +.if !empty(FONTS_DIRS.type1:M*) +USE_TOOLS+= type1inst:run +FILES_SUBST+= TYPE1INST=${TOOLS_PATH.type1inst:Q} +FONTS_DIRS.x11+= ${FONTS_DIRS.type1} +.endif +.if !empty(FONTS_DIRS.x11:M*) +USE_TOOLS+= mkfontdir:run +FILES_SUBST+= MKFONTDIR=${TOOLS_PATH.mkfontdir:Q} +.endif + +${_INSTALL_FONTS_DATAFILE}: + ${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${.TARGET:H} + ${_PKG_SILENT}${_PKG_DEBUG}${RM} -f ${.TARGET} ${.TARGET}.tmp + ${_PKG_SILENT}${_PKG_DEBUG}${TOUCH} ${TOUCH_ARGS} ${.TARGET}.tmp + ${_PKG_SILENT}${_PKG_DEBUG}${_FUNC_STRIP_PREFIX}; \ + set -- dummy ${FONTS_DIRS.ttf}; shift; \ + exec 1>>${.TARGET}.tmp; \ + while ${TEST} $$# -gt 0; do \ + dir="$$1"; shift; \ + dir=`strip_prefix "$$dir"`; \ + ${ECHO} "# FONTS: $$dir ttf"; \ + done + ${_PKG_SILENT}${_PKG_DEBUG}${_FUNC_STRIP_PREFIX}; \ + set -- dummy ${FONTS_DIRS.type1}; shift; \ + exec 1>>${.TARGET}.tmp; \ + while ${TEST} $$# -gt 0; do \ + dir="$$1"; shift; \ + dir=`strip_prefix "$$dir"`; \ + ${ECHO} "# FONTS: $$dir type1"; \ + done + ${_PKG_SILENT}${_PKG_DEBUG}${_FUNC_STRIP_PREFIX}; \ + set -- dummy ${FONTS_DIRS.x11}; shift; \ + exec 1>>${.TARGET}.tmp; \ + while ${TEST} $$# -gt 0; do \ + dir="$$1"; shift; \ + dir=`strip_prefix "$$dir"`; \ + ${ECHO} "# FONTS: $$dir x11"; \ + done + ${_PKG_SILENT}${_PKG_DEBUG}${MV} -f ${.TARGET}.tmp ${.TARGET} + +${_INSTALL_FONTS_FILE}: ${_INSTALL_FONTS_DATAFILE} +${_INSTALL_FONTS_FILE}: ../../mk/pkginstall/fonts + ${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${.TARGET:H} + ${_PKG_SILENT}${_PKG_DEBUG} \ + ${SED} ${FILES_SUBST_SED} ../../mk/pkginstall/fonts > ${.TARGET} + ${_PKG_SILENT}${_PKG_DEBUG} \ + if ${_ZERO_FILESIZE_P} ${_INSTALL_FONTS_DATAFILE}; then \ + ${RM} -f ${.TARGET}; \ + ${TOUCH} ${TOUCH_ARGS} ${.TARGET}; \ + fi + +# 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. +# +# PKG_CONFIG indicates whether the INSTALL/DEINSTALL scripts should do +# automatic config file and directory handling, or if it should +# merely inform the admin of the list of required files and +# directories needed to use the package. It is either YES or NO +# and defaults to YES. +# +# PKG_CONFIG_PERMS indicates whether to automatically correct permissions +# and ownership on pre-existing files and directories, or if it +# should merely inform the admin of the list of files and +# directories whose permissions and ownership need to be fixed. It +# is either YES or NO and defaults to NO. +# +# PKG_RCD_SCRIPTS indicates whether to automatically install rc.d scripts +# 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. +# +# PKG_UPDATE_FONTS_DB indicates whether to automatically update the fonts +# databases in directories where fonts have been installed or +# removed. 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_CONFIG_PERMS?= NO +PKG_RCD_SCRIPTS?= NO +PKG_REGISTER_SHELLS?= YES +PKG_UPDATE_FONTS_DB?= YES +FILES_SUBST+= PKG_CREATE_USERGROUP=${PKG_CREATE_USERGROUP:Q} +FILES_SUBST+= PKG_CONFIG=${PKG_CONFIG:Q} +FILES_SUBST+= PKG_CONFIG_PERMS=${PKG_CONFIG_PERMS:Q} +FILES_SUBST+= PKG_RCD_SCRIPTS=${PKG_RCD_SCRIPTS:Q} +FILES_SUBST+= PKG_REGISTER_SHELLS=${PKG_REGISTER_SHELLS:Q} +FILES_SUBST+= PKG_UPDATE_FONTS_DB=${PKG_UPDATE_FONTS_DB:Q} + +# Substitute for various programs used in the DEINSTALL/INSTALL scripts and +# in the rc.d 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+= ECHO_N=${ECHO_N:Q} +FILES_SUBST+= EGREP=${EGREP:Q} +FILES_SUBST+= EXPR=${EXPR:Q} +FILES_SUBST+= FALSE=${FALSE:Q} +FILES_SUBST+= FIND=${FIND:Q} +FILES_SUBST+= GREP=${GREP:Q} +FILES_SUBST+= GROUPADD=${GROUPADD:Q} +FILES_SUBST+= GTAR=${GTAR:Q} +FILES_SUBST+= HEAD=${HEAD:Q} +FILES_SUBST+= ID=${ID:Q} +FILES_SUBST+= INSTALL_INFO=${INSTALL_INFO:Q} +FILES_SUBST+= LINKFARM=${LINKFARM:Q} +FILES_SUBST+= LN=${LN:Q} +FILES_SUBST+= LS=${LS:Q} +FILES_SUBST+= MKDIR=${MKDIR:Q} +FILES_SUBST+= MV=${MV:Q} +FILES_SUBST+= PERL5=${PERL5:Q} +FILES_SUBST+= PKG_ADMIN=${PKG_ADMIN_CMD:Q} +FILES_SUBST+= PKG_INFO=${PKG_INFO_CMD:Q} +FILES_SUBST+= PW=${PW:Q} +FILES_SUBST+= PWD_CMD=${PWD_CMD:Q} +FILES_SUBST+= RM=${RM:Q} +FILES_SUBST+= RMDIR=${RMDIR:Q} +FILES_SUBST+= SED=${SED:Q} +FILES_SUBST+= SETENV=${SETENV:Q} +FILES_SUBST+= SH=${SH:Q} +FILES_SUBST+= SORT=${SORT:Q} +FILES_SUBST+= SU=${SU:Q} +FILES_SUBST+= TEST=${TEST:Q} +FILES_SUBST+= TOUCH=${TOUCH:Q} +FILES_SUBST+= TR=${TR:Q} +FILES_SUBST+= TRUE=${TRUE:Q} +FILES_SUBST+= USERADD=${USERADD:Q} +FILES_SUBST+= XARGS=${XARGS:Q} + +FILES_SUBST_SED= ${FILES_SUBST:S/=/@!/:S/$/!g/:S/^/ -e s!@/} + +PKG_REFCOUNT_DBDIR?= ${PKG_DBDIR}.refcount + +INSTALL_SCRIPTS_ENV= PKG_PREFIX=${PREFIX} +INSTALL_SCRIPTS_ENV+= PKG_METADATA_DIR=${_PKG_DBDIR}/${PKGNAME} +INSTALL_SCRIPTS_ENV+= PKG_REFCOUNT_DBDIR=${PKG_REFCOUNT_DBDIR} + +.PHONY: pre-install-script post-install-script + +DEINSTALL_FILE= ${PKG_DB_TMPDIR}/+DEINSTALL +INSTALL_FILE= ${PKG_DB_TMPDIR}/+INSTALL +_DEINSTALL_FILE= ${_PKGINSTALL_DIR}/DEINSTALL +_INSTALL_FILE= ${_PKGINSTALL_DIR}/INSTALL +_DEINSTALL_FILE_DFLT= ${_PKGINSTALL_DIR}/DEINSTALL.default +_INSTALL_FILE_DFLT= ${_PKGINSTALL_DIR}/INSTALL.default + +.PHONY: generate-install-scripts +generate-install-scripts: \ + ${_DEINSTALL_FILE} ${_INSTALL_FILE} \ + ${_DEINSTALL_FILE_DFLT} ${_INSTALL_FILE_DFLT} +.if !exists(${DEINSTALL_FILE}) || !exists(${INSTALL_FILE}) + ${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${INSTALL_FILE:H} + ${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${DEINSTALL_FILE:H} + ${_PKG_SILENT}${_PKG_DEBUG} \ + if ${CMP} -s ${_INSTALL_FILE_DFLT:Q} ${_INSTALL_FILE:Q}; then \ + ${TRUE}; \ + else \ + ${CP} -f ${_INSTALL_FILE} ${INSTALL_FILE}; \ + ${CP} -f ${_DEINSTALL_FILE} ${DEINSTALL_FILE}; \ + fi + ${_PKG_SILENT}${_PKG_DEBUG} \ + if ${CMP} -s ${_DEINSTALL_FILE_DFLT:Q} ${_DEINSTALL_FILE:Q}; then \ + ${TRUE}; \ + else \ + ${CP} -f ${_DEINSTALL_FILE} ${DEINSTALL_FILE}; \ + fi +.endif + +${_DEINSTALL_FILE_DFLT}: ${_DEINSTALL_TEMPLATES_DFLT} + ${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${.TARGET:H} + ${_PKG_SILENT}${_PKG_DEBUG}${CAT} ${.ALLSRC} | \ + ${SED} ${FILES_SUBST_SED} > ${.TARGET} + ${_PKG_SILENT}${_PKG_DEBUG}${CHMOD} +x ${.TARGET} + +${_INSTALL_FILE_DFLT}: ${_INSTALL_TEMPLATES_DFLT} + ${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${.TARGET:H} + ${_PKG_SILENT}${_PKG_DEBUG}${CAT} ${.ALLSRC} | \ + ${SED} ${FILES_SUBST_SED} > ${.TARGET} + ${_PKG_SILENT}${_PKG_DEBUG}${CHMOD} +x ${.TARGET} + +${_DEINSTALL_FILE}: ${DEINSTALL_SRC} + ${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${.TARGET:H} + ${_PKG_SILENT}${_PKG_DEBUG}${RM} -f ${.TARGET} ${.TARGET}.tmp + ${_PKG_SILENT}${_PKG_DEBUG}${TOUCH} ${TOUCH_ARGS} ${.TARGET}.tmp + ${_PKG_SILENT}${_PKG_DEBUG} \ + exec 1>>${.TARGET}.tmp; \ + case ${.ALLSRC:Q}"" in \ + "") ${ECHO} "#!${SH}" ; \ + ${ECHO} "exit 0" ;; \ + *) ${CAT} ${.ALLSRC} | ${SED} ${FILES_SUBST_SED} ;; \ + esac + ${_PKG_SILENT}${_PKG_DEBUG}${MV} -f ${.TARGET}.tmp ${.TARGET} + ${_PKG_SILENT}${_PKG_DEBUG}${CHMOD} +x ${.TARGET} + +${_INSTALL_FILE}: ${INSTALL_SRC} + ${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${.TARGET:H} + ${_PKG_SILENT}${_PKG_DEBUG}${RM} -f ${.TARGET} ${.TARGET}.tmp + ${_PKG_SILENT}${_PKG_DEBUG}${TOUCH} ${TOUCH_ARGS} ${.TARGET}.tmp + ${_PKG_SILENT}${_PKG_DEBUG} \ + exec 1>>${.TARGET}.tmp; \ + case ${.ALLSRC:Q}"" in \ + "") ${ECHO} "#!${SH}" ; \ + ${ECHO} "exit 0" ;; \ + *) ${CAT} ${.ALLSRC} | ${SED} ${FILES_SUBST_SED} ;; \ + esac + ${_PKG_SILENT}${_PKG_DEBUG}${MV} -f ${.TARGET}.tmp ${.TARGET} + ${_PKG_SILENT}${_PKG_DEBUG}${CHMOD} +x ${.TARGET} + +pre-install-script: + ${_PKG_SILENT}${_PKG_DEBUG} \ + if ${TEST} -x ${INSTALL_FILE}; then \ + cd ${PKG_DB_TMPDIR} && ${SETENV} ${INSTALL_SCRIPTS_ENV} \ + ${_PKG_DEBUG_SCRIPT} ${INSTALL_FILE} ${PKGNAME} \ + PRE-INSTALL; \ + fi + +post-install-script: + ${_PKG_SILENT}${_PKG_DEBUG} \ + if ${TEST} -x ${INSTALL_FILE}; then \ + cd ${PKG_DB_TMPDIR} && ${SETENV} ${INSTALL_SCRIPTS_ENV} \ + ${_PKG_DEBUG_SCRIPT} ${INSTALL_FILE} ${PKGNAME} \ + POST-INSTALL; \ + fi + +# rc.d scripts are automatically generated and installed into the rc.d +# scripts example directory at the post-install step. The following +# variables are relevent to this process: +# +# RCD_SCRIPTS lists the basenames of the rc.d scripts +# +# RCD_SCRIPT_SRC.<script> the source file for <script>; this will +# be run through FILES_SUBST to generate +# the rc.d script (defaults to +# ${FILESDIR}/<script>.sh) +# +# If the source rc.d script is not present, then the automatic handling +# doesn't occur. + +.PHONY: generate-rcd-scripts +generate-rcd-scripts: # do nothing + +.PHONY: install-rcd-scripts +post-install: install-rcd-scripts +install-rcd-scripts: # do nothing + +.for _script_ in ${RCD_SCRIPTS} +RCD_SCRIPT_SRC.${_script_}?= ${FILESDIR}/${_script_}.sh +RCD_SCRIPT_WRK.${_script_}?= ${WRKDIR}/${_script_} + +. if !empty(RCD_SCRIPT_SRC.${_script_}) +. if exists(${RCD_SCRIPT_SRC.${_script_}}) +generate-rcd-scripts: ${RCD_SCRIPT_WRK.${_script_}} +${RCD_SCRIPT_WRK.${_script_}}: ${RCD_SCRIPT_SRC.${_script_}} + @${ECHO_MSG} "${_PKGSRC_IN}> Creating ${.TARGET}" + ${_PKG_SILENT}${_PKG_DEBUG}${CAT} ${.ALLSRC} | \ + ${SED} ${FILES_SUBST_SED} > ${.TARGET} + ${_PKG_SILENT}${_PKG_DEBUG}${CHMOD} +x ${.TARGET} + +install-rcd-scripts: install-rcd-${_script_} +install-rcd-${_script_}: ${RCD_SCRIPT_WRK.${_script_}} + ${_PKG_SILENT}${_PKG_DEBUG} \ + if [ -f ${RCD_SCRIPT_WRK.${_script_}} ]; then \ + ${MKDIR} ${PREFIX}/${RCD_SCRIPTS_EXAMPLEDIR}; \ + ${INSTALL_SCRIPT} ${RCD_SCRIPT_WRK.${_script_}} \ + ${PREFIX}/${RCD_SCRIPTS_EXAMPLEDIR}/${_script_}; \ + fi +. endif +. endif +.endfor + +_PKGINSTALL_COOKIE= ${WRKDIR}/.pkginstall_done + +_PKGINSTALL_TARGETS+= _build +_PKGINSTALL_TARGETS+= acquire-pkginstall-lock +_PKGINSTALL_TARGETS+= ${_PKGINSTALL_COOKIE} +_PKGINSTALL_TARGETS+= release-pkginstall-lock + +.ORDER: ${_PKGINSTALL_TARGETS} + +.PHONY: pkginstall install-script-data +pkginstall: ${_PKGINSTALL_TARGETS} + +.PHONY: acquire-pkginstall-lock release-pkginstall-lock +acquire-pkginstall-lock: + ${_ACQUIRE_LOCK} +release-pkginstall-lock: + ${_RELEASE_LOCK} + +.PHONY: real-pkginstall +real-pkginstall: generate-rcd-scripts generate-install-scripts + ${_PKG_SILENT}${_PKG_DEBUG}${TOUCH} ${TOUCH_FLAGS} ${_PKGINSTALL_COOKIE} + +${_PKGINSTALL_COOKIE}: + ${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR} && ${MAKE} ${MAKEFLAGS} real-pkginstall PKG_PHASE=build diff --git a/mk/pkginstall/deinstall b/mk/pkginstall/deinstall new file mode 100644 index 00000000000..cb31eb8584a --- /dev/null +++ b/mk/pkginstall/deinstall @@ -0,0 +1,73 @@ +# $NetBSD: deinstall,v 1.1 2006/05/21 23:50:15 jlam Exp $ + +case ${STAGE} in +VIEW-DEINSTALL) + 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} + ;; + esac + ;; + esac + # + # Unregister info files. + # + ${TEST} ! -x ./+INFO_FILES || + ./+INFO_FILES REMOVE ${PKG_METADATA_DIR} + # + # Remove shells from /etc/shells. + # + ${TEST} ! -x ./+SHELL || + ./+SHELL REMOVE ${PKG_METADATA_DIR} + ${TEST} ! -x ./+SHELL || + ./+SHELL CHECK-REMOVE ${PKG_METADATA_DIR} + ;; + +DEINSTALL) + # Remove configuration files if they don't differ from the default + # config file. + # + ${TEST} ! -x ./+FILES || + ./+FILES REMOVE ${PKG_METADATA_DIR} + ;; + +POST-DEINSTALL) + if [ "${PKG_INSTALLATION_TYPE}" = "pkgviews" -a \ + "${_PKG_CONFIG}" = "yes" -a -n "${CONF_DEPENDS}" ]; then + if [ -h ${PKG_SYSCONFDIR} ]; then + ${RM} -f ${PKG_SYSCONFDIR} + fi + ${RMDIR} -p `${DIRNAME} ${PKG_SYSCONFDIR}` 2>/dev/null || ${TRUE} + fi + # + # Update any fonts databases. + # + ${TEST} ! -x ./+FONTS || + ./+FONTS ${PKG_METADATA_DIR} + # + # Remove empty directories and unused users/groups. + # + ${TEST} ! -x ./+DIRS || + ./+DIRS REMOVE ${PKG_METADATA_DIR} + ${TEST} ! -x ./+USERGROUP || + ./+USERGROUP 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 ./+DIRS || + ./+DIRS CHECK-REMOVE ${PKG_METADATA_DIR} + ;; +esac + diff --git a/mk/pkginstall/deinstall-pre b/mk/pkginstall/deinstall-pre new file mode 100644 index 00000000000..679374c7e13 --- /dev/null +++ b/mk/pkginstall/deinstall-pre @@ -0,0 +1,15 @@ +# $NetBSD: deinstall-pre,v 1.1 2006/05/21 23:50:15 jlam Exp $ + +# Ensure that the VIEW-DEINSTALL action is called for overwrite packages. +# This is here to ensure that it's the first DEINSTALL action (before +# any DEINSTALL_TEMPLATE DEINSTALL actions). +# +case ${STAGE} in +DEINSTALL) + if [ "${PKG_INSTALLATION_TYPE}" = "overwrite" ]; then + ${SETENV} PKG_PREFIX="${PKG_PREFIX}" \ + $0 ${PKGNAME} VIEW-DEINSTALL + fi + ;; +esac + diff --git a/mk/pkginstall/dirs b/mk/pkginstall/dirs new file mode 100644 index 00000000000..361060edade --- /dev/null +++ b/mk/pkginstall/dirs @@ -0,0 +1,374 @@ +# $NetBSD: dirs,v 1.1 2006/05/21 23:50:15 jlam Exp $ +# +# Generate a +DIRS script that reference counts directories that are +# required for the proper functioning of the package. +# +case "${STAGE},$1" in +UNPACK,|UNPACK,+DIRS) + ${CAT} > ./+DIRS << 'EOF' +#!@SH@ +# +# +DIRS - reference-counted directory management script +# +# Usage: ./+DIRS ADD|REMOVE|PERMS [metadatadir] +# ./+DIRS CHECK-ADD|CHECK-REMOVE|CHECK-PERMS [metadatadir] +# +# This script supports two actions, ADD and REMOVE, that will add or +# remove the directories needed by the package associated with +# <metadatadir>. The CHECK-ADD action will check whether any directories +# needed by the package are missing, and print an informative message +# noting those directories. The CHECK-REMOVE action will check whether +# any directories needed by the package still exist, and print an +# informative message noting those directories. The CHECK-ADD and +# CHECK-REMOVE actions return non-zero if they detect either missing +# or existing directories, respectively. The PERMS action will correct +# any ownership or permission discrepancies between the existing +# directories and the data in this script, and the CHECK-PERMS action +# will check whether any directories have the wrong ownership or +# permission and print an informative message noting those directories. +# The CHECK-PERMS action will return non-zero if it detects directories +# with wrong ownership or permissions. +# +# Lines starting with "# DIR: " are data read by this script that +# name the directories that this package requires to exist to function +# correctly, e.g. +# +# # DIR: /etc/foo m +# # DIR: /var/log/foo/tmp mo 0700 foo-user foo-group +# # DIR: share/foo-plugins fm +# +# For each DIR entry, if the directory path is relative, then it is taken +# to be relative to ${PKG_PREFIX}. +# +# The second field in each DIR entry is a set of flags with the following +# meanings: +# +# f ignore ${PKG_CONFIG} +# m create (make) the directory when ADDing +# o directory is owned by the package +# +AWK="@AWK@" +CAT="@CAT@" +CHGRP="@CHGRP@" +CHMOD="@CHMOD@" +CHOWN="@CHOWN@" +ECHO="@ECHO@" +GREP="@GREP@" +LS="@LS@" +MKDIR="@MKDIR@" +MV="@MV@" +PWD_CMD="@PWD_CMD@" +RM="@RM@" +RMDIR="@RMDIR@" +SED="@SED@" +SORT="@SORT@" +TEST="@TEST@" +TRUE="@TRUE@" + +SELF=$0 +ACTION=$1 +PKG_METADATA_DIR="${2-`${PWD_CMD}`}" +: ${PKGNAME=${PKG_METADATA_DIR##*/}} +: ${PKG_DBDIR=${PKG_METADATA_DIR%/*}} +: ${PKG_REFCOUNT_DBDIR=${PKG_DBDIR}.refcount} +: ${PKG_PREFIX=@PREFIX@} + +PKG_REFCOUNT_DIRS_DBDIR="${PKG_REFCOUNT_DBDIR}/dirs" + +case "${PKG_CONFIG:-@PKG_CONFIG@}" in +[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) + _PKG_CONFIG=yes + ;; +[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) + _PKG_CONFIG=no + ;; +esac +case "${PKG_CONFIG_PERMS:-@PKG_CONFIG_PERMS@}" in +[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) + _PKG_CONFIG_PERMS=yes + ;; +[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) + _PKG_CONFIG_PERMS=no + ;; +esac + +exitcode=0 +case $ACTION in +ADD) + ${SED} -n "/^\# DIR: /{s/^\# DIR: //;p;}" ${SELF} | ${SORT} -u | + while read dir d_flags d_mode d_user d_group; do + case $dir in + "") continue ;; + [!/]*) dir="${PKG_PREFIX}/$dir" ;; + esac + case $d_flags in + *m*) ;; + *) continue ;; + esac + shadow_dir="${PKG_REFCOUNT_DIRS_DBDIR}$dir" + perms="$shadow_dir/+PERMISSIONS" + preexist="$shadow_dir/+PREEXISTING" + token="$shadow_dir/${PKGNAME}" + if ${TEST} ! -d "$shadow_dir"; then + ${MKDIR} $shadow_dir + ${TEST} ! -d "$dir" || + ${ECHO} "${PKGNAME}" > $preexist + fi + if ${TEST} -f "$token" && \ + ${GREP} "^${PKG_METADATA_DIR}$" $token >/dev/null; then + : + else + ${ECHO} "${PKG_METADATA_DIR}" >> $token + fi + case $d_mode$d_user$d_group in + "") ;; + *) ${ECHO} "$d_user $d_group $d_mode" > $perms ;; + esac + case $d_flags:$_PKG_CONFIG in + *f*:*|*:yes) + ${MKDIR} $dir + case $d_user in + "") ;; + *) ${CHOWN} $d_user $dir ;; + esac + case $d_group in + "") ;; + *) ${CHGRP} $d_group $dir ;; + esac + case $d_mode in + "") ;; + *) ${CHMOD} $d_mode $dir ;; + esac + ;; + esac + done + ;; + +REMOVE) + ${SED} -n "/^\# DIR: /{s/^\# DIR: //;p;}" ${SELF} | ${SORT} -ru | + while read dir d_flags d_mode d_user d_group; do + case $dir in + "") continue ;; + [!/]*) dir="${PKG_PREFIX}/$dir" ;; + esac + case $d_flags in + *m*) ;; + *) continue ;; + esac + shadow_dir="${PKG_REFCOUNT_DIRS_DBDIR}$dir" + 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 + "") + ${TEST} -f "$preexist" || + { case $d_flags:$_PKG_CONFIG in + *f*:*|*:yes) + ${RMDIR} -p $dir 2>/dev/null || ${TRUE}; + ;; + esac; } + ${RM} -f $perms $preexist $token $token.tmp.* + ${RMDIR} -p $shadow_dir 2>/dev/null || ${TRUE} + ;; + *) + ${MV} -f $tokentmp $token + ;; + esac + fi + done + ;; + +PERMS) + ${SED} -n "/^\# DIR: /{s/^\# DIR: //;p;}" ${SELF} | ${SORT} -u | + while read dir d_flags d_mode d_user d_group; do + case $_PKG_CONFIG:$_PKG_CONFIG_PERMS in + yes:yes) ;; + *) continue ;; + esac + case $dir in + "") continue ;; + [!/]*) dir="${PKG_PREFIX}/$dir" ;; + esac + case $d_user in + "") ;; + *) ${CHOWN} $d_user $dir ;; + esac + case $d_group in + "") ;; + *) ${CHGRP} $d_group $dir ;; + esac + case $d_mode in + "") ;; + *) ${CHMOD} $d_mode $dir ;; + esac + done + ;; + +CHECK-ADD) + ${SED} -n "/^\# DIR: /{s/^\# DIR: //;p;}" ${SELF} | ${SORT} -u | + { while read dir d_flags d_mode d_user d_group; do + case $dir in + "") continue ;; + [!/]*) dir="${PKG_PREFIX}/$dir" ;; + esac + ${TEST} ! -d "$dir" || continue + case $d_flags in + *m*) ;; + *) continue ;; + esac + case "$printed_header" in + yes) ;; + *) printed_header=yes + ${ECHO} "===========================================================================" + ${ECHO} "The following directories should be created for ${PKGNAME}:" + ${ECHO} "" + ;; + esac + case $d_user:$d_group:$d_mode in + [!:]*:[!:]*:[!:]*) + ${ECHO} " $dir (m=$d_mode, o=$d_user, g=$d_group)" + ;; + *) + ${ECHO} " $dir" + ;; + esac + done + case "$printed_header" in + yes) ${ECHO} "" + ${ECHO} "===========================================================================" + exit 1 + ;; + esac; } + ${TEST} $? -eq 0 || exitcode=1 + ;; + +CHECK-REMOVE) + ${SED} -n "/^\# DIR: /{s/^\# DIR: //;p;}" ${SELF} | ${SORT} -ru | + { while read dir d_flags d_mode d_user d_group; do + case $dir in + "") continue ;; + [!/]*) dir="${PKG_PREFIX}/$dir" ;; + esac + ${TEST} -d "$dir" || continue + case $d_flags in + *o*) ;; + *) continue ;; + esac + shadow_dir="${PKG_REFCOUNT_DIRS_DBDIR}$dir" + ${TEST} ! -d "$shadow_dir" || continue # refcount isn't zero + case "$printed_header" in + yes) ;; + *) printed_header=yes + ${ECHO} "===========================================================================" + ${ECHO} "The following directories are no longer being used by ${PKGNAME}," + ${ECHO} "and they can be removed if no other packages are using them:" + ${ECHO} "" + ;; + esac + ${ECHO} " $dir" + done + case "$printed_header" in + yes) ${ECHO} "" + ${ECHO} "===========================================================================" + exit 1 + ;; + esac; } + ${TEST} $? -eq 0 || exitcode=1 + ;; + +CHECK-PERMS) + tmpdir="./.pkginstall.$$" + ${MKDIR} -p $tmpdir 2>/dev/null || exit 1 + ${CHMOD} 0700 $tmpdir + ${SED} -n "/^\# DIR: /{s/^\# DIR: //;p;}" ${SELF} | ${SORT} -ru | + { while read dir d_flags d_mode d_user d_group; do + case $dir in + "") continue ;; + [!/]*) dir="${PKG_PREFIX}/$dir" ;; + esac + ${TEST} -d "$dir" || continue + case $d_user:$d_group:$d_mode in + ::) continue ;; + esac + + perms=`${LS} -ld $dir | ${AWK} '{ print $1":"$3":"$4 }'` + testpath="$tmpdir/dir_perms" + ${MKDIR} -p $testpath + ${CHMOD} $d_mode $testpath 2>/dev/null + longmode=`${LS} -ld $testpath | ${AWK} '{ print $1 }'` + case $d_mode:$d_user:$d_group in + :[!:]*:) + case "$perms" in + *:$d_user:*) continue ;; + esac + ;; + :[!:]*:[!:]*) + case "$perms" in + *:$d_user:$d_group) continue ;; + esac + ;; + [!:]*::) + case "$perms" in + $longmode:*:*) continue ;; + esac + ;; + [!:]*:[!:]*:) + case "$perms" in + $longmode:$d_user:*) continue ;; + esac + ;; + [!:]*:[!:]*:[!:]*) + case "$perms" in + $longmode:$d_user:$d_group) continue ;; + esac + ;; + esac + + case "$printed_header" in + yes) ;; + *) printed_header=yes + ${ECHO} "===========================================================================" + ${ECHO} "The following directories are used by ${PKGNAME} and" + ${ECHO} "have the wrong ownership and/or permissions:" + ${ECHO} "" + ;; + esac + case $d_mode:$d_user:$d_group in + [!:]*::) + ${ECHO} " $dir (m=$d_mode)" + ;; + [!:]*:[!:]*:) + ${ECHO} " $dir (m=$d_mode, o=$d_user)" + ;; + [!:]*:[!:]*:[!:]*) + ${ECHO} " $dir (m=$d_mode, o=$d_user, g=$d_group)" + ;; + esac + done + case "$printed_header" in + yes) ${ECHO} "" + ${ECHO} "===========================================================================" + exit 1 + ;; + esac; } + ${RM} -fr $tmpdir + ${TEST} $? -eq 0 || exitcode=1 + ;; + +*) + ${ECHO} "Usage: ./+DIRS ADD|REMOVE|PERMS [metadatadir]" + ${ECHO} " ./+DIRS CHECK-ADD|CHECK-REMOVE|CHECK-PERMS [metadatadir]" + ;; +esac +exit $exitcode + +EOF + ${SED} -n "/^\# DIR: /p" ${SELF} >> ./+DIRS + ${CHMOD} +x ./+DIRS + ;; +esac + diff --git a/mk/pkginstall/files b/mk/pkginstall/files new file mode 100644 index 00000000000..aad8bb1062a --- /dev/null +++ b/mk/pkginstall/files @@ -0,0 +1,459 @@ +# $NetBSD: files,v 1.1 2006/05/21 23:50:15 jlam Exp $ +# +# Generate a +FILES script that reference counts config files that are +# required for the proper functioning of the package. +# +case "${STAGE},$1" in +UNPACK,|UNPACK,+FILES) + ${CAT} > ./+FILES << 'EOF' +#!@SH@ +# +# +FILES - reference-counted configuration file management script +# +# Usage: ./+FILES ADD|REMOVE|PERMS [metadatadir] +# ./+FILES VIEW-REMOVE depotdir viewdir +# ./+FILES CHECK-ADD|CHECK-REMOVE|CHECK-PERMS [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>. The PERMS action +# will correct any ownership or permission discrepancies between the +# existing files and the data in this script, and the CHECK-PERMS +# action will check whether any files have the wrong ownership or +# permission and print an informative message noting those files. The +# CHECK-PERMS action will return non-zero if it detects files with +# wrong ownership or permissions. +# +# 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 +# +# For each FILE entry, if the file path is relative, then it is taken to +# be relative to ${PKG_PREFIX}. +# +# The second field in each FILE entry is a set of flags with the following +# meaning: +# +# c file is copied into place +# f ignore ${PKG_CONFIG} +# r file is an rc.d script (consider ${PKG_RCD_SCRIPTS}) +# +AWK="@AWK@" +CAT="@CAT@" +CP="@CP@" +CHGRP="@CHGRP@" +CHMOD="@CHMOD@" +CHOWN="@CHOWN@" +CMP="@CMP@" +ECHO="@ECHO@" +GREP="@GREP@" +LS="@LS@" +MKDIR="@MKDIR@" +MV="@MV@" +PWD_CMD="@PWD_CMD@" +RM="@RM@" +RMDIR="@RMDIR@" +SED="@SED@" +SORT="@SORT@" +TEST="@TEST@" +TRUE="@TRUE@" + +SELF=$0 +ACTION=$1 + +: ${PKG_PREFIX=@PREFIX@} + +case "${PKG_CONFIG:-@PKG_CONFIG@}" in +[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) + _PKG_CONFIG=yes + ;; +[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) + _PKG_CONFIG=no + ;; +esac +case "${PKG_CONFIG_PERMS:-@PKG_CONFIG_PERMS@}" in +[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) + _PKG_CONFIG_PERMS=yes + ;; +[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) + _PKG_CONFIG_PERMS=no + ;; +esac +case "${PKG_RCD_SCRIPTS:-@PKG_RCD_SCRIPTS@}" in +[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) + _PKG_RCD_SCRIPTS=yes + ;; +[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) + _PKG_RCD_SCRIPTS=no + ;; +esac + +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 ;; + [!/]*) file="${PKG_PREFIX}/$file" ;; + esac + case $f_flags in + *c*) ;; + *) continue ;; + esac + case $f_eg in + "") continue ;; + [!/]*) f_eg="${PKG_PREFIX}/$f_eg" ;; + 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 "$f_flags:$_PKG_CONFIG:$_PKG_RCD_SCRIPTS" in + *f*:*:*|[!r]:yes:*|[!r][!r]:yes:*|[!r][!r][!r]:yes:*|*r*:yes:yes) + 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_user in + "") ;; + *) ${CHOWN} $f_user $file ;; + esac + case $f_group in + "") ;; + *) ${CHGRP} $f_group $file ;; + esac + case $f_mode in + "") ;; + *) ${CHMOD} $f_mode $file ;; + esac + fi + ;; + esac + 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 ;; + [!/]*) file="${PKG_PREFIX}/$file" ;; + esac + case $f_flags in + *c*) ;; + *) continue ;; + esac + case $f_eg in + "") continue ;; + [!/]*) f_eg="${PKG_PREFIX}/$f_eg" ;; + 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" && \ + ${CMP} -s "$file" "$f_eg"; then + case "$f_flags:$_PKG_CONFIG:$_PKG_RCD_SCRIPTS" in + *f*:*:*|[!r]:yes:*|[!r][!r]:yes:*|[!r][!r][!r]:yes:*|*r*:yes:yes) + ${RM} -f "$file" + ;; + esac + fi + ${RM} -f $perms $preexist $token $token.tmp.* + ${RMDIR} -p $shadow_dir 2>/dev/null || ${TRUE} + ;; + *) + ${MV} -f $tokentmp $token + ;; + esac + fi + done + ;; + +PERMS) + ${SED} -n "/^\# FILE: /{s/^\# FILE: //;p;}" ${SELF} | ${SORT} -ru | + while read file f_flags f_eg f_mode f_user f_group; do + case $_PKG_CONFIG:$_PKG_CONFIG_PERMS in + yes:yes) ;; + *) continue ;; + esac + case $file in + "") continue ;; + [!/]*) file="${PKG_PREFIX}/$file" ;; + esac + case $f_user in + "") ;; + *) ${CHOWN} $f_user $file ;; + esac + case $f_group in + "") ;; + *) ${CHGRP} $f_group $file ;; + esac + case $f_mode in + "") ;; + *) ${CHMOD} $f_mode $file ;; + esac + 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}/*) link="${VIEWDIR}/${file#${DEPOTDIR}/}" ;; + [!/]*) link="${VIEWDIR}/$file" ;; + *) continue ;; + esac + 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 ;; + [!/]*) file="${PKG_PREFIX}/$file" ;; + esac + ${TEST} ! -f "$file" || continue + case $f_flags in + *c*) ;; + *) continue ;; + esac + case $f_eg in + "") continue ;; + [!/]*) f_eg="${PKG_PREFIX}/$f_eg" ;; + 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 (m=$f_mode, o=$f_user)" + ;; + [!:]*:[!:]*:[!:]*) + ${ECHO} " $file (m=$f_mode, o=$f_user, g=$f_group)" + ;; + 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 ;; + [!/]*) file="${PKG_PREFIX}/$file" ;; + esac + ${TEST} -f "$file" || continue + 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 files 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 + ;; + +CHECK-PERMS) + tmpdir="./.pkginstall.$$" + ${MKDIR} -p $tmpdir 2>/dev/null || exit 1 + ${CHMOD} 0700 $tmpdir + ${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 ;; + [!/]*) file="${PKG_PREFIX}/$file" ;; + esac + ${TEST} -f "$file" || continue + case $f_mode:$f_user:$f_group in + ::) continue ;; + esac + + perms=`${LS} -l $file | ${AWK} '{ print $1":"$3":"$4 }'` + testpath="$tmpdir/file_perms" + ${ECHO} > $testpath + ${CHMOD} $f_mode $testpath 2>/dev/null + longmode=`${LS} -l $testpath | ${AWK} '{ print $1 }'` + case $f_mode:$f_user:$f_group in + :[!:]*:) + case "$perms" in + *:$f_user:*) continue ;; + esac + ;; + :[!:]*:[!:]*) + case "$perms" in + *:$f_user:$f_group) continue ;; + esac + ;; + [!:]*::) + case "$perms" in + $longmode:*:*) continue ;; + esac + ;; + [!:]*:[!:]*:) + case "$perms" in + $longmode:$f_user:*) continue ;; + esac + ;; + [!:]*:[!:]*:[!:]*) + case "$perms" in + $longmode:$f_user:$f_group) continue ;; + esac + ;; + esac + + case "$printed_header" in + yes) ;; + *) printed_header=yes + ${ECHO} "===========================================================================" + ${ECHO} "The following files are used by ${PKGNAME} and have" + ${ECHO} "the wrong ownership and/or permissions:" + ${ECHO} "" + ;; + esac + case $f_mode:$f_user:$f_group in + [!:]*::) + ${ECHO} " $file (m=$f_mode)" + ;; + [!:]*:[!:]*:) + ${ECHO} " $file (m=$f_mode, o=$f_user)" + ;; + [!:]*:[!:]*:[!:]*) + ${ECHO} " $file (m=$f_mode, o=$f_user, g=$f_group)" + ;; + esac + done + case "$printed_header" in + yes) ${ECHO} "" + ${ECHO} "===========================================================================" + exit 1 + ;; + esac; } + ${RM} -fr $tmpdir + ${TEST} $? -eq 0 || exitcode=1 + ;; + +*) + ${ECHO} "Usage: ./+FILES ADD|REMOVE|PERMS [metadatadir]" + ${ECHO} " ./+FILES VIEW-REMOVE depotdir viewdir" + ${ECHO} " ./+FILES CHECK-ADD|CHECK-REMOVE|CHECK-PERMS [metadatadir]" + ;; +esac +exit $exitcode + +EOF + ${SED} -n "/^\# FILE: /p" ${SELF} >> ./+FILES + ${CHMOD} +x ./+FILES + ;; +esac + diff --git a/mk/pkginstall/fonts b/mk/pkginstall/fonts new file mode 100644 index 00000000000..52c68387fa3 --- /dev/null +++ b/mk/pkginstall/fonts @@ -0,0 +1,101 @@ +# $NetBSD: fonts,v 1.1 2006/05/21 23:50:15 jlam Exp $ +# +# Generate a +FONTS script that updates font databases for the package. +# +case "${STAGE},$1" in +UNPACK,|UNPACK,+FONTS) + ${CAT} > ./+FONTS << 'EOF' +#!@SH@ +# +# +FONTS - font database management script +# +# Usage: ./+FONTS [metadatadir] +# +# This scripts rebuilds font databases needed by the package associated +# with <metadatadir>. +# +# Lines starting with "# FONTS: " are data read by this script that name +# the directories in which the font database will be rebuilt. +# +# # FONTS: /usr/pkg/lib/X11/fonts/TTF ttf +# # FONTS: /usr/pkg/lib/X11/fonts/Type1 type1 +# # FONTS: /usr/pkg/lib/X11/fonts/misc x11 +# +# For each FONTS entry, if the path is relative, that it is taken to be +# relative to ${PKG_PREFIX}. +# + +ECHO="@ECHO@" +FIND="@FIND@" +GREP="@GREP@" +MKFONTDIR="@MKFONTDIR@" +PWD_CMD="@PWD_CMD@" +RM="@RM@" +SED="@SED@" +SORT="@SORT@" +TEST="@TEST@" +TRUE="@TRUE@" +TTMKFDIR="@TTMKFDIR@" +TYPE1INST="@TYPE1INST@" + +SELF=$0 +PKG_METADATA_DIR="${1-`${PWD_CMD}`}" +: ${PKGNAME=${PKG_METADATA_DIR##*/}} +: ${PKG_PREFIX=@PREFIX@} + +case "${PKG_UPDATE_FONTS_DB:-@PKG_UPDATE_FONTS_DB@}" in +[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) + _PKG_UPDATE_FONTS_DB=yes + ;; +[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) + _PKG_UPDATE_FONTS_DB=no + ;; +esac + +${SED} -n "/^\# FONTS: /{s/^\# FONTS: //;p;}" ${SELF} | ${SORT} -u | +{ while read dir font_type; do + case ${_PKG_UPDATE_FONTS_DB} in + no) continue ;; + esac + case $dir in + "") continue ;; + [!/]*) dir="${PKG_PREFIX}/$dir" ;; + esac + ${TEST} -d "$dir" || continue + case "$printed_header" in + yes) ;; + *) printed_header=yes + ${ECHO} "===========================================================================" + ${ECHO} "Updating font databases in the following directories:" + ${ECHO} "" + ;; + esac + ( ${ECHO} " $dir ($font_type)" + cd $dir + case $font_type in + [tT][tT][fF]) update_cmd="${TTMKFDIR}" ;; + [tT][yY][pP][eE]1) update_cmd="${TYPE1INST}; ${RM} type1inst.log" ;; + [xX]11) update_cmd="${MKFONTDIR}" ;; + esac + ${TEST} -f "$update_cmd" || update_cmd="${TRUE}" + $update_cmd >/dev/null + # + # Remove fonts databases if there are no fonts in the directory. + # We filter out the encodings.dir, fonts.{alias,dirs,scale}, and + # Fontmap database files from the directory listing. + # + ${FIND} . -type f | ${GREP} -v "/encodings.dir" | ${GREP} -v "/fonts\." | ${GREP} -v "/Fontmap" >/dev/null || ${RM} -f fonts.* Fontmap* + ) +done +case "$printed_header" in +yes) ${ECHO} "" + ${ECHO} "===========================================================================" + ;; +esac; } + +EOF + ${SED} -n "/^\# FONTS: /p" ${SELF} >> ./+FONTS + ${CHMOD} +x ./+FONTS + ;; +esac + diff --git a/mk/pkginstall/footer b/mk/pkginstall/footer new file mode 100644 index 00000000000..4f9974ccf3e --- /dev/null +++ b/mk/pkginstall/footer @@ -0,0 +1,4 @@ +# $NetBSD: footer,v 1.1 2006/05/21 23:50:15 jlam Exp $ + +exit 0 + diff --git a/mk/pkginstall/header b/mk/pkginstall/header new file mode 100644 index 00000000000..47c91b7981e --- /dev/null +++ b/mk/pkginstall/header @@ -0,0 +1,86 @@ +#!@SH@ +# +# $NetBSD: header,v 1.1 2006/05/21 23:50:15 jlam Exp $ + +SELF="$0" +PKGNAME="$1" +STAGE="$2" +shift 2 + +AWK="@AWK@" +BASENAME="@BASENAME@" +CAT="@CAT@" +CHGRP="@CHGRP@" +CHMOD="@CHMOD@" +CHOWN="@CHOWN@" +CMP="@CMP@" +CP="@CP@" +DIRNAME="@DIRNAME@" +ECHO="@ECHO@" +ECHO_N="@ECHO_N@" +EGREP="@EGREP@" +EXPR="@EXPR@" +FALSE="@FALSE@" +FIND="@FIND@" +GREP="@GREP@" +GTAR="@GTAR@" +HEAD="@HEAD@" +ID="@ID@" +LINKFARM="@LINKFARM@" +LN="@LN@" +LS="@LS@" +MKDIR="@MKDIR@" +MV="@MV@" +PERL5="@PERL5@" +PKG_ADMIN="@PKG_ADMIN@" +PKG_INFO="@PKG_INFO@" +PWD_CMD="@PWD_CMD@" +RM="@RM@" +RMDIR="@RMDIR@" +SED="@SED@" +SETENV="@SETENV@" +SH="@SH@" +SORT="@SORT@" +SU="@SU@" +TEST="@TEST@" +TOUCH="@TOUCH@" +TR="@TR@" +TRUE="@TRUE@" +XARGS="@XARGS@" + +: ${PKG_METADATA_DIR=`${PWD_CMD}`} +PKGBASE="@PKGBASE@" + +LOCALBASE="@LOCALBASE@" +X11BASE="@X11BASE@" +DEPOTBASE="@DEPOTBASE@" +PREFIX="@PREFIX@" +case ${PKG_PREFIX} in +${LOCALBASE}/*) VIEW="${PKG_PREFIX#${LOCALBASE}/}" ;; +*) VIEW="" ;; +esac + +PKG_SYSCONFBASE="@PKG_SYSCONFBASE@" +PKG_SYSCONFDEPOTBASE="@PKG_SYSCONFDEPOTBASE@" +PKG_SYSCONFBASEDIR="@PKG_SYSCONFBASEDIR@" +PKG_SYSCONFDIR="@PKG_SYSCONFDIR@" +CONF_DEPENDS="@CONF_DEPENDS@" + +case ${VIEW} in +"") PKG_SYSCONFVIEWBASE="${PKG_SYSCONFBASE}" ;; +*) PKG_SYSCONFVIEWBASE="${PKG_SYSCONFBASE}/${VIEW}" ;; +esac + +CONF_IGNORE_FILES="*[~#] *.OLD *.orig *,v .pkgsrc */.pkgsrc" + +PKG_INSTALLATION_TYPE="@PKG_INSTALLATION_TYPE@" + +case "${PKG_CONFIG:-@PKG_CONFIG@}" in +[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) + _PKG_CONFIG=yes + ;; +[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) + _PKG_CONFIG=yes + ;; +esac + diff --git a/mk/pkginstall/info-files b/mk/pkginstall/info-files new file mode 100644 index 00000000000..ae68d087e11 --- /dev/null +++ b/mk/pkginstall/info-files @@ -0,0 +1,136 @@ +# $NetBSD: info-files,v 1.1 2006/05/21 23:50:15 jlam Exp $ +# +# Generate an +INFO_FILES script that handles info file registration for +# the package. +# +case "${STAGE},$1" in +UNPACK,|UNPACK,+INFO_FILES) + ${CAT} > ./+INFO_FILES << 'EOF' +#!@SH@ +# +# +INFO_FILES - info file registration management script +# +# Usage: ./+INFO_FILES ADD|REMOVE [metadatadir] +# +# This script supports two actions, ADD and REMOVE, that will add or +# remove entries for info files from the package associated with +# <metadatadir> from the info index files (the "dir" file in the +# same directory as the info files). +# +# Lines starting with "# INFO: " are data read by this script that +# name the info files and directory containing the "dir" index that will +# that will be updated. If the directory is not specified, then the +# "dir" index is assumed to be in the same directory as the info file. +# +# # INFO: /usr/pkg/info/bar.info /usr/pkg/info +# # INFO: /usr/pkg/info/baz.info /usr/pkg/info +# +# For each INFO entry, if the path is relative, that it is taken to be +# relative to ${PKG_PREFIX}. +# + +ECHO="@ECHO@" +GREP="@GREP@" +INSTALL_INFO="@INSTALL_INFO@" +MKDIR="@MKDIR@" +PWD_CMD="@PWD_CMD@" +RM="@RM@" +RMDIR="@RMDIR@" +SED="@SED@" +SORT="@SORT@" +TEST="@TEST@" + +SELF=$0 +ACTION=$1 + +PKG_METADATA_DIR="${2-`${PWD_CMD}`}" +: ${PKGNAME=${PKG_METADATA_DIR##*/}} +: ${PKG_PREFIX=@PREFIX@} + +exitcode=0 +case $ACTION in +ADD) + ${SED} -n "/^\# INFO: /{s/^\# INFO: //;p;}" ${SELF} | ${SORT} -u | + { while read file infodir; do + case $file in + "") continue ;; + [!/]*) file="${PKG_PREFIX}/$file" ;; + esac + + if ${TEST} ! -f "$file"; then + : + else + case "$printed_header" in + yes) ;; + *) printed_header=yes + ${ECHO} "===========================================================================" + ${ECHO} "Registering info files for ${PKGNAME}:" + ${ECHO} "" + ;; + esac + + ${TEST} -n "$infodir" || infodir="${file%/*}" + infoindex="$infodir/dir" + nentries="`${GREP} -c '^\*' $infoindex 2>/dev/null`" + case "$nentries" in + [0-9]*) ${TEST} $nentries -gt 0 || ${RM} $infoindex ;; + esac + ${ECHO} " $file" + ${MKDIR} -p "$infodir" + ${INSTALL_INFO} --info-dir="$infodir" --delete $file >/dev/null 2>&1 + ${INSTALL_INFO} --info-dir="$infodir" $file >/dev/null 2>&1 + fi + done + case "$printed_header" in + yes) ${ECHO} "" + ${ECHO} "===========================================================================" + ;; + esac; } + ;; + +REMOVE) + ${SED} -n "/^\# INFO: /{s/^\# INFO: //;p;}" ${SELF} | ${SORT} -u | + { while read file infodir; do + case $file in + "") continue ;; + [!/]*) file="${PKG_PREFIX}/$file" ;; + esac + + if ${TEST} ! -f "$file"; then + : + else + case "$printed_header" in + yes) ;; + *) printed_header=yes + ${ECHO} "===========================================================================" + ${ECHO} "Unregistering info files for ${PKGNAME}:" + ${ECHO} "" + ;; + esac + + ${TEST} -n "$infodir" || infodir="${file%/*}" + infoindex="$infodir/dir" + ${ECHO} " $file" + ${INSTALL_INFO} --info-dir="$infodir" --delete $file >/dev/null 2>&1 + nentries="`${GREP} -c '^\*' $infoindex 2>/dev/null`" + case "$nentries" in + [0-9]*) ${TEST} $nentries -gt 1 || ${RM} $infoindex ;; + esac + ${RMDIR} -p "$infodir" 2>/dev/null || ${TRUE} + fi + done + case "$printed_header" in + yes) ${ECHO} "" + ${ECHO} "===========================================================================" + ;; + esac; } + ;; +esac +exit $exitcode + +EOF + ${SED} -n "/^\# INFO: /p" ${SELF} >> ./+INFO_FILES + ${CHMOD} +x ./+INFO_FILES + ;; +esac + diff --git a/mk/pkginstall/install b/mk/pkginstall/install new file mode 100644 index 00000000000..a060d9f7b07 --- /dev/null +++ b/mk/pkginstall/install @@ -0,0 +1,97 @@ +# $NetBSD: install,v 1.1 2006/05/21 23:50:15 jlam Exp $ + +case ${STAGE} in +PRE-INSTALL) + # + # Unpack the helper scriptlets. + # + ${SH} ${SELF} ${PKGNAME} UNPACK + # + # Require that necessary users and groups exist or else fail the + # installation of the package. + # + ${TEST} ! -x ./+USERGROUP || + { ./+USERGROUP ADD ${PKG_METADATA_DIR} + if ./+USERGROUP CHECK-ADD ${PKG_METADATA_DIR}; then + : + else + exit 1 + fi; } + # + # Create package directories at pre-install time. + # + if [ "${PKG_INSTALLATION_TYPE}" = "pkgviews" -a \ + "${_PKG_CONFIG}" = "yes" -a -n "${CONF_DEPENDS}" ]; then + pkg=`${PKG_ADMIN} -b -d ${DEPOTBASE} -s "" lsbest "${CONF_DEPENDS}"` + sysconfdir=`${PKG_INFO} -B -K ${DEPOTBASE} $pkg | \ + ${AWK} '/^PKG_SYSCONFDIR=/ { \ + gsub("^PKG_SYSCONFDIR=[ ]*", ""); \ + print; \ + }' \ + ` + if [ -d $sysconfdir -a ! -d ${PKG_SYSCONFDIR} ]; then + ${MKDIR} -p `${DIRNAME} ${PKG_SYSCONFDIR}` + ${LN} -sf $sysconfdir ${PKG_SYSCONFDIR} + fi + fi + ${TEST} ! -x ./+DIRS || + ./+DIRS ADD ${PKG_METADATA_DIR} + ${TEST} ! -x ./+DIRS || + ./+DIRS PERMS ${PKG_METADATA_DIR} + ;; + +POST-INSTALL) + # + # Copy configuration/support files into place. + # + ${TEST} ! -x ./+FILES || + ./+FILES ADD ${PKG_METADATA_DIR} + ${TEST} ! -x ./+FILES || + ./+FILES PERMS ${PKG_METADATA_DIR} + # + # Set special permissions on any files/directories that need them. + # + ${TEST} ! -x ./+PERMS || + ./+PERMS ${PKG_METADATA_DIR} + # + # Update any fonts databases. + # + ${TEST} ! -x ./+FONTS || + ./+FONTS ${PKG_METADATA_DIR} + + # Check for any missing bits after we're finished installing. + # + ${TEST} ! -x ./+DIRS || + ./+DIRS CHECK-ADD ${PKG_METADATA_DIR} + ${TEST} ! -x ./+DIRS || + ./+DIRS CHECK-PERMS ${PKG_METADATA_DIR} + ${TEST} ! -x ./+FILES || + ./+FILES CHECK-ADD ${PKG_METADATA_DIR} + ${TEST} ! -x ./+FILES || + ./+FILES CHECK-PERMS ${PKG_METADATA_DIR} + ;; + +VIEW-INSTALL) + # + # Register shells in /etc/shells. + # + ${TEST} ! -x ./+SHELL || + ./+SHELL ADD ${PKG_METADATA_DIR} + ${TEST} ! -x ./+SHELL || + ./+SHELL CHECK-ADD ${PKG_METADATA_DIR} + # + # Register info files. + # + ${TEST} ! -x ./+INFO_FILES || + ./+INFO_FILES ADD ${PKG_METADATA_DIR} + + # If ${PKG_SYSCONFBASE} points outside of ${PREFIX}, then add the + # package config files to the proper view. + # + if [ "${_PKG_CONFIG}" = "yes" -a -n "${PKG_SYSCONFDEPOTBASE}" ]; then + ${SETENV} PLIST_IGNORE_FILES="${CONF_IGNORE_FILES}" \ + ${LINKFARM} -t ${PKG_SYSCONFVIEWBASE} -d ${PKG_SYSCONFDEPOTBASE} ${PKGNAME} + fi + ;; +esac + diff --git a/mk/pkginstall/install-post b/mk/pkginstall/install-post new file mode 100644 index 00000000000..2e2ea84fd3a --- /dev/null +++ b/mk/pkginstall/install-post @@ -0,0 +1,15 @@ +# $NetBSD: install-post,v 1.1 2006/05/21 23:50:15 jlam Exp $ + +# Ensure that the VIEW-INSTALL action is called for overwrite packages. +# This is here to ensure that it's the final POST-INSTALL action (after +# any INSTALL_TEMPLATE POST-INSTALL actions). +# +case ${STAGE} in +POST-INSTALL) + if [ "${PKG_INSTALLATION_TYPE}" = "overwrite" ]; then + ${SETENV} PKG_PREFIX="${PKG_PREFIX}" \ + $0 ${PKGNAME} VIEW-INSTALL + fi + ;; +esac + diff --git a/mk/pkginstall/perms b/mk/pkginstall/perms new file mode 100644 index 00000000000..2f898469d55 --- /dev/null +++ b/mk/pkginstall/perms @@ -0,0 +1,96 @@ +# $NetBSD: perms,v 1.1 2006/05/21 23:50:15 jlam Exp $ +# +# Generate a +PERMS script that sets the special permissions on files +# and directories used by the package. +# +case "${STAGE},$1" in +UNPACK,|UNPACK,+PERMS) + ${CAT} > ./+PERMS << 'EOF' +#!@SH@ +# +# +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 +# +# For each PERMS entry, if the file path is relative, then it is taken to +# be relative to ${PKG_PREFIX}. +# +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##*/}} +: ${PKG_PREFIX=@PREFIX@} + +${SED} -n "/^\# PERMS: /{s/^\# PERMS: //;p;}" ${SELF} | ${SORT} -u | +{ while read file f_mode f_user f_group; do + case $file in + "") continue ;; + [!/]*) file="${PKG_PREFIX}/$file" ;; + esac + ${TEST} -f "$file" || continue + 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_user in + "") ;; + *) ${CHOWN} $f_user $file ;; + esac + case $f_group in + "") ;; + *) ${CHGRP} $f_group $file ;; + esac + case $f_mode in + "") ;; + *) ${CHMOD} $f_mode $file ;; + esac +done +case "$printed_header" in +yes) ${ECHO} "" + ${ECHO} "===========================================================================" + ;; +esac; } + +EOF + ${SED} -n "/^\# PERMS: /p" ${SELF} >> ./+PERMS + ${CHMOD} +x ./+PERMS + ;; +esac + diff --git a/mk/pkginstall/shell b/mk/pkginstall/shell new file mode 100644 index 00000000000..73da476d3df --- /dev/null +++ b/mk/pkginstall/shell @@ -0,0 +1,233 @@ +# $NetBSD: shell,v 1.1 2006/05/21 23:50:15 jlam Exp $ +# +# Generate a +SHELL script that handles shell registration for the package. +# +case "${STAGE},$1" in +UNPACK,|UNPACK,+SHELL) + ${CAT} > ./+SHELL << 'EOF' +#!@SH@ +# +# +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@" +TRUE="@TRUE@" +TOUCH="@TOUCH@" + +SELF=$0 +ACTION=$1 + +PKG_METADATA_DIR="${2-`${PWD_CMD}`}" +: ${PKG_PREFIX=@PREFIX@} +: ${PKGNAME=${PKG_METADATA_DIR##*/}} + +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 + +exitcode=0 +case $ACTION in +ADD) + ${SED} -n "/^\# SHELL: /{s/^\# SHELL: //;p;}" ${SELF} | ${SORT} -u | + { while read shell; do + case ${_PKG_REGISTER_SHELLS} in + no) continue ;; + esac + case $shell in + /*) continue ;; + *) if [ ${PKG_PREFIX} = / ] ; then + shell="/$shell" + else + shell="${PKG_PREFIX}/$shell" + fi ;; + esac + ${TEST} -f "$shell" || continue + + shelldb="/etc/shells" + ${TEST} -f "$shelldb" || continue + 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 ${_PKG_REGISTER_SHELLS} in + no) continue ;; + esac + case $shell in + /*) continue ;; + *) if [ ${PKG_PREFIX} = / ] ; then + shell="/$shell" + else + shell="${PKG_PREFIX}/$shell" + fi ;; + 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 ;; + *) if [ ${PKG_PREFIX} = / ] ; then + shell="/$shell" + else + shell="${PKG_PREFIX}/$shell" + fi ;; + 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 ;; + *) if [ ${PKG_PREFIX} = / ] ; then + shell="/$shell" + else + shell="${PKG_PREFIX}/$shell" + fi ;; + 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 + +EOF + ${SED} -n "/^\# SHELL: /p" ${SELF} >> ./+SHELL + ${CHMOD} +x ./+SHELL + ;; +esac + diff --git a/mk/pkginstall/usergroup b/mk/pkginstall/usergroup new file mode 100644 index 00000000000..9d89271f35d --- /dev/null +++ b/mk/pkginstall/usergroup @@ -0,0 +1,382 @@ +# $NetBSD: usergroup,v 1.1 2006/05/21 23:50:15 jlam Exp $ +# +# Generate a +USERGROUP script that reference-counts users and groups +# that are required for the proper functioning of the package. +# +case "${STAGE},$1" in +UNPACK,|UNPACK,+USERGROUP) + ${CAT} > ./+USERGROUP << 'EOF' +#!@SH@ +# +# +USERGROUP - users and groups management script +# +# Usage: ./+USERGROUP ADD|REMOVE [metadatadir] +# ./+USERGROUP CHECK-ADD|CHECK-REMOVE [metadatadir] +# +# This script supports two actions, ADD and REMOVE, that will add or +# remove the users and groups needed by the package associated with +# <metadatadir>. The CHECK-ADD action will check whether any users or +# groups needed by the package are missing, and print an informative +# message noting those users and groups. The CHECK-REMOVE action will +# check whether any users and groups needed by the package still exist, +# and print an informative message noting those users and groups. The +# CHECK-ADD and CHECK-REMOVE actions return non-zero if they detect +# either missing or existing users/groups, respectively. +# +# Lines starting with "# USER: " or "# GROUP: " are data read by this +# script that name the users and groups that this package requires to +# exist to function correctly, e.g. +# +# # USER: foo:foogrp::The Foomister +# # GROUP: foogrp +# +# The USER lines are of the form: +# +# user:group[:[userid][:[descr][:[home][:shell]]]] +# +# Only the user and group are required; everything else is optional, +# but the colons must be in the right places when specifying optional +# bits. +# +# The GROUP lines are of the form: +# +# group[:groupid] +# +# Only the group is required; the groupid is optional. +# +AWK="@AWK@" +CAT="@CAT@" +CHGRP="@CHGRP@" +CHMOD="@CHMOD@" +CHOWN="@CHOWN@" +ECHO="@ECHO@" +GREP="@GREP@" +LS="@LS@" +MKDIR="@MKDIR@" +PWD_CMD="@PWD_CMD@" +RM="@RM@" +RMDIR="@RMDIR@" +SED="@SED@" +SORT="@SORT@" +TEST="@TEST@" +TRUE="@TRUE@" + +SELF=$0 +ACTION=$1 +PKG_METADATA_DIR="${2-`${PWD_CMD}`}" +: ${PKGNAME=${PKG_METADATA_DIR##*/}} +: ${PKG_DBDIR=${PKG_METADATA_DIR%/*}} +: ${PKG_REFCOUNT_DBDIR=${PKG_DBDIR}.refcount} + +PKG_REFCOUNT_USERS_DBDIR="${PKG_REFCOUNT_DBDIR}/users" +PKG_REFCOUNT_GROUPS_DBDIR="${PKG_REFCOUNT_DBDIR}/groups" + +case "${PKG_CREATE_USERGROUP:-@PKG_CREATE_USERGROUP@}" in +[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) + _PKG_CREATE_USERGROUP=yes + ;; +[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) + _PKG_CREATE_USERGROUP=no + ;; +esac + +listwrap() +{ + _length=$1 + _buffer= + while read _line; do + set -- $_line + for _word; do + case $_buffer in + "") _buffer="$_word" ;; + *) _buffer="$_buffer $_word" ;; + esac + if ${TEST} ${#_buffer} -gt $_length; then + ${ECHO} " $_buffer" + _buffer= + fi + done + done + case $_buffer in + "") ;; + *) ${ECHO} " $_buffer" ;; + esac +} + +# DO NOT CHANGE THE FOLLOWING LINE! +# platform-specific adduser/addgroup functions + +exitcode=0 +case $ACTION in +ADD) + ${SED} -n "/^\# GROUP: /{s/^\# GROUP: //;p;}" ${SELF} | ${SORT} -u | + { while read line; do + SAVEIFS="$IFS"; IFS=":" + set -- $line + group="$1"; groupid="$2" + IFS="$SAVEIFS" + case $group in + "") continue ;; + esac + shadow_dir="${PKG_REFCOUNT_GROUPS_DBDIR}/$group" + preexist="$shadow_dir/+PREEXISTING" + token="$shadow_dir/${PKGNAME}" + if ${TEST} ! -d "$shadow_dir"; then + ${MKDIR} $shadow_dir + group_exists $group $groupid && + ${ECHO} "${PKGNAME}" > $preexist + fi + if ${TEST} -f "$token" && \ + ${GREP} "^${PKG_METADATA_DIR}$" $token >/dev/null; then + : + else + ${ECHO} "${PKG_METADATA_DIR}" >> $token + fi + case ${_PKG_CREATE_USERGROUP} in + yes) + group_exists $group $groupid + case $? in + 0) ;; + 1) addgroup "$group" "$groupid" ;; + esac + ;; + esac + done; } + ${SED} -n "/^\# USER: /{s/^\# USER: //;p;}" ${SELF} | ${SORT} -u | + { while read line; do + SAVEIFS="$IFS"; IFS=":" + set -- $line + user="$1"; group="$2"; userid="$3" + descr="$4"; home="$5" shell="$6" + IFS="$SAVEIFS" + case $user in + "") continue ;; + esac + case $group in + "") continue ;; + esac + shadow_dir="${PKG_REFCOUNT_USERS_DBDIR}/$user" + preexist="$shadow_dir/+PREEXISTING" + token="$shadow_dir/${PKGNAME}" + if ${TEST} ! -d "$shadow_dir"; then + ${MKDIR} $shadow_dir + user_exists $user $userid && + ${ECHO} "${PKGNAME}" > $preexist + fi + if ${TEST} -f "$token" && \ + ${GREP} "^${PKG_METADATA_DIR}$" $token >/dev/null; then + : + else + ${ECHO} "${PKG_METADATA_DIR}" >> $token + fi + case ${_PKG_CREATE_USERGROUP} in + yes) + group_exists $group || continue + user_exists $user $userid + case $? in + 0) ;; + 1) adduser "$user" "$group" "$userid" \ + "$descr" "$home" "$shell" + ;; + esac + ;; + esac + done; } + ;; + +REMOVE) + ${SED} -n "/^\# USER: /{s/^\# USER: //;p;}" ${SELF} | ${SORT} -u | + { while read line; do + SAVEIFS="$IFS"; IFS=":" + set -- $line + user="$1"; group="$2"; userid="$3" + descr="$4"; home="$5" shell="$6" + IFS="$SAVEIFS" + case $user in + "") continue ;; + esac + shadow_dir="${PKG_REFCOUNT_USERS_DBDIR}/$user" + 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 + "") + ${RM} -f $preexist $token $token.tmp.* + ${RMDIR} -p $shadow_dir 2>/dev/null || ${TRUE} + ;; + *) + ${MV} -f $tokentmp $token + ;; + esac + fi + done; } + ${SED} -n "/^\# GROUP: /{s/^\# GROUP: //;p;}" ${SELF} | ${SORT} -u | + { while read line; do + SAVEIFS="$IFS"; IFS=":" + set -- $line + group="$1"; groupid="$2" + IFS="$SAVEIFS" + case $group in + "") continue ;; + esac + shadow_dir="${PKG_REFCOUNT_GROUPS_DBDIR}/$group" + 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 + "") + ${RM} -f $preexist $token $token.tmp.* + ${RMDIR} -p $shadow_dir 2>/dev/null || ${TRUE} + ;; + *) + ${MV} -f $tokentmp $token + ;; + esac + fi + done; } + ;; + +CHECK-ADD) + ${SED} -n "/^\# GROUP: /{s/^\# GROUP: //;p;}" ${SELF} | ${SORT} -u | + { while read line; do + SAVEIFS="$IFS"; IFS=":" + set -- $line + group="$1"; groupid="$2" + IFS="$SAVEIFS" + case $group in + "") continue ;; + *) group_exists $group $groupid && continue ;; + esac + case "$printed_header" in + yes) ;; + *) printed_header=yes + ${ECHO} "===========================================================================" + ${ECHO} "The following groups need to be created for ${PKGNAME}:" + ${ECHO} "" + ;; + esac + case $groupid in + "") ${ECHO} " $group" ;; + *) ${ECHO} " $group (gid = $groupid)" ;; + esac + done + case "$printed_header" in + yes) ${ECHO} "" + ${ECHO} "===========================================================================" + exit 1 + ;; + esac; } + ${TEST} $? -eq 0 || exitcode=1 + ${SED} -n "/^\# USER: /{s/^\# USER: //;p;}" ${SELF} | ${SORT} -u | + { while read line; do + SAVEIFS="$IFS"; IFS=":" + set -- $line + user="$1"; group="$2"; userid="$3" + descr="$4"; home="$5" shell="$6" + IFS="$SAVEIFS" + case $user in + "") continue ;; + *) user_exists $user $userid && continue ;; + esac + case "$printed_header" in + yes) ;; + *) printed_header=yes + ${ECHO} "===========================================================================" + ${ECHO} "The following users need to be created for ${PKGNAME}:" + ${ECHO} "" + ;; + esac + : ${home:="@PKG_USER_HOME@"} + : ${shell:="@PKG_USER_SHELL@"} + case $userid in + "") ${ECHO} " $user: $group, $home, $shell" ;; + *) ${ECHO} " $user (uid = $userid): $group, $home, $shell" ;; + esac + done + case "$printed_header" in + yes) ${ECHO} "" + ${ECHO} "===========================================================================" + exit 1 + ;; + esac; } + ${TEST} $? -eq 0 || exitcode=1 + ;; + +CHECK-REMOVE) + ${SED} -n "/^\# USER: /{s/^\# USER: //;p;}" ${SELF} | ${SORT} -u | + { while read line; do + SAVEIFS="$IFS"; IFS=":" + set -- $line + user="$1"; group="$2"; userid="$3" + descr="$4"; home="$5" shell="$6" + IFS="$SAVEIFS" + case $user in + "") continue ;; + *) user_exists $user $userid || continue ;; + esac + shadow_dir="${PKG_REFCOUNT_USERS_DBDIR}/$user" + ${TEST} ! -d "$shadow_dir" || continue # refcount isn't zero + existing_users="$existing_users $user" + done + case $existing_users in + "") ;; + *) ${ECHO} "===========================================================================" + ${ECHO} "The following users are no longer being used by ${PKGNAME}," + ${ECHO} "and they can be removed if no other software is using them:" + ${ECHO} "" + ${ECHO} "$existing_users" | listwrap 40 + ${ECHO} "" + ${ECHO} "===========================================================================" + exit 1 + ;; + esac; } + ${TEST} $? -eq 0 || exitcode=1 + ${SED} -n "/^\# GROUP: /{s/^\# GROUP: //;p;}" ${SELF} | ${SORT} -u | + { while read line; do + SAVEIFS="$IFS"; IFS=":" + set -- $line + group="$1"; groupid="$2" + IFS="$SAVEIFS" + case $group in + "") continue ;; + *) group_exists $group $groupid || continue ;; + esac + shadow_dir="${PKG_REFCOUNT_GROUPS_DBDIR}/$group" + ${TEST} ! -d "$shadow_dir" || continue # refcount isn't zero + existing_groups="$existing_groups $group" + done + case $existing_groups in + "") ;; + *) ${ECHO} "===========================================================================" + ${ECHO} "The following groups are no longer being used by ${PKGNAME}," + ${ECHO} "and they can be removed if no other software is using them:" + ${ECHO} "" + ${ECHO} "$existing_groups" | listwrap 40 + ${ECHO} "" + ${ECHO} "===========================================================================" + exit 1 + ;; + esac; } + ${TEST} $? -eq 0 || exitcode=1 + ;; + +*) + ${ECHO} "Usage: ./+USERGROUP ADD|REMOVE [metadatadir]" + ${ECHO} " ./+USERGROUP CHECK-ADD|CHECK-REMOVE [metadatadir]" + ;; +esac +exit $exitcode + +EOF + ${SED} -n "/^\# GROUP: /p" ${SELF} >> ./+USERGROUP + ${SED} -n "/^\# USER: /p" ${SELF} >> ./+USERGROUP + ${CHMOD} +x ./+USERGROUP + ;; +esac + diff --git a/mk/pkginstall/usergroup-check b/mk/pkginstall/usergroup-check new file mode 100755 index 00000000000..8561cabcf97 --- /dev/null +++ b/mk/pkginstall/usergroup-check @@ -0,0 +1,126 @@ +#!/bin/sh +# +# $NetBSD: usergroup-check,v 1.1 2006/05/21 23:50:15 jlam Exp $ +# +# Copyright (c) 2006 The NetBSD Foundation, Inc. +# All rights reserved. +# +# This code is derived from software contributed to The NetBSD Foundation +# by Johnny C. Lam. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. All advertising materials mentioning features or use of this software +# must display the following acknowledgement: +# This product includes software developed by the NetBSD +# Foundation, Inc. and its contributors. +# 4. Neither the name of The NetBSD Foundation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +###################################################################### +# +# NAME +# usergroup-check -- verify that users/groups match numeric IDs +# +# SYNOPSIS +# usergroup-check -g [group_entry ...] +# usergroup-check -u [user_entry ...] +# +# DESCRIPTION +# usergroup-check checks for the existence of users and groups +# and verifies that they match the requested numeric IDs if +# given. The group_entry format matches that of /etc/group and +# the user_entry format matches that of /etc/passwd, though the +# field contents may be empty. +# +# usergroup-check exits 0 if the users and groups exist and match +# the numeric IDs, and >0 otherwise. +# +# OPTIONS +# The following command line arguments are supported. +# +# -g Indicates that the subsequent arguments are group entries. +# +# -u Indicates that the subsequent arguments are user entries. +# +###################################################################### + +: ${PERL5=perl} + +self="${0##*/}" + +usage() { + echo 1>&2 "usage: $self -g [group_entry ...]" + echo 1>&2 " $self -u [user_entry ...]" +} + +if test $# -lt 1; then + usage; exit 1 +fi + +check= +case "$1" in +-g) check=groups ;; +-u) check=users ;; +*) usage; exit 1 ;; +esac +shift + +missing_groups= +missing_users= + +case $check in +groups) + while test $# -gt 0; do + entry="$1"; shift + ( SAVEIFS="$IFS"; IFS=":" + set -- $entry; group="$1"; groupid="$2" + IFS="$SAVEIFS" + gid=`${PERL5} -le 'print scalar getgrnam shift' $group` + test -n "$gid" || exit 1 + case "$groupid" in + ""|$gid) exit 0 ;; + *) exit 1 ;; + esac ) || missing_groups="$missing_groups $i" + done + ;; + +users) + missing_users= + while test $# -gt 0; do + entry="$1"; shift + ( SAVEIFS="$IFS"; IFS=":" + set -- $entry; user="$1"; userid="$3" + IFS="$SAVEIFS" + gid=`${PERL5} -le 'print scalar getpwnam shift' $user` + test -n "$gid" || exit 1 + case "$userid" in + ""|$gid) exit 0 ;; + *) exit 1 ;; + esac ) || missing_users="$missing_users $i" + done + ;; +esac + +test -z "$missing_groups" -a -z "$missing_users" || exit 1 +exit 0 diff --git a/mk/pkginstall/usergroupfuncs b/mk/pkginstall/usergroupfuncs new file mode 100644 index 00000000000..77e4f8b4e4b --- /dev/null +++ b/mk/pkginstall/usergroupfuncs @@ -0,0 +1,148 @@ +# $NetBSD: usergroupfuncs,v 1.1 2006/05/21 23:50:15 jlam Exp $ +# +# Default implementations of user_exists() and group_exists() shell +# functions for checking the existence of users and groups, and of +# adduser() and addgroup() shell functions for adding users and groups. +# Assume there are NetBSD/Solaris-compatible versions of useradd(8) and +# groupadd(8) available through ${USERADD} and ${GROUPADD}, respectively. +# +# Platform-specific replacements for this file should be located at: +# +# pkgsrc/mk/pkginstall/usergroupfuncs.${OPSYS} +# + +# group_exists group [groupid] +# Returns 0 if $group exists and has gid $groupid +# Returns 1 if neither $group nor $groupid exist +# Returns 2 if $group or $groupid exist but don't match +# Returns 3 for all errors +# +group_exists() +{ + _group="$1"; _groupid="$2" + ${TEST} -n "$_group" || return 3 + + # Check using chgrp to work properly in an NSS/NIS environment. + _tmpdir="./.pkginstall.$$" + ${MKDIR} -p $_tmpdir 2>/dev/null || return 3 + ${CHMOD} 0700 $_tmpdir + _testpath="$_tmpdir/group_exists" + ${ECHO} > $_testpath + if ${CHGRP} $_group $_testpath >/dev/null 2>&1; then + # $_group exists + _id=`${LS} -ln $_testpath 2>/dev/null | ${AWK} '{ print $4 }'` + ${TEST} -n "$_groupid" || _groupid=$_id + if ${TEST} "$_groupid" = "$_id"; then + ${RM} -fr $_tmpdir; return 0 + fi + ${RM} -fr $_tmpdir; return 2 + elif ${TEST} -z "$_groupid"; then + # $_group doesn't exist and $_groupid is not set + ${RM} -fr $_tmpdir; return 1 + elif ${CHGRP} $_groupid $_testpath >/dev/null 2>&1; then + _name=`${LS} -l $_testpath 2>/dev/null | ${AWK} '{ print $4 }'` + if ${TEST} "$_name" != "$_groupid"; then + # $_group doesn't exist, but $_groupid exists + ${RM} -fr $_tmpdir; return 2 + fi + # neither $_group nor $_groupid exist + ${RM} -fr $_tmpdir; return 1 + fi + ${RM} -fr $_tmpdir; return 3 +} + +# user_exists user [userid] +# Returns 0 if $user exists and has uid $userid +# Returns 1 if neither $user nor $userid exist +# Returns 2 if $user or $userid exist but don't match +# Returns 3 for all errors +# +user_exists() +{ + _user="$1"; _userid="$2" + ${TEST} -n "$_user" || return 3 + + # Check using chown to work properly in an NSS/NIS environment. + _tmpdir="./.pkginstall.$$" + ${MKDIR} -p $_tmpdir 2>/dev/null || return 3 + ${CHMOD} 0700 $_tmpdir + _testpath="$_tmpdir/user_exists" + ${ECHO} > $_testpath + if ${CHOWN} $_user $_testpath >/dev/null 2>&1; then + # $_user exists + _id=`${LS} -ln $_testpath 2>/dev/null | ${AWK} '{ print $3 }'` + ${TEST} -n "$_userid" || _userid=$_id + if ${TEST} "$_userid" = "$_id"; then + ${RM} -fr $_tmpdir; return 0 + fi + ${RM} -fr $_tmpdir; return 2 + elif ${TEST} -z "$_userid"; then + # $_user doesn't exist and $_userid is not set + ${RM} -fr $_tmpdir; return 1 + elif ${CHOWN} $_userid $_testpath >/dev/null 2>&1; then + _name=`${LS} -l $_testpath 2>/dev/null | ${AWK} '{ print $3 }'` + if ${TEST} "$_name" != "$_userid"; then + # $_user doesn't exist, but $_userid exists + ${RM} -fr $_tmpdir; return 2 + fi + # neither $_user nor $_userid exist + ${RM} -fr $_tmpdir; return 1 + fi + ${RM} -fr $_tmpdir; return 3 +} + +# adduser user group [userid] [descr] [home] [shell] +adduser() +{ + user="$1"; group="$2"; userid="$3" + descr="$4"; home="$5" shell="$6" + ${TEST} $# -eq 6 || return 1 + ${TEST} -n "$user" || return 2 + ${TEST} -n "$group" || return 2 + + USERADD="@USERADD@" + + case $user in + ${PKGNAME%-[0-9]*}) descr_dflt="$user user" ;; + *) descr_dflt="${PKGNAME%-[0-9]*} $user user" ;; + esac + : ${descr:="$descr_dflt"} + : ${home:="@PKG_USER_HOME@"} + : ${shell:="@PKG_USER_SHELL@"} + + if ${TEST} -n "${USERADD}" -a -x "${USERADD}"; then + ${ECHO} "Creating user: $user" + case $userid in + "") + ${USERADD} \ + -c "$descr" -d "$home" -s "$shell" \ + -g $group $user + ;; + *) + ${USERADD} \ + -c "$descr" -d "$home" -s "$shell" \ + -g $group -u $userid $user + ;; + esac + fi + return 0 +} + +# adduser group [groupid] +addgroup() +{ + group="$1"; groupid="$2" + ${TEST} $# -eq 2 || return 1 + ${TEST} -n "$group" || return 2 + + GROUPADD="@GROUPADD@" + + if ${TEST} -n "${GROUPADD}" -a -x "${GROUPADD}"; then + ${ECHO} "Creating group: $group"; + case $groupid in + "") ${GROUPADD} $group ;; + *) ${GROUPADD} -g $groupid $group ;; + esac + fi + return 0 +} diff --git a/mk/pkginstall/usergroupfuncs.DragonFly b/mk/pkginstall/usergroupfuncs.DragonFly new file mode 100644 index 00000000000..25ff3163103 --- /dev/null +++ b/mk/pkginstall/usergroupfuncs.DragonFly @@ -0,0 +1,142 @@ +# $NetBSD: usergroupfuncs.DragonFly,v 1.1 2006/05/21 23:50:15 jlam Exp $ +# +# Platform-specific adduser and addgroup functionality +# on top of pw(8). + +# group_exists group [groupid] +# Returns 0 if $group exists and has gid $groupid +# Returns 1 if neither $group nor $groupid exist +# Returns 2 if $group or $groupid exist but don't match +# Returns 3 for all errors +# +group_exists() +{ + _group="$1"; _groupid="$2" + ${TEST} -n "$_group" || return 3 + + # Check using chgrp to work properly in an NSS/NIS environment. + _tmpdir="./.pkginstall.$$" + ${MKDIR} -p $_tmpdir 2>/dev/null || return 3 + ${CHMOD} 0700 $_tmpdir + _testpath="$_tmpdir/group_exists" + ${ECHO} > $_testpath + if ${CHGRP} $_group $_testpath >/dev/null 2>&1; then + # $_group exists + _id=`${LS} -ln $_testpath 2>/dev/null | ${AWK} '{ print $4 }'` + ${TEST} -n "$_groupid" || _groupid=$_id + if ${TEST} "$_groupid" = "$_id"; then + ${RM} -fr $_tmpdir; return 0 + fi + ${RM} -fr $_tmpdir; return 2 + elif ${TEST} -z "$_groupid"; then + # $_group doesn't exist and $_groupid is not set + ${RM} -fr $_tmpdir; return 1 + elif ${CHGRP} $_groupid $_testpath >/dev/null 2>&1; then + _name=`${LS} -l $_testpath 2>/dev/null | ${AWK} '{ print $4 }'` + if ${TEST} "$_name" != "$_groupid"; then + # $_group doesn't exist, but $_groupid exists + ${RM} -fr $_tmpdir; return 2 + fi + # neither $_group nor $_groupid exist + ${RM} -fr $_tmpdir; return 1 + fi + ${RM} -fr $_tmpdir; return 3 +} + +# user_exists user [userid] +# Returns 0 if $user exists and has uid $userid +# Returns 1 if neither $user nor $userid exist +# Returns 2 if $user or $userid exist but don't match +# Returns 3 for all errors +# +user_exists() +{ + _user="$1"; _userid="$2" + ${TEST} -n "$_user" || return 3 + + # Check using chown to work properly in an NSS/NIS environment. + _tmpdir="./.pkginstall.$$" + ${MKDIR} -p $_tmpdir 2>/dev/null || return 3 + ${CHMOD} 0700 $_tmpdir + _testpath="$_tmpdir/user_exists" + ${ECHO} > $_testpath + if ${CHOWN} $_user $_testpath >/dev/null 2>&1; then + # $_user exists + _id=`${LS} -ln $_testpath 2>/dev/null | ${AWK} '{ print $3 }'` + ${TEST} -n "$_userid" || _userid=$_id + if ${TEST} "$_userid" = "$_id"; then + ${RM} -fr $_tmpdir; return 0 + fi + ${RM} -fr $_tmpdir; return 2 + elif ${TEST} -z "$_userid"; then + # $_user doesn't exist and $_user is not set + ${RM} -fr $_tmpdir; return 1 + elif ${CHOWN} $_userid $_testpath >/dev/null 2>&1; then + _name=`${LS} -l $_testpath 2>/dev/null | ${AWK} '{ print $3 }'` + if ${TEST} "$_name" != "$_userid"; then + # $_user doesn't exist, but $_userid exists + ${RM} -fr $_tmpdir; return 2 + fi + # neither $_user nor $_userid exist + ${RM} -fr $_tmpdir; return 1 + fi + ${RM} -fr $_tmpdir; return 3 +} + +# adduser user group [userid] [descr] [home] [shell] +adduser() +{ + user="$1"; group="$2"; userid="$3" + descr="$4"; home="$5" shell="$6" + ${TEST} $# -eq 6 || return 1 + ${TEST} -n "$user" || return 2 + ${TEST} -n "$group" || return 2 + + PW="@PW@" + + case $user in + ${PKGNAME%-[0-9]*}) descr_dflt="$user user" ;; + *) descr_dflt="${PKGNAME%-[0-9]*} $user user" ;; + esac + : ${descr:="$descr_dflt"} + : ${home:="@PKG_USER_HOME@"} + : ${shell:="@PKG_USER_SHELL@"} + + if ${TEST} -n "${PW}" -a -x "${PW}"; then + ${ECHO} "Creating user: $user" + case $userid in + "") + ${PW} useradd \ + $user \ + -c "$descr" -d "$home" -s "$shell" \ + -g $group + ;; + *) + ${PW} useradd \ + $user \ + -c "$descr" -d "$home" -s "$shell" \ + -g $group -u $userid + ;; + esac + fi + return 0 +} + +# adduser group [groupid] +addgroup() +{ + group="$1"; groupid="$2" + ${TEST} $# -eq 2 || return 1 + ${TEST} -n "$group" || return 2 + + PW="@PW@" + + if ${TEST} -n "${PW}" -a -x "${PW}"; then + ${ECHO} "Creating group: $group"; + case $groupid in + "") ${PW} groupadd $group ;; + *) ${PW} groupadd $group -g $groupid ;; + esac + fi + return 0 +} diff --git a/mk/pkginstall/usergroupfuncs.FreeBSD b/mk/pkginstall/usergroupfuncs.FreeBSD new file mode 100644 index 00000000000..763e5b1e4b1 --- /dev/null +++ b/mk/pkginstall/usergroupfuncs.FreeBSD @@ -0,0 +1,142 @@ +# $NetBSD: usergroupfuncs.FreeBSD,v 1.1 2006/05/21 23:50:15 jlam Exp $ +# +# Platform-specific adduser and addgroup functionality +# on top of pw(8). + +# group_exists group [groupid] +# Returns 0 if $group exists and has gid $groupid +# Returns 1 if neither $group nor $groupid exist +# Returns 2 if $group or $groupid exist but don't match +# Returns 3 for all errors +# +group_exists() +{ + _group="$1"; _groupid="$2" + ${TEST} -n "$_group" || return 3 + + # Check using chgrp to work properly in an NSS/NIS environment. + _tmpdir="./.pkginstall.$$" + ${MKDIR} -p $_tmpdir 2>/dev/null || return 3 + ${CHMOD} 0700 $_tmpdir + _testpath="$_tmpdir/group_exists" + ${ECHO} > $_testpath + if ${CHGRP} $_group $_testpath >/dev/null 2>&1; then + # $_group exists + _id=`${LS} -ln $_testpath 2>/dev/null | ${AWK} '{ print $4 }'` + ${TEST} -n "$_groupid" || _groupid=$_id + if ${TEST} "$_groupid" = "$_id"; then + ${RM} -fr $_tmpdir; return 0 + fi + ${RM} -fr $_tmpdir; return 2 + elif ${TEST} -z "$_groupid"; then + # $_group doesn't exist and $_groupid is not set + ${RM} -fr $_tmpdir; return 1 + elif ${CHGRP} $_groupid $_testpath >/dev/null 2>&1; then + _name=`${LS} -l $_testpath 2>/dev/null | ${AWK} '{ print $4 }'` + if ${TEST} "$_name" != "$_groupid"; then + # $_group doesn't exist, but $_groupid exists + ${RM} -fr $_tmpdir; return 2 + fi + # neither $_group nor $_groupid exist + ${RM} -fr $_tmpdir; return 1 + fi + ${RM} -fr $_tmpdir; return 3 +} + +# user_exists user [userid] +# Returns 0 if $user exists and has uid $userid +# Returns 1 if neither $user nor $userid exist +# Returns 2 if $user or $userid exist but don't match +# Returns 3 for all errors +# +user_exists() +{ + _user="$1"; _userid="$2" + ${TEST} -n "$_user" || return 3 + + # Check using chown to work properly in an NSS/NIS environment. + _tmpdir="./.pkginstall.$$" + ${MKDIR} -p $_tmpdir 2>/dev/null || return 3 + ${CHMOD} 0700 $_tmpdir + _testpath="$_tmpdir/user_exists" + ${ECHO} > $_testpath + if ${CHOWN} $_user $_testpath >/dev/null 2>&1; then + # $_user exists + _id=`${LS} -ln $_testpath 2>/dev/null | ${AWK} '{ print $3 }'` + ${TEST} -n "$_userid" || _userid=$_id + if ${TEST} "$_userid" = "$_id"; then + ${RM} -fr $_tmpdir; return 0 + fi + ${RM} -fr $_tmpdir; return 2 + elif ${TEST} -z "$_userid"; then + # $_user doesn't exist and $_user is not set + ${RM} -fr $_tmpdir; return 1 + elif ${CHOWN} $_userid $_testpath >/dev/null 2>&1; then + _name=`${LS} -l $_testpath 2>/dev/null | ${AWK} '{ print $3 }'` + if ${TEST} "$_name" != "$_userid"; then + # $_user doesn't exist, but $_userid exists + ${RM} -fr $_tmpdir; return 2 + fi + # neither $_user nor $_userid exist + ${RM} -fr $_tmpdir; return 1 + fi + ${RM} -fr $_tmpdir; return 3 +} + +# adduser user group [userid] [descr] [home] [shell] +adduser() +{ + user="$1"; group="$2"; userid="$3" + descr="$4"; home="$5" shell="$6" + ${TEST} $# -eq 6 || return 1 + ${TEST} -n "$user" || return 2 + ${TEST} -n "$group" || return 2 + + PW="@PW@" + + case $user in + ${PKGNAME%-[0-9]*}) descr_dflt="$user user" ;; + *) descr_dflt="${PKGNAME%-[0-9]*} $user user" ;; + esac + : ${descr:="$descr_dflt"} + : ${home:="@PKG_USER_HOME@"} + : ${shell:="@PKG_USER_SHELL@"} + + if ${TEST} -n "${PW}" -a -x "${PW}"; then + ${ECHO} "Creating user: $user" + case $userid in + "") + ${PW} useradd \ + $user \ + -c "$descr" -d "$home" -s "$shell" \ + -g $group + ;; + *) + ${PW} useradd \ + $user \ + -c "$descr" -d "$home" -s "$shell" \ + -g $group -u $userid + ;; + esac + fi + return 0 +} + +# adduser group [groupid] +addgroup() +{ + group="$1"; groupid="$2" + ${TEST} $# -eq 2 || return 1 + ${TEST} -n "$group" || return 2 + + PW="@PW@" + + if ${TEST} -n "${PW}" -a -x "${PW}"; then + ${ECHO} "Creating group: $group"; + case $groupid in + "") ${PW} groupadd $group ;; + *) ${PW} groupadd $group -g $groupid ;; + esac + fi + return 0 +} |