summaryrefslogtreecommitdiff
path: root/scripts/qw
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/qw')
-rwxr-xr-xscripts/qw54
1 files changed, 54 insertions, 0 deletions
diff --git a/scripts/qw b/scripts/qw
new file mode 100755
index 0000000..c952a3f
--- /dev/null
+++ b/scripts/qw
@@ -0,0 +1,54 @@
+#!/bin/sh
+
+help() {
+cat << EOF
+${0}: Qemu Wrapper, very simple script for abriviating \
+verbose qemu commands and options
+
+options:
+ -c create an Image.img with 10G space
+ -r [input.iso] run input.iso
+EOF
+}
+
+err() {
+ for line in "${@}"; do
+ echo "${line}" >&2
+ done
+ exit 1
+}
+
+run() {
+ if ! ${1} > /dev/null 2>&1; then
+ err "${2}"
+ fi
+
+ [ -n "${3}" ] && echo "${3}"
+ exit 0
+}
+
+if ! command -v qemu-img > /dev/null 2>&1 || \
+ command -v qemu-system-x86_64 > /dev/null 2>&1; then
+ err "${0}: qemu must be properly installed"
+fi
+
+if [ $# != 2 ] && [ $# != 1 ]; then
+ err "${0}: Invalid usage" "Try '${0} -h' for help."
+fi
+
+while getopts "cr:" option ;do
+ case "${option}" in
+ c)
+ run "qemu-img create -f qcow2 Image.img 10G" \
+ "${0}: Failed to create Image.img"
+ ;;
+ r)
+ run "qemu-system-x86_64 -enable-kvm -cdrom "${OPTARG}" \
+ -boot menu=on -drive file=Image.img -m 4G" \
+ "${0}: Failed to run image"
+ ;;
+ h) help ;;
+
+ *) err "Try '${0} -h' for help." ;;
+ esac
+done