pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/mk/install First try at fixing a deficiency in the pac...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/2a1b58819064
branches:  trunk
changeset: 511903:2a1b58819064
user:      jlam <jlam%pkgsrc.org@localhost>
date:      Tue Apr 25 19:54:39 2006 +0000

description:
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.

diffstat:

 mk/install/bsd.pkginstall.mk |   10 ++-
 mk/install/deinstall         |    6 +-
 mk/install/dirs              |  123 +++++++++++++++++++++++++++++++++++++-
 mk/install/files             |  134 ++++++++++++++++++++++++++++++++++++++++--
 mk/install/install           |   14 ++-
 5 files changed, 263 insertions(+), 24 deletions(-)

diffs (truncated from 486 to 300 lines):

diff -r ff05ba3ed0f2 -r 2a1b58819064 mk/install/bsd.pkginstall.mk
--- a/mk/install/bsd.pkginstall.mk      Tue Apr 25 17:46:14 2006 +0000
+++ b/mk/install/bsd.pkginstall.mk      Tue Apr 25 19:54:39 2006 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: bsd.pkginstall.mk,v 1.47 2006/04/23 00:00:43 jlam Exp $
+# $NetBSD: bsd.pkginstall.mk,v 1.48 2006/04/25 19:54:39 jlam Exp $
 #
 # This Makefile fragment is included by bsd.pkg.mk and implements the
 # common INSTALL/DEINSTALL scripts framework.  To use the pkginstall
@@ -745,6 +745,12 @@
 #      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".
@@ -761,11 +767,13 @@
 #
 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}
diff -r ff05ba3ed0f2 -r 2a1b58819064 mk/install/deinstall
--- a/mk/install/deinstall      Tue Apr 25 17:46:14 2006 +0000
+++ b/mk/install/deinstall      Tue Apr 25 19:54:39 2006 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: deinstall,v 1.39 2006/03/15 04:52:57 jlam Exp $
+# $NetBSD: deinstall,v 1.40 2006/04/25 19:54:39 jlam Exp $
 
 case ${STAGE} in
 VIEW-DEINSTALL)
@@ -37,8 +37,6 @@
        #
        ${TEST} ! -x ./+FILES ||
                ./+FILES REMOVE ${PKG_METADATA_DIR}
-       ${TEST} ! -x ./+RCD_SCRIPTS ||
-               ./+RCD_SCRIPTS REMOVE ${PKG_METADATA_DIR}
        ;;
 
 POST-DEINSTALL)
@@ -68,8 +66,6 @@
                ./+USERGROUP CHECK-REMOVE ${PKG_METADATA_DIR}
        ${TEST} ! -x ./+FILES ||
                ./+FILES CHECK-REMOVE ${PKG_METADATA_DIR}
-       ${TEST} ! -x ./+RCD_SCRIPTS ||
-               ./+RCD_SCRIPTS CHECK-REMOVE ${PKG_METADATA_DIR}
        ${TEST} ! -x ./+DIRS ||
                ./+DIRS CHECK-REMOVE ${PKG_METADATA_DIR}
        ;;
diff -r ff05ba3ed0f2 -r 2a1b58819064 mk/install/dirs
--- a/mk/install/dirs   Tue Apr 25 17:46:14 2006 +0000
+++ b/mk/install/dirs   Tue Apr 25 19:54:39 2006 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: dirs,v 1.10 2006/03/19 23:58:14 jlam Exp $
+# $NetBSD: dirs,v 1.11 2006/04/25 19:54:39 jlam Exp $
 #
 # Generate a +DIRS script that reference counts directories that are
 # required for the proper functioning of the package.
@@ -10,8 +10,8 @@
 #
 # +DIRS - reference-counted directory management script
 #
-# Usage: ./+DIRS ADD|REMOVE [metadatadir]
-#        ./+DIRS CHECK-ADD|CHECK-REMOVE [metadatadir]
+# 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
@@ -21,7 +21,13 @@
 # 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.
+# 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
@@ -41,12 +47,14 @@
 #      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@"
@@ -75,6 +83,14 @@
        _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
@@ -162,6 +178,23 @@
        done
        ;;
 
