lockbox

password manager
Log | Files | Refs | README | LICENSE

commit b91b39a447b2ebb333d49558f61297f556c03b03
parent 9aeac99f42ac7d06e49a2b5a076a4687a2717336
Author: Sean Enck <sean@ttypty.com>
Date:   Tue, 20 Jul 2021 18:52:43 -0400

version info

Diffstat:
M.gitignore | 1+
Mcmd/bash/completions.bash | 2+-
Mcmd/lb/main.go | 2++
Mconfigure | 8+++++++-
Aversion.sh | 33+++++++++++++++++++++++++++++++++
5 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,2 +1,3 @@ bin/ Makefile +generated.go diff --git a/cmd/bash/completions.bash b/cmd/bash/completions.bash @@ -4,7 +4,7 @@ _lb() { local cur opts cur=${COMP_WORDS[COMP_CWORD]} if [ $COMP_CWORD -eq 1 ]; then - opts="ls clip show -c insert rm rekey totp list pwgen stats" + opts="version ls clip show -c insert rm rekey totp list pwgen stats" COMPREPLY=( $(compgen -W "$opts" -- $cur) ) else if [ $COMP_CWORD -eq 2 ]; then diff --git a/cmd/lb/main.go b/cmd/lb/main.go @@ -113,6 +113,8 @@ func main() { for _, f := range files { fmt.Println(f) } + case "version": + fmt.Printf("version: %s (%s)\n", internal.Version, internal.BuiltOn) case "insert": multi := false idx := 2 diff --git a/configure b/configure @@ -7,6 +7,7 @@ STATS_ON=1 DIFF_ON=1 APPS=(lb lb-rekey lb-rw) BIN_PATH="bin/" +GENERATED="internal/generated.go" for i in "$@"; do case $i in @@ -57,10 +58,15 @@ _generate() { echo "# Autogenerated file FLAGS := -ldflags '-linkmode external -extldflags \$(LDFLAGS) -w' -trimpath -buildmode=pie -mod=readonly -modcacherw -all: ${binapps[@]} +all: prep ${binapps[@]} + +prep: + mkdir -p $BIN_PATH + ./version.sh $GENERATED ${BIN_PATH}generated.go clean: rm -rf $BIN_PATH + rm -f $GENERATED " cnt=0 diff --git a/version.sh b/version.sh @@ -0,0 +1,33 @@ +#!/bin/bash +GEN=$1 +VERS=$2 +VERS_NAME="Version" +_version_info() { + echo "// Version is the hash/version info for lb" + git log -n 1 --format=%h | sed 's/^/'$VERS_NAME' = "/g;s/$/"/g' + echo "// BuiltOn is the date lb was built" + date "+%Y-%m-%dT%H:%M%S" | sed 's/^/BuiltOn = "/g;s/$/"/g' +} + +_version() { + echo "package internal + +const (" + _version_info | sed 's/^/\t/g' + echo ")" +} + +_getvers() { + cat $1 | grep "$VERS_NAME =" | awk '{print $3}' +} + +_version > $VERS +if [ -e $GEN ]; then + OLDVERS=$(_getvers $GEN) + NEWVERS=$(_getvers $VERS) + if [[ "$NEWVERS" == "$OLDVERS" ]]; then + rm -f $VERS + exit 0 + fi +fi +mv $VERS $GEN