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