fix: general fixes for syntax and naming

This commit is contained in:
ahoemann 2024-11-07 10:17:27 +01:00
parent d172c755e6
commit ce339b69d2
2 changed files with 25 additions and 30 deletions

3
.sources Normal file
View file

@ -0,0 +1,3 @@
# Sources list
debian=""
openbsd="test"

52
shemum
View file

@ -3,14 +3,12 @@
# Author: Adrian Erik Hoemann # Author: Adrian Erik Hoemann
# Date: 9.18.2024 # Date: 9.18.2024
# TODO: Implement operating system installer variable list.
# Debug mode # Debug mode
# Default: true # Default: true
DEBUG=true DEBUG=true
# Debug mode check # Debug mode check
if [$DEBUG -eq true] if [ $DEBUG ]; then
set +x set +x
fi fi
@ -24,58 +22,52 @@ ISO_PATH="$ROOT_PATH/$OS_NAME/$OS_NAME.iso"
IMG_PATH="$ROOT_PATH/$OS_NAME/$OS_NAME.img" IMG_PATH="$ROOT_PATH/$OS_NAME/$OS_NAME.img"
# Sources default values # Sources default values
. ".env" #. ".env"
# Sources virtual machine specific values # Sources virtual machine specific values
. "$ROOT_PATH/$OS_NAME/.env" #. "$ROOT_PATH/$OS_NAME/.env"
# Functions # Functions
# Defines install image source # Defines install image source
function def_os_source() { source() {
case $OS_NAME in while read LINE; do
"openbsd") if [ $LINE == $OS_NAME* ]; then
INSTALL_IMG="https://cdn.openbsd.org/pub/OpenBSD/7.5/i386/cd75.iso" $OS_NAME=$LINE
;; fi
"debian") done < .sources
INSTALL_IMG=""
;;
*)
error "INSTALL_IMG for $OS_NAME not found"
;;
esac
} }
function check() { check() {
if [ -z $OS_NAME ] if [ -z $OS_NAME ]; then
error "Operating system is empty" error "Operating system is not defined"
fi fi
if [ -z $INSTALL_IMG ] if [ -z $INSTALL_IMG ]; then
info "$INSTALL_IMG is not set" info "$OS_NAME source not set, please update your .sources file"
fi fi
} }
function error() { error() {
printf "$@" >&2 printf "$@" >&2
exit 1 exit 1
} }
function warn() { warn() {
printf "$@" >&2 printf "$@" >&2
} }
function info() { info() {
printf "$@" >&1 printf "$@" >&1
} }
# Virtual machine removal # Virtual machine removal
function remove() { remove() {
rm -r $ROOT_PATH/$OS_NAME rm -r $ROOT_PATH/$OS_NAME
} }
# Virtual machine start without a console # Virtual machine start without a console
function start() { start() {
qemu-system-x86_64 -boot c \ qemu-system-x86_64 -boot c \
-display none \ -display none \
-drive file=$IMG_PATH,format=raw \ -drive file=$IMG_PATH,format=raw \
@ -83,7 +75,7 @@ function start() {
} }
# Virtual machine start with a console # Virtual machine start with a console
function console() { console() {
qemu-system-x86_64 -boot c \ qemu-system-x86_64 -boot c \
-display curses \ -display curses \
-drive file=$IMG_PATH,format=raw \ -drive file=$IMG_PATH,format=raw \
@ -91,7 +83,7 @@ function console() {
} }
# Virtual machine initialization with a console # Virtual machine initialization with a console
function init() { init() {
def_os_source def_os_source
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
@ -111,7 +103,7 @@ function init() {
} }
# Display usage # Display usage
function usage() { usage() {
printf "Usage: shemum [init] <virtual machine name> <disk size>" printf "Usage: shemum [init] <virtual machine name> <disk size>"
printf " init initialize a virtual machine" printf " init initialize a virtual machine"
printf " start start a QEMU virtual machine without console output" printf " start start a QEMU virtual machine without console output"