From 6f4f76a38153d21d9c8d3034f997d28d7f2fba83 Mon Sep 17 00:00:00 2001 From: Valentin Vidic Date: Thu, 28 Aug 2008 13:01:57 +0200 Subject: [PATCH] Handle errors in download and kernel size checks. --- src/functions.sh | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/functions.sh b/src/functions.sh index 0ddd941..5fce053 100644 --- a/src/functions.sh +++ b/src/functions.sh @@ -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" } -- 1.7.10.4