This repository has been archived on 2024-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/common/bin/devtunnel

12 lines
573 B
Plaintext
Raw Normal View History

2019-11-12 16:39:31 -06:00
#!/usr/bin/env moon
arg_spec = {
{"target", "REMOTE_MACHINE", "remote"}
2019-11-28 08:22:32 -06:00
{"fwd", "FORWARD_PORTS", "1313,3000,4800:8000,8080,1234,4400:4000,40080:80,40443:443"}
2019-11-12 16:39:31 -06:00
{"sargs", "SSH_ARGS", "-XY"}
}
args = {v[1], os.getenv(v[2]) or arg[i] or v[3] for i, v in ipairs(arg_spec)}
ports = {a, (if b == "" then a else b) for a, b in args.fwd\gmatch "(%d+):?(%d*),?"}
pargs = table.concat ["-L #{k}:localhost:#{v}" for k,v in pairs ports], " "
for k,v in pairs ports do print "Forwarding localhost:#{k} to #{args.target}:#{v}"
os.execute "ssh -N #{args.target} #{pargs} #{args.sargs}"