aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2013-07-08 12:43:58 +1200
committerTom Ryder <tom@sanctum.geek.nz>2013-07-08 12:43:58 +1200
commit5a35110868d49ab12d874ba6c3eca887f158f8a4 (patch)
tree445230c2de15da5d9193e236db2140cc2c790c5d
parentInitial commit (diff)
downloadpsshd-5a35110868d49ab12d874ba6c3eca887f158f8a4.tar.gz
psshd-5a35110868d49ab12d874ba6c3eca887f158f8a4.zip
Shaky first commit, but should be legible
-rw-r--r--README.markdown9
-rw-r--r--README.md4
-rw-r--r--examples/psshd.profile.sh8
-rwxr-xr-xpsshd67
4 files changed, 84 insertions, 4 deletions
diff --git a/README.markdown b/README.markdown
new file mode 100644
index 0000000..9817034
--- /dev/null
+++ b/README.markdown
@@ -0,0 +1,9 @@
+psshd
+=====
+
+Persistent, daemonized autossh tunnels. Requires start-stop-daemon(8) and
+autossh(1) commands. Designed to be called for login shells, in ~/.profile or
+~/.bash\_profile.
+
+ $ psshd -p 9010 -- -fN -D 8001 myvps
+
diff --git a/README.md b/README.md
deleted file mode 100644
index eabcc30..0000000
--- a/README.md
+++ /dev/null
@@ -1,4 +0,0 @@
-psshd
-=====
-
-Persistent, daemonized autossh tunnels
diff --git a/examples/psshd.profile.sh b/examples/psshd.profile.sh
new file mode 100644
index 0000000..c45085f
--- /dev/null
+++ b/examples/psshd.profile.sh
@@ -0,0 +1,8 @@
+# Persistent, daemonised SSH tunnel to your favourite VPS, setting up a SOCKS
+# proxy on port 8001, and using port 9010 for management. Goes nicely in a
+# ~/.profile or ~/.bash_profile script.
+psshd -p 9010 \
+ -- -fN \
+ -D 8001 \
+ myvps
+
diff --git a/psshd b/psshd
new file mode 100755
index 0000000..cbbb1ba
--- /dev/null
+++ b/psshd
@@ -0,0 +1,67 @@
+#!/usr/bin/env bash
+
+#
+# Wrapper around autossh and start-stop-daemon for basic persistence. Intended
+# to be called as a script from profile.d for automatic SSH tunnels.
+#
+# Takes one required option -p, the autossh monitoring port number to use. Cut
+# the options off with -- and the remainder of the arguments are passed to the
+# autossh binary.
+#
+# $ psshd -p 9001 -- -fN -D 8001 remotehost
+#
+# @author Tom Ryder <tom@sanctum.geek.nz>
+# @copyright 2013
+#
+
+# Just stop if any problems
+set -o errexit
+
+# Path to autossh binary (not any wrapper script)
+autossh=/usr/lib/autossh/autossh
+
+# Path to start-stop-daemon binary
+startstopdaemon=/sbin/start-stop-daemon
+
+# Set up a PID dir
+dir=${TMPDIR:-/tmp}/psshd-${UID}
+mkdir -p $dir
+
+# Get port in options
+while getopts ':p:' opt
+do
+ case $opt in
+ p)
+ port=$OPTARG
+ ;;
+ \?)
+ echo "Invalid option $OPTARG" >&2
+ exit 1
+ ;;
+ :)
+ echo "Option -$OPTARG requires an argument" >&2
+ exit 1
+ ;;
+ esac
+done
+shift $((OPTIND-1))
+
+# If no port, give up with usage instructions
+if [[ ! -n "$port" ]]
+then
+ echo "USAGE: $0 -p <port number> -- <ssh arguments>"
+ exit 1
+fi
+
+# Export the two settings autossh absolutely needs
+export AUTOSSH_PORT=$port
+export AUTOSSH_PIDFILE=${dir}/psshd-port-${port}.pid
+
+# Use start-stop-daemon to run it sanely
+$startstopdaemon \
+ --start \
+ --quiet \
+ --pidfile $AUTOSSH_PIDFILE \
+ --exec $autossh \
+ -- "$@"
+