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

svn at pcbsd.org svn at pcbsd.org
Fri Jul 20 08:01:48 PDT 2012


Author: kris
Date: 2012-07-20 15:01:48 +0000 (Fri, 20 Jul 2012)
New Revision: 17844

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

Add some new sanity checking to pc-updatemanager. Now before we even begin
to download a major upgrade, we will check /, /usr, /usr/local and /boot to ensure
that we have some basic sane free space available. Some of the failures we've
seen has been because of full file-systems, and this should help catch it
before the user tries to do the upgrade. 



Modified: pcbsd/current/src-sh/pc-updatemanager/pc-updatemanager
===================================================================
--- pcbsd/current/src-sh/pc-updatemanager/pc-updatemanager	2012-07-20 14:49:02 UTC (rev 17843)
+++ pcbsd/current/src-sh/pc-updatemanager/pc-updatemanager	2012-07-20 15:01:48 UTC (rev 17844)
@@ -67,6 +67,34 @@
 	exit 1
 }
 
+get_free_mb_on_dir() 
+{
+   dfdir="$1"
+
+   if [ ! -d "$dfdir" ] ; then
+      return 1
+   fi
+   
+   # First check if this is a mount point and cycle down until we figure it out
+   while :
+   do
+     mount | grep "on ${dfdir} " >/dev/null 2>/dev/null
+     if [ $? -eq 0 ] ; then
+        partdev=`mount | grep "on ${dfdir} " | head -n 1 | cut -d ' ' -f 1` 
+        break
+     fi
+     dfdir=`dirname ${dfdir}`
+   done
+
+   free=`df -m | grep "^${partdev} " | head -n 1 | awk '{print $4}'`
+   if [ $? -ne 0 -o -z "$free" ] ; then
+      return 1
+   fi
+ 
+   echo "$free"
+   return 0
+}
+
 # Run-command, don't halt if command exits with non-0
 rc_nohalt()
 {
@@ -415,9 +443,57 @@
   return $?
 }
 
+# Make sure we have free space in necessary places for system upgrade
+sanity_check_disk_space()
+{
+   free=`get_free_mb_on_dir "/usr"`
+   if [ $? -eq 0 -a $(is_num "$free") ] ; then
+     #echo "Free Space on /usr: $free"
+     if [ $free -lt 2000 ] ; then
+       exit_err "Less than 2GB free on /usr, please clear some additional space to continue!"
+     fi
+   else
+     exit_err "Could not determine free space on /usr"
+   fi
+
+   free=`get_free_mb_on_dir "/"`
+   if [ $? -eq 0 -a $(is_num "$free") ] ; then
+     #echo "Free Space on /: $free"
+     if [ $free -lt 1000 ] ; then
+       exit_err "Less than 1GB free on /, please clear some additional space to continue!"
+     fi
+   else
+     exit_err "Could not determine free space on /"
+   fi
+
+   free=`get_free_mb_on_dir "/boot"`
+   if [ $? -eq 0 -a $(is_num "$free") ] ; then
+     #echo "Free Space on /boot: $free"
+     if [ $free -lt 512 ] ; then
+       exit_err "Less than 512MB free on /boot, please clear some additional space to continue!"
+     fi
+   else
+     exit_err "Could not determine free space on /boot"
+   fi
+
+   free=`get_free_mb_on_dir "/usr/local"`
+   if [ $? -eq 0 -a $(is_num "$free") ] ; then
+     #echo "Free Space on /usr/local: $free"
+     if [ $free -lt 6000 ] ; then
+       exit_err "Less than 6GB free on /usr/local, please clear some additional space to continue!"
+     fi
+   else
+     exit_err "Could not determine free space on /usr/local"
+   fi
+
+}
+
 start_major_update() {
  	up="`echo $1 | sed 's|release-||g'`"
 
+	# Make sure we have disk space enough to do the upgrade
+	sanity_check_disk_space
+
 	# Create the stage directory for this update
  	STAGEDIR="${DOWNLOADDIR}/${up}" 
 	if [ ! -e "${STAGEDIR}" ] ; then



More information about the Commits mailing list