Skip to content

Commit

Permalink
Merge branch 'release/0.0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
axllent committed Mar 22, 2019
2 parents 2b7c351 + 6c19853 commit 8da40b0
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
39 changes: 35 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
9 changes: 7 additions & 2 deletions goiplookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 8 additions & 4 deletions updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

Expand All @@ -166,4 +168,6 @@ func SelfUpdate() {
fmt.Println(fmt.Sprintf("Error: %s", err))
os.Exit(1)
}

fmt.Println("Done")
}
2 changes: 1 addition & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8da40b0

Please sign in to comment.