+PERMS)
+       ${SED} -n "/^\# DIR: /{s/^\# DIR: //;p;}" ${SELF} | ${SORT} -u |
+       while read dir d_flags d_user d_group d_mode; do
+               case $dir in
+               "")     continue ;;
+               [!/]*)  dir="${PKG_PREFIX}/$dir" ;;
+               esac
+               case $d_user/$d_group/$d_mode/$_PKG_CONFIG/$_PKG_CONFIG_PERMS in
+               [!/]*/[!/]*/[!/]*/yes/yes)
+                       ${CHOWN} $d_user $dir
+                       ${CHGRP} $d_group $dir
+                       ${CHMOD} $d_mode $dir
+                       ;;
+               esac
+       done
+       ;;
+
 CHECK-ADD)
        ${SED} -n "/^\# DIR: /{s/^\# DIR: //;p;}" ${SELF} | ${SORT} -u |
        { while read dir d_flags d_user d_group d_mode; do
@@ -234,9 +267,87 @@
        ${TEST} $? -eq 0 || exitcode=1
        ;;
 
+CHECK-PERMS)
+       tmpdir="${TMPDIR:-/tmp}/private.$$"
+       ${MKDIR} -p $tmpdir 2>/dev/null || exit 1
+       ${CHMOD} 700 $tmpdir
+       ${SED} -n "/^\# DIR: /{s/^\# DIR: //;p;}" ${SELF} | ${SORT} -ru |
+       { while read dir d_flags d_user d_group d_mode; 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 }'`
+               ${MKDIR} -p $tmpdir/tmp
+               ${CHMOD} $d_mode $tmpdir/tmp 2>/dev/null
+               longmode=`${LS} -ld $tmpdir/tmp | ${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 -rf $tmpdir
+       ${TEST} $? -eq 0 || exitcode=1
+       ;;
+
 *)
-       ${ECHO} "Usage: ./+DIRS ADD|REMOVE [metadatadir]"
-       ${ECHO} "       ./+DIRS CHECK-ADD|CHECK-REMOVE [metadatadir]"
+       ${ECHO} "Usage: ./+DIRS ADD|REMOVE|PERMS [metadatadir]"
+       ${ECHO} "       ./+DIRS CHECK-ADD|CHECK-REMOVE|CHECK-PERMS [metadatadir]"
        ;;
 esac
 exit $exitcode
diff -r ff05ba3ed0f2 -r 2a1b58819064 mk/install/files
--- a/mk/install/files  Tue Apr 25 17:46:14 2006 +0000
+++ b/mk/install/files  Tue Apr 25 19:54:39 2006 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files,v 1.10 2006/03/19 23:58:14 jlam Exp $
+# $NetBSD: files,v 1.11 2006/04/25 19:54:39 jlam Exp $
 #
 # Generate a +FILES script that reference counts config files that are
 # required for the proper functioning of the package.
@@ -10,9 +10,9 @@
 #
 # +FILES - reference-counted configuration file management script
 #
-# Usage: ./+FILES ADD|REMOVE [metadatadir]
+# Usage: ./+FILES ADD|REMOVE|PERMS [metadatadir]
 #        ./+FILES VIEW-REMOVE depotdir viewdir
-#        ./+FILES CHECK-ADD|CHECK-REMOVE [metadatadir]
+#        ./+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
@@ -23,7 +23,13 @@
 # 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>.
+# 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
@@ -42,6 +48,7 @@
 #      f       ignore ${PKG_CONFIG}
 #      r       file is an rc.d script (consider ${PKG_RCD_SCRIPTS})
 #
+AWK="@AWK@"
 CAT="@CAT@"
 CP="@CP@"
 CHGRP="@CHGRP@"
@@ -50,6 +57,7 @@
 CMP="@CMP@"
 ECHO="@ECHO@"
 GREP="@GREP@"
+LS="@LS@"
 MKDIR="@MKDIR@"
 MV="@MV@"
 PWD_CMD="@PWD_CMD@"
@@ -73,6 +81,14 @@
        _PKG_CONFIG=no
        ;;
 esac
+case "${PKG_CONFIG_PERMS:-@PKG_CONFIG_PERMS@}" in
+[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)



Home | Main Index | Thread Index | Old Index