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

svn at pcbsd.org svn at pcbsd.org
Thu Mar 15 14:03:13 PDT 2012


Author: kris
Date: 2012-03-15 21:03:13 +0000 (Thu, 15 Mar 2012)
New Revision: 15825

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

Add updating functionality to pc-metapkgmanager, which of course works
in a chroot as well



Modified: pcbsd/current/src-sh/pc-metapkgmanager/pc-metapkgmanager
===================================================================
--- pcbsd/current/src-sh/pc-metapkgmanager/pc-metapkgmanager	2012-03-15 19:46:34 UTC (rev 15824)
+++ pcbsd/current/src-sh/pc-metapkgmanager/pc-metapkgmanager	2012-03-15 21:03:13 UTC (rev 15825)
@@ -43,9 +43,14 @@
 			    <loc> should be a FTP / HTTP url where pkg_add
 			    can fetch packages, or an absolute path to
 			    location of pkg files on disk.
+  checkup		 -- Check for updates to pkgs
   del pkg1,pkg2	  	 -- Delete the specified list of meta-packages
   list     	         -- List the available meta-packages
   status <pkg>    	 -- List the status of the specified meta-packages
+  update pkg1,pkg2 <loc> -- Update all system packages, or just <pkg> if specified
+			    <loc> should be a FTP / HTTP url where pkg_add
+			    can fetch packages, or an absolute path to
+			    location of pkg files on disk.
   --pkgset <pkgset>	 -- Change default pkgset we are using
   --chroot <dir>	 -- Operate on the directory specififed using chroot
 
@@ -402,10 +407,186 @@
 }
 
 
