[PC-BSD Commits] r15823 - pcbsd/current/src-sh/pc-metapkgmanager

svn at pcbsd.org svn at pcbsd.org
Thu Mar 15 11:57:44 PDT 2012


Author: kris
Date: 2012-03-15 18:57:43 +0000 (Thu, 15 Mar 2012)
New Revision: 15823

Modified:
   pcbsd/current/src-sh/pc-metapkgmanager/pc-metapkgmanager
Log:

Add --chroot funcionality which allows us to install meta-pkgs into a 
chroot / jail environment. Will be used by warden down the road. 



Modified: pcbsd/current/src-sh/pc-metapkgmanager/pc-metapkgmanager
===================================================================
--- pcbsd/current/src-sh/pc-metapkgmanager/pc-metapkgmanager	2012-03-15 18:03:04 UTC (rev 15822)
+++ pcbsd/current/src-sh/pc-metapkgmanager/pc-metapkgmanager	2012-03-15 18:57:43 UTC (rev 15823)
@@ -47,6 +47,7 @@
   list     	         -- List the available meta-packages
   status <pkg>    	 -- List the status of the specified meta-packages
   --pkgset <pkgset>	 -- Change default pkgset we are using
+  --chroot <dir>	 -- Operate on the directory specififed using chroot
 
 EOF
         exit 1
@@ -73,7 +74,13 @@
 
 	# If a pre-install script, run it now
 	if [ -e "${MPDIR}/${_apkg}/pre-install.sh" ] ; then
-		sh ${MPDIR}/${_apkg}/pre-install.sh >/dev/null 2>/dev/null
+	  if [ -z "$_chroot" ] ; then
+	    sh ${MPDIR}/${_apkg}/pre-install.sh >/dev/null 2>/dev/null
+	  else
+	    cp ${MPDIR}/${_apkg}/pre-install.sh ${_chroot}/.pre-install.sh.$$ >/dev/null 2>/dev/null
+	    chroot "$_chroot" sh /.pre-install.sh.$$ >/dev/null 2>/dev/null
+	    rm ${_chroot}/.pre-install.sh.$$
+          fi
 	fi
 
         # Now query pkg_info to confirm each pkg is installed
@@ -84,33 +91,57 @@
 		# Start installing the packages now
 		if [ "$loc" = "NET" ] ; then
 			PACKAGESITE="$2" ; export PACKAGESITE
-			pkg_add -f -r "$pkg" >>${LOGFILE} 2>>${LOGFILE}
+			${_chrootcmd} pkg_add -f -r "$pkg" >>${LOGFILE} 2>>${LOGFILE}
 		else
-			cd "${2}"
-			pkg_add -f "${pkg}.tbz" >>${LOGFILE} 2>>${LOGFILE}
+		  if [ -z "$_chroot" ] ; then
+		     cd "${2}"
+		     pkg_add -f "${pkg}.tbz" >>${LOGFILE} 2>>${LOGFILE}
+		  else
+		     # Do some nullfs mounting to get our dist dir into the chroot
+		     mkdir ${_chroot}/.mnt.$$
+		     mount_nullfs "$2" "${_chroot}/.mnt.$$"
+		     ${_chrootcmd} pkg_add -f "/.mnt.$$/${pkg}.tbz" >>${LOGFILE} 2>>${LOGFILE}
+		  fi
 		fi
         done < ${MPDIR}/${_apkg}/pkg-list
 
+	# Umount any nullfs stuff in chroot
+        if [ -n "${_chroot}" -a "$loc" = "PATH" ] ; then
+	   sleep 1
+	   umount -f ${_chroot}/.mnt.$$
+	   rmdir ${_chroot}/.mnt.$$
+	fi
+
 	# Make sure the program appears fully installed now, if not set error
 	stat_metapkg ${_apkg}
 	if [ "$?" != "0" ] ; then _pkgStatus=1 ; fi
 
 	# Apply our PC-BSD specific xdg menu entry files
-	/usr/local/bin/pc-xdgutil updatemenu >>${LOGFILE} 2>>${LOGFILE}
+	if [ -z "$_chroot" ] ; then
+	  /usr/local/bin/pc-xdgutil updatemenu >>${LOGFILE} 2>>${LOGFILE}
+	elif [ -e "${_chroot}/usr/local/bin/pc-xdgutil" ] ; then
+	  chroot ${_chroot} /usr/local/bin/pc-xdgutil updatemenu >>${LOGFILE} 2>>${LOGFILE}
+	fi
 
 	# Hack to ensure that we share cursors / icons between linux / FBSD apps
-	if [ ! -h "/compat/linux/usr/share/icons" ] ; then
-		rm -rf /compat/linux/usr/share/icons
-		ln -fs /usr/local/lib/X11/icons /compat/linux/usr/share/icons
+	if [ ! -h "${_chroot}/compat/linux/usr/share/icons" ] ; then
+	   rm -rf ${_chroot}/compat/linux/usr/share/icons 2>/dev/null
+	   ln -fs /usr/local/lib/X11/icons ${_chroot}/compat/linux/usr/share/icons 2>/dev/null
 	fi
-	if [ ! -h "/compat/linux/usr/share/fonts" ] ; then
-		rm -rf /compat/linux/usr/share/fonts
-		ln -fs /usr/local/lib/X11/fonts /compat/linux/usr/share/fonts
+	if [ ! -h "${_chroot}/compat/linux/usr/share/fonts" ] ; then
+	   rm -rf ${_chroot}/compat/linux/usr/share/fonts 2>/dev/null 
+	   ln -fs /usr/local/lib/X11/fonts ${_chroot}/compat/linux/usr/share/fonts 2>/dev/null
 	fi
 
 	# If a post-install script, run it now
 	if [ -e "${MPDIR}/${_apkg}/post-install.sh" ] ; then
-		sh ${MPDIR}/${_apkg}/post-install.sh >/dev/null 2>/dev/null
+	  if [ -z "$_chroot" ] ; then
+	    sh ${MPDIR}/${_apkg}/post-install.sh >/dev/null 2>/dev/null
+	  else
+	    cp ${MPDIR}/${_apkg}/post-install.sh ${_chroot}/.post-install.sh.$$ >/dev/null 2>/dev/null
+	    chroot "$_chroot" sh /.post-install.sh.$$ >/dev/null 2>/dev/null
+	    rm ${_chroot}/.post-install.sh.$$
+          fi
 	fi
 
 	echo "Finished Meta-Package: $_apkg"
@@ -135,7 +166,7 @@
 		_iList=""
 		while read pkg
 		do
-			pkg_info $pkg >/dev/null 2>/dev/null
+			${_chrootcmd} pkg_info $pkg >/dev/null 2>/dev/null
 			if [ "$?" != "0" ] ; then continue; fi
 			_iList="${_iList}${pkg}:"
 		done < ${i}/pkg-list
@@ -151,7 +182,13 @@
 
 	# If a pre-remove script, run it now
 	if [ -e "${MPDIR}/${_dpkg}/pre-remove.sh" ] ; then
-		sh ${MPDIR}/${_dpkg}/pre-remove.sh >/dev/null 2>/dev/null
+	  if [ -z "$_chroot" ] ; then
+	    sh ${MPDIR}/${_dpkg}/pre-remove.sh >/dev/null 2>/dev/null
+	  else
+	    cp ${MPDIR}/${_dpkg}/pre-remove.sh ${_chroot}/.pr.sh.$$ >/dev/null 2>/dev/null
+	    chroot "$_chroot" sh /.pr.sh.$$ >/dev/null 2>/dev/null
+	    rm ${_chroot}/.pr.sh.$$
+          fi
 	fi
 
 	# Lets remove the pkgs from this meta-pkg
@@ -159,7 +196,7 @@
 	do
 
 		# Make sure this pkg is installed
-		pkg_info $rmPkg >/dev/null 2>/dev/null
+		${_chrootcmd} pkg_info $rmPkg >/dev/null 2>/dev/null
 		if [ "$?" != "0" ] ; then 
 			echo "Already uninstalled: ${rmPkg}" 
 			echo "Already uninstalled: ${rmPkg}" >>${LOGFILE}
@@ -167,7 +204,7 @@
 		fi
 
 		# confirm this package isn't required by any others
-		pkg_info -R ${rmPkg} 2>/dev/null | grep "Required by:" >/dev/null 2>/dev/null
+		${_chrootcmd} pkg_info -R ${rmPkg} 2>/dev/null | grep "Required by:" >/dev/null 2>/dev/null
 		if [ "$?" = "0" ] ; then 
 			echo "Skipping Required: ${rmPkg}" 
 			echo "Skipping Required: ${rmPkg}" >>${LOGFILE}
