Implement distribution-specific builds

Make more things configurable at compile time so building binaries for distributions is easier while complying with the license.
pull/141/head
Sefa Eyeoglu 3 years ago committed by GitHub
parent a0620ae92c
commit 9b651eb701
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

1
.gitignore vendored

@ -1,3 +1,2 @@
bin/ bin/
version.go
licenses.go licenses.go

@ -1,7 +1,11 @@
UPDATE_URL=https://noisetorch.epicgamer.org
UPDATE_PUBKEY=3mL+rBi4yBZ1wGimQ/oSQCjxELzgTh+673H4JdzQBOk=
VERSION := $(shell git describe --tags)
dev: rnnoise dev: rnnoise
mkdir -p bin/ mkdir -p bin/
go generate go generate
go build -o bin/noisetorch go build -ldflags '-X main.version=${VERSION}' -o bin/noisetorch
release: rnnoise release: rnnoise
mkdir -p bin/ mkdir -p bin/
mkdir -p tmp/ mkdir -p tmp/
@ -14,7 +18,7 @@ release: rnnoise
mkdir -p tmp/.local/bin/ mkdir -p tmp/.local/bin/
go generate go generate
CGO_ENABLED=0 GOOS=linux go build -tags release -a -ldflags '-s -w -extldflags "-static"' . CGO_ENABLED=0 GOOS=linux go build -tags release -a -ldflags '-s -w -extldflags "-static" -X main.version=${VERSION} -X main.distribution=official -X main.updateURL=${UPDATE_URL} -X main.publicKeyString=${UPDATE_PUBKEY}' .
upx noisetorch upx noisetorch
mv noisetorch tmp/.local/bin/ mv noisetorch tmp/.local/bin/
cd tmp/; \ cd tmp/; \

@ -22,7 +22,6 @@ import (
"github.com/aarzilli/nucular/style" "github.com/aarzilli/nucular/style"
) )
//go:generate go run scripts/embedversion.go
//go:generate go run scripts/embedlicenses.go //go:generate go run scripts/embedlicenses.go
//go:embed c/ladspa/rnnoise_ladspa.so //go:embed c/ladspa/rnnoise_ladspa.so
@ -42,6 +41,11 @@ type device struct {
const appName = "NoiseTorch" const appName = "NoiseTorch"
var version = "unknown" // will be changed by build
var distribution = "custom" // ditto
var updateURL = "" // ditto
var publicKeyString = "" // ditto
func main() { func main() {
opt := parseCLIOpts() opt := parseCLIOpts()
@ -50,7 +54,7 @@ func main() {
} else { } else {
log.SetOutput(ioutil.Discard) log.SetOutput(ioutil.Discard)
} }
log.Printf("Application starting. Version: %s\n", version) log.Printf("Application starting. Version: %s (%s)\n", version, distribution)
log.Printf("CAP_SYS_RESOURCE: %t\n", hasCapSysResource(getCurrentCaps())) log.Printf("CAP_SYS_RESOURCE: %t\n", hasCapSysResource(getCurrentCaps()))
initializeConfigIfNot() initializeConfigIfNot()

@ -1,24 +0,0 @@
package main
import (
"os"
"os/exec"
"strings"
)
func main() {
cmd := exec.Command("git", "describe", "--tags")
ret, err := cmd.Output()
if err != nil {
panic("Couldn't read git tags to embed version number")
}
version := strings.TrimSpace(string(ret))
out, _ := os.Create("version.go")
defer out.Close()
out.Write([]byte("package main\n\n//THIS FILE IS AUTOMATICALLY GENERATED BY `go generate` DO NOT EDIT!\n\nvar version=\""))
out.Write([]byte(version))
out.Write([]byte("\"\n"))
}

@ -22,8 +22,8 @@ func main() {
var doSign bool var doSign bool
flag.BoolVar(&doSign, "s", false, "Sign the release tar") flag.BoolVar(&doSign, "s", false, "Sign the release tar")
var doVerify bool var publicKeyString string
flag.BoolVar(&doVerify, "v", false, "Verify the signature of the tar") flag.StringVar(&publicKeyString, "k", "", "Public key to verify against (runs verifier if set)")
flag.Parse() flag.Parse()
@ -56,9 +56,8 @@ func main() {
os.Exit(0) os.Exit(0)
} }
if doVerify { if publicKeyString != "" {
pubStr := "3mL+rBi4yBZ1wGimQ/oSQCjxELzgTh+673H4JdzQBOk=" pub, err := base64.StdEncoding.DecodeString(publicKeyString)
pub, err := base64.StdEncoding.DecodeString(pubStr)
if err != nil { if err != nil {
panic(err) panic(err)
} }

@ -345,7 +345,7 @@ func versionView(ctx *ntcontext, w *nucular.Window) {
w.Row(50).Dynamic(1) w.Row(50).Dynamic(1)
w.Label("Version", "CB") w.Label("Version", "CB")
w.Row(50).Dynamic(1) w.Row(50).Dynamic(1)
w.Label(version, "CB") w.Label(fmt.Sprintf("%s (%s)", version, distribution), "CB")
w.Row(50).Dynamic(1) w.Row(50).Dynamic(1)
w.Spacing(1) w.Spacing(1)
w.Row(20).Dynamic(2) w.Row(20).Dynamic(2)

@ -1,5 +1,3 @@
// +build release
package main package main
import ( import (
@ -14,9 +12,6 @@ import (
"strings" "strings"
) )
var updateURL = "https://noisetorch.epicgamer.org"
var publicKeyString = "3mL+rBi4yBZ1wGimQ/oSQCjxELzgTh+673H4JdzQBOk="
type updateui struct { type updateui struct {
serverVersion string serverVersion string
available bool available bool
@ -24,7 +19,14 @@ type updateui struct {
updatingText string updatingText string
} }
func updateable() bool {
return updateURL != "" && publicKeyString != ""
}
func updateCheck(ctx *ntcontext) { func updateCheck(ctx *ntcontext) {
if !updateable() {
return
}
log.Println("Checking for updates") log.Println("Checking for updates")
bodybuf, err := fetchFile("version.txt") bodybuf, err := fetchFile("version.txt")
if err != nil { if err != nil {
@ -41,6 +43,9 @@ func updateCheck(ctx *ntcontext) {
} }
func update(ctx *ntcontext) { func update(ctx *ntcontext) {
if !updateable() {
return
}
sig, err := fetchFile("NoiseTorch_x64.tgz.sig") sig, err := fetchFile("NoiseTorch_x64.tgz.sig")
if err != nil { if err != nil {
log.Println("Couldn't fetch signature", err) log.Println("Couldn't fetch signature", err)
@ -94,8 +99,9 @@ func fetchFile(file string) ([]byte, error) {
func publickey() []byte { func publickey() []byte {
pub, err := base64.StdEncoding.DecodeString(publicKeyString) pub, err := base64.StdEncoding.DecodeString(publicKeyString)
if err != nil { if err != nil { // Should only happen when distributor ships an invalid public key
panic(err) // it's hardcoded, we should never hit this, panic if we do log.Fatalf("Error while reading public key: %s\nContact the distribution '%s' about this error.\n", err, distribution)
os.Exit(1)
} }
return pub return pub
} }

@ -1,18 +0,0 @@
// +build !release
package main
type updateui struct {
serverVersion string
available bool
triggered bool
updatingText string
}
func updateCheck(ctx *ntcontext) {
// noop for non-release versions
}
func update(ctx *ntcontext) {
// noop for non-release versions
}
Loading…
Cancel
Save