]> git.ipfire.org Git - people/jschlag/ipfire-3.x-image.git/commitdiff
Add cmd() function
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Sun, 18 Nov 2018 17:23:41 +0000 (17:23 +0000)
committerJonatan Schlag <jonatan.schlag@ipfire.org>
Sun, 18 Nov 2018 17:25:11 +0000 (17:25 +0000)
This makes it easier to log what commands are executed.

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
generate_image.sh

index 4b9b5f73ea7b56d20ae315198b192ab9247c41b1..6cff68d319787f4c37e3bf0386780b0a028f445a 100755 (executable)
@@ -32,6 +32,26 @@ log() {
        echo "[${level}] ${message}"
 }
 
+cmd() {
+       local cmd=$@
+       local ret
+
+       log DEBUG "Running command: ${cmd}"
+
+       ${cmd}
+       ret=$?
+
+       case "${ret}" in
+               ${EXIT_OK})
+                       return ${EXIT_OK}
+                       ;;
+               *)
+                       log DEBUG "Returned with code '${ret}'"
+                       return ${ret}
+                       ;;
+       esac
+}
+
 cleanup() {
        # Unmount image
        umount ${IMAGE_MOUNT_DIR}
@@ -88,7 +108,7 @@ compress_image() {
                                log ERROR "Failed to compress the image. The file already exists"
                                return ${EXIT_ERROR}
                        fi
-                       xz "-${level}" "${image_file}"
+                       cmd xz "-${level}" "${image_file}"
                        ;;
                "zip")
                # Check that the file does not exist yet
@@ -97,7 +117,7 @@ compress_image() {
                                return ${EXIT_ERROR}
 
                        fi
-                       zip "-${level}" "${image_file}.zip" "${image_file}"
+                       cmd zip "-${level}" "${image_file}.zip" "${image_file}"
                        # Remove the file which we compressed+
                        rm -f "${image_file}"
                        ;;
@@ -180,15 +200,12 @@ convert_image() {
        fi
 
        if [[ ${type} = "qcow2" ]]; then
-               local cmd="qemu-img convert -c -O ${type} ${from} ${to}.${type}"
+               local command="qemu-img convert -c -O ${type} ${from} ${to}.${type}"
        else
-               local cmd="qemu-img convert -O ${type} ${from} ${to}.${type}"
+               local command="qemu-img convert -O ${type} ${from} ${to}.${type}"
        fi
 
-       log debug "${cmd}"
-
-       # Execute the command to convert the image
-       ${cmd}
+       cmd ${command}
 }
 
 get_compression_type() {