sbctl: implement a hidden version command

Signed-off-by: Morten Linderud <morten@linderud.pw>
This commit is contained in:
Morten Linderud
2024-07-31 12:32:45 +02:00
parent f1e8535986
commit fff86bf4dd
4 changed files with 34 additions and 2 deletions

1
.gitignore vendored
View File

@@ -3,3 +3,4 @@ releases/*
/sbctl
docs/*.8
rootfs*
VERSION

View File

@@ -11,6 +11,10 @@ GOFLAGS ?= -buildmode=pie -trimpath
TAG = $(shell git describe --abbrev=0 --tags)
GIT_DESCRIBE = $(shell git describe | sed 's/-/./g;s/^v//;')
VERSION = $(shell if test -f VERSION; then cat VERSION; else echo -n $(GIT_DESCRIBE) ; fi)
all: man build
build: sbctl
man: $(MANS)
@@ -21,7 +25,7 @@ docs/sbctl.%: docs/sbctl.%.txt docs/asciidoc.conf
.PHONY: sbctl
sbctl:
go build -o $@ ./cmd/$@
go build -ldflags="-X github.com/foxboron/sbctl.Version=$(VERSION)" -o $@ ./cmd/$@
.PHONY: completions
completions: sbctl
@@ -42,8 +46,9 @@ install: sbctl completions man
.PHONY: release
release:
echo -n "$(GIT_DESCRIBE)" > VERSION
mkdir -p releases
git archive --prefix=${PROGNM}-${TAG}/ -o releases/${PROGNM}-${TAG}.tar.gz ${TAG};
git archive --prefix=${PROGNM}-${TAG}/ --add-file=VERSION -o releases/${PROGNM}-${TAG}.tar.gz ${TAG};
gpg --detach-sign -o releases/${PROGNM}-${TAG}.tar.gz.sig releases/${PROGNM}-${TAG}.tar.gz
gh release upload ${TAG} releases/${PROGNM}-${TAG}.tar.gz.sig releases/${PROGNM}-${TAG}.tar.gz ${TAG}

25
cmd/sbctl/version.go Normal file
View File

@@ -0,0 +1,25 @@
package main
import (
"fmt"
"github.com/foxboron/sbctl"
"github.com/spf13/cobra"
)
var (
versionCmd = &cobra.Command{
Use: "version",
Short: "Print sbctl version",
Hidden: true,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(sbctl.Version)
},
}
)
func init() {
CliCommands = append(CliCommands, cliCommand{
Cmd: versionCmd,
})
}

View File

@@ -20,6 +20,7 @@ import (
var (
DatabasePath = "/usr/share/secureboot/"
Version = "unknown"
)
// Functions that doesn't fit anywhere else