From 37caf10ca435a89ccf9fe46f75424256e1c198b1 Mon Sep 17 00:00:00 2001 From: primardj Date: Sun, 21 Jan 2024 02:50:10 +0000 Subject: [PATCH] add a script to connect to the vm by ssh, add uefi option and a few others to vm-start --- ssh-local.sh | 69 ++++++++++++++++++++++++++++++++++++++++ vm-start.sh | 89 ++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 152 insertions(+), 6 deletions(-) create mode 100755 ssh-local.sh diff --git a/ssh-local.sh b/ssh-local.sh new file mode 100755 index 0000000..7470298 --- /dev/null +++ b/ssh-local.sh @@ -0,0 +1,69 @@ +#/bin/bash + +# +# little class about bash extension parametters. +# +# ${myvar#pattern} delete shortest occurence from the begining +# ${myvar##pattern} delete longuest occurence from begining +# ${myvar%pattern} delete shortest occurence from the end +# ${myvar%%pattern} delete longuest occurence from the end +# +# conclusion, use of # will delete the pattern at begining +# and % will delete the parameter at the end. + + +USER="root" +PORT=10022 +VERSION="1.0" + +HELP_MESSAGE=" +ssh-local [OPTION] [OPTION=VALUE] + +script which permit to launch ssh to connect to the vm on localhost without letting any traces on this computer. + + -u ,--user= Select the user, by default root + -p ,--port= Select the port, by default 10022 + -v, --version print the version and exit + -h, --help print this help and exit +" + + +# looking for double parametters. + +for (( arg=1; arg<$#; arg++)); do + value="$((arg+1))" + if [ "${!arg}" == "-u" ] + then + USER=${!value} + elif [ "${!arg}" == "-p" ] + then + PORT=${!value} + fi +done + + +# looking for all parametter alone + +for i in "$@"; do + if [ "${i%=*}" == "--user" ] + then + USER="${i#*=}" + elif [ "${i%=*}" == "--port" ] + then + PORT="${i#*=}" + elif [ "${i}" == "--version" ] || [ "${i}" == "-v" ] + then + echo "Prog ssh-local v.${VERSION}" + exit 0 + elif [ "${i}" == "--help" ] || [ "${i}" == "-h" ] + then + echo "$HELP_MESSAGE" + exit 0 + fi +done + +echo user=${USER} +echo port=${PORT} + +ssh -o "StrictHostKeyChecking no" -o "UserKnownHostsFile=/dev/null" ${USER}@localhost -p ${PORT} + diff --git a/vm-start.sh b/vm-start.sh index 3dc4c1d..8e81204 100755 --- a/vm-start.sh +++ b/vm-start.sh @@ -1,11 +1,50 @@ #!/bin/bash # -#RESULT_POSSIBLE=("init","start","start-backup","create","backup","restore") +#RESULT_POSSIBLE=("init","start","start-backup","create","backup","restore","suppr") -VERSION=0.5 -MAIN_LOCATION="$HOME/virtual-machine/" +VERSION=0.6 +USAGE="vm-start NAME COMMAND [PARAMETER] [OPTION] +Script to manage virtual machine easily. + +NAME is the name of the virtual machine to use. + +COMMAND available + init Create the conf file in conf/NAME_var.sh + start Start the virtual machine using the variabes in conf/NAME_var.sh + start-backup Start the virtual machine using the backup volume if it exists. + create Create the virtual machine using the conf in conf/NAME_var.sh + backup Create a backup file for the vm + restore Restore the virtual machine using to backup file + suppr Suppr all data related to the virtual machine other than the conf file. + +COMMAND TODO + suppr-all Suppr all data related to the vm even the conf file #TODO + +PARAMETTER available + -h, --help Print this help and exit + -v, --version Print the version of this program and quit + +OPTION available + NPROC= Def the number of proc of the vm + MEMORY= Def the qty of memory allocated to the vm + SIZE= Def the size that should be allocated by create + UEFI= Select if there will be an UEFI by default. + can be either set or unset. By default is unset. + OPTIONS=