diff --git a/.sources b/.sources new file mode 100644 index 0000000..1a045a3 --- /dev/null +++ b/.sources @@ -0,0 +1,3 @@ +# Sources list +debian="" +openbsd="test" diff --git a/shemum b/shemum index 5d21bb5..a5c3a29 100755 --- a/shemum +++ b/shemum @@ -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] " printf " init initialize a virtual machine" printf " start start a QEMU virtual machine without console output"