Created
July 31, 2011 06:07
-
-
Save sshirokov/1116473 to your computer and use it in GitHub Desktop.
Tunnel Package For Emacs Nerds v0.0.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; Tunnel boot scaffold [elisp] | |
| (defun toggle-tunnel-out (&optional again) | |
| (interactive "P") | |
| (let* ((bname " *tun*") | |
| (tun (get-buffer bname))) | |
| (if tun | |
| (let ((kill-buffer-query-functions nil)) | |
| (kill-buffer tun)) | |
| (async-shell-command "~/bin/loop-tunnel.sh" " *tun*"))) | |
| (when again (toggle-tunnel-out))) | |
| ;; boot [init.el, elisp] | |
| (if (boundp 'tunneled-out) | |
| (message "Already tunneled...") | |
| (toggle-tunnel-out) | |
| (setq tunneled-out t)) | |
| ### SSH config ### | |
| ### ~/.ssh/config | |
| Host server | |
| HostName server.jesuswasa.cat | |
| User yshirokov | |
| Host server-tun | |
| HostName server.jesuswasa.cat | |
| User yshirokov | |
| PasswordAuthentication no | |
| ExitOnForwardFailure yes | |
| ConnectTimeout 5 | |
| ServerAliveInterval 5 | |
| #Forwards | |
| DynamicForward localhost:8888 | |
| #IRC | |
| LocalForward 12533 localhost:12533 | |
| #Back to this machine from a known host. | |
| RemoteForward 2222 localhost:22 | |
| #Anything else follows | |
| ## Shell helpers [for each file in this list: chmod +x path] | |
| # ~/bin/loop-tunnel.sh | |
| #!/usr/bin/env bash | |
| while true | |
| do ~/bin/tunnel.sh | |
| echo "Disconnected!" | |
| sleep 0.5 | |
| echo "De-idling..." | |
| ~/bin/de-idle.sh | |
| echo "Reconnecting..." | |
| done | |
| # ~/bin/tunnel.sh | |
| #!/bin/sh | |
| ssh server-tun 'perl -e "\$|++; while(1) { print \"Maint: \$i\\r\"; \$i++; sleep 1;}"' | |
| # ~/bin/de-idle.sh | |
| #!/bin/sh | |
| ## Salt this to taste. This stops the failure to reconnect because the back-tunnel still exists | |
| ssh root@server "lsof -i :2222 | awk '{print \$2}' | grep -e '[0-9]' | xargs kill #De-idle" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment