#!/bin/sh # opens a ssh tunnel and starts a new firefox instance # configure your firefox profil to use the ssh tunnel user=$USER host=$(hostname) port=9999 url=$user@$host while [ $# -ne 0 ]; do case "$1" in -u|--url) if [ "x$2" = "x" ]; then echo "$1 requires an argument. Abort." 1>&2 exit 1 else url="$2" fi shift shift ;; -h|--host) if [ "x$2" = "x" ]; then echo "$1 requires an argument. Abort." 1>&2 exit 1 else host="$2" fi shift shift ;; -p|--port) if [ "x$2" = "x" ]; then echo "$1 requires an argument. Abort." 1>&2 exit 1 else port="$2" fi shift shift ;; *) echo "Usage: '$(basename $0) [-u HOST] [-p PORT]'" echo "Default connection is set to $url:$port" exit 1 esac done if [ "x$host" = x ]; then echo "No host given. Abort." 1>&2 exit 1 fi if [ "x$port" = x ]; then echo "No pott given. Abort." 1>&2 exit 1 fi if [ x$(netstat -tulpen 2>/dev/null | grep 127.0.0.1:$port | head -1 | cut -d "/" -f2) = "xssh" ]; then echo "Using existing ssh tunnel." else nohup ssh -f -N $url -D $port >>/tmp/nohub.ssh$port.log 2>&1 & if [ $? -ne 0 ]; then echo "Failed to create the ssh tunnel. Read /tmp/nohub.ssh$port.log for more information." exit 1 fi fi nohup firefox -no-remote -P proxy >>/tmp/nohub.fx.log 2>&1 & if [ $? -ne 0 ]; then echo "Failed to start Firefox. Read /tmp/nohub.fx.log for more information." exit 1 fi echo "Proxying all traffic through '$url:$port'." exit 0