@@ -184,7 +221,7 @@
 
 		echo "Removing: ${rmPkg}"
 		echo "Removing: ${rmPkg}" >>${LOGFILE}
-		pkg_delete -f ${rmPkg} >>${LOGFILE} 2>>${LOGFILE}
+		${_chrootcmd} pkg_delete -f ${rmPkg} >>${LOGFILE} 2>>${LOGFILE}
 
 	done < ${MPDIR}/${_dpkg}/pkg-list
 
@@ -194,7 +231,13 @@
 
 	# If a post-remove script, run it now
 	if [ -e "${MPDIR}/${_dpkg}/post-remove.sh" ] ; then
-		sh ${MPDIR}/${_dpkg}/post-remove.sh >/dev/null 2>/dev/null
+	  if [ -z "$_chroot" ] ; then
+	    sh ${MPDIR}/${_dpkg}/post-remove.sh >/dev/null 2>/dev/null
+	  else
+	    cp ${MPDIR}/${_dpkg}/post-remove.sh ${_chroot}/.pr.sh.$$ >/dev/null 2>/dev/null
+	    chroot "$_chroot" sh /.pr.sh.$$ >/dev/null 2>/dev/null
+	    rm ${_chroot}/.pr.sh.$$
+          fi
 	fi
 
         # Now check what packages we have and prune those whom aren't needed
@@ -203,7 +246,7 @@
         z="1"
         do
                 FOUND=""
-                for j in `pkg_info -I -a | cut -d ' ' -f 1`
+                for j in `${_chrootcmd} pkg_info -I -a | cut -d ' ' -f 1`
                 do
                         echo "$kPkgs" | grep "${j}:" >/dev/null 2>/dev/null
                         if [ "$?" != "0" ] ; then
@@ -222,10 +265,10 @@
 
 # Check if the specified pkg doesn't have anything which requires it, and remove it if so
 check_remove_pkg() {
-        pkg_info -R "${1}" | grep "Required" >/dev/null 2>/dev/null
+        ${_chrootcmd} pkg_info -R "${1}" | grep "Required" >/dev/null 2>/dev/null
         if [ "$?" != "0" ] ; then
 		echo "Removing non-used pkg: $1" >>${LOGFILE} 2>>${LOGFILE} 
-                pkg_delete -f ${1} >>${LOGFILE} 2>>${LOGFILE}
+                ${_chrootcmd} pkg_delete -f ${1} >>${LOGFILE} 2>>${LOGFILE}
                 return 0
         fi
         return 1
@@ -284,7 +327,7 @@
 	# Now query pkg_info to confirm each pkg is installed
 	while read pkg
 	do
-		pkg_info $pkg >/dev/null 2>/dev/null
+		${_chrootcmd} pkg_info $pkg >/dev/null 2>/dev/null
 		if [ "$?" != "0" ] ; then 
 			nfound=1
 		else
@@ -359,6 +402,11 @@
 }
 
 
+# Unset some vars
+_chroot=""
+_chrootcmd=""
+_pkgflags=""
+
 if [ $# -eq 0 ]; then display_usage; fi
 
 # Parse ye olde cli flags
@@ -368,6 +416,16 @@
        add) parse_metapkgs "$2" "add" "$3" ; exit 0 ;;
        del) parse_metapkgs "$2" "del" ; exit 0 ;;
     status) stat_metapkg "$2" ; exit 0 ;;
+  --chroot) if [ -z "$2" ] ; then display_usage ; fi  
+	    _chroot="$2" 
+            if [ ! -e "${_chroot}/usr/sbin/pkg_add" ] ; then
+              echo "Invalid chroot dir: ${_chroot}"
+              exit 1
+	    fi
+	    _pkgflags="-C ${_chroot}"
+	    _chrootcmd="chroot ${_chroot}"
+	    shift
+            ;;
   --pkgset) if [ -z "$2" ] ; then display_usage ; fi  
             PKGSET="$2" 
             if [ ! -d "${DBDIR}/$PKGSET" ] ; then
@@ -377,7 +435,6 @@
             MPDIR="${DBDIR}/${PKGSET}"
             shift ;;
          *) display_usage ;;
-    #if [ $# -gt 1 ]; then display_usage; fi
   esac
   shift
 done



More information about the Commits mailing list