From 98896d3e6c7e88c3674db7e86af3bc8bd8db17d9 Mon Sep 17 00:00:00 2001 From: MB <michael.blaschek@univie.ac.at> Date: Wed, 24 Mar 2021 16:08:24 +0100 Subject: [PATCH] updated some connection tools --- SSH-VPN-VNC/add_xrandr_resolution.sh | 18 ++-- SSH-VPN-VNC/{connect2jet.sh => connect2jet} | 0 SSH-VPN-VNC/connect2vpn | 33 +++++++ SSH-VPN-VNC/mountserver | 98 +++++++++++++++++++++ 4 files changed, 143 insertions(+), 6 deletions(-) mode change 100644 => 100755 SSH-VPN-VNC/add_xrandr_resolution.sh rename SSH-VPN-VNC/{connect2jet.sh => connect2jet} (100%) create mode 100755 SSH-VPN-VNC/connect2vpn create mode 100755 SSH-VPN-VNC/mountserver diff --git a/SSH-VPN-VNC/add_xrandr_resolution.sh b/SSH-VPN-VNC/add_xrandr_resolution.sh old mode 100644 new mode 100755 index 915b22b..a6e5f9c --- a/SSH-VPN-VNC/add_xrandr_resolution.sh +++ b/SSH-VPN-VNC/add_xrandr_resolution.sh @@ -1,16 +1,22 @@ #!/bin/bash -# +# By Michael Blaschek +# Date 15.08.2020 +# CC BY 4.0 International +# University of Vienna, Austria + +# Description: # Add custom VNC resolution -# Author: M Blaschek -# Date: 08-2020 # Requires: xrandr and a running VNC session - -if [ $# -ne 2 ]; then +if [ $# -lt 2 ]; then echo "e.g. try: $0 1920 1380" echo "or 2560 1320" else - command=$(cvt $1 $2 60 | grep Modeline | awk '{for(i=3;i<NF;i++){printf "%s ",$i}}') + refresh=60 + if [ $# -eq 3 ]; then + refresh=$3 + fi + command=$(cvt $1 $2 $refresh | grep Modeline | awk '{for(i=3;i<NF;i++){printf "%s ",$i}}') xrandr --newmode "$1x$2" ${command/Modeline/} xrandr --addmode VNC-0 "$1x$2" xrandr -d $DISPLAY -s "$1x$2" diff --git a/SSH-VPN-VNC/connect2jet.sh b/SSH-VPN-VNC/connect2jet similarity index 100% rename from SSH-VPN-VNC/connect2jet.sh rename to SSH-VPN-VNC/connect2jet diff --git a/SSH-VPN-VNC/connect2vpn b/SSH-VPN-VNC/connect2vpn new file mode 100755 index 0000000..fd29539 --- /dev/null +++ b/SSH-VPN-VNC/connect2vpn @@ -0,0 +1,33 @@ +#!/bin/bash +# By Michael Blaschek +# Date 23.03.2021 +# CC BY 4.0 International +# University of Vienna, Austria + +# Description: +# Connect to VPN from the University of Vienna +# Watch connection + +if [ -n $VPN_USER ]; then + echo "set VPN_USER to your u:account username" + exit 1 +fi + +f5fpc -h 2> /dev/null 1>/dev/null +if [ $? -ne 0 ]; then + echo "[VPN] Install Big-IP Edge Client. f5fpc missing" + exit 1 +fi + +if [ $# -eq 0 ]; then + echo "[VPN] Connecting split-tunnel ..." + f5fpc -s -t vpn.univie.ac.at -u ${VPN_USER} +else + echo "[VPN] Connecting full-tunnel ..." + f5fpc -s -t vpn.univie.ac.at:8443 -u ${VPN_USER} +fi +# Show status +watch -n 10 'f5fpc --info' +echo "[VPN] Shutting down ..." +# Disconnect +f5fpc -o \ No newline at end of file diff --git a/SSH-VPN-VNC/mountserver b/SSH-VPN-VNC/mountserver new file mode 100755 index 0000000..a0323c0 --- /dev/null +++ b/SSH-VPN-VNC/mountserver @@ -0,0 +1,98 @@ +#!/bin/bash +# By Michael Blaschek +# Date 23.03.2021 +# CC BY 4.0 International +# University of Vienna, Austria + +# Description: +# Connect a mount point from a remote server + +CURRENT_MOUNTS=$HOME/.currentmounts + +check(){ + status=0 + if [ -f ${CURRENT_MOUNTS} ]; then + # check mount points + while read line; + do + local_dir=$(echo "$line" | cut -d" " -f3) + mount | grep $local_dir > /dev/null + if [ $? -eq 0 ]; then + status=1 + echo "$line" >> ${CURRENT_MOUNTS}.2 + echo "[CHECK] $local_dir [OK]" + else + echo "[CHECK] $local_dir [X]" + fi + done < ${CURRENT_MOUNTS} + mv ${CURRENT_MOUNTS}.2 ${CURRENT_MOUNTS} + fi + return $status +} + +fun_unmount(){ + if [ $# -eq 0 ]; then + # unmount everything + if [ -f ${CURRENT_MOUNTS} ]; then + # check mount points + # need to redirect file input to unit-3, so that STDIN is available for read again + while read line <&3; + do + local_dir=$(echo "$line" | cut -d" " -f3) + fun_unmount ${local_dir} + done 3<${CURRENT_MOUNTS} + rm ${CURRENT_MOUNTS} + fi + else + mount | grep $1 > /dev/null + if [ $? -eq 0 ]; then + local_dir=$(mount | grep $1 | tail -n1 | cut -d" " -f3) + read -p "[UNMOUNT] ${local_dir} (y/n)?" REPLY + case "$REPLY" in + Y*|y*) fusermount -u ${local_dir}; echo "[UNMOUNT] ${local_dir} [OK]";; + *) echo "[UNMOUNT] ${local_dir} [X]";; + esac + fi + fi +} + +fun_mount(){ + # Make directory + mkdir -p $3 + # Mount using sshfs + sshfs $1:$2 $3 + echo "$1 $2 $3" >> ${CURRENT_MOUNTS} + echo "[MOUNT] $3 [OK]" +} +# +# Check if a mount point is active ? +# + +sshfs -h 2> /dev/null 1> /dev/null +if [ $? -ne 0 ]; then + echo "[MOUNT] sshfs is required to be installed." + exit 0 +fi + +if [ $# -ne 3 ]; then + check + if [ $? -eq 0 ]; then + echo "mountserver [host] [remotedir] [localdir]" + exit 1 + fi + echo "[MOUNT] unmounting ..." + # unmount ? + fun_unmount +else + # mount + host=$1 + host_dir=$2 + local_dir=$3 + fun_unmount ${local_dir} + read -p "[MOUNT] ${local_dir} (y/n)?" REPLY + case "$REPLY" in + Y*|y*) fun_mount $host $host_dir $local_dir;; + *) exit 0;; + esac +fi + -- GitLab