summaryrefslogtreecommitdiff
path: root/localautossh
diff options
context:
space:
mode:
authorroot <root@jellyfish>2012-08-29 13:10:59 +0200
committerroot <root@jellyfish>2012-08-29 13:10:59 +0200
commitf6ff956c2ae924c3cb97b07fd2d00c616e231daa (patch)
tree2724454f8e2f03fe12d33d68d483bffeea41bfb1 /localautossh
parent0a3f52758fa6f0a9aa1721816b946ec7f220bb0f (diff)
Restructure to use start/stop action, and to use notify-bin if available.
Diffstat (limited to 'localautossh')
-rwxr-xr-xlocalautossh41
1 files changed, 33 insertions, 8 deletions
diff --git a/localautossh b/localautossh
index 053394d..f49580c 100755
--- a/localautossh
+++ b/localautossh
@@ -6,8 +6,37 @@
# to 22 on the local host. On remote host do:
# ssh -p 2200 localhost
#
-# $Id: localautossh,v 1.2 2008-03-28 09:28:55 jonas Exp $
-#
+# Recommends: notify-bin
+
+set -e
+
+action="$1"
+remotehost="$2"
+remoteport="${3:-2200}"
+
+info() {
+ if [ -n "$DISPLAY" ] && [ -e /usr/bin/notify-send ]; then
+ notify-send "$1" "$2"
+ else
+ echo >&2 "$1"
+ echo >&2 "$2"
+ fi
+}
+
+case "$action" in
+ start)
+ info "Starting remote help..." "Establishing a connection tunnel from $remotehost into this machine..."
+ ;;
+ stop)
+ killall -KILL autossh
+ info "Remote help is off!" "Connection tunnels into this machine is now inactive."
+ exit $?
+ ;;
+ *)
+ echo 2>& "Wrong action passed to localautossh!"
+ exit 1
+ ;;
+esac
if [ -z "$SSH_ASKPASS" ]; then
export SSH_ASKPASS="ssh-askpass"
@@ -18,11 +47,6 @@ if [ "X$SSH_AUTH_SOCK" = "X" ]; then
ssh-add $HOME/.ssh/id_rsa
fi
-remoteport="2200"
-if [ -n "$2" ]; then
- remoteport="$(expr 2200 + "$2")"
-fi
-
#AUTOSSH_POLL=600
#AUTOSSH_PORT=20000
#AUTOSSH_GATETIME=30
@@ -31,4 +55,5 @@ fi
#AUTOSSH_PATH=/usr/local/bin/ssh
export AUTOSSH_POLL AUTOSSH_LOGFILE AUTOSSH_DEBUG AUTOSSH_PATH AUTOSSH_GATETIME AUTOSSH_PORT
-autossh -2 -fN -M 20000 -R $remoteport:localhost:22 "$1"
+autossh -2 -f -N -M 20000 -R $remoteport:localhost:22 "$remotehost"
+info "Remote help is on!" "Connection tunnel from $remotehost into this machine is now active."