+checkup_pkgs() {
+
+  _nodsp="$1"
+
+  # Checkout the installed pkgs and compare to master list
+  local fPkgUp=0
+  ls ${_chroot}/var/db/pkg > /tmp/.pkgList.$$
+  cat ${MPDIR}/master-pkg-index | cut -d ":" -f 1-2 | sed 's|:|-|g' > /tmp/.pkgList2.$$
+  diff /tmp/.pkgList.$$ /tmp/.pkgList2.$$ | grep '^<' | sed 's|< ||g' > /tmp/.dList.$$
+  rm /tmp/.pkgList.$$
+  rm /tmp/.pkgList2.$$
+  while read pLine
+  do
+    pName=`echo $pLine | rev | cut -d "-" -f 2-25 | rev`
+    pVer=`echo $pLine | rev | cut -d "-" -f 1 | rev`
+		
+    # Make sure this version isn't in our index
+    grep "^${pName}:${pVer}" ${MPDIR}/master-pkg-index >/dev/null 2>/dev/null
+    if [ $? -eq 0 ] ; then continue ; fi
+
+    # Make sure the old pkg is something we've updated, not the user manually
+    grep "^${pName}:${pVer}" ${MPDIR}/master-pkg-index-old >/dev/null 2>/dev/null
+    if [ $? -ne 0 ] ; then continue ; fi
+
+    # Get the info from master-pkg-index
+    iLine=`grep "^${pName}:" ${MPDIR}/master-pkg-index`
+    if [ -z "$iLine" ] ; then continue ; fi
+    iVer="`echo $iLine | cut -d ':' -f 2`"
+    iSiz="`echo $iLine | cut -d ':' -f 3`"
+    iFile="`echo $iLine | cut -d ':' -f 4`"
+
+    # Is this version different?
+    if [ "$pVer" = "$iVer" ] ; then continue ; fi
+
+    if [ $fPkgUp -eq 0 -a "$_nodsp" != "YES" ] ; then 
+       echo "The following package updates are available:"
+       echo ""
+       fPkgUp=1
+    fi
+
+    if [ "$_nodsp" != "YES" ] ; then
+      # Display the pkg update data
+      echo "PKGUPDATE: ${pName} ${pVer} -> ${iVer}"
+      echo "PKGUPDATEKB: ${iSiz}"
+      echo "PKGUPDATEFILE: ${iFile}"
+      echo "To update this pkg run \"${0} updatepkgs ${pName}\""
+      echo ""
+    fi
+
+    # Save the variable of available pkg updates
+    PKGUPDATES="${PKGUPDATES}${pName}:"
+  done < /tmp/.dList.$$
+  rm /tmp/.dList.$$
+
+  # Display command to use for pkg-updating
+  if [ $fPkgUp -eq 1 -a "$_nodsp" != "YES" ] ; then 
+     echo " "
+     echo "To update all run \"${0} updatepkgs\""
+     echo " "
+  elif [ "$_nodsp" != "YES" ] ; then
+     echo "All packages are up to date!"
+  fi
+  return 0
+}
+
+updatepkgs() {
+  # Check for updates to the pkgs quietly
+  checkup_pkgs "YES"
+  if [ -z "$1" -a -z "$PKGUPDATES" ] ; then
+     echo "No packages need updating!"
+     exit 1
+  fi
+  if [ -n "$1" ] ; then
+     for pkg in `echo $1 | sed 's|,| |g'`
+     do
+       echo "$PKGUPDATES" | grep -q "${pkg}:"
+       if [ $? -ne 0 ] ; then
+         echo "No update available for ${pkg}!"
+         exit 1
+       fi
+     done
+  fi
+
+  # Figure out the type of location we are installing from
+  echo $2 | grep -e '^http://' -e '^ftp://' >/dev/null 2>/dev/null
+  if [ "$?" = "0" ] ; then
+     loc="NET"
+     PACKAGESITE="$2" ; export PACKAGESITE
+  else
+     if [ ! -d "${2}" ] ; then exit_err "The pkg location $2 does not exist!" ; fi
+     loc="PATH"
+     cd "${2}"
+  fi
+
+  if [ "$loc" = "PATH" -a -n "$_chroot" ] ; then
+     # Do some nullfs mounting to get our dist dir into the chroot
+     mkdir ${_chroot}/.mnt.$$
+     mount_nullfs "$2" "${_chroot}/.mnt.$$"
+  fi
+
+  # Do the updates now
+  if [ -z "$1" ] ; then
+    # Updating all
+    get_num_pkgs "`echo $PKGUPDATES | sed 's|:| |g'`"
+    echo "Pending Meta-Package changes: $VAL"
+    echo "Pending Meta-Package changes: $VAL" >>${LOGFILE}
+    for pkg in `echo $PKGUPDATES | sed 's|:| |g'`
+    do
+      do_update "$pkg"
+    done
+  else
+    # Updating a list of pkgs
+    get_num_pkgs "$1"
+    echo "Pending Meta-Package changes: $VAL"
+    echo "Pending Meta-Package changes: $VAL" >>${LOGFILE}
+    for pkg in `echo $1 | sed 's|,| |g'`
+    do
+      do_update "$pkg"
+    done
+  fi
+
+  # Unmount any distdir
+  if [ "$loc" = "PATH" -a -n "$_chroot" ] ; then
+     umount -f ${_chroot}/.mnt.$$
+     rmdir ${_chroot}/.mnt.$$
+  fi
+
+  echo "Meta-Package changes finished!"
+
+}
+
+do_update() {
+  _pU="$1"
+  # get the old pkg-name
+  oPkg=$(get_pkg_from_name $_pU sys)
+  nPkg=$(get_pkg_from_name $_pU ${MPDIR}/master-pkg-index)
+  echo "Updating package: $oPkg -> $nPkg"
+  echo "Updating package: $oPkg -> $nPkg" >> ${LOGFILE}
+
+  # Remove the old pkg
+  #echo "${_chrootcmd} pkg_delete -f $oPkg"
+  ${_chrootcmd} pkg_delete -f "$oPkg" >>${LOGFILE} 2>>${LOGFILE}
+
+  # Start installing the packages now
+  if [ "$loc" = "NET" ] ; then
+     #echo "${_chrootcmd} pkg_add -f -r $nPkg"
+     ${_chrootcmd} pkg_add -f -r "$nPkg" >>${LOGFILE} 2>>${LOGFILE}
+  else
+     if [ -z "$_chroot" ] ; then
+        pkg_add -f "${nPkg}.tbz" >>${LOGFILE} 2>>${LOGFILE}
+     else
+        ${_chrootcmd} pkg_add -f "/.mnt.$$/${nPkg}.tbz" >>${LOGFILE} 2>>${LOGFILE}
+     fi
+  fi
+
+}
+
+get_pkg_from_name() {
+  if [ "$2" = "sys" ] ; then
+    ${_chrootcmd} pkg_info | cut -d ' ' -f 1 >/tmp/.plist.$$ 2>/dev/null
+  else
+    cat $2 | cut -d ':' -f 1-2 | sed 's|:|-|g' > /tmp/.plist.$$ 2>/dev/null 
+  fi
+
+  while read line
+  do
+    pName=`echo $line | rev | cut -d "-" -f 2-25 | rev`
+    if [ "$pName" != "$1" ] ; then continue; fi
+    pVer=`echo $line | rev | cut -d "-" -f 1 | rev`
+    echo "${pName}-${pVer}"
+    break
+  done < /tmp/.plist.$$
+  rm /tmp/.plist.$$ 2>/dev/null
+}
+
 # Unset some vars
 _chroot=""
 _chrootcmd=""
 _pkgflags=""
+PKGUPDATES=""
 
 if [ $# -eq 0 ]; then display_usage; fi
 
@@ -416,6 +597,8 @@
        add) parse_metapkgs "$2" "add" "$3" ; exit 0 ;;
        del) parse_metapkgs "$2" "del" ; exit 0 ;;
     status) stat_metapkg "$2" ; exit 0 ;;
+   checkup) checkup_pkgs ; exit 0 ;;
+    update) updatepkgs "${2}" "${3}" ; exit 0 ;;
   --chroot) if [ -z "$2" ] ; then display_usage ; fi  
 	    _chroot="$2" 
             if [ ! -e "${_chroot}/usr/sbin/pkg_add" ] ; then



More information about the Commits mailing list