cmd/mkinitfs: add --version option

This commit is contained in:
Clayton Craft
2023-02-18 16:47:09 -08:00
parent 4259478755
commit 89f1e067da
2 changed files with 17 additions and 4 deletions

View File

@@ -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()