Skip to content

Commit

Permalink
Merge pull request #4 from sudosammy/dev
Browse files Browse the repository at this point in the history
fix daily update check bug & add build script + version push
  • Loading branch information
sudosammy authored Jul 28, 2018
2 parents e643574 + 9c7e46a commit c58cdb6
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.env
dev
knary.log
blacklist.txt
knary.exe
dev
knary.exe
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.0
1.1.1
29 changes: 29 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# https://www.digitalocean.com/community/tutorials/how-to-build-go-executables-for-multiple-platforms-on-ubuntu-16-04
package=$1
version=$2
if [[ -z "$package" ]]; then
echo "usage: $0 main.go <version>"
exit 1
fi
package_split=(${package//\// })

platforms=("windows/amd64" "linux/amd64" "darwin/amd64")

for platform in "${platforms[@]}"
do
platform_split=(${platform//\// })
GOOS=${platform_split[0]}
GOARCH=${platform_split[1]}
output_name='knary-'$version'-'$GOOS'-'$GOARCH
if [ $GOOS = "windows" ]; then
output_name+='.exe'
fi

env GOOS=$GOOS GOARCH=$GOARCH CGO_ENABLED=0 go build -o $output_name $package
if [ $? -ne 0 ]; then
echo 'An error has occurred! Aborting the script execution...'
exit 1
fi
done
25 changes: 19 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import (
"github.com/fatih/color"
"github.com/joho/godotenv"
"github.com/miekg/dns"
"github.com/robfig/cron"

"fmt"
"log"
"os"
"sync"
"time"

//"./libknary"
"github.com/sudosammy/knary/libknary"
)

const (
VERSION = "1.1.0"
VERSION = "1.1.1"
GITHUB = "https://github.com/sudosammy/knary"
GITHUBVERSION = "https://raw.githubusercontent.com/sudosammy/knary/master/VERSION"
)
Expand All @@ -30,10 +30,23 @@ func main() {
log.Fatal(err)
}

// set cron for update checks
cron := cron.New()
cron.AddFunc("@daily", func() { libknary.CheckUpdate(VERSION, GITHUBVERSION, GITHUB) })
defer cron.Stop()
// set ticker for update checks
// https://stackoverflow.com/questions/16466320/is-there-a-way-to-do-repetitive-tasks-at-intervals-in-golang
ticker := time.NewTicker(24 * time.Hour)
quit := make(chan struct{})
go func() {
for {
select {
case <-ticker.C:
libknary.CheckUpdate(VERSION, GITHUBVERSION, GITHUB)
case <-quit:
ticker.Stop()
return
}
}
}()
defer close(quit)

// check for updates on first run
libknary.CheckUpdate(VERSION, GITHUBVERSION, GITHUB)

Expand Down
Binary file modified screenshots/run.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c58cdb6

Please sign in to comment.