[PC-BSD Commits] r19038 - pcbsd/current/src-sh/pc-updatemanager

svn at pcbsd.org svn at pcbsd.org
Tue Sep 11 08:03:10 PDT 2012


Author: kris
Date: 2012-09-11 15:03:10 +0000 (Tue, 11 Sep 2012)
New Revision: 19038

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

Switch pc-updatemanager to use the new libsh



Modified: pcbsd/current/src-sh/pc-updatemanager/pc-updatemanager
===================================================================
--- pcbsd/current/src-sh/pc-updatemanager/pc-updatemanager	2012-09-11 14:55:16 UTC (rev 19037)
+++ pcbsd/current/src-sh/pc-updatemanager/pc-updatemanager	2012-09-11 15:03:10 UTC (rev 19038)
@@ -2,6 +2,9 @@
 # Script which performs updating services
 ############################################################################
 
+# Source our functions
+. /usr/local/share/pcbsd/scripts/functions.sh
+
 PROGDIR="/usr/local/share/pcbsd/pc-updatemanager" ; export PROGDIR
 
 # Set the pub openssl key
@@ -283,96 +286,6 @@
 	fi
 }
 
-# Function which uses "fetch" to download a file, and display a progress report
-fetch_file()
-{
-  local FETCHFILE="$1"
-  local FETCHOUTFILE="$2"
-  local EXITFAILED="$3"
-
-  local numAtt=0
-
-  while
-  z=1
-  do
-    numAtt=`expr $numAtt + 1`
-    # If the var PCFETCHGUI is unset, use regular fetch command
-    if [ -z "$PCFETCHGUI" ] ; then
-      fetch -o ${FETCHOUTFILE} "${FETCHFILE}"
-      if [ $? -eq 0 ] ; then return 0 ; fi
-      if [ $numAtt -gt 4 ] ; then return 1 ; fi
-      # Sleep before retrying a failed download
-      sleep 30 
-      continue
-    fi
-
-    SIZEFILE="${DOWNLOADDIR}/.fetchSize"
-    EXITFILE="${DOWNLOADDIR}/.fetchExit"
-
-    rm ${SIZEFILE} 2>/dev/null >/dev/null
-    rm ${FETCHOUTFILE} 2>/dev/null >/dev/null
-
-    fetch -s "${FETCHFILE}" >${SIZEFILE}
-    SIZE="`cat ${SIZEFILE}`"
-    SIZE="`expr ${SIZE} / 1024 2>/dev/null`"
-    echo "FETCH: ${FETCHFILE}"
- 
-    ( fetch -o ${FETCHOUTFILE} "${FETCHFILE}" >/dev/null 2>/dev/null ; echo "$?" > ${EXITFILE} ) &
-    PID="$!"
-    while
-    z=1
-    do
-
-      if [ -e "${FETCHOUTFILE}" ]
-      then
-        DSIZE=`du -k ${FETCHOUTFILE} | tr -d '\t' | cut -d '/' -f 1`
-        if [ $(is_num "$DSIZE") ] ; then
-        if [ $SIZE -lt $DSIZE ] ; then DSIZE="$SIZE"; fi 
-      	  echo "SIZE: ${SIZE} DOWNLOADED: ${DSIZE}"
-        fi
-      fi
-
-      # Check if the download is finished
-      ps -p ${PID} >/dev/null 2>/dev/null
-      if [ $? -ne 0 ]
-      then
-      break;
-      fi
-
-      sleep 1
-    done
-
-    echo "FETCHDONE"
-
-    EXIT="`cat ${EXITFILE}`"
-    rm ${SIZEFILE} 2>/dev/null >/dev/null
-    rm ${EXITFILE} 2>/dev/null >/dev/null
-
-    if [ "${EXIT}" != "0" -a "$EXITFAILED" = "1" ]; then
-      if [ $numAtt -gt 4 ] ; then 
-        exit_err "Error: Failed to download ${FETCHFILE}"
-      else
-	# Sleep before retrying a failed download
-        sleep 30 
-	continue
-      fi
-    fi
-
-
-    if [ "${EXIT}" = "0" ]; then
-      return 0
-    else
-      if [ $numAtt -gt 4 ] ; then 
-        return -1
-      else
-	sleep 1
-	continue
-      fi
-    fi
-  done
-
-};
-
 start_pcbsd_patch() {
 	up="$1"
 
@@ -395,23 +308,20 @@
         touch ${TRIGGERFILE}
         echo "DOWNLOADING: ${PATCHNAME}"
         echo "DOWNLOADING: ${PATCHNAME}" >${TRIGGERFILE}
-	fetch_file "${FILEURL}" "${DOWNLOADDIR}/${FILENAME}" "1"
-        if [ "$?" = "0" ]
+
+	# Get the file
+    	get_file "${FILEURL}" "${DOWNLOADDIR}/${FILENAME}" 3
+
+ 	# Check the md5 checksum
+        if [ "$FILEMD5" != "`md5 -q ${DOWNLOADDIR}/${FILENAME} 2>/dev/null`" ]
         then
-          if [ "$FILEMD5" != "`md5 -q ${DOWNLOADDIR}/${FILENAME} 2>/dev/null`" ]
-          then
-            # Download MD5 doesn't match! Delete the file
-            rm ${DOWNLOADDIR}/${FILENAME}
-            echo "FAILED: ${PATCHNAME}" >${TRIGGERFILE}
-            exit_err "Failed to download: ${PATCHNAME}"
-          else 
-            echo "DOWNLOADFINISHED: ${PATCHNAME}"
-            echo "DOWNLOADFINISHED: ${PATCHNAME}" >${TRIGGERFILE}
-          fi
-        else
-          rm ${DOWNLOADDIR}/${FILENAME} >/dev/null 2>/dev/null
+          # Download MD5 doesn't match! Delete the file
+          rm ${DOWNLOADDIR}/${FILENAME}
           echo "FAILED: ${PATCHNAME}" >${TRIGGERFILE}
           exit_err "Failed to download: ${PATCHNAME}"
+        else 
+          echo "DOWNLOADFINISHED: ${PATCHNAME}"
+          echo "DOWNLOADFINISHED: ${PATCHNAME}" >${TRIGGERFILE}
         fi
 
         echo "INSTALLING: ${PATCHNAME}" >${TRIGGERFILE}
@@ -436,13 +346,6 @@
         rm ${DOWNLOADDIR}/${FILENAME} >/dev/null 2>/dev/null
 }
 
