vm-start/remote_connection.sh

75 lines
1.9 KiB
Bash
Raw Normal View History

#/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.
2024-01-22 01:44:36 +01:00
User="root"
Port=10022
Version="1.1.0"
2024-01-22 01:44:36 +01:00
Help_message="
$(basename $0) [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>,--user=<user> Select the user, by default root
-p <port>,--port=<port> Select the port, by default 10022
-v, --version print the version and exit
-h, --help print this help and exit
-H <hostname>, --hostname=<hostname> Select the host to connect #TODO
-P <protocol>, --protocol=<protocol> Select the protocol to use #TODO
"
# looking for double parametters.
for (( arg=1; arg<$#; arg++)); do
value="$((arg+1))"
if [ "${!arg}" == "-u" ]
then
2024-01-22 01:44:36 +01:00
User=${!value}
elif [ "${!arg}" == "-p" ]
then
2024-01-22 01:44:36 +01:00
Port=${!value}
fi
done
# looking for all parametter alone
for i in "$@"; do
if [ "${i%=*}" == "--user" ]
then
2024-01-22 01:44:36 +01:00
User="${i#*=}"
elif [ "${i%=*}" == "--port" ]
then
2024-01-22 01:44:36 +01:00
Port="${i#*=}"
elif [ "${i}" == "--version" ] || [ "${i}" == "-v" ]
then
echo "$(basename $0) v.${Version}"
exit 0
elif [ "${i}" == "--help" ] || [ "${i}" == "-h" ]
then
2024-01-22 01:44:36 +01:00
echo "$Help_message"
exit 0
fi
done
2024-01-22 01:44:36 +01:00
echo try to connect with user=${User} and port=${Port}
echo port=${Port}
2024-01-22 01:44:36 +01:00
ssh -o "StrictHostKeyChecking no" -o "UserKnownHostsFile=/dev/null" -p ${Port} ${User}@localhost
2024-02-02 16:17:48 +01:00
# add possibility for vnc and rsp
# rsp command to connect: xfreerdp /v:hostname /u:user /dynamic-resolution