From 85b1bfa70513125af6942aa25578f4fbc14dd774 Mon Sep 17 00:00:00 2001 From: Maurits van der Schee Date: Sun, 8 Nov 2020 16:00:06 +0100 Subject: [PATCH] Add build version --- .gitignore | 3 +- build.sh | 82 +++++++++++++++++++++++++++- go.sum | 3 - file/file.go => keystore/keystore.go | 2 +- main.go | 31 ++++++----- version.env | 3 + 6 files changed, 101 insertions(+), 23 deletions(-) rename file/file.go => keystore/keystore.go (99%) create mode 100644 version.env diff --git a/.gitignore b/.gitignore index cbfd81f..9ef1877 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ config.txt -go-soft-token* +go-soft-token +dist/ diff --git a/build.sh b/build.sh index 7a36d08..440fd1c 100644 --- a/build.sh +++ b/build.sh @@ -1,3 +1,79 @@ -#!/bin/bash -env GOOS=windows GOARCH=386 go build -go build +#!/usr/bin/env bash + +gawk -i inplace -F '=' '/CURRENT_BUILD_VERSION/{$2=$2+1";"}1' OFS='=' version.env + +source version.env + +package_name="go-soft-token" + +#the full list of the platforms run: go tool dist list +platforms=( +#"aix/ppc64" +#"android/386" +#"android/amd64" +#"android/arm" +#"android/arm64" +#"darwin/386" +"darwin/amd64" +#"darwin/arm" +#"darwin/arm64" +#"dragonfly/amd64" +#"freebsd/386" +#"freebsd/amd64" +#"freebsd/arm" +#"illumos/amd64" +#"js/wasm" +#"linux/386" +"linux/amd64" +#"linux/arm" +#"linux/arm64" +#"linux/mips" +#"linux/mips64" +#"linux/mips64le" +#"linux/mipsle" +#"linux/ppc64" +#"linux/ppc64le" +#"linux/s390x" +#"nacl/386" +#"nacl/amd64p32" +#"nacl/arm" +#"netbsd/386" +#"netbsd/amd64" +#"netbsd/arm" +#"netbsd/arm64" +#"openbsd/386" +#"openbsd/amd64" +#"openbsd/arm" +#"openbsd/arm64" +#"plan9/386" +#"plan9/amd64" +#"plan9/arm" +#"solaris/amd64" +#"windows/386" +"windows/amd64" +#"windows/arm" +) + +VERSION=$CURRENT_MAJOR_VERSION'.'$CURRENT_MINOR_VERSION'.'$CURRENT_BUILD_VERSION + +echo Building version $VERSION + +for platform in "${platforms[@]}" +do + platform_split=(${platform//\// }) + GOOS=${platform_split[0]} + GOARCH=${platform_split[1]} + output_name=$package_name'-'$GOOS'-'$GOARCH + if [ $GOOS = "windows" ]; then + output_name+='.exe' + fi + + mkdir -p dist/$VERSION + env GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-X main.version=$VERSION" -o dist/$VERSION/$output_name + if [ $? -ne 0 ]; then + echo 'An error has occurred! Aborting the script execution...' + exit 1 + fi +done + +go build -ldflags "-X main.version=$VERSION" diff --git a/go.sum b/go.sum index 117f49a..9f28beb 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,5 @@ github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= -github.com/gdamore/tcell v1.4.0 h1:vUnHwJRvcPQa3tzi+0QI4U9JINXYJlOz9yiaiPQ2wMU= -github.com/gdamore/tcell/v2 v2.0.0 h1:GRWG8aLfWAlekj9Q6W29bVvkHENc6hp79XOqG4AWDOs= -github.com/gdamore/tcell/v2 v2.0.0/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA= github.com/gdamore/tcell/v2 v2.0.1-0.20201017141208-acf90d56d591 h1:0WWUDZ1oxq7NxVyGo8M3KI5jbkiwNAdZFFzAdC68up4= github.com/gdamore/tcell/v2 v2.0.1-0.20201017141208-acf90d56d591/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA= github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac= diff --git a/file/file.go b/keystore/keystore.go similarity index 99% rename from file/file.go rename to keystore/keystore.go index 13a26d3..a3d7497 100644 --- a/file/file.go +++ b/keystore/keystore.go @@ -1,4 +1,4 @@ -package file +package keystore import ( "crypto/aes" diff --git a/main.go b/main.go index fb5c4fe..56652ca 100644 --- a/main.go +++ b/main.go @@ -7,15 +7,18 @@ import ( "strings" "time" - "github.com/mevdschee/go-soft-token/file" "github.com/xlzd/gotp" "encoding/base32" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" + + "github.com/mevdschee/go-soft-token/keystore" ) +var version = "custom" + // Config struct that holds account info type Config struct { Accounts []Account `json:"accounts"` @@ -31,7 +34,7 @@ type Account struct { func readConfig(password, filename string) (Config, error) { var config Config - data, err := file.Read(password, filename) + data, err := keystore.Read(password, filename) if err != nil { return config, err } @@ -51,7 +54,7 @@ func writeConfig(config Config, filename string) error { return err } - err = file.Write(password, filename, data) + err = keystore.Write(password, filename, data) if err != nil { return err } @@ -111,16 +114,14 @@ func main() { drawSpinner := func() { frames := []string{ - "| o |", - "| o |", - "| o |", - "| o |", - "| o|", - "| o |", - "| o |", - "| o |", - "| o |", - "|o |", + "|o----|", + "|-o---|", + "|--o--|", + "|---o-|", + "|----o|", + "|---o-|", + "|--o--|", + "|-o---|", } spinnerIndex = (spinnerIndex + 1) % len(frames) spinner.SetText(frames[spinnerIndex]) @@ -128,7 +129,7 @@ func main() { updateTimer := func() { for { - time.Sleep(250 * time.Millisecond) + time.Sleep(1 * time.Second) app.QueueUpdateDraw(func() { drawToken() drawSpinner() @@ -301,7 +302,7 @@ func main() { SetItemPadding(3). AddPasswordField("Password", "", 26, '*', nil). AddButton("Ok", func() { go passwordSubmitHandler() }). - SetTitle(" Unlock "). + SetTitle("go-soft-token v"+version). SetTitleColor(tcell.ColorYellow). SetBorder(true). SetBackgroundColor(tcell.NewHexColor(0x222222)). diff --git a/version.env b/version.env new file mode 100644 index 0000000..e91c21e --- /dev/null +++ b/version.env @@ -0,0 +1,3 @@ +CURRENT_MAJOR_VERSION=0 +CURRENT_MINOR_VERSION=9 +CURRENT_BUILD_VERSION=1;