Handle errors in download and kernel size checks.
authorValentin Vidic <Valentin.Vidic@CARNet.hr>
Thu, 28 Aug 2008 11:01:57 +0000 (13:01 +0200)
committerValentin Vidic <Valentin.Vidic@CARNet.hr>
Thu, 28 Aug 2008 11:01:57 +0000 (13:01 +0200)
src/functions.sh

index 0ddd941..5fce053 100644 (file)
@@ -831,6 +831,11 @@ check_archives_space() {
   available_disk_space=$(free_space /var/cache/apt/archives/)
   archives_size=$(download_size dist-upgrade)
 
+  if [ $? -ne 0 ]; then
+    log "Failed to get download size, skipping check."
+    return 0
+  fi
+
   log "Archives space: ${available_disk_space}MB"
   log "Download size: ${archives_size}MB"
 
@@ -846,6 +851,11 @@ check_kernel_space() {
   available_disk_space=$(free_space /)
   kernel_size=$(installed_size kernel-2.6-cn)
 
+  if [ $? -ne 0 ]; then
+    log "Failed to get installed size, skipping check."
+    return 0
+  fi
+
   log "Free space in /: ${available_disk_space}MB"
   log "Kernel size: ${kernel_size}MB"
 
@@ -870,7 +880,15 @@ free_space() {
 download_size() {
   local size
   size=$(LC_ALL=C apt-get --yes --print-uris "$@" \
-         | sed -n '/^Need to get / {s///; s/B.*//; p}')
+         | grep '^Need to get ')
+
+  if [ $? -ne 0 ]; then
+    log "Failed to get download size for 'apt-get $@'."
+    return 1
+  fi
+
+  size=${size#Need to get }
+  size=${size%%B*}
 
   size_to_mb "${size}B"
 }
@@ -879,7 +897,14 @@ installed_size() {
   local package size
   package=$1
   size=$(apt-cache show $package \
-         | awk '$1 == "Installed-Size:" {print $2; exit}')
+         | grep '^Installed-Size:')
+
+  if [ $? -ne 0 ]; then
+    log "Failed to get installed size for '$package'."
+    return 1
+  fi
+
+  size=${size#*: }
 
   size_to_mb "${size}kB"
 }