Skip to content
Snippets Groups Projects
Commit c2d0b447 authored by Alberto LIVIO BECCARIA's avatar Alberto LIVIO BECCARIA
Browse files

Code restyling and improved argument parsing in vm-start.

parent 0ea53ba1
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
#############################################
# VirtualBox VM Scripts 18.5.4 - vm-setup
# VirtualBox VM Scripts - vm-setup
# by ulisse aka A. Livio Beccaria
#
# vm-setup sets a VM up
......
#!/bin/bash
#############################################
# VirtualBox VM Scripts 18.5.4 - vm-start
# VirtualBox VM Scripts - vm-start
# by ulisse aka A. Livio Beccaria
#
# vm-start starts a VM :)
#############################################
APP_NAME="vm-start - VirtualBox VM Scripts"
VERSION="18.5.4"
VERSION="18.5.7"
AUTHOR="DiSIT"
# source folder
......@@ -157,14 +157,14 @@ vm_discard_state() {
##############
vm_start_run() {
# --fullscreen?
if [ "${FULLSCREEN}" == "1" ]; then
if [[ ${FULLSCREEN} == 1 ]]; then
# VBoxManage has no option for fullscreen mode, use VBoxSDL (no menu available in fullscreen)
# VBoxSDL --startvm "${VM_NAME}" --fullscreen &
# VBoxSDL --startvm "${VM_NAME}" --fullscreen
# options below could be useful in setting the fullscreen resolution, when known
# --fullscreenresize --fixedmode 1152 864 32 &
# --fullscreenresize --fixedmode 1152 864 32
#
# the following command can also be used to start the VM in fullscreen (GUI mode)
/usr/bin/VirtualBox --startvm "${VM_NAME}" --fullscreen &
/usr/bin/VirtualBox --startvm "${VM_NAME}" --fullscreen
else
VBoxManage startvm "${VM_NAME}"
fi
......@@ -172,44 +172,70 @@ vm_start_run() {
###############################################################################
# print title
title
###############################################################################
# Parse arguments
#################
[ "$#" -gt 0 ] || usage "ERROR: one argument required ($# provided)."
# get VM ID or name
VM_ID=$1
shift
# read the options (command line options override settings file values)
OPTS=`getopt -o fgirsd --long fullscreen,gui,no-init,no-run,discard-state,debug -n "$0" -- "$@"`
eval set -- "$OPTS"
# extract options and their arguments into variables
while true ; do
case "$1" in
-f|--fullscreen) FULLSCREEN="1" ; shift ;;
-g|--gui) FULLSCREEN="0" ; shift ;;
-r|--no-run) NO_RUN="1" ; shift ;;
-i|--no-init) NO_INIT="1"; shift ;;
-s|--discard-state) DISCARD_STATE="1"; shift ;;
-d|--debug) DEBUG="1"; shift ;;
--) shift ; break ;;
[[ "$#" -ge 1 ]] || usage "ERROR: one argument required ($# provided)."
VM_ID=""
DEBUG=0
FULLSCREEN_CL=-1
FULLSCREEN=0
NO_RUN=0
NO_INIT=0
DISCARD_STATE=0
while [ "$1" != "" ]; do
PARAM=`echo $1 | awk -F= '{print $1}'`
VALUE=`echo $1 | awk -F= '{print $2}'`
case ${PARAM} in
-h | --help)
usage ""
exit 0
;;
-g | --gui)
FULLSCREEN_CL=0
shift
;;
-f | --fullscreen)
FULLSCREEN_CL=1
shift
;;
-i |--no-init)
NO_INIT=1
shift
;;
-r |--no-run)
NO_RUN=1
shift
;;
-s | --discard-state)
DISCARD_STATE=1
shift
;;
-d | --debug)
DEBUG=1
shift
;;
*)
if [[ "${VM_ID}" == "" ]]; then
VM_ID=${PARAM}
shift
else
usage "ERROR: unknown argument \"${PARAM}\"."
exit 1
fi
;;
esac
done
###############################################################################
# print title
title
# print debug info if needed
debug
# include global settings
. "${SRC_DIR}/settings/settings"
......@@ -218,7 +244,7 @@ if [ ! -f "$SRC_DIR/settings/${VM_ID}.settings" ]; then
result=`get_vm_id_by_name "${VM_ID}"`
VM_ID=$result
if [ ! -f "$SRC_DIR/settings/${VM_ID}.settings" ]; then
usage "ERROR: wrong vm id or name."
usage "ERROR: wrong vm_id or name."
fi
fi
......@@ -226,6 +252,15 @@ fi
. "${SRC_DIR}/settings/${VM_ID}.settings"
# override VM fullscreen setting if set on command line
if [[ ${FULLSCREEN_CL} != -1 ]]; then
FULLSCREEN=${FULLSCREEN_CL}
fi
# print debug info if needed
debug
# check if VM exists
VBoxManage showvminfo "${VM_NAME}" &> /dev/null
[ "$?" -eq 0 ] || die "ERROR: VM not configured. Run 'vm-setup ${VM_ID}' and try again."
......@@ -242,17 +277,17 @@ if [ "$current_snapshot_folder" != "${USER_TMP_DIR}" ]; then
fi
# --no-init?
if [ "${NO_INIT}" != "1" ]; then
if [[ ${NO_INIT} == 0 ]]; then
vm_start_init
fi
# --discard-state?
if [ "${DISCARD_STATE}" == "1" ]; then
if [[ ${DISCARD_STATE} == 1 ]]; then
vm_discard_state
fi
# --no-run?
if [ "${NO_RUN}" != "1" ]; then
if [[ ${NO_RUN} == 0 ]]; then
vm_start_run
fi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment