mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-12 13:25:38 +08:00
committed by
Victor Vrantchan
parent
a6a2433ab2
commit
9b4d4c6180
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,2 @@
|
||||
vendor/
|
||||
SCEPCACert.pem
|
||||
mdm.db
|
||||
build/
|
||||
|
||||
5
main.go
5
main.go
@@ -8,6 +8,8 @@ import (
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
"github.com/micromdm/micromdm/version"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -21,6 +23,9 @@ func main() {
|
||||
}
|
||||
var run func([]string) error
|
||||
switch strings.ToLower(os.Args[1]) {
|
||||
case "version", "-version":
|
||||
version.Print()
|
||||
return
|
||||
case "serve":
|
||||
run = serve
|
||||
case "dep-token":
|
||||
|
||||
27
release.sh
Executable file
27
release.sh
Executable file
@@ -0,0 +1,27 @@
|
||||
VERSION="$(git describe --tags --always --dirty)"
|
||||
NAME=micromdm
|
||||
USER=$(whoami)
|
||||
BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||
NOW=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
||||
REVISION=$(git rev-parse HEAD)
|
||||
GOVERSION=$(go version | awk '{print $3}')
|
||||
|
||||
echo "Building $NAME version $VERSION"
|
||||
|
||||
mkdir -p build
|
||||
|
||||
build() {
|
||||
echo -n "=> $1-$2: "
|
||||
GOOS=$1 GOARCH=$2 CGO_ENABLED=0 go build -o build/$NAME-$1-$2 -ldflags "\
|
||||
-X github.com/micromdm/micromdm/version.version=${VERSION}\
|
||||
-X github.com/micromdm/micromdm/version.branch=${BRANCH}\
|
||||
-X github.com/micromdm/micromdm/version.buildUser=${USER}\
|
||||
-X github.com/micromdm/micromdm/version.buildDate=${NOW}\
|
||||
-X github.com/micromdm/micromdm/version.revision=${REVISION}\
|
||||
-X github.com/micromdm/micromdm/version.goVersion=${GOVERSION}\
|
||||
" ./*.go
|
||||
du -h build/$NAME-$1-$2
|
||||
}
|
||||
|
||||
build "darwin" "amd64"
|
||||
build "linux" "amd64"
|
||||
69
version/version.go
Normal file
69
version/version.go
Normal file
@@ -0,0 +1,69 @@
|
||||
// Package version provides utilities for displaying version information.
|
||||
package version
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// go build -ldflags "-X github.com/micromdm/micromdm/version.version=1.0.0"
|
||||
var (
|
||||
version = "unknown"
|
||||
branch = "unknown"
|
||||
revision = "unknown"
|
||||
goVersion = "unknown"
|
||||
buildDate = "unknown"
|
||||
buildUser = "unknown"
|
||||
appName = "micromdm"
|
||||
)
|
||||
|
||||
// Info holds version and build info about the app.
|
||||
type Info struct {
|
||||
Version string `json:"version"`
|
||||
Branch string `json:"branch"`
|
||||
Revision string `json:"revision"`
|
||||
GoVersion string `json:"go_version"`
|
||||
BuildDate string `json:"build_date"`
|
||||
BuildUser string `json:"build_user"`
|
||||
}
|
||||
|
||||
// Version returns a struct with the current version information.
|
||||
func Version() Info {
|
||||
return Info{
|
||||
Version: version,
|
||||
Branch: branch,
|
||||
Revision: revision,
|
||||
GoVersion: goVersion,
|
||||
BuildDate: buildDate,
|
||||
BuildUser: buildUser,
|
||||
}
|
||||
}
|
||||
|
||||
// Print outputs the app name and version string.
|
||||
func Print() {
|
||||
v := Version()
|
||||
fmt.Printf("%s version %s\n", appName, v.Version)
|
||||
}
|
||||
|
||||
// PrintFull outputs the app name and detailed version information.
|
||||
func PrintFull() {
|
||||
v := Version()
|
||||
fmt.Printf("%s - version %s\n", appName, v.Version)
|
||||
fmt.Printf(" branch: \t%s\n", v.Branch)
|
||||
fmt.Printf(" revision: \t%s\n", v.Revision)
|
||||
fmt.Printf(" build date: \t%s\n", v.BuildDate)
|
||||
fmt.Printf(" build user: \t%s\n", v.BuildUser)
|
||||
fmt.Printf(" go version: \t%s\n", v.GoVersion)
|
||||
}
|
||||
|
||||
// Handler provides an HTTP Handler which returns JSON formatted version info.
|
||||
func Handler() http.Handler {
|
||||
v := Version()
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
enc := json.NewEncoder(w)
|
||||
enc.SetIndent("", " ")
|
||||
enc.Encode(v)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user