#!/usr/bin/env sh # # Author: Adrian Erik Hoemann # Date: 9.18.2024 # # Dependencies: # * qemu # * sh # * curl # * syslog # - logger # Debug mode # To enable debug mode remove the comment. # Default: ON #:exec 1> >(logger -s -t $(basename $0)) 2>&1 # Virtual machine settings RAM="512M" CPU="1" DISK_SIZE="8G" # Arguments OPTION=$1 OS_NAME=$2 #DISK_SIZE=$3 # Defining paths ROOT_PATH="$HOME/Machines" ISO_PATH="$ROOT_PATH/$OS_NAME/$OS_NAME.iso" IMG_PATH="$ROOT_PATH/$OS_NAME/$OS_NAME.img" # 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") 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") qemu-system-x86_64 -boot c \ -display curses \ -drive file=$IMG_PATH,format=raw \ -m $RAM -smp $CPU ;; "start") qemu-system-x86_64 -boot c \ -display none \ -drive file=$IMG_PATH,format=raw \ -m $RAM -smp $CPU ;; *) 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" esac