From 665c244522b18dc90d44307f53cbd050cb2452d1 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 1 Sep 2021 12:57:18 -0500 Subject: [PATCH] BUILD: add a build makefile target Signed-off-by: Jeff Carr --- .gitignore | 1 + Makefile | 10 ++++ README.md | 6 +-- example-controlgallery/Makefile | 3 ++ example-controlgallery/controlgallery.go | 1 - example-expect/main.go | 61 ++++++++++++++++++++++++ example-shell/env.go | 2 + example-shell/ls.go | 4 +- 8 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 example-controlgallery/Makefile create mode 100644 example-expect/main.go diff --git a/.gitignore b/.gitignore index 7a39c5e..d0121a0 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ example-splash/example-splash example-ssh/ssh-client example-ssh/ssh-ed25519 example-ssh/with-passwd +example-expect/example-expect diff --git a/Makefile b/Makefile index 25af30b..d3caf70 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,16 @@ GO111MODULE=on run: +build: + # shell things + cd example-expect; go install # traditional 'expect' shell automation + cd example-shell; go install # a tty wrapper + + # GUI things + cd example-splash; go install # an example GUI with drop down menus, etc + cd example-systray; go install # an example systray menu (cross platform) + cd example-controlgallery; go install # an example GUI with drop down menus, etc + debug: go build -ldflags "-X main.GITCOMMIT=${GITCOMMIT} -X main.GOVERSION='${GOVERSION}' -X main.BUILDTIME='${BUILDTIME}' -X main.VERSION=${VERSION}" diff --git a/README.md b/README.md index 1d7c8d7..8cb52bb 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,9 @@ be sub-par verses the Linux and Macintosh versions # build ``` -go get -v -t -u git.wit.org/wit/control-panel-tests -cd ~/go/src/git.wit.org/wit/control-panel-tests -make +go get -v -t -u git.wit.org/jcarr/golang-examples +cd ~/go/src/git.wit.org/jcarr/golang-examples +make build ``` # screenshots diff --git a/example-controlgallery/Makefile b/example-controlgallery/Makefile new file mode 100644 index 0000000..f1f692a --- /dev/null +++ b/example-controlgallery/Makefile @@ -0,0 +1,3 @@ +all: + go get -v -t -u . + go install diff --git a/example-controlgallery/controlgallery.go b/example-controlgallery/controlgallery.go index e2d2dc2..6a9ea38 100644 --- a/example-controlgallery/controlgallery.go +++ b/example-controlgallery/controlgallery.go @@ -1,6 +1,5 @@ // 12 august 2018 -// +build OMIT package main diff --git a/example-expect/main.go b/example-expect/main.go new file mode 100644 index 0000000..3517a03 --- /dev/null +++ b/example-expect/main.go @@ -0,0 +1,61 @@ +package main + +import ( + "flag" + "fmt" + "log" + "regexp" + "time" + + "golang.org/x/crypto/ssh" + + "google.golang.org/grpc/codes" + + "github.com/google/goexpect" + "github.com/google/goterm/term" +) + +const ( + timeout = 10 * time.Minute +) + +var ( + addr = flag.String("address", "", "address of telnet server") + user = flag.String("user", "user", "username to use") + pass1 = flag.String("pass1", "pass1", "password to use") + pass2 = flag.String("pass2", "pass2", "alternate password to use") +) + +func main() { + flag.Parse() + fmt.Println(term.Bluef("SSH Example")) + + sshClt, err := ssh.Dial("tcp", *addr, &ssh.ClientConfig{ + User: *user, + Auth: []ssh.AuthMethod{ssh.Password(*pass1)}, + HostKeyCallback: ssh.InsecureIgnoreHostKey(), + }) + if err != nil { + log.Fatalf("ssh.Dial(%q) failed: %v", *addr, err) + } + defer sshClt.Close() + + e, _, err := expect.SpawnSSH(sshClt, timeout) + if err != nil { + log.Fatal(err) + } + defer e.Close() + + e.ExpectBatch([]expect.Batcher{ + &expect.BCas{[]expect.Caser{ + &expect.Case{R: regexp.MustCompile(`router#`), T: expect.OK()}, + &expect.Case{R: regexp.MustCompile(`Login: `), S: *user, + T: expect.Continue(expect.NewStatus(codes.PermissionDenied, "wrong username")), Rt: 3}, + &expect.Case{R: regexp.MustCompile(`Password: `), S: *pass1, T: expect.Next(), Rt: 1}, + &expect.Case{R: regexp.MustCompile(`Password: `), S: *pass2, + T: expect.Continue(expect.NewStatus(codes.PermissionDenied, "wrong password")), Rt: 1}, + }}, + }, timeout) + + fmt.Println(term.Greenf("All done")) +} diff --git a/example-shell/env.go b/example-shell/env.go index d8f52d5..bb99ea9 100644 --- a/example-shell/env.go +++ b/example-shell/env.go @@ -1,3 +1,5 @@ +// +build ignore + package main import ( diff --git a/example-shell/ls.go b/example-shell/ls.go index 9cf4ab1..4d7546a 100644 --- a/example-shell/ls.go +++ b/example-shell/ls.go @@ -1,4 +1,6 @@ -package main +// +build ignore + +package ls import ( "io"