pkgsrc/mk/install/deinstall
jlam ede4976eb9 First try at fixing a deficiency in the package +INSTALL scripts,
where they don't verify that any pre-existing config files and
directories have the correct permissions.  For example, if you are
upgrading a package to a newer version and the config files and
directories used by the package need to have different permissions
than in previous versions of the package, then the new package may
fail to work because it can't access pre-existing files and directories.

This commit improves on this by doing the following:

(1) Teach the +FILES and +DIRS scriptlets two new actions "PERMS" and
    "CHECK-PERMS".  "PERMS" fixes permissions on existing files and
    directories.  "CHECK-PERMS" will verify those same bits and warn
    the user when they are wrong.  The "CHECK-PERMS" actions for the
    two scriptlets are run immediately after the "ADD" actions.

(2) Add a new variable PKG_CONFIG_PERMS that controls whether the
    "PERMS" action will automatically fix permissions.  PKG_CONFIG_PERMS
    is only consulted if PKG_CONFIG is "yes".  PKG_CONFIG_PERMS can
    be set in the shell environment when running pkg_add, e.g.:

        export PKG_CONFIG=yes
        export PKG_CONFIG_PERMS=yes
        pkg_add /path/to/binary/package.tgz

    The default value of PKG_CONFIG_PERMS embedded into the +INSTALL
    script may also be set in /etc/mk.conf.  This value defaults to
    "no", so that by default, the +INSTALL script will not modify or
    destroy any existing configuration files or directories.

The +INSTALL script will now always warn you if there are files or
directories whose permissions differ from what the package is expecting
to use, and if PKG_CONFIG_PERMS is set to "yes", then it will go ahead
and fix those permissions for you automatically.
2006-04-25 19:54:39 +00:00

73 lines
1.7 KiB
Text

# $NetBSD: deinstall,v 1.40 2006/04/25 19:54:39 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