Commits

Josh VanderLinden  committed f447ec7

Turned this into a functional Arch package

  • Participants
  • Parent commits 1167f84

Comments (0)

Files changed (9)

+pkg/
+*.tar.xz
+# Maintainer: Josh VanderLinden <arch@cloudlery.com>
+pkgname=autotunnel
+pkgver=0.2.0
+pkgrel=1
+pkgdesc="Easily create tunnels, reverse tunnels, and socks proxies"
+arch=('any')
+url="http://www.codekoala.com/"
+license=('BSD')
+depends=(
+  'autossh'
+  'openssh'
+)
+optdepends=(
+  'supervisor: systemd-less magic'
+  'systemd: preferred method of operation'
+)
+backup=(
+  'etc/autotunnel/default.conf'
+  'etc/supervisor.d/autotunnel.ini'
+)
+md5sums=() #generate with 'makepkg -g'
+
+package() {
+  cd ..
+
+  mkdir -p ${pkgdir}/etc/autotunnel
+  mkdir -p ${pkgdir}/etc/supervisor.d
+  mkdir -p ${pkgdir}/usr/local/bin
+  mkdir -p ${pkgdir}/usr/lib/systemd/system
+
+  cp default.conf ${pkgdir}/etc/autotunnel/
+  cp autotunnel.ini ${pkgdir}/etc/supervisor.d/
+  cp autotunnel ${pkgdir}/usr/local/bin/
+  cp *.service ${pkgdir}/usr/lib/systemd/system/
+}
+
+# vim:set ts=2 sw=2 et:
+#!/bin/bash
+
+get_config() {
+  CONFIG=$1
+  [[ -z ${CONFIG} ]] && CONFIG=/etc/autotunnel/default.conf
+  [[ ! -f ${CONFIG} ]] && echo "Invalid configuration file ${CONFIG}" && exit 1
+
+  echo "Reading config from ${CONFIG}"
+  source ${CONFIG}
+}
+
+if [[ "$1" == "-k" ]]; then
+  # kill mode
+  get_config $2
+  pkill -SIGKILL -f "autossh -M ${AUTOSSH_PORT}"
+  exit 0
+else
+  # launch mode
+  get_config $1
+  DEBUG=$2
+fi
+
+if [[ -z ${TUNNELS} ]] && [[ -z ${REVERSE} ]] && [[ ${SOCKS_PORT} -eq 0 ]]; then
+  echo "Nothing to do; aborting"
+  exit 2
+fi
+
+if [[ ${SOCKS_PORT} -gt 0 ]]; then
+  DO_SOCKS="-D ${SOCKS_PORT}"
+else
+  DO_SOCKS=""
+fi
+
+CMD="autossh -M ${AUTOSSH_PORT} -NT ${USER}@${HOST} ${DO_SOCKS}"
+for t in ${TUNNELS[@]}; do
+    CMD="${CMD} -L ${t}"
+done
+
+for rt in ${REVERSE[@]}; do
+    CMD="${CMD} -R ${rt}"
+done
+
+[[ ! -z ${DEBUG} ]] && echo ${CMD}
+
+$CMD

File autotunnel.ini

+[program:Tunnel]
+command=/home/wheaties/bin/tunnel_to_home.sh
+numprocs=1
+autostart=true
+autorestart=true
+startsecs=15
+starretries=999999
+user=wheaties

File autotunnel.service

+[Unit]
+Description=Auto tunneling daemon
+After=network.target
+Wants=network.target
+
+[Service]
+Type=simple
+ExecStart=/usr/local/bin/autotunnel /etc/autotunnel/default.conf
+ExecStop=/usr/local/bin/autotunnel -k /etc/autotunnel/default.conf
+KillMode=none
+
+[Install]
+WantedBy=multi-user.target

File autotunnel@.service

+[Unit]
+Description=Auto tunneling daemon for profile %i
+After=network.target
+Wants=network.target
+
+[Service]
+Type=simple
+ExecStart=/usr/local/bin/autotunnel /etc/autotunnel/%i.conf
+ExecStop=/usr/local/bin/autotunnel -k /etc/autotunnel/%i.conf
+
+[Install]
+WantedBy=multi-user.target

File default.conf

+#!/bin/bash
+
+# The user you wish to login as to create tunnels
+USER=user
+
+# The hostname/IP of the system you wish to create tunnels to
+HOST=yourhost.com
+
+# Set to some other port, such as 8080, if you wish to setup a SOCKS proxy as
+# well. This would allow you to access the Internet via the remote $HOST.
+SOCKS_PORT=0
+
+# Normal tunnels to establish
+#
+# Normal tunnels allow you to access ports on the remote $HOST by accessing
+# ports on your local system.
+#
+# For example, the following will create a tunnel to $HOST that allows you to
+# access remote port 3389 (RDP) on local port 33890. Likewise, it allows you to
+# access remote port 5900 (VNC) on local port 59000.
+# TUNNELS=(
+#   '33890:localhost:3389'
+#   '59000:localhost:5900'
+# )
+TUNNELS=()
+
+# Reverse tunnels to establish
+#
+# Reverse tunnels allow you to access ports on your local machine by accessing
+# local ports on the remote $HOST when you're logged in on that system. This is
+# a great way to create your own little VPN of sorts.
+#
+# For example, say your local system is PC A and your remote $HOST is PC B.
+# When logged into PC B (either normally or via SSH), the following allows you
+# to SSH into PC A. One would simply run a command like `ssh
+# pc_a_user@localhost -p 2222` on PC B.
+# REVERSE=(
+#   '2222:localhost:22'
+# )
+REVERSE=()
+
+# AutoSSH monitoring port
+#
+# This is used by autossh to make sure the connection is online. It should be
+# different for every configuration you plan to run simultaneously.
+AUTOSSH_PORT=8090

File tunnel.ini

-[program:Tunnel]
-command=/home/wheaties/bin/tunnel_to_home.sh
-numprocs=1
-autostart=true
-autorestart=true
-startsecs=15
-starretries=999999
-user=wheaties

File tunnel_to_home.sh

-#!/bin/bash
-
-TUNNELS=(
-    '8079:localhost:80'     # nginx on laptop
-    '33890:localhost:3389'  # RDP
-    '9091:localhost:9091'   # transmission
-    '59000:localhost:5900'  # x11vnc
-    '18084:localhost:18083' # vboxweb
-)
-REVERSE=(
-    '2040:sikuli:4949'      # sikuli: munin
-    '2041:sikuli:22'        # sikuli: ssh
-    '2042:stc-tasvm-staging:4949'   # tasvm (staging): munin
-    '2043:stc-tasvm-staging:22'     # tasvm (staging): ssh
-    '2044:stc-tasvm:4949'   # tasvm: munin
-    '2045:stc-tasvm:22'     # tasvm: ssh
-    '2046:stc-tas:4949'     # spare box: munin
-    '2047:stc-tas:22'       # spare box: ssh
-    '2048:localhost:22'     # SSH
-    '2049:localhost:4949'   # munin
-    '59000:localhost:5900'  # x11vnc
-    '9000:localhost:8000'   # django
-    '9001:localhost:80'     # nginx
-)
-
-CMD="autossh -M 8090 -NT wheaties@codekoala.homeip.net -D 8888"
-for t in ${TUNNELS[@]}; do
-    CMD="${CMD} -L ${t}"
-done
-
-for rt in ${REVERSE[@]}; do
-    CMD="${CMD} -R ${rt}"
-done
-
-if [[ "$1" == "" ]]; then
-    `$CMD`
-else
-    echo ${CMD}
-fi