1
0
Fork 0
mirror of https://github.com/Luzifer/shareport.git synced 2024-11-08 06:10:06 +00:00

Add variables to be added to the script

This commit is contained in:
Knut Ahlers 2019-11-28 20:08:50 +01:00
parent b3fc17cb4e
commit 9bb5a0858b
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
3 changed files with 24 additions and 15 deletions

1
go.mod
View file

@ -3,6 +3,7 @@ module github.com/Luzifer/shareport
go 1.13 go 1.13
require ( require (
github.com/Luzifer/go_helpers/v2 v2.10.0
github.com/Luzifer/rconfig/v2 v2.2.1 github.com/Luzifer/rconfig/v2 v2.2.1
github.com/pkg/errors v0.8.1 github.com/pkg/errors v0.8.1
github.com/sirupsen/logrus v1.4.2 github.com/sirupsen/logrus v1.4.2

5
go.sum
View file

@ -1,9 +1,14 @@
github.com/Luzifer/go_helpers v2.8.1+incompatible h1:9YvrAn7pU2viK5vRpAnI+0gyz+Tw8rxWHVIYHi642zk=
github.com/Luzifer/go_helpers/v2 v2.10.0 h1:rA3945P6tH1PKRdcVD+nAdAWojfgwX8wQm/jjUNPmfg=
github.com/Luzifer/go_helpers/v2 v2.10.0/go.mod h1:ZnWxPjyCdQ4rZP3kNiMSUW/7FigU1X9Rz8XopdJ5ZCU=
github.com/Luzifer/rconfig v2.2.0+incompatible h1:Kle3+rshPM7LxciOheaR4EfHUzibkDDGws04sefQ5m8= github.com/Luzifer/rconfig v2.2.0+incompatible h1:Kle3+rshPM7LxciOheaR4EfHUzibkDDGws04sefQ5m8=
github.com/Luzifer/rconfig/v2 v2.2.1 h1:zcDdLQlnlzwcBJ8E0WFzOkQE1pCMn3EbX0dFYkeTczg= github.com/Luzifer/rconfig/v2 v2.2.1 h1:zcDdLQlnlzwcBJ8E0WFzOkQE1pCMn3EbX0dFYkeTczg=
github.com/Luzifer/rconfig/v2 v2.2.1/go.mod h1:OKIX0/JRZrPJ/ZXXWklQEFXA6tBfWaljZbW37w+sqBw= github.com/Luzifer/rconfig/v2 v2.2.1/go.mod h1:OKIX0/JRZrPJ/ZXXWklQEFXA6tBfWaljZbW37w+sqBw=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf/go.mod h1:hyb9oH7vZsitZCiBt0ZvifOrB+qc8PS5IiilCIb87rg=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/leekchan/gtf v0.0.0-20190214083521-5fba33c5b00b/go.mod h1:thNruaSwydMhkQ8dXzapABF9Sc1Tz08ZBcDdgott9RA=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=

33
main.go
View file

@ -16,22 +16,24 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh"
"github.com/Luzifer/go_helpers/v2/env"
"github.com/Luzifer/rconfig/v2" "github.com/Luzifer/rconfig/v2"
) )
var ( var (
cfg = struct { cfg = struct {
DebugRemote bool `flag:"debug-remote" default:"false" description:"Send remote stderr local terminal"` DebugRemote bool `flag:"debug-remote" default:"false" description:"Send remote stderr local terminal"`
IdentityFile string `flag:"identity-file,i" vardefault:"ssh_key" description:"Identity file to use for connecting to the remote"` IdentityFile string `flag:"identity-file,i" vardefault:"ssh_key" description:"Identity file to use for connecting to the remote"`
IdentityFilePassword string `flag:"identity-file-password" default:"" description:"Password for the identity file"` IdentityFilePassword string `flag:"identity-file-password" default:"" description:"Password for the identity file"`
LocalAddr string `flag:"local-addr,l" default:"" description:"Local address / port to forward" validate:"nonzero"` LocalAddr string `flag:"local-addr,l" default:"" description:"Local address / port to forward" validate:"nonzero"`
LogLevel string `flag:"log-level" default:"info" description:"Log level (debug, info, warn, error, fatal)"` LogLevel string `flag:"log-level" default:"info" description:"Log level (debug, info, warn, error, fatal)"`
RemoteHost string `flag:"remote-host" default:"" description:"Remote host and port in format host:port" validate:"nonzero"` RemoteHost string `flag:"remote-host" default:"" description:"Remote host and port in format host:port" validate:"nonzero"`
RemoteCommand string `flag:"remote-command" default:"" description:"Remote command to execute after connect"` RemoteCommand string `flag:"remote-command" default:"" description:"Remote command to execute after connect"`
RemoteListen string `flag:"remote-listen" default:"localhost:0" description:"Address to listen on remote (port is available in script)"` RemoteListen string `flag:"remote-listen" default:"localhost:0" description:"Address to listen on remote (port is available in script)"`
RemoteScript string `flag:"remote-script" default:"" description:"Bash script to push and execute (overwrites remote-command)"` RemoteScript string `flag:"remote-script" default:"" description:"Bash script to push and execute (overwrites remote-command)"`
RemoteUser string `flag:"remote-user" vardefault:"remote_user" description:"User to use to connect to remote host"` RemoteUser string `flag:"remote-user" vardefault:"remote_user" description:"User to use to connect to remote host"`
VersionAndExit bool `flag:"version" default:"false" description:"Prints current version and exits"` Vars []string `flag:"var,v" default:"" description:"Environment variables to pass to the script (Format VAR=value)"`
VersionAndExit bool `flag:"version" default:"false" description:"Prints current version and exits"`
}{} }{}
running = true running = true
@ -167,10 +169,11 @@ func main() {
} }
defer session.Close() defer session.Close()
for k, v := range map[string]string{ envVars := env.ListToMap(cfg.Vars)
"PORT": port, envVars["PORT"] = port
"LISTEN": remoteListener.Addr().String(), envVars["LISTEN"] = remoteListener.Addr().String()
} {
for k, v := range envVars {
fmt.Fprintf(scriptIn, "export %s=%q\n", k, v) fmt.Fprintf(scriptIn, "export %s=%q\n", k, v)
} }