add: info error warn functions; fix: syntax error in function declaration
This commit is contained in:
parent
15fc39a355
commit
21404908d8
1 changed files with 50 additions and 24 deletions
54
shemum
54
shemum
|
@ -3,6 +3,8 @@
|
||||||
# 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
|
||||||
# To enable debug mode remove the comment.
|
# To enable debug mode remove the comment.
|
||||||
# Default: true
|
# Default: true
|
||||||
|
@ -28,7 +30,10 @@ IMG_PATH="$ROOT_PATH/$OS_NAME/$OS_NAME.img"
|
||||||
# Sources virtual machine specific values
|
# Sources virtual machine specific values
|
||||||
. "$ROOT_PATH/$OS_NAME/.env"
|
. "$ROOT_PATH/$OS_NAME/.env"
|
||||||
|
|
||||||
# Defines install image repository.
|
# Functions
|
||||||
|
|
||||||
|
# Defines install image source
|
||||||
|
def_os_source() {
|
||||||
case $OS_NAME in
|
case $OS_NAME in
|
||||||
"openbsd")
|
"openbsd")
|
||||||
INSTALL_IMG="https://cdn.openbsd.org/pub/OpenBSD/7.5/i386/cd75.iso"
|
INSTALL_IMG="https://cdn.openbsd.org/pub/OpenBSD/7.5/i386/cd75.iso"
|
||||||
|
@ -37,20 +42,41 @@ case $OS_NAME in
|
||||||
INSTALL_IMG=""
|
INSTALL_IMG=""
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "$OS_NAME is not an option" >&2
|
err_func "INSTALL_IMG for $OS_NAME not found"
|
||||||
exit 1
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
# Functions
|
check_func() {
|
||||||
|
if [ -z $OS_NAME ]
|
||||||
|
err_func "Operating system is empty"
|
||||||
|
fi
|
||||||
|
if [ -z $INSTALL_IMG ]
|
||||||
|
info_func "$INSTALL_IMG is not set"
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
err_func() {
|
||||||
|
printf "$@" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
warn_func() {
|
||||||
|
printf "$@" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
info_func() {
|
||||||
|
printf "$@" >&1
|
||||||
|
}
|
||||||
|
|
||||||
# Virtual machine removal
|
# Virtual machine removal
|
||||||
remove_func function {
|
remove_func() {
|
||||||
rm -r $ROOT_PATH/$OS_NAME
|
rm -r $ROOT_PATH/$OS_NAME
|
||||||
}
|
}
|
||||||
|
|
||||||
# Virtual machine start without a console
|
# Virtual machine start without a console
|
||||||
start_func function {
|
start_func() {
|
||||||
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 \
|
||||||
|
@ -58,7 +84,7 @@ start_func function {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Virtual machine start with a console
|
# Virtual machine start with a console
|
||||||
console_func function {
|
console_func() {
|
||||||
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 \
|
||||||
|
@ -66,17 +92,17 @@ console_func function {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Virtual machine initialization with a console
|
# Virtual machine initialization with a console
|
||||||
init_func function {
|
init_func() {
|
||||||
|
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
|
||||||
if [ ! -f $ISO_PATH ] && [ ! -z $INSTALL_IMG ]; then
|
if [ ! -f $ISO_PATH ] && [ ! -z $INSTALL_IMG ]; then
|
||||||
echo $INSTALL_IMG
|
info_func "Fetching $OSNAME installer at: $INSTALL_IMG"
|
||||||
curl -o $ISO_PATH $INSTALL_IMG
|
curl -o $ISO_PATH $INSTALL_IMG
|
||||||
elif [ ! -z $INSTALL_IMG ]; then
|
elif [ ! -z $INSTALL_IMG ]; then
|
||||||
echo "Current INSTALL_IMG for $OS_NAME: $ISO_PATH"
|
info_func "Current INSTALL_IMG for $OS_NAME: $ISO_PATH"
|
||||||
else:
|
else
|
||||||
echo "Install image path is missing" >&2
|
err_func "Install image path is missing"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
qemu-system-x86_64 -boot d \
|
qemu-system-x86_64 -boot d \
|
||||||
-display curses \
|
-display curses \
|
||||||
|
@ -86,7 +112,7 @@ init_func function {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Display usage
|
# Display usage
|
||||||
usage_func function {
|
usage_func() {
|
||||||
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"
|
||||||
|
|
Loading…
Reference in a new issue