diff --git a/.sources b/.sources deleted file mode 100644 index 1a045a3..0000000 --- a/.sources +++ /dev/null @@ -1,3 +0,0 @@ -# Sources list -debian="" -openbsd="test" diff --git a/Makefile b/Makefile index 84d7737..f92bc3e 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,4 @@ install: cp $PWD/shemum /usr/bin/shemum - cp $PWD/.env $HOME/.env - cp $PWD/.sources $HOME/.sources clean: rm -f /usr/bin/shemum diff --git a/shemum b/shemum index a5c3a29..141698b 100755 --- a/shemum +++ b/shemum @@ -4,11 +4,12 @@ # Date: 9.18.2024 # Debug mode +# To enable debug mode remove the comment. # Default: true DEBUG=true # Debug mode check -if [ $DEBUG ]; then +if [$DEBUG -eq true] set +x fi @@ -21,112 +22,68 @@ ROOT_PATH="$HOME/Machines" ISO_PATH="$ROOT_PATH/$OS_NAME/$OS_NAME.iso" IMG_PATH="$ROOT_PATH/$OS_NAME/$OS_NAME.img" -# Sources default values -#. ".env" +# Sources defualt values +. ".env" # Sources virtual machine specific values -#. "$ROOT_PATH/$OS_NAME/.env" +. "$ROOT_PATH/$OS_NAME/.env" -# Functions - -# Defines install image source -source() { - while read LINE; do - if [ $LINE == $OS_NAME* ]; then - $OS_NAME=$LINE - fi - done < .sources -} - -check() { - if [ -z $OS_NAME ]; then - error "Operating system is not defined" - fi - if [ -z $INSTALL_IMG ]; then - info "$OS_NAME source not set, please update your .sources file" - fi - -} - -error() { - printf "$@" >&2 - exit 1 -} - -warn() { - printf "$@" >&2 -} - -info() { - printf "$@" >&1 -} - -# Virtual machine removal -remove() { - rm -r $ROOT_PATH/$OS_NAME -} - -# Virtual machine start without a console -start() { - 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() { - 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() { - def_os_source - mkdir -p "$ROOT_PATH/$OS_NAME" - qemu-img create $IMG_PATH $DISK_SIZE - if [ ! -f $ISO_PATH ] && [ ! -z $INSTALL_IMG ]; then - info "Fetching $OSNAME installer at: $INSTALL_IMG" - curl -o $ISO_PATH $INSTALL_IMG - elif [ ! -z $INSTALL_IMG ]; then - info "Current INSTALL_IMG for $OS_NAME: $ISO_PATH" - else - error "Install image path is missing" - 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 -} - -# Display usage -usage() { - 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" -} +# Defines install image repository. +case $OS_NAME in + "openbsd") + INSTALL_IMG="https://cdn.openbsd.org/pub/OpenBSD/7.5/i386/cd75.iso" + ;; + "debian") + INSTALL_IMG="" + ;; + *) + echo "$OS_NAME is not an option" >&2 + exit 1 + ;; +esac # Options case $OPTION in + # Initializes the VM and starts the installer image. "init") - 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 ;; "console") - console + qemu-system-x86_64 -boot c \ + -display curses \ + -drive file=$IMG_PATH,format=raw \ + -m $RAM -smp $CPU ;; "start") - start + qemu-system-x86_64 -boot c \ + -display none \ + -drive file=$IMG_PATH,format=raw \ + -m $RAM -smp $CPU ;; "remove") - remove + rm -r $ROOT_PATH/$OS_NAME ;; *) - usage + 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" esac