Browse code

Beef up error handling (#886666)

Dean Troyer authored on 2011/11/06 06:55:15
Showing 1 changed files
... ...
@@ -14,6 +14,9 @@ MIN_PKGS=${MIN_PKGS:-"apt-utils gpgv openssh-server"}
14 14
 TOOLS_DIR=$(cd $(dirname "$0") && pwd)
15 15
 TOP_DIR=`cd $TOOLS_DIR/..; pwd`
16 16
 
17
+# exit on error to stop unexpected errors
18
+set -o errexit
19
+
17 20
 usage() {
18 21
     echo "Usage: $0 - Prepare Ubuntu images"
19 22
     echo ""
... ...
@@ -44,6 +47,14 @@ cleanup() {
44 44
     trap 2; kill -2 $$
45 45
 }
46 46
 
47
+# apt-get wrapper to just get arguments set correctly
48
+function apt_get() {
49
+    local sudo="sudo"
50
+    [ "$(id -u)" = "0" ] && sudo="env"
51
+    $sudo DEBIAN_FRONTEND=noninteractive apt-get \
52
+        --option "Dpkg::Options::=--force-confold" --assume-yes "$@"
53
+}
54
+
47 55
 while getopts f:hmr: c; do
48 56
     case $c in
49 57
         f)  FORMAT=$OPTARG
... ...
@@ -107,7 +118,14 @@ case $DIST_NAME in
107 107
                 ;;
108 108
 esac
109 109
 
110
-trap cleanup SIGHUP SIGINT SIGTERM
110
+trap cleanup SIGHUP SIGINT SIGTERM SIGQUIT
111
+
112
+# Check for dependencies
113
+
114
+if [ ! -x "`which qemu-img`" -o ! -x "`which qemu-nbd`" ]; then
115
+    # Missing KVM?
116
+    apt_get install qemu-kvm
117
+fi
111 118
 
112 119
 # Prepare the base image
113 120