cmd/mkinitfs: add --version option
This commit is contained in:
3
Makefile
3
Makefile
@@ -1,6 +1,7 @@
|
||||
.POSIX:
|
||||
.SUFFIXES: .1 .1.scd
|
||||
|
||||
VERSION?=`git describe --tags --dirty 2>/dev/null || echo 0.0.0`
|
||||
VPATH=doc
|
||||
PREFIX?=/usr/local
|
||||
BINDIR?=$(PREFIX)/sbin
|
||||
@@ -8,7 +9,7 @@ MANDIR?=$(PREFIX)/share/man
|
||||
SHAREDIR?=$(PREFIX)/share
|
||||
GO?=go
|
||||
GOFLAGS?=
|
||||
LDFLAGS+=-s -w
|
||||
LDFLAGS+=-s -w -X main.Version=$(VERSION)
|
||||
RM?=rm -f
|
||||
GOTEST=go test -count=1 -race
|
||||
|
||||
|
@@ -6,6 +6,7 @@ package main
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
@@ -26,7 +27,21 @@ import (
|
||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/pkgs/deviceinfo"
|
||||
)
|
||||
|
||||
// set at build time
|
||||
var Version string
|
||||
|
||||
func main() {
|
||||
|
||||
outDir := flag.String("d", "/boot", "Directory to output initfs(-extra) and other boot files")
|
||||
var showVersion bool
|
||||
flag.BoolVar(&showVersion, "version", false, "Print version and quit.")
|
||||
flag.Parse()
|
||||
|
||||
if showVersion {
|
||||
fmt.Printf("%s - %s\n", filepath.Base(os.Args[0]), Version)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
deviceinfoFile := "/etc/deviceinfo"
|
||||
if !misc.Exists(deviceinfoFile) {
|
||||
log.Print("NOTE: deviceinfo (from device package) not installed yet, " +
|
||||
@@ -40,9 +55,6 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
outDir := flag.String("d", "/boot", "Directory to output initfs(-extra) and other boot files")
|
||||
flag.Parse()
|
||||
|
||||
defer misc.TimeFunc(time.Now(), "mkinitfs")
|
||||
|
||||
kernVer, err := misc.GetKernelVersion()
|
||||
|
Reference in New Issue
Block a user