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
Executable File

#!/usr/bin/env moon
arg_spec = {
{"target", "REMOTE_MACHINE", "remote"}
{"fwd", "FORWARD_PORTS", "1313,3000,4800:8000,8080,1234,4400:4000,40080:80,40443:443"}
{"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}"