From 9048475efd2aa02b8ee2c4b028b3136564057928 Mon Sep 17 00:00:00 2001 From: BonzaiBrains <133261117+BonzaiBrains@users.noreply.github.com> Date: Thu, 31 Oct 2024 12:41:40 +0100 Subject: [PATCH 1/5] add: remove function --- shemum | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/shemum b/shemum index 141698b..9c95ae1 100755 --- a/shemum +++ b/shemum @@ -42,6 +42,15 @@ case $OS_NAME in ;; esac +# Functions + +# Virtual machine removal +remove function { + rm -r $ROOT_PATH/$OS_NAME +} + + + # Options case $OPTION in # Initializes the VM and starts the installer image. @@ -76,7 +85,7 @@ case $OPTION in -m $RAM -smp $CPU ;; "remove") - rm -r $ROOT_PATH/$OS_NAME + remove ;; *) echo "Usage: shemum [init] " From 75420d0f32511ecb6265c78c51e2deddceabe00f Mon Sep 17 00:00:00 2001 From: BonzaiBrains <133261117+BonzaiBrains@users.noreply.github.com> Date: Thu, 31 Oct 2024 12:43:13 +0100 Subject: [PATCH 2/5] add: start function --- shemum | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/shemum b/shemum index 9c95ae1..1b48fc9 100755 --- a/shemum +++ b/shemum @@ -49,7 +49,12 @@ remove function { rm -r $ROOT_PATH/$OS_NAME } - +start function { + qemu-system-x86_64 -boot c \ + -display none \ + -drive file=$IMG_PATH,format=raw \ + -m $RAM -smp $CPU +} # Options case $OPTION in @@ -79,10 +84,7 @@ case $OPTION in -m $RAM -smp $CPU ;; "start") - qemu-system-x86_64 -boot c \ - -display none \ - -drive file=$IMG_PATH,format=raw \ - -m $RAM -smp $CPU + start ;; "remove") remove From f95c0e5bfc1fcd4b9350c54591fec60ea099b1ac Mon Sep 17 00:00:00 2001 From: BonzaiBrains <133261117+BonzaiBrains@users.noreply.github.com> Date: Thu, 31 Oct 2024 12:47:03 +0100 Subject: [PATCH 3/5] add: console function; style: function names For more information see: https://google.github.io/styleguide/shellguide.html#s7.1-function-names --- shemum | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/shemum b/shemum index 1b48fc9..1eb999c 100755 --- a/shemum +++ b/shemum @@ -45,17 +45,26 @@ esac # Functions # Virtual machine removal -remove function { +remove_func function { rm -r $ROOT_PATH/$OS_NAME } -start function { +# Virtual machine start without a console +start_func function { qemu-system-x86_64 -boot c \ -display none \ -drive file=$IMG_PATH,format=raw \ -m $RAM -smp $CPU } +# Virtual machine start with a console +console_func function { + qemu-system-x86_64 -boot c \ + -display curses \ + -drive file=$IMG_PATH,format=raw \ + -m $RAM -smp $CPU +} + # Options case $OPTION in # Initializes the VM and starts the installer image. @@ -78,16 +87,13 @@ case $OPTION in -m $RAM -smp $CPU ;; "console") - qemu-system-x86_64 -boot c \ - -display curses \ - -drive file=$IMG_PATH,format=raw \ - -m $RAM -smp $CPU + console_func ;; "start") - start + start_func ;; "remove") - remove + remove_func ;; *) echo "Usage: shemum [init] " From 442ff6bcbc557fee7f27613eba348e477ecfcd85 Mon Sep 17 00:00:00 2001 From: BonzaiBrains <133261117+BonzaiBrains@users.noreply.github.com> Date: Thu, 31 Oct 2024 12:56:44 +0100 Subject: [PATCH 4/5] add: init function --- shemum | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/shemum b/shemum index 1eb999c..e9bf6e4 100755 --- a/shemum +++ b/shemum @@ -65,26 +65,30 @@ console_func function { -m $RAM -smp $CPU } +init_func function { + mkdir -p "$ROOT_PATH/$OS_NAME" + qemu-img create $IMG_PATH $DISK_SIZE + if [ ! -f $ISO_PATH ] && [ ! -z $INSTALL_IMG ]; then + echo $INSTALL_IMG + curl -o $ISO_PATH $INSTALL_IMG + elif [ ! -z $INSTALL_IMG ]; then + echo "Current INSTALL_IMG for $OS_NAME: $ISO_PATH" + else: + echo "Install image path is missing" >&2 + exit 1 + fi + qemu-system-x86_64 -boot d \ + -display curses \ + -drive file=$ISO_PATH,media=cdrom \ + -drive file=$IMG_PATH,format=raw \ + -m $RAM -smp $CPU +} + # Options case $OPTION in # Initializes the VM and starts the installer image. "init") - mkdir -p "$ROOT_PATH/$OS_NAME" - qemu-img create $IMG_PATH $DISK_SIZE - if [ ! -f $ISO_PATH ] && [ ! -z $INSTALL_IMG ]; then - echo $INSTALL_IMG - curl -o $ISO_PATH $INSTALL_IMG - elif [ ! -z $INSTALL_IMG ]; then - echo "Current INSTALL_IMG for $OS_NAME: $ISO_PATH" - else: - echo "Install image path is missing" >&2 - exit 1 - fi - qemu-system-x86_64 -boot d \ - -display curses \ - -drive file=$ISO_PATH,media=cdrom \ - -drive file=$IMG_PATH,format=raw \ - -m $RAM -smp $CPU + init_func ;; "console") console_func From 1aaaf60b2d8874010fb87e6c7ae9d908d6f552c0 Mon Sep 17 00:00:00 2001 From: BonzaiBrains <133261117+BonzaiBrains@users.noreply.github.com> Date: Thu, 31 Oct 2024 13:01:37 +0100 Subject: [PATCH 5/5] add: usage function --- shemum | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/shemum b/shemum index e9bf6e4..6036d6f 100755 --- a/shemum +++ b/shemum @@ -65,6 +65,7 @@ console_func function { -m $RAM -smp $CPU } +# Virtual machine initialization with a console init_func function { mkdir -p "$ROOT_PATH/$OS_NAME" qemu-img create $IMG_PATH $DISK_SIZE @@ -84,6 +85,15 @@ init_func function { -m $RAM -smp $CPU } +# Display usage +usage_func function { + printf "Usage: shemum [init] " + printf " init initialize a virtual machine" + printf " start start a QEMU virtual machine without console output" + printf " console start a QEMU virtual machine with console output" + printf " remove remove virtual machine directory and all it's contents" +} + # Options case $OPTION in # Initializes the VM and starts the installer image. @@ -100,11 +110,7 @@ case $OPTION in remove_func ;; *) - echo "Usage: shemum [init] " - echo " init initialize a virtual machine" - echo " start start a QEMU virtual machine without console output" - echo " console start a QEMU virtual machine with console output" - echo " remove remove virtual machine directory and all it's contents" + usage_func esac