Skip to content

Commit

Permalink
Add --version, clean before build deb, add checksum, don't gitignore …
Browse files Browse the repository at this point in the history
…deb build

Signed-off-by: Daniel Lublin <daniel@lublin.se>
  • Loading branch information
quite committed Dec 1, 2022
1 parent 95e19d1 commit 5d55fcf
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ runrandom: apps
cp -af apps/random/random.bin cmd/runrandom/app.bin
go build ./cmd/runrandom

TKEY_SSH_AGENT_VERSION ?=
# .PHONY to let go-build handle deps and rebuilds
.PHONY: tkey-ssh-agent
tkey-ssh-agent: apps
cp -af apps/signerapp/app.bin cmd/tkey-ssh-agent/app.bin
CGO_ENABLED=0 go build -trimpath ./cmd/tkey-ssh-agent
CGO_ENABLED=0 go build -ldflags "-X main.version=$(TKEY_SSH_AGENT_VERSION)" -trimpath ./cmd/tkey-ssh-agent

.PHONY: clean
clean:
Expand Down
31 changes: 30 additions & 1 deletion cmd/tkey-ssh-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"log"
"os"
"path/filepath"
"runtime/debug"
"strings"
"syscall"

Expand All @@ -22,16 +23,22 @@ var le = log.New(os.Stderr, "", 0)

const progname = "tkey-ssh-agent"

var version string

func main() {
syscall.Umask(0o077)

exit := func(code int) {
os.Exit(code)
}

if version == "" {
version = readBuildInfo()
}

var sockPath, devPath, fileUSS, pinentry string
var speed int
var enterUSS, showPubkeyOnly, listPortsOnly bool
var enterUSS, showPubkeyOnly, listPortsOnly, versionOnly bool
pflag.CommandLine.SetOutput(os.Stderr)
pflag.CommandLine.SortFlags = false
pflag.StringVarP(&sockPath, "agent-socket", "a", "",
Expand All @@ -50,6 +57,8 @@ func main() {
"Read `FILE` and hash its contents as the USS. Use '-' (dash) to read from stdin. The full contents are hashed unmodified (e.g. newlines are not stripped).")
pflag.StringVar(&pinentry, "pinentry", "",
"Pinentry `PROGRAM` for use by --uss. The default is found by looking in your gpg-agent.conf for pinentry-program, or 'pinentry' if not found there.")
pflag.BoolVar(&versionOnly, "version", false,
"Output version information.")
pflag.Usage = func() {
desc := fmt.Sprintf(`Usage: %[1]s -a|-k|-L [flags...]
Expand Down Expand Up @@ -77,6 +86,11 @@ green when the stick must be touched to complete a signature.`, progname)
exit(2)
}

if versionOnly {
fmt.Printf("%s %s\n", progname, version)
exit(0)
}

exclusive := 0
if sockPath != "" {
exclusive++
Expand Down Expand Up @@ -156,6 +170,21 @@ green when the stick must be touched to complete a signature.`, progname)
exit(0)
}

func readBuildInfo() string {
version := "devel without BuildInfo"
if info, ok := debug.ReadBuildInfo(); ok {
sb := strings.Builder{}
sb.WriteString("devel")
for _, setting := range info.Settings {
if strings.HasPrefix(setting.Key, "vcs") {
sb.WriteString(fmt.Sprintf(" %s=%s", setting.Key, setting.Value))
}
}
version = sb.String()
}
return version
}

func printPorts() (int, error) {
ports, err := util.GetSerialPorts()
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions debian/.gitignore

This file was deleted.

21 changes: 15 additions & 6 deletions debian/build-pkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ set -eu

# # TODO
#
# lintian ./tkey-ssh-agent_0.1-1_amd64.deb
# E: tkey-ssh-agent: no-changelog usr/share/doc/tkey-ssh-agent/changelog.Debian.gz (non-native package)
# - We currently dig out the version from a git tag, so we can't build from
# tarball. Not great.
#
# - lintian ./tkey-ssh-agent_0.1-1_amd64.deb
# E: tkey-ssh-agent: no-changelog usr/share/doc/tkey-ssh-agent/changelog.Debian.gz (non-native package)

pkgname="tkey-ssh-agent"
debian_revision="1"
Expand All @@ -20,8 +23,9 @@ destdir="$PWD/build"
rm -rf "$destdir"
mkdir "$destdir"

pushd ..
pushd >/dev/null ..

# upstream_version is the version of the program we're packaging
upstream_version="$(git describe --dirty --always | sed -n "s/^v\(.*\)/\1/p")"
if [[ -z "$upstream_version" ]]; then
printf "found no tag (with v-prefix) to use for upstream_version\n"
Expand All @@ -33,14 +37,15 @@ if [[ ! "$upstream_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
fi
pkgversion="$upstream_version-$debian_revision"

make tkey-ssh-agent

make clean
make TKEY_SSH_AGENT_VERSION="$upstream_version" tkey-ssh-agent
make DESTDIR="$destdir" \
PREFIX=/usr \
SYSTEMDDIR=/usr/lib/systemd \
UDEVDIR=/usr/lib/udev \
install
popd

popd >/dev/null

install -Dm644 deb/copyright "$destdir"/usr/share/doc/tkey-ssh-agent/copyright
install -Dm644 deb/lintian--overrides "$destdir"/usr/share/lintian/overrides/tkey-ssh-agent
Expand All @@ -52,3 +57,7 @@ sed -e "s/##VERSION##/$pkgversion/" \
deb/control.tmpl >"$destdir/DEBIAN/control"

dpkg-deb --root-owner-group -Zgzip --build "$destdir" .

for f in *.deb; do
sha512sum "$f" >"$f".sha512
done

0 comments on commit 5d55fcf

Please sign in to comment.