diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a3a7d2..a23b914 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [development] + +- Better version feedback and update information +- Strip binaries with `-ldflags "-s -w"` + + ## [0.0.4] - Fix bug whereby executable path wasn't detected on `self-update` diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..511d5ec --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) +Copyright (c) 2019 Ralph Slooten + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Makefile b/Makefile index a6c2e24..e4f286b 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,44 @@ GOPATH := ${PWD} export GOPATH -VERSION=`git describe --tags` -LDFLAGS=-ldflags "-X main.version=${VERSION}" +TAG=`git describe --tags` +VERSION ?= `git describe --tags` +LDFLAGS=-ldflags "-s -extldflags \"--static\" -w -X main.version=${VERSION}" geoiplookup: goiplookup.go go get github.com/oschwald/geoip2-golang - go build ${LDFLAGS} - strip goiplookup + CGO_ENABLED=0 go build ${LDFLAGS} clean: rm -rf pkg src goiplookup + +release: + go get github.com/oschwald/geoip2-golang + mkdir -p dist + rm -f dist/goiplookup_${VERSION}_* + + echo "Building binaries for ${VERSION}" + + echo "- linux-amd64" + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ${LDFLAGS} -o dist/goiplookup_${VERSION}_linux_amd64 + bzip2 dist/goiplookup_${VERSION}_linux_amd64 + + echo "- linux-386" + CGO_ENABLED=0 GOOS=linux GOARCH=386 go build ${LDFLAGS} -o dist/goiplookup_${VERSION}_linux_386 + bzip2 dist/goiplookup_${VERSION}_linux_386 + + echo "- linux-arm" + CGO_ENABLED=0 GOOS=linux GOARCH=arm go build ${LDFLAGS} -o dist/goiplookup_${VERSION}_linux_arm + bzip2 dist/goiplookup_${VERSION}_linux_arm + + echo "- linux-arm64" + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build ${LDFLAGS} -o dist/goiplookup_${VERSION}_linux_arm64 + bzip2 dist/goiplookup_${VERSION}_linux_arm64 + + echo "- darwin-amd64" + CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build ${LDFLAGS} -o dist/goiplookup_${VERSION}_darwin_amd64 + bzip2 dist/goiplookup_${VERSION}_darwin_amd64 + + echo "- darwin-386" + CGO_ENABLED=0 GOOS=darwin GOARCH=386 go build ${LDFLAGS} -o dist/goiplookup_${VERSION}_darwin_386 + bzip2 dist/goiplookup_${VERSION}_darwin_386 diff --git a/goiplookup.go b/goiplookup.go index 93e16da..09594c7 100644 --- a/goiplookup.go +++ b/goiplookup.go @@ -39,10 +39,15 @@ func main() { flag.Parse() if *showversion { - fmt.Println(fmt.Sprintf("Current: %s", version)) + fmt.Println(fmt.Sprintf("Version %s", version)) latest, err := LatestRelease() if err == nil && version != latest { - fmt.Println(fmt.Sprintf("Latest: %s", latest)) + fmt.Println(fmt.Sprintf("Version %s available", latest)) + if _, err := GetUpdateURL(); err == nil { + fmt.Println(fmt.Sprintf("Run `%s self-update` to update", os.Args[0])) + } + } else { + fmt.Println("You have the latest version") } return } diff --git a/updater.go b/updater.go index 29b6875..cf6b9d6 100644 --- a/updater.go +++ b/updater.go @@ -110,9 +110,10 @@ func ExtractDatabaseFile(dst string, targz string) error { func SelfUpdate() { tmp_dir := os.TempDir() bz2file := filepath.Join(tmp_dir, "goiplookup.bz2") - newexec := filepath.Join(tmp_dir, "goiplookup.tmp") + newexec := filepath.Join(tmp_dir, "goiplookup.tmp") download_url, err := GetUpdateURL() + fmt.Println(fmt.Sprintf("Updating %s", os.Args[0])) if err != nil { fmt.Println(fmt.Sprintf("Error: %s", err)) os.Exit(1) @@ -151,12 +152,13 @@ func SelfUpdate() { // replace os.Args[0] with new file // cannot overwrite open file so rename then delete - // get executable's absolute path - oldexec, _ := os.Readlink("/proc/self/exe") + // get executable's absolute path + oldexec, _ := os.Readlink("/proc/self/exe") - err = ReplaceFile(oldexec, newexec) + err = ReplaceFile(oldexec, newexec) if err != nil { fmt.Println(fmt.Sprintf("Error: %s", err)) + fmt.Println("You may require root permissions.") os.Exit(1) } @@ -166,4 +168,6 @@ func SelfUpdate() { fmt.Println(fmt.Sprintf("Error: %s", err)) os.Exit(1) } + + fmt.Println("Done") } diff --git a/utils.go b/utils.go index 8fb99fa..ca6ed5c 100644 --- a/utils.go +++ b/utils.go @@ -175,7 +175,7 @@ func GetUpdateURL() (string, error) { Verbose(fmt.Sprintf("Latest release is %s", result.TagName)) if version == result.TagName { - return "", fmt.Errorf("You already have the latest version: %s", version) + return "", fmt.Errorf("You already have the latest version (%s)", version) } link_os := runtime.GOOS