From 5a35110868d49ab12d874ba6c3eca887f158f8a4 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 8 Jul 2013 12:43:58 +1200 Subject: Shaky first commit, but should be legible --- README.markdown | 9 +++++++ README.md | 4 --- examples/psshd.profile.sh | 8 ++++++ psshd | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 README.markdown delete mode 100644 README.md create mode 100644 examples/psshd.profile.sh create mode 100755 psshd 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 +# @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 -- " + 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 \ + -- "$@" + -- cgit v1.2.3