Subject: Re: pkg/36362: pkgsrc bulk builds doesn't support SU_CMD
To: None <pkg-manager@netbsd.org, gnats-admin@netbsd.org,>
From: Aleksey Cheusov <cheusov@tut.by>
List: pkgsrc-bugs
Date: 05/20/2007 21:35:02
The following reply was made to PR pkg/36362; it has been noted by GNATS.

From: Aleksey Cheusov <cheusov@tut.by>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: pkg/36362: pkgsrc bulk builds doesn't support SU_CMD
Date: Mon, 21 May 2007 00:30:49 +0300

 I forget to attach a patch. Sorry.
 
 
 Index: mk/bulk/build
 ===================================================================
 RCS file: /cvsroot/pkgsrc/mk/bulk/build,v
 retrieving revision 1.101
 diff -u -r1.101 build
 --- mk/bulk/build	7 Mar 2007 23:32:49 -0000	1.101
 +++ mk/bulk/build	20 May 2007 20:32:03 -0000
 @@ -31,6 +31,13 @@
  #
  
  ##
 +## Funcs
 +##
 +if test -f mk/bulk/build.funcs; then
 +    . mk/bulk/build.funcs
 +fi
 +
 +##
  ## Globals
  ##
  scriptdir=`dirname "$0"`
 @@ -257,7 +264,7 @@
  		SUPPORTSFILE BULK_BUILD_ID_FILE BUILDLOG BROKENFILE
  		BROKENWRKLOG
  		AWK GREP MAIL_CMD MKDIR PERL5 SED
 -		PKG_DELETE PKG_INFO PKGBASE"
 +		PKG_DELETE PKG_INFO PKGBASE SU_CMD"
  
  	values=`cd "$pkglint_dir" && $BMAKE show-vars VARNAMES="$vars" USE_TOOLS="awk grep mail mkdir perl sed"`
  
 @@ -271,6 +278,7 @@
  	done <<EOF
  $values
  EOF
 +
  	echo "------------------------------------------"
  	[ "$PKGBASE" = "pkglint" ] \
  	|| die	"Error reading the variables." \
 @@ -349,10 +357,10 @@
  					;;
  				* )
  					echo "build> ${PKG_DELETE} -r ${pkgname}"
 -					${PKG_DELETE} -r "${pkgname}"
 +					run_cmd_su ${PKG_DELETE} -r "${pkgname}"
  					if ${PKG_INFO} -qe "${pkgname}"; then
  						echo "build> $pkgname ($pkgdir) did not deinstall nicely.  Forcing the deinstall"
 -						${PKG_DELETE} -f "${pkgname}" || true
 +						run_cmd_su ${PKG_DELETE} -f "${pkgname}" || true
  					fi
  					;;
  			esac
 Index: mk/bulk/build.funcs
 ===================================================================
 RCS file: mk/bulk/build.funcs
 diff -N mk/bulk/build.funcs
 --- /dev/null	1 Jan 1970 00:00:00 -0000
 +++ mk/bulk/build.funcs	20 May 2007 20:32:03 -0000
 @@ -0,0 +1,8 @@
 +# Run command with special priviledges
 +run_cmd_su () {
 +	if [ -n "$SU_CMD" -a _"`id -u`" != _0 ]; then
 +		eval "${SU_CMD} '$@'"
 +	else
 +		eval "$@"
 +	fi
 +}
 Index: mk/bulk/pre-build
 ===================================================================
 RCS file: /cvsroot/pkgsrc/mk/bulk/pre-build,v
 retrieving revision 1.66
 diff -u -r1.66 pre-build
 --- mk/bulk/pre-build	28 Jan 2007 19:23:22 -0000	1.66
 +++ mk/bulk/pre-build	20 May 2007 20:32:03 -0000
 @@ -6,6 +6,11 @@
  # (c) 2000 Hubert Feyrer, All Rights Reserved.
  #
  
 +# Funcs
 +if [ -f mk/bulk/build.funcs ]; then
 +    . mk/bulk/build.funcs
 +fi
 +
  #set -v		# Debug
  
  # Pull in USR_PKGSRC:
 @@ -63,6 +68,7 @@
  LOCALBASE=`( cd ${PKGLINT_PKG_DIR} ; ${BMAKE} show-var VARNAME=LOCALBASE )`;
  X11BASE=`( cd ${PKGLINT_PKG_DIR} ; ${BMAKE} show-var VARNAME=X11BASE )`;
  DISTDIR=`( cd ${PKGLINT_PKG_DIR} ; ${BMAKE} show-var VARNAME=DISTDIR )`;
 +SU_CMD="`( cd ${PKGLINT_PKG_DIR} ; ${BMAKE} show-var VARNAME=SU_CMD )`";
  
  # Create ${BULKFILESDIR} if necessary
  echo "pre-build> Creating ${BULKFILESDIR} if necessary"
 @@ -126,7 +132,7 @@
  		do
  			if ${PKG_TOOLS_BIN}/pkg_info -K "$dbdir" -qe "$pkg"; then
  				echo "pre-build> ${PKG_TOOLS_BIN}/pkg_delete -r ${pkg}"
 -				${PKG_TOOLS_BIN}/pkg_delete -K "$dbdir" -r "$pkg"
 +				run_cmd_su ${PKG_TOOLS_BIN}/pkg_delete -K "$dbdir" -r "$pkg"
  			fi
  		done
  		#
 @@ -137,36 +143,35 @@
  		do
  			if ${PKG_TOOLS_BIN}/pkg_info -K "$dbdir" -qe "$pkg"; then
  				echo "pre-build> ${PKG_TOOLS_BIN}/pkg_delete -f ${pkg}"
 -				${PKG_TOOLS_BIN}/pkg_delete -K "$dbdir" -f "$pkg"
 +				run_cmd_su ${PKG_TOOLS_BIN}/pkg_delete -K "$dbdir" -f "$pkg"
  			fi
  		done
  
  		# We've tried our best to get rid of the pkgs, now do it
  		# the hard way.  If it wasn't for stuff in $X11BASE, I
  		# wouldn't have hard feelings about this!
 -		rm -fr *
 +		run_cmd_su rm -fr *
  	fi
  done
  
 -cd "$LOCALBASE" && rm -fr * && rm -fr .??*;
 +cd "$LOCALBASE" && run_cmd_su rm -fr * && run_cmd_su rm -fr .??*;
  if [ x"$BMAKE" = x"bmake" ]; then
  	( cd "$LOCALBASE" && tar xf /tmp/$$.tar )
  fi
  
  # Stuff known to be broken
 -rm -fr "$X11BASE/share/gimp"
 -rm -fr "$X11BASE/share/gnome"
 -rm -fr "$X11BASE/share/kde"
 -rm -fr "$X11BASE/share/netscape"
 -rm -fr /var/tmp/inst*
 -rm -fr "$X11BASE/lib/libgimp"*	# gimp doesn't build with old libs around
 -rm -fr /nonexistent		# broken useradd on pop3d
 -rm -fr /home/majordom		# mail/majordomo pkg
 -rm -fr /home/nut		# sysutils/ups-net
 -rm -fr /var/wwwoffle		# www/wwwoffle
 -rm -fr /tmp/config-guess-*
 -rm -fr /tmp/mod*
 -
 +run_cmd_su rm -fr "$X11BASE/share/gimp"
 +run_cmd_su rm -fr "$X11BASE/share/gnome"
 +run_cmd_su rm -fr "$X11BASE/share/kde"
 +run_cmd_su rm -fr "$X11BASE/share/netscape"
 +run_cmd_su rm -fr /var/tmp/inst*
 +run_cmd_su rm -fr "$X11BASE/lib/libgimp"*	# gimp doesn't build with old libs around
 +run_cmd_su rm -fr /nonexistent		# broken useradd on pop3d
 +run_cmd_su rm -fr /home/majordom		# mail/majordomo pkg
 +run_cmd_su rm -fr /home/nut		# sysutils/ups-net
 +#run_cmd_su rm -fr /var/wwwoffle		# www/wwwoffle
 +run_cmd_su rm -fr /tmp/config-guess-*
 +run_cmd_su rm -fr /tmp/mod*
  
  # Clean up state files
  cd "${USR_PKGSRC}"
 @@ -250,7 +255,7 @@
  		do
  			if ${PKG_TOOLS_BIN}/pkg_info -K "$dbdir" -qe "$pkg"; then
  				echo "pre-build> ${PKG_TOOLS_BIN}/pkg_delete -r ${pkg}"
 -				${PKG_TOOLS_BIN}/pkg_delete -K "$dbdir" -r "$pkg"
 +				run_cmd_su ${PKG_TOOLS_BIN}/pkg_delete -K "$dbdir" -r "$pkg"
  			fi
  		done
  	fi
 
 -- 
 Best regards, Aleksey Cheusov.