style: made functions more readable
This commit is contained in:
parent
d4c06eda43
commit
d172c755e6
1 changed files with 21 additions and 21 deletions
42
shemum
42
shemum
|
@ -32,7 +32,7 @@ IMG_PATH="$ROOT_PATH/$OS_NAME/$OS_NAME.img"
|
|||
# Functions
|
||||
|
||||
# Defines install image source
|
||||
def_os_source() {
|
||||
function def_os_source() {
|
||||
case $OS_NAME in
|
||||
"openbsd")
|
||||
INSTALL_IMG="https://cdn.openbsd.org/pub/OpenBSD/7.5/i386/cd75.iso"
|
||||
|
@ -41,41 +41,41 @@ def_os_source() {
|
|||
INSTALL_IMG=""
|
||||
;;
|
||||
*)
|
||||
err_func "INSTALL_IMG for $OS_NAME not found"
|
||||
error "INSTALL_IMG for $OS_NAME not found"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
check_func() {
|
||||
function check() {
|
||||
if [ -z $OS_NAME ]
|
||||
err_func "Operating system is empty"
|
||||
error "Operating system is empty"
|
||||
fi
|
||||
if [ -z $INSTALL_IMG ]
|
||||
info_func "$INSTALL_IMG is not set"
|
||||
info "$INSTALL_IMG is not set"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
err_func() {
|
||||
function error() {
|
||||
printf "$@" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
warn_func() {
|
||||
function warn() {
|
||||
printf "$@" >&2
|
||||
}
|
||||
|
||||
info_func() {
|
||||
function info() {
|
||||
printf "$@" >&1
|
||||
}
|
||||
|
||||
# Virtual machine removal
|
||||
remove_func() {
|
||||
function remove() {
|
||||
rm -r $ROOT_PATH/$OS_NAME
|
||||
}
|
||||
|
||||
# Virtual machine start without a console
|
||||
start_func() {
|
||||
function start() {
|
||||
qemu-system-x86_64 -boot c \
|
||||
-display none \
|
||||
-drive file=$IMG_PATH,format=raw \
|
||||
|
@ -83,7 +83,7 @@ start_func() {
|
|||
}
|
||||
|
||||
# Virtual machine start with a console
|
||||
console_func() {
|
||||
function console() {
|
||||
qemu-system-x86_64 -boot c \
|
||||
-display curses \
|
||||
-drive file=$IMG_PATH,format=raw \
|
||||
|
@ -91,17 +91,17 @@ console_func() {
|
|||
}
|
||||
|
||||
# Virtual machine initialization with a console
|
||||
init_func() {
|
||||
function 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_func "Fetching $OSNAME installer at: $INSTALL_IMG"
|
||||
info "Fetching $OSNAME installer at: $INSTALL_IMG"
|
||||
curl -o $ISO_PATH $INSTALL_IMG
|
||||
elif [ ! -z $INSTALL_IMG ]; then
|
||||
info_func "Current INSTALL_IMG for $OS_NAME: $ISO_PATH"
|
||||
info "Current INSTALL_IMG for $OS_NAME: $ISO_PATH"
|
||||
else
|
||||
err_func "Install image path is missing"
|
||||
error "Install image path is missing"
|
||||
fi
|
||||
qemu-system-x86_64 -boot d \
|
||||
-display curses \
|
||||
|
@ -111,7 +111,7 @@ init_func() {
|
|||
}
|
||||
|
||||
# Display usage
|
||||
usage_func() {
|
||||
function 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"
|
||||
|
@ -122,19 +122,19 @@ usage_func() {
|
|||
# Options
|
||||
case $OPTION in
|
||||
"init")
|
||||
init_func
|
||||
init
|
||||
;;
|
||||
"console")
|
||||
console_func
|
||||
console
|
||||
;;
|
||||
"start")
|
||||
start_func
|
||||
start
|
||||
;;
|
||||
"remove")
|
||||
remove_func
|
||||
remove
|
||||
;;
|
||||
*)
|
||||
usage_func
|
||||
usage
|
||||
esac
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue