summaryrefslogtreecommitdiff
path: root/mk/install
diff options
context:
space:
mode:
authorjlam <jlam@pkgsrc.org>2001-11-19 16:18:44 +0000
committerjlam <jlam@pkgsrc.org>2001-11-19 16:18:44 +0000
commitc850f81b615ba9e58563fe40c1075ad3aea9ffa4 (patch)
treea60637d6a03f36964a4f6c39dd848d88feaed3f4 /mk/install
parent014a83ae0f4570b0f6917cb8545ebc2d1bc8b231 (diff)
downloadpkgsrc-c850f81b615ba9e58563fe40c1075ad3aea9ffa4.tar.gz
Common INSTALL/DEINSTALL scripts and Makefile magic to automatically perform
many of the tasks that need to be done when package is installed or deinstalled: * creating user/group for the package, * creating and removing directories with special permissions and ownership, * copying config files to their final locations, and removing them at deinstall time if they don't differ from the example ones, * reminding the package admin of files he may want to customize or of files/directories he may want to remove.
Diffstat (limited to 'mk/install')
-rw-r--r--mk/install/deinstall153
-rw-r--r--mk/install/footer7
-rw-r--r--mk/install/header51
-rw-r--r--mk/install/install177
4 files changed, 388 insertions, 0 deletions
diff --git a/mk/install/deinstall b/mk/install/deinstall
new file mode 100644
index 00000000000..41512fe9628
--- /dev/null
+++ b/mk/install/deinstall
@@ -0,0 +1,153 @@
+# start of deinstall
+#
+# $NetBSD: deinstall,v 1.1 2001/11/19 16:18:44 jlam Exp $
+
+ALL_FILES="${CONF_FILES} ${SUPPORT_FILES} ${RCD_SCRIPTS}"
+set -- ${CONF_FILES_PERMS}
+while [ $# -gt 0 ]
+do
+ samplefile="$1"; file="$2"; owner="$3"; group="$4"; mode="$5"
+ shift; shift; shift; shift; shift
+ ALL_FILES="${ALL_FILES} ${samplefile} ${file}"
+done
+
+ALL_MAKE_DIRS="${MAKE_DIRS}"
+set -- ${MAKE_DIRS_PERMS}
+while [ $# -gt 0 ]
+do
+ dir="$1"; owner="$2"; group="$3"; mode="$4"
+ shift; shift; shift; shift
+ ALL_MAKE_DIRS="${ALL_MAKE_DIRS} ${dir}"
+done
+ALL_DIRS="${ALL_MAKE_DIRS} ${OWN_DIRS}"
+set -- ${OWN_DIRS_PERMS}
+while [ $# -gt 0 ]
+do
+ dir="$1"; owner="$2"; group="$3"; mode="$4"
+ shift; shift; shift; shift
+ ALL_DIRS="${ALL_DIRS} ${dir}"
+done
+ALL_DIRS=` \
+ ${ECHO} ${ALL_DIRS} | \
+ ${SED} "s,[ ][ ]*, ,g" | \
+ ${TR} ' ' "\012" | \
+ ${SORT} -r \
+`
+
+case ${STAGE} in
+DEINSTALL)
+ # Remove configuration files if they don't differ from the default
+ # config file.
+ #
+ set -- ${ALL_FILES}
+ while [ $# -gt 0 ]
+ do
+ samplefile="$1"; file="$2"
+ shift; shift
+
+ if [ "${file}" != "${samplefile}" -a \
+ -f ${file} -a -f ${samplefile} ]
+ then
+ if ${CMP} -s ${file} ${samplefile}
+ then
+ ${RM} -f ${file}
+ fi
+ fi
+ done
+ ;;
+
+POST-DEINSTALL)
+ modified_files=''
+ set -- ${ALL_FILES}
+ while [ $# -gt 0 ]
+ do
+ samplefile="$1"; file="$2"
+ shift; shift
+
+ if [ -f ${file} ]
+ then
+ modified_files="${modified_files} ${file}"
+ fi
+ done
+
+ existing_dirs=''
+ set -- ${ALL_DIRS}
+ while [ $# -gt 0 ]
+ do
+ dir=$1; shift
+ is_make_dir=0
+ for make_dir in __dummy ${ALL_MAKE_DIRS}
+ do
+ if [ "${make_dir}" != "__dummy" -a \
+ "${dir}" = "${make_dir}" ]
+ then
+ is_make_dir=1
+ break
+ fi
+ done
+
+ ${RMDIR} -p ${dir} 2>/dev/null || ${TRUE}
+ if [ ${is_make_dir} -eq 0 -a -d ${dir} ]
+ then
+ existing_dirs="${existing_dirs} ${dir}"
+ fi
+ done
+
+ if [ -n "${PKG_USER}" -o -n "${PKG_GROUP}" -o \
+ -n "${modified_files}" -o -n "${existing_dirs}" ]
+ then
+ ${CAT} << EOF
+===========================================================================
+If you won't be using ${PKGNAME} any longer, you may want to remove
+EOF
+ if [ -n "${PKG_USER}" ]
+ then
+ ${CAT} << EOF
+
+ * the \`${PKG_USER}' user
+EOF
+ fi
+ if [ -n "${PKG_GROUP}" ]
+ then
+ ${CAT} << EOF
+
+ * the \`${PKG_GROUP}' group
+EOF
+ fi
+ if [ -n "${modified_files}" ]
+ then
+ ${CAT} << EOF
+
+ * the following files:
+
+EOF
+ for file in ${modified_files}
+ do
+ ${ECHO} " ${file}"
+ done
+ fi
+ if [ -n "${existing_dirs}" ]
+ then
+ ${CAT} << EOF
+
+ * the following directories:
+
+EOF
+ for dir in ${existing_dirs}
+ do
+ ${ECHO} " ${dir}"
+ done
+ fi
+ ${CAT} << EOF
+===========================================================================
+EOF
+ fi
+ ;;
+
+*)
+ ${ECHO} "Unexpected argument: ${STAGE}"
+ exit 1
+ ;;
+esac
+
+# end of deinstall
diff --git a/mk/install/footer b/mk/install/footer
new file mode 100644
index 00000000000..44719cce24c
--- /dev/null
+++ b/mk/install/footer
@@ -0,0 +1,7 @@
+# start of footer
+#
+# $NetBSD: footer,v 1.1 2001/11/19 16:18:44 jlam Exp $
+
+exit 0
+
+# end of footer
diff --git a/mk/install/header b/mk/install/header
new file mode 100644
index 00000000000..8e6278f2356
--- /dev/null
+++ b/mk/install/header
@@ -0,0 +1,51 @@
+#!@SH@
+#
+# start of header
+#
+# $NetBSD: header,v 1.1 2001/11/19 16:18:44 jlam Exp $
+
+PKGNAME=$1
+STAGE=$2
+
+AWK="@AWK@"
+BASENAME="@BASENAME@"
+CAT="@CAT@"
+CHGRP="@CHGRP@"
+CHMOD="@CHMOD@"
+CHOWN="@CHOWN@"
+CMP="@CMP@"
+CP="@CP@"
+DIRNAME="@DIRNAME@"
+ECHO="@ECHO@"
+EGREP="@EGREP@"
+FALSE="@FALSE@"
+GROUPADD="@GROUPADD@"
+ID="@ID@"
+LN="@LN@"
+MKDIR="@MKDIR@"
+MV="@MV@"
+RM="@RM@"
+RMDIR="@RMDIR@"
+SED="@SED@"
+SORT="@SORT@"
+TOUCH="@TOUCH@"
+TR="@TR@"
+TRUE="@TRUE@"
+USERADD="@USERADD@"
+
+PKG_USER="@PKG_USER@"
+PKG_GROUP="@PKG_GROUP@"
+PKG_GROUP="@PKG_GROUP@"
+PKG_GROUPID="@PKG_GROUPID@"
+
+CONF_FILES="@CONF_FILES@"
+CONF_FILES_PERMS="@CONF_FILES_PERMS@"
+SUPPORT_FILES="@SUPPORT_FILES@"
+RCD_SCRIPTS="@RCD_SCRIPTS@"
+
+MAKE_DIRS="@MAKE_DIRS@"
+MAKE_DIRS_PERMS="@MAKE_DIRS_PERMS@"
+OWN_DIRS="@OWN_DIRS@"
+OWN_DIRS_PERMS="@OWN_DIRS_PERMS@"
+
+# end of header
diff --git a/mk/install/install b/mk/install/install
new file mode 100644
index 00000000000..9344ee3915a
--- /dev/null
+++ b/mk/install/install
@@ -0,0 +1,177 @@
+# start of install
+#
+# $NetBSD: install,v 1.1 2001/11/19 16:18:44 jlam Exp $
+
+case ${STAGE} in
+PRE-INSTALL)
+ if [ -n "${PKG_GROUP}" ]
+ then
+ # We need to check that ${PKG_GROUP} exists before adding the
+ # user. Do it with chgrp to be able to use NIS.
+ #
+ ${TOUCH} /tmp/grouptest.$$
+ ${CHGRP} ${PKG_GROUP} /tmp/grouptest.$$ >/dev/null 2>&1
+ if [ $? -eq 0 ]
+ then
+ ${ECHO} "Group '${PKG_GROUP}' already exists."
+ else
+ groupid_option=
+ if [ -n "${PKG_GROUPID}" ]
+ then
+ groupid_option="-g ${PKG_GROUPID}"
+ fi
+ ${ECHO} "Creating '${PKG_GROUP}' group..."
+ ${GROUPADD} ${groupid_option} ${PKG_GROUP}
+ ${ECHO} "Done."
+ fi
+ ${RM} -f /tmp/grouptest.$$
+ fi
+
+ if [ -n "${PKG_USER}" -a -n "${PKG_GROUP}" ]
+ then
+ # Use `id' to be able to use NIS.
+ ${ID} ${PKG_USER} >/dev/null 2>&1
+ if [ $? -eq 0 ]
+ then
+ ${ECHO} "User '${PKG_USER}' already exists."
+ else
+ userid_option=
+ if [ -n "${PKG_USERID}" ]
+ then
+ userid_option="-u ${PKG_USERID}"
+ fi
+ ${ECHO} "Creating '${PKG_USER}' user..."
+ ${USERADD} -c "@PKG_USER_DESCR@" \
+ ${userid_option} \
+ -g ${PKG_GROUP} \
+ -d @PKG_USER_HOME@ \
+ -s @PKG_USER_SHELL@ \
+ ${PKG_USER}
+ ${ECHO} "Done."
+ fi
+ fi
+ ;;
+
+POST-INSTALL)
+ # Create package directories.
+ set -- ${MAKE_DIRS} ${OWN_DIRS}
+ for dir
+ do
+ ${MKDIR} ${dir}
+ done
+ set -- ${MAKE_DIRS_PERMS} ${OWN_DIRS_PERMS}
+ while [ $# -gt 0 ]
+ do
+ dir="$1"; owner="$2"; group="$3"; mode="$4"
+ shift; shift; shift; shift
+ ${MKDIR} ${dir}
+ ${CHOWN} ${owner} ${dir}
+ ${CHGRP} ${group} ${dir}
+ ${CHMOD} ${mode} ${dir}
+ done
+
+ if [ -n "${CONF_FILES}" -o -n "${CONF_FILES_PERMS}" -o \
+ -n "${SUPPORT_FILES}" ]
+ then
+ ${ECHO} "Installing configuration files:"
+ fi
+ set -- ${CONF_FILES}
+ while [ $# -gt 0 ]
+ do
+ samplefile="$1"; file="$2"
+ shift; shift
+
+ if [ -f ${file} ]
+ then
+ ${ECHO} " ${file} already exists"
+ else
+ ${ECHO} " ${file}"
+ ${CP} ${samplefile} ${file}
+ ${CHMOD} @CONF_FILES_MODE@ ${file}
+ fi
+ done
+ set -- ${CONF_FILES_PERMS}
+ while [ $# -gt 0 ]
+ do
+ samplefile="$1"; file="$2"; owner="$3"; group="$4"; mode="$5"
+ shift; shift; shift; shift; shift
+
+ if [ -f ${file} ]
+ then
+ ${ECHO} " ${file} already exists"
+ else
+ ${ECHO} " ${file}"
+ ${CP} ${samplefile} ${file}
+ ${CHOWN} ${owner} ${file}
+ ${CHGRP} ${group} ${file}
+ ${CHMOD} ${mode} ${file}
+ fi
+ done
+ set -- ${SUPPORT_FILES}
+ while [ $# -gt 0 ]
+ do
+ samplefile="$1"; file="$2"
+ shift; shift
+
+ if [ -f ${file} ]
+ then
+ ${ECHO} " ${file} already exists"
+ else
+ ${ECHO} " ${file}"
+ ${CP} ${samplefile} ${file}
+ ${CHMOD} @SUPPORT_FILES_MODE@ ${file}
+ fi
+ done
+ set -- ${RCD_SCRIPTS}
+ while [ $# -gt 0 ]
+ do
+ samplefile="$1"; file="$2"
+ shift; shift
+
+ if [ -f ${file} ]
+ then
+ ${ECHO} " ${file} already exists"
+ else
+ ${ECHO} " ${file}"
+ ${CP} ${samplefile} ${file}
+ ${CHMOD} @RCD_SCRIPTS_MODE@ ${file}
+ fi
+ done
+
+ if [ -n "${CONF_FILES}" -o -n "${CONF_FILES_PERMS}" ]
+ then
+ ${CAT} << EOF
+
+===========================================================================
+You may wish to customize the following files:
+
+EOF
+ set -- ${CONF_FILES}
+ while [ $# -gt 0 ]
+ do
+ samplefile="$1"; file="$2"
+ shift; shift
+
+ ${ECHO} " ${file}"
+ done
+ set -- ${CONF_FILES_PERMS}
+ while [ $# -gt 0 ]
+ do
+ samplefile="$1"; file="$2"; owner="$3"; group="$4"; mode="$5"
+ shift; shift; shift; shift; shift
+
+ ${ECHO} " ${file}"
+ done
+ ${CAT} << EOF
+===========================================================================
+EOF
+ fi
+ ;;
+
+*)
+ ${ECHO} "Unexpected argument: ${STAGE}"
+ exit 1
+ ;;
+esac
+
+# end of install