# Copyright (C) - IPFire Development Team <info@ipfire.org> #
###############################################################################
+#Path of the script
+
+SCRIPT_PATH="$(dirname "$(readlink -f "$0")")"
+
# Constants
# Proper error codes
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}
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
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}"
;;
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() {
#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