-# Make sure we have a numeric
-is_num()
-{
-  expr $1 + 1 2>/dev/null
-  return $?
-}
-
 # Make sure we have free space in necessary places for system upgrade
 sanity_check_disk_space()
 {
@@ -590,12 +493,7 @@
 	  fi
 
 	  # Download the file
-	  fetch_file "${MIRRORDIR}/$dFile" "${STAGEDIR}/$dFile" "1" "0"
-	  if [ $? -ne 0 ] ; then
-            rm ${STAGEDIR}/$dFile >/dev/null 2>/dev/null
-            echo "FAILED: ${up}" >${TRIGGERFILE}
-            exit_err "Failed to download: ${STAGEDIR}/$dFile"
-	  fi
+	  get_file "${MIRRORDIR}/$dFile" "${STAGEDIR}/$dFile" 3
 	done
 
 	# Verify the md5 sums of .txz files
@@ -642,20 +540,12 @@
 	  fi
 
 	  # Download the file
-	  fetch_file "${MIRRORDIR}/metapackages/${PKGSET}/packages/${dFile}.txz" "${STAGEDIR}/packages/${dFile}.txz" "1" "0"
-	  if [ $? -ne 0 ] ; then
-            echo "FAILED: ${dFile}.txz" >${TRIGGERFILE}
-            exit_err "Failed to download: ${STAGEDIR}/packages/${dFile}.txz"
-	  fi
+	  get_file "${MIRRORDIR}/metapackages/${PKGSET}/packages/${dFile}.txz" "${STAGEDIR}/packages/${dFile}.txz" 3
 
-	  # Download the md5 file
-	  fetch_file "${MIRRORDIR}/metapackages/${PKGSET}/packages/${dFile}.txz.sha256" "${STAGEDIR}/packages/${dFile}.txz.sha256" "1" "0"
-	  if [ $? -ne 0 ] ; then
-            echo "FAILED: ${dFile}.txz.sha256" >${TRIGGERFILE}
-            exit_err "Failed to download: ${STAGEDIR}/packages/${dFile}.txz.sha256"
-	  fi
+	  # Download the sha256 file
+	  get_file "${MIRRORDIR}/metapackages/${PKGSET}/packages/${dFile}.txz.sha256" "${STAGEDIR}/packages/${dFile}.txz.sha256" 3
 
-	  # Confirm the md5
+	  # Confirm the sha256
 	  if [ "`sha256 -q ${STAGEDIR}/packages/${dFile}.txz`" !=  "`cat ${STAGEDIR}/packages/${dFile}.txz.sha256`" ] ; then
             echo "FAILED: ${dFile}.txz" >${TRIGGERFILE}
             exit_err "Checksum failed for: ${STAGEDIR}/packages/${dFile}.txz"



More information about the Commits mailing list