#!/bin/sh
#
# ---
# script by Ypnose - http://ywstd.fr

set -e

# effective UID
USEREUID="$(/usr/bin/id -u)"
SO_TMPF="/tmp/socks_${USEREUID}"
SO_PORT="${SO_PORT:-1337}"

trap 'un_sock' HUP INT EXIT

un_sock() {
  if [ -f "${SO_TMPF}" ]; then
    rm "${SO_TMPF}"
  fi
}

if [ -z "$1" ] || [ "$1" = "-h" ]; then
  print "usage: ${0##*/} [SSH_ARGS]"
  exit
fi

un_sock >"${SO_TMPF}"
# additional options can be passed using command line
ssh -C -D "${SO_PORT}" -N "$@"

exit
