diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b8b90a97c40c01b7cca0208235ca9e54dad0850..e8149ee6d0bd6b2401cc75e4ceb03329955c5afd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -97,6 +97,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/ ## [next release] ## Added + issue #653 - added a couple of scriptsto ease vnc conection from remote a file copying. The scripts support + linux and macos ## Fixed issue #448 - Added Sky Offsets to calibration tool client issue #585 - Fixed misshandled schedule with NULL as backend (Dry Run) diff --git a/Medicina/Misc/MedScripts/src/Makefile b/Medicina/Misc/MedScripts/src/Makefile index 224bfb1f4f9f9cd7b511976e3788587c37472aca..1f1f60d7da2b5c7fa53ffe7d135b7310faae2ff6 100644 --- a/Medicina/Misc/MedScripts/src/Makefile +++ b/Medicina/Misc/MedScripts/src/Makefile @@ -53,7 +53,7 @@ pppppp_MODULES = # new bootup scripts (discos): SCRIPTS=discosup discosdown discosConsole -SCRIPTS_L = escs escsConsole +SCRIPTS_L = med-vnc med-copy #INSTALL_FILES = ../app-defaults/escsStartup.xml diff --git a/Medicina/Misc/MedScripts/src/med-copy b/Medicina/Misc/MedScripts/src/med-copy new file mode 100644 index 0000000000000000000000000000000000000000..54edf5f28f89242d0dea80676657caa91dd5a274 --- /dev/null +++ b/Medicina/Misc/MedScripts/src/med-copy @@ -0,0 +1,147 @@ +#!/usr/bin/env bash + +print_help() { + echo " " + echo "`basename $0` v1.0" + echo " " + echo "Copy files from and toward the DISCOS system." + echo "Usage: '`basename $0` [-t|--port portnumber] -r|--remote @ -d|--download Source Destination" + echo " '`basename $0` [-t|--port portnumber] -r|--remote @ -u|--upload Source Destination" + echo " '`basename $0` -h|--help'" + echo "-d | --download this allows to download files or folders from DISCOS to your local machine" + echo "-h | --help prints this help message and exit" + echo "-p | --port ssh port, if different from the default one" + echo "-r | --remote provides the credentials to log into DISCOS" + echo " indicates the project for which files are copied." + echo " access point into the observatory lan. This information is provided by local staff." + echo " Use 'local' if already inside the local area network." + echo "-u | --upload this allows to upload files or folders to DISCOS from your local machine" + exit 1 +} + +current_system="LINUX" +upload="" +download="" +ssh_port="22" +project="" +gatein="" +local="FALSE" +src="" +dest="" + +while [[ $# -gt 0 ]] +do +key="$1" +case $key in + -h|--help) + print_help + ;; + -p|--port) + ssh_port=$2 + shift + shift + ;; + -d|--download) + download="TRUE" + shift + ;; + -u|--upload) + upload="TRUE" + shift + ;; + -r|--remote) + if [[ $2 == *"@"* ]]; then + while IFS='@' read -ra ARG; do + if [[ "${#ARG[@]}" -ne 2 ]]; then + echo -e "Please provide a correct @ pair, retry!" + print_help + fi + project=${ARG[0]} + gatein=${ARG[1]} + done <<< "$2" + else + echo "Bad argument format: '$2'!" + print_help + fi + shift + shift + ;; + *) + if [[ "$src" == "" ]] + then + src=$key + elif [[ "$dest" == "" ]] + then + dest=$key + else + echo "Too many arguments provided!" + print_help + fi + shift + ;; +esac +done + +if [[ "$src" == "" || "$dest" == "" ]]; then + echo -e "Inconsistent input, both source and destination should be provided!" + print_help +fi + +if [[ "$gatein" == "" ]]; then + echo -e "Remote credentials must be provided!" + print_help +fi + +if [[ "$gatein" == "local" ]]; then + local="TRUE" +fi + +if [[ "$upload" == "" && "$download" == "" ]]; then + echo -e "Inconsistent input, at least one of '--upload' and '--download' should be provided!" + print_help +fi + +if [[ "$upload" != "" && "$download" != "" ]]; then + echo -e "Inconsistent input, only one of '--upload' and '--download' should be provided!" + print_help +fi + +if [[ "$OSTYPE" == *"linux-gnu"* ]] +then + echo -e "Linux OS is detected..." + current_system="LINUX" +elif [[ "$OSTYPE" == *"darwin"* ]] +then + echo -e "Mac OS is detected..." + current_system="MACOS" +else + echo -e "Not supported OS, some unpredictable results may happen!" +fi + +#echo $local +#echo $project +#echo $gatein +#echo $ssh_port +#echo $files +#echo $upload +#echo $download +#echo $current_system + +proxy="ProxyCommand=ssh -p ""$ssh_port"" -W %h:%p observer@""$gatein" +#echo $proxy + + +if [[ "$local" == "FALSE" ]]; then + if [[ "$upload" == "TRUE" ]]; then + scp -r -P 9922 -o "$proxy" $src "$project"@192.167.189.98:$dest 2> /dev/null + elif [[ "$download" == "TRUE" ]]; then + scp -r -P 9922 -o "$proxy" "$project"@192.167.189.98:$src $dest 2> /dev/null + fi +else + if [[ "$upload" == "TRUE" ]]; then + scp -r -P 9922 $src "$project"@192.167.189.98:$dest 2> /dev/null + elif [[ "$download" == "TRUE" ]]; then + scp -r -P 9922 "$project"@192.167.189.98:$src $dest 2> /dev/null + fi +fi + diff --git a/Medicina/Misc/MedScripts/src/med-vnc b/Medicina/Misc/MedScripts/src/med-vnc new file mode 100644 index 0000000000000000000000000000000000000000..e06585f535c602e96be3adf6a5ce583581db8a87 --- /dev/null +++ b/Medicina/Misc/MedScripts/src/med-vnc @@ -0,0 +1,174 @@ +#!/usr/bin/env bash + +print_help() { + echo " " + echo "`basename $0` v1.0" + echo " " + echo "Start a new session toward DISCOS control software" + echo "Usage: '`basename $0` [OPTIONS] [-t|--port portnumber] @'" + echo " '`basename $0` -r|--roles'" + echo " '`basename $0` -h|--help'" + echo " indicates the role (observer or administrative privileges) for which the connection is done" + echo " access point into the observatory LAN. This information is provided by local staff." + echo " Use 'local' if already inside the local area network." + echo "-h | --help prints this help message and exit" + echo "-r | --roles shows all the available roles" + echo "-p | --port ssh port if different from the default one" + echo "Options:" + echo " -v | --viewonly start the vncviewer in view only mode" + exit 1 +} + +vnc_avail="TRUE" +local_connection="FALSE" +ssh_port="22" +viewonly="" +role="" +gatein="" +remote_port=0 +current_system="LINUX" + +remote_sessions=( "discos:9901:15001" "observer:9902:15002" ) + + +while [[ $# -gt 0 ]] +do +key="$1" + +case $key in + -h|--help) + print_help + ;; + -r|--roles) + echo "Available roles are: " + for session in "${remote_sessions[@]}" ; do + echo "${session%%:*}" + done + exit 0 + ;; + -p|--port) + ssh_port=$2 + shift + shift + ;; + -v|--viewonly) + viewonly="-ViewOnly" + shift + ;; + *) + if [[ $1 == *"@"* ]]; then + while IFS='@' read -ra ARG; do + if [[ "${#ARG[@]}" -ne 2 ]]; then + echo "Please provide a correct @ pair, retry!" + print_help + fi + role=${ARG[0]} + gatein=${ARG[1]} + done <<< "$1" + else + echo "Unrecognized option: '$1'!" + print_help + fi + shift + ;; +esac +done + +if [[ "$gatein" == "local" ]]; then + local_connection="TRUE" +fi + +if [[ "$OSTYPE" == *"linux-gnu"* ]] +then + echo -e "Linux OS is detected..." + current_system="LINUX" +elif [[ "$OSTYPE" == *"darwin"* ]] +then + echo -e "Mac OS is detected..." + current_system="MACOS" +else + echo -e "Not supported OS, some unpredictable results may happen!" +fi + +if ! hash vncviewer &>/dev/null; then + echo -e "'vncviewer' is not installed, this script is setting up the connection but won't automatically start vnc.\nA custom client should be manually started." + vnc_avail="FALSE" +fi + +if hash netstat &>/dev/null; then + if [[ "$current_system" == "LINUX" ]]; then + PORTCOMMAND="netstat -tulpn" + else + PORTCOMMAND="netstat -avnp tcp" + fi +else + echo -e "This program requires 'netstat' to be installed.\nThe package to install may vary depending on your operating system.\n" + print_help +fi + +for session in "${remote_sessions[@]}" ; do + role_name="${session%%:*}" + ports="${session#*:}" + rport="${ports%:*}" + lport="${ports#*:}" + if [[ "$role" == "$role_name" ]]; then + if [ "$local_connection" = "TRUE" ]; then + #this is for local area connection when it will enabled + #remote_port=$lport + remote_port=$rport + ssh_port=5122 + else + remote_port=$rport + fi + break + fi +done + +if [[ $remote_port -eq 0 ]]; then + echo "Please, provide a correct role, use the switch '--roles' for a complete list of available roles" + print_help +fi + +for i in {0..50} +do + local_port_attempt=$((9000 + i)) + if ! $PORTCOMMAND | grep 127.0.0.1[.:]$local_port_attempt &>/dev/null; then + local_port=$local_port_attempt + break + fi +done + +if [[ -z "$local_port" ]]; then + echo "Could not find an available port in range 9000-9050" + exit 1 +fi + +#echo $local_connection +#echo $role +#echo $remote_port +#echo $local_port +#echo $gatein +#echo $ssh_port +#echo $viewonly +#echo $vnc_avail + +if [[ "$local_connection" = "TRUE" ]]; then + echo "Connecting from local area...." + #ssh -N -f -L $local_port:192.168.1.99:$remote_port $role@192.167.189.98 +else + echo "Connecting from wide area....." +fi +ssh -N -f -p $ssh_port -L $local_port:192.167.189.98:$remote_port $role@$gatein +if [[ "$vnc_avail" == "TRUE" ]]; then + echo "Starting vncviewer...." + vncviewer localhost:$local_port $viewonly &>/dev/null +else + echo "Connection is set, please use your preferred vnc client to connect to 'localhost', port "$local_port +fi + + + + + + +