]> git.ipfire.org Git - people/jschlag/ipfire-3.x-image.git/blobdiff - generate_image.sh
Fix copying the grub config
[people/jschlag/ipfire-3.x-image.git] / generate_image.sh
index 4b9b5f73ea7b56d20ae315198b192ab9247c41b1..ddb3813f9209b019b49af2823fc505218ec6cde7 100755 (executable)
@@ -4,6 +4,10 @@
 # Copyright (C) - IPFire Development Team <info@ipfire.org>                   #
 ###############################################################################
 
+#Path of the script
+
+SCRIPT_PATH="$(dirname "$(readlink -f "$0")")"
+
 # Constants
 
 # Proper error codes
@@ -32,6 +36,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 +112,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 +121,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 +204,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() {
@@ -409,7 +430,7 @@ yes | pakfire --root=${IMAGE_MOUNT_DIR} ${ENABLE_LOCAL} install @Base ${PACKAGES
 
 #Hack to install a /etc/default/grub file
 
-cp -f grub "${IMAGE_MOUNT_DIR}/etc/default"
+cmd cp -f "${SCRIPT_PATH}/grub" "${IMAGE_MOUNT_DIR}/etc/default"
 
 #
 ## Install grub2 if neccessary