Skip to content
Snippets Groups Projects
Commit 2cd74fd9 authored by ulisse's avatar ulisse
Browse files

now vm id or name MUST be the first argument, flags may follow

parent 844bc061
No related branches found
No related tags found
No related merge requests found
......@@ -13,34 +13,15 @@ SRC_DIR="$(dirname $(readlink -f $0))"
. ${SRC_DIR}/settings/common
# read all parameters
# set an initial value for the flags
NO_INIT=""
NO_RUN=""
# read the options (command line options override settings file values)
OPTS=`getopt -o fgir --long fullscreen,gui,no-init,no-run -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="" ; shift ;;
-r|--no-run) NO_RUN="1" ; shift ;;
-i|--no-init) NO_INIT="1"; shift ;;
--) shift ; break ;;
esac
done
[ "$#" -eq 1 ] || usage_vm-start "Error: one parameter required ($# provided)."
VM_ID=$1
[ "$#" -gt 0 ] || usage_vm-start "Error: one parameter required ($# provided)."
# include global settings
. ${SRC_DIR}/settings/settings
# get VM ID or name
VM_ID=$1
shift
# VM_ID lookup in settings files by ID or NAME
if [ ! -f "$SRC_DIR/settings/${VM_ID}.settings" ]; then
result=`get_vm_id_by_name "${VM_ID}"`
......@@ -50,27 +31,29 @@ if [ ! -f "$SRC_DIR/settings/${VM_ID}.settings" ]; then
fi
fi
if [ $DEBUG -eq 1 ]; then
echo "vm_id = $VM_ID"
echo "fullscreen = $FULLSCREEN"
echo "no-init = $NO_INIT"
echo "no-run = $NO_RUN"
exit 1
fi
# include VM settings
. "${SRC_DIR}/settings/${VM_ID}.settings"
# 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."
# read the options (command line options override settings file values)
OPTS=`getopt -o fgir --long fullscreen,gui,no-init,no-run -n "$0" -- "$@"`
eval set -- "$OPTS"
# create temporary folder
if [ ! -d $TMP_DIR ]; then
mkdir $TMP_DIR
fi
# extract options and their arguments into variables
while true ; do
case "$1" in
-f|--fullscreen) FULLSCREEN="1" ; shift ;;
-g|--gui) FULLSCREEN="" ; shift ;;
-r|--no-run) NO_RUN="1" ; shift ;;
-i|--no-init) NO_INIT="1"; shift ;;
--) shift ; break ;;
esac
done
# no-init?
if [ "${NO_INIT}" != "1" ]; then
vm_start_init () {
# create temporary folder
if [ ! -d $TMP_DIR ]; then
mkdir $TMP_DIR
fi
# remove files older than 12 hours
#find ${TMP_DIR} -name "*" -type f -mmin +720 -delete
......@@ -132,12 +115,9 @@ if [ "${NO_INIT}" != "1" ]; then
else
echo "Differential disk: autoreset=on"
fi
fi
# start vm
}
# --no-run?
if [ "${NO_RUN}" != "1" ]; then
vm_start_run() {
# --fullscreen?
if [ "${FULLSCREEN}" != "" ]; then
# VBoxManage has no option for fullscreen mode, use VBoxSDL (no menu available in fullscreen)
......@@ -150,5 +130,28 @@ if [ "${NO_RUN}" != "1" ]; then
else
VBoxManage startvm "${VM_NAME}"
fi
}
if [ $DEBUG -eq 1 ]; then
echo "vm_id = $VM_ID"
echo "fullscreen = $FULLSCREEN"
echo "no-init = $NO_INIT"
echo "no-run = $NO_RUN"
exit 1
fi
# 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."
# --no-init?
if [ "${NO_INIT}" != "1" ]; then
vm_start_init
fi
# --no-run?
if [ "${NO_RUN}" != "1" ]; then
vm_start_run
fi
exit 0
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