pkgsrc-Users archive

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

pkg_chk and root priviledges



As far as I understand pkg_chk can be used for updating packages if
it is run as root because pkg_add and pkg_delete commands are run without
any su/sudo prefixes (I saw PKG_DELETE and PKG_ADD variables in the code)

The attached patch adds -S option, if it is applied
pkg_add/pkg_delete commands are run with SU_CMD prefix obtained from mk.conf.

I assume adding -S option is more convenient for typical usage
than setting PKG_DELETE and PKG_ADD variables.

Any comments?
? README.html
? pkg_chk__SU_CMD.patch
? pkg_chk__tbz.patch
Index: files/pkg_chk.sh
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_chk/files/pkg_chk.sh,v
retrieving revision 1.42
diff -u -r1.42 pkg_chk.sh
--- files/pkg_chk.sh    20 Sep 2006 21:54:13 -0000      1.42
+++ files/pkg_chk.sh    4 Nov 2006 20:52:12 -0000
@@ -97,7 +97,7 @@
     {
     for pkg in $* ; do
        if [ -d $PKG_DBDIR/$pkg ] ; then
-           run_cmd "${PKG_DELETE} -r $pkg" 1
+           run_cmd_su "${PKG_DELETE} -r $pkg" 1
        fi
     done
     }
@@ -175,7 +175,8 @@
        cd $PKGSRCDIR/pkgtools/pkg_chk
        extract_make_vars Makefile AWK GREP GZIP_CMD SED SORT TSORT PACKAGES \
                        PKG_ADD PKG_DELETE PKG_INFO PKG_DBDIR PKGCHK_CONF \
-                       PKGCHK_UPDATE_CONF PKGCHK_TAGS PKGCHK_NOTAGS PKG_SUFX
+                       PKGCHK_UPDATE_CONF PKGCHK_TAGS PKGCHK_NOTAGS \
+                       PKG_SUFX SU_CMD
        if [ -z "$PACKAGES" ];then
            PACKAGES=$PKGSRCDIR/packages
        fi
@@ -477,7 +478,7 @@
        if [ -n "$saved_PKG_PATH" ] ; then
            export PKG_PATH=$saved_PKG_PATH
        fi
-       run_cmd "${PKG_ADD} $PACKAGES/$PKGNAME$PKG_SUFX"
+       run_cmd_su "${PKG_ADD} $PACKAGES/$PKGNAME$PKG_SUFX"
        if [ -n "$saved_PKG_PATH" ] ; then
            unset PKG_PATH
        fi
@@ -536,6 +537,15 @@
     fi
     }
 
+run_cmd_su()
+    {
+    if [ -n "$SU_CMD" ]; then
+       run_cmd "${SU_CMD} '$1'" "$2"
+    else
+       run_cmd "$1" "$2"
+    fi
+    }
+
 set_path()
     {
     arg=$1
@@ -570,6 +580,7 @@
        -q      Do not display actions or take any action; only list packages
        -r      Recursively remove mismatches (use with care) (implies -i)
        -s      Use source for building packages
+       -S      Prepand pkg_add/pkg_delete with $SU_CMD obtained from mk.conf
        -U tags Comma separated list of pkgchk.conf tags to unset
        -u      Update all mismatched packages (implies -i)
        -v      Verbose
@@ -630,6 +641,7 @@
        -U )    opt_U="$2" ; shift ;;
        -u )    opt_u=1 ;;
        -v )    opt_v=1 ;;
+       -S )    opt_S=1 ;;
        -- )    shift; break ;;
     esac
     shift
@@ -709,6 +721,10 @@
     PACKAGES="$PACKAGES/All"
 fi
 
+if [ -z "$opt_S" ] ; then
+    SU_CMD=
+fi
+
 if [ -n "$opt_N" ]; then
        ${PKG_INFO} | \
                ${SED} -e "s/[  ].*//" -e "s/-[^-]*$//" \
-- 
Best regards, Aleksey Cheusov.


Home | Main Index | Thread Index | Old Index