Merge pull request #1 from BonzaiBrains/functions

Functions
This commit is contained in:
BonzaiBrains 2024-10-31 13:02:41 +01:00 committed by GitHub
commit 15fc39a355
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

63
shemum
View file

@ -42,10 +42,31 @@ case $OS_NAME in
;; ;;
esac esac
# Options # Functions
case $OPTION in
# Initializes the VM and starts the installer image. # Virtual machine removal
"init") remove_func function {
rm -r $ROOT_PATH/$OS_NAME
}
# 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
}
# Virtual machine initialization with a console
init_func function {
mkdir -p "$ROOT_PATH/$OS_NAME" mkdir -p "$ROOT_PATH/$OS_NAME"
qemu-img create $IMG_PATH $DISK_SIZE qemu-img create $IMG_PATH $DISK_SIZE
if [ ! -f $ISO_PATH ] && [ ! -z $INSTALL_IMG ]; then if [ ! -f $ISO_PATH ] && [ ! -z $INSTALL_IMG ]; then
@ -62,28 +83,34 @@ case $OPTION in
-drive file=$ISO_PATH,media=cdrom \ -drive file=$ISO_PATH,media=cdrom \
-drive file=$IMG_PATH,format=raw \ -drive file=$IMG_PATH,format=raw \
-m $RAM -smp $CPU -m $RAM -smp $CPU
}
# Display usage
usage_func function {
printf "Usage: shemum [init] <virtual machine name> <disk size>"
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.
"init")
init_func
;; ;;
"console") "console")
qemu-system-x86_64 -boot c \ console_func
-display curses \
-drive file=$IMG_PATH,format=raw \
-m $RAM -smp $CPU
;; ;;
"start") "start")
qemu-system-x86_64 -boot c \ start_func
-display none \
-drive file=$IMG_PATH,format=raw \
-m $RAM -smp $CPU
;; ;;
"remove") "remove")
rm -r $ROOT_PATH/$OS_NAME remove_func
;; ;;
*) *)
echo "Usage: shemum [init] <virtual machine name> <disk size>" usage_func
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"
esac esac