From 8ca5028430907806310e5b210fd49f345ffba2ef Mon Sep 17 00:00:00 2001 From: Chiradeep Vittal Date: Tue, 18 Jan 2011 17:05:04 -0800 Subject: [PATCH] bug 3981: Add more logs for long running operations --- scripts/storage/secondary/createtmplt.sh | 28 ++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/scripts/storage/secondary/createtmplt.sh b/scripts/storage/secondary/createtmplt.sh index 3f81e5b81d2..f73a9876fe7 100755 --- a/scripts/storage/secondary/createtmplt.sh +++ b/scripts/storage/secondary/createtmplt.sh @@ -3,7 +3,7 @@ # createtmplt.sh -- install a template usage() { - printf "Usage: %s: -t -n -f -c -d -h [-u]\n" $(basename $0) >&2 + printf "Usage: %s: -t -n -f -c -d -h [-u] \n" $(basename $0) >&2 } @@ -45,6 +45,25 @@ untar() { } +is_compressed() { + local ft=$(file $1| awk -F" " '{print $2}') + local tmpfile=${1}.tmp + + case $ft in + gzip) ctype="gzip" + ;; + bzip2) ctype="bz2" + ;; + ZIP) ctype="zip" + ;; + *) echo "File $1 does not appear to be compressed" >&2 + return 1 + ;; + esac + echo "Uncompressing to $tmpfile (type $ctype)...could take a long time" >&2 + return 0 +} + uncompress() { local ft=$(file $1| awk -F" " '{print $2}') local tmpfile=${1}.tmp @@ -56,8 +75,8 @@ uncompress() { ;; ZIP) unzip -q -p $1 | cat > $tmpfile ;; - *) printf "$1" - return 0 + *) printf "$1" + return 0 ;; esac @@ -78,7 +97,7 @@ create_from_file() { local tmpltimg=$2 local tmpltname=$3 - #copy the file to the disk + echo "Moving to /$tmpltfs/$tmpltname...could take a while" >&2 mv $tmpltimg /$tmpltfs/$tmpltname } @@ -147,6 +166,7 @@ if [ -n "$cksum" ] then verify_cksum $cksum $tmpltimg fi +is_compressed $tmpltimg tmpltimg2=$(uncompress $tmpltimg) rollback_if_needed $tmpltfs $? "failed to uncompress $tmpltimg\n"