diff --git a/Makefile b/Makefile index 5ff0a25..3bacfa0 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,13 @@ LDFLAGS=-ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD} -w" PLATFORMS=darwin linux ARCHITECTURES=amd64 +BASIC_PATH=cmd/basic/main.go +BASIC=myip-basic +FULL_PATH=cmd/myip/main.go +FULL=myip +GUI_PATH=cmd/myip/main.go +GUI=cmd/myip/main.go + default: build install: @@ -21,25 +28,31 @@ clean: .PHONY: basic basic: - go build ${LDFLAGS} -o dist/myip-basic basic/main.go + go build ${LDFLAGS} -o dist/${BASIC} ${BASIC_PATH} build: - go build ${LDFLAGS} -o dist/myip + go build ${LDFLAGS} -o dist/${FULL} ${FULL_PATH} build-unix: $(foreach GOOS, $(PLATFORMS), $(foreach GOARCH, $(ARCHITECTURES), \ - $(shell export GOOS=$(GOOS); export GOARCH=$(GOARCH); go build ${LDFLAGS} -o dist/$(PROJ)_$(VERSION)_$(GOOS)_$(GOARCH)/$(PROJ)))) + $(shell export GOOS=$(GOOS); export GOARCH=$(GOARCH); go build ${LDFLAGS} -o dist/${FULL} ${FULL_PATH}) \ + $(shell cd dist; tar -czf ${FULL}_$(VERSION)_$(GOOS)_$(GOARCH).tar.gz ${FULL}) \ + )) + rm dist/${FULL} $(foreach GOOS, $(PLATFORMS), $(foreach GOARCH, $(ARCHITECTURES), \ - $(shell export GOOS=$(GOOS); export GOARCH=$(GOARCH); go build ${LDFLAGS} -o dist/$(PROJ)-basic_$(VERSION)_$(GOOS)_$(GOARCH)/$(PROJ)-basic basic/main.go))) + $(shell export GOOS=$(GOOS); export GOARCH=$(GOARCH); go build ${LDFLAGS} -o dist/${BASIC} ${BASIC_PATH}) \ + $(shell cd dist; tar -czf ${BASIC}_$(VERSION)_$(GOOS)_$(GOARCH).tar.gz ${BASIC}) \ + )) + rm dist/${BASIC} build-win: - $(shell export GOOS=windows; export GOARCH=amd64; go build ${LDFLAGS} -o dist/$(PROJ)_$(VERSION)_windows_amd64/$(PROJ).exe) - $(shell export GOOS=windows; export GOARCH=amd64; go build ${LDFLAGS} -o dist/$(PROJ)-basic_$(VERSION)_windows_amd64/$(PROJ)-basic.exe basic/main.go) + $(shell export GOOS=windows; export GOARCH=amd64; go build ${LDFLAGS} -o dist/$(PROJ)_$(VERSION)_windows_amd64/${FULL}.exe ${FULL_PATH}) + $(shell export GOOS=windows; export GOARCH=amd64; go build ${LDFLAGS} -o dist/$(PROJ)-basic_$(VERSION)_windows_amd64/${BASIC}.exe ${BASIC_PATH}) build-mac-m1: - $(shell export GOOS=darwin; export GOARCH=arm64; go build ${LDFLAGS} -o dist/$(PROJ)_$(VERSION)_darwin_arm64/$(PROJ)) - $(shell export GOOS=darwin; export GOARCH=arm64; go build ${LDFLAGS} -o dist/$(PROJ)-basic_$(VERSION)_darwin_arm64/$(PROJ)-basic basic/main.go) + $(shell export GOOS=darwin; export GOARCH=arm64; go build ${LDFLAGS} -o dist/$(PROJ)_$(VERSION)_darwin_arm64/${FULL} ${FULL_PATH}) + $(shell export GOOS=darwin; export GOARCH=arm64; go build ${LDFLAGS} -o dist/$(PROJ)-basic_$(VERSION)_darwin_arm64/${BASIC} ${BASIC_PATH}) build-zip: cd dist; for f in * ;do if ! [[ $$f =~ "gz" ]] ; then tar -czf $${f}.tar.gz $${f}; fi done diff --git a/README.md b/README.md index 148326f..88a7200 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,13 @@ Use "myip [command] --help" for more information about a command. ``` +## Install + +``` +sudo rm -f /usr/local/bin/myip +sudo sh -c "curl -fsSL https://release.kumoly.io/tools/myip/0.1.6/linux/amd64 | tar -C /usr/local/bin/ -xz" +``` + ## Docker ### Server diff --git a/cmd/client.go b/client.go similarity index 98% rename from cmd/client.go rename to client.go index 173b0a7..2f7e9b1 100644 --- a/cmd/client.go +++ b/client.go @@ -1,4 +1,4 @@ -package cmd +package myip import ( "errors" @@ -75,6 +75,9 @@ func init() { ClientCmd.Flags().BoolVar(&cronMode, "cron", false, "run as cron service") ClientCmd.Flags().StringVarP(&cronSpec, "spec", "s", "0 */5 * * * *", "hostname to connect") + + ClientCmd.AddCommand(ServerCmd) + ClientCmd.AddCommand(LocalIPCmd) } func Scan() error { diff --git a/basic/main.go b/cmd/basic/main.go similarity index 96% rename from basic/main.go rename to cmd/basic/main.go index d12d0bc..f831128 100644 --- a/basic/main.go +++ b/cmd/basic/main.go @@ -29,7 +29,7 @@ func init() { name, _ = os.Hostname() flag.BoolVar(&showVer, "v", false, "show version") flag.StringVar(&host, "u", "kumoly.io", "hostname to ask for") - flag.StringVar(&port, "p", "5080", "port to listen|connect") + flag.StringVar(&port, "p", "5080", "port to connect") flag.Usage = func() { fmt.Fprintf(os.Stderr, "Usage: myip-basic [options]\n") diff --git a/main.go b/cmd/myip/main.go similarity index 64% rename from main.go rename to cmd/myip/main.go index 7c0d0ea..0eb6765 100644 --- a/main.go +++ b/cmd/myip/main.go @@ -6,7 +6,7 @@ import ( "os" "github.com/spf13/cobra" - "kumoly.io/tools/myip/cmd" + "kumoly.io/tools/myip" ) var Version = "v0.1.0" @@ -24,14 +24,12 @@ var versionCmd = &cobra.Command{ func init() { log.SetFlags(0) log.SetOutput(os.Stdout) - cmd.ClientCmd.Version = Version + "-" + Build - cmd.ClientCmd.AddCommand(versionCmd) - cmd.ClientCmd.AddCommand(cmd.ServerCmd) - cmd.ClientCmd.AddCommand(cmd.LocalIPCmd) + myip.ClientCmd.Version = Version + "-" + Build + myip.ClientCmd.AddCommand(versionCmd) } func main() { - if err := cmd.ClientCmd.Execute(); err != nil { + if err := myip.ClientCmd.Execute(); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } diff --git a/cmd/localip.go b/localip.go similarity index 98% rename from cmd/localip.go rename to localip.go index ffedea3..d3f0984 100644 --- a/cmd/localip.go +++ b/localip.go @@ -1,4 +1,4 @@ -package cmd +package myip import ( "github.com/spf13/cobra" diff --git a/cmd/server.go b/server.go similarity index 99% rename from cmd/server.go rename to server.go index 5f864a1..f360f61 100644 --- a/cmd/server.go +++ b/server.go @@ -1,4 +1,4 @@ -package cmd +package myip import ( "fmt"