Skip to content

Commit

Permalink
Add build version
Browse files Browse the repository at this point in the history
  • Loading branch information
mevdschee committed Nov 8, 2020
1 parent 3a55722 commit 85b1bfa
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
config.txt
go-soft-token*
go-soft-token
dist/
82 changes: 79 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
2 changes: 1 addition & 1 deletion file/file.go → keystore/keystore.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package file
package keystore

import (
"crypto/aes"
Expand Down
31 changes: 16 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -111,24 +114,22 @@ 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])
}

updateTimer := func() {
for {
time.Sleep(250 * time.Millisecond)
time.Sleep(1 * time.Second)
app.QueueUpdateDraw(func() {
drawToken()
drawSpinner()
Expand Down Expand Up @@ -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)).
Expand Down
3 changes: 3 additions & 0 deletions version.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CURRENT_MAJOR_VERSION=0
CURRENT_MINOR_VERSION=9
CURRENT_BUILD_VERSION=1;

0 comments on commit 85b1bfa

Please sign in to comment.