[mike@mwxm4]

This commit is contained in:
2026-05-21 15:37:44 +02:00
parent ddbfcc1093
commit 7fa27818cc
3 changed files with 50 additions and 43 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
package main package main
var build = "305" var build = "339"
+39 -36
View File
@@ -8,7 +8,6 @@ import (
"flag" "flag"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@@ -19,7 +18,7 @@ import (
"github.com/AlecAivazis/survey/v2" "github.com/AlecAivazis/survey/v2"
) )
var version = "1.18.4" var version = "1.19.2"
var VERSIONURL = "http://gozilla.fhi.mpg.de/gbld/version.txt" var VERSIONURL = "http://gozilla.fhi.mpg.de/gbld/version.txt"
var UPDATEBASEURL = "http://gozilla.fhi.mpg.de/gbld" var UPDATEBASEURL = "http://gozilla.fhi.mpg.de/gbld"
@@ -31,7 +30,7 @@ var GO string
var GOIMPORTS string var GOIMPORTS string
var done chan bool var done chan bool
var r1, r2, r3 *regexp.Regexp
func main() { // ========================================================================================== main func main() { // ========================================================================================== main
@@ -77,16 +76,16 @@ func main() { // ===============================================================
info() info()
P() P()
P(Cw("Usage:")) P(Cw("Usage:"))
P(Cy(" gbld [-b] [-1] [-i] [-a] [-c <CMD>] [-o <OPTIONS>] [build name]")) P(Cy(" gbld [-b] [-1] [-i] [-c <CMD>] [-o <OPTIONS>] [build name]"))
P(Cy(" gbld -u")) P(Cy(" gbld [-a] [-u]"))
P(Cw(" -b build only")) P(Cw(" -b build only"))
P(Cw(" -1 run only once")) P(Cw(" -1 run only once"))
P(Cw(" -i run gpimports before build")) P(Cw(" -i run gpimports before build"))
P(Cw(" -a build for all platforms"))
P(Cw(" -o <OPTIONS> exec options")) P(Cw(" -o <OPTIONS> exec options"))
P(Cw(" -c <CMD> run command after build")) P(Cw(" -c <CMD> run command after build"))
P(Cw(" -v show version")) P(Cw(" -v show version"))
P(Cw(" -h show help")) P(Cw(" -h show help"))
P(Cw(" -a build for all platforms"))
P(Cw(" -u upload builds to gozilla")) P(Cw(" -u upload builds to gozilla"))
P() P()
P(Cw(" · if build is supplied the current directory name will be used")) P(Cw(" · if build is supplied the current directory name will be used"))
@@ -150,14 +149,33 @@ func main() { // ===============================================================
var st int = 1 var st int = 1
var xmd *exec.Cmd = nil var xmd *exec.Cmd = nil
if (!*opt_1) { if (!*opt_1 && !*opt_a && !*opt_u) {
PN("\033[2J\033[1;1H") PN("\033[2J\033[1;1H")
}
info() info()
if *opt_a { // ······························································· build for other platforms
targetversion:=gettargetversion(file)
P(Ccb("build for all platforms"))
for _, osys := range oses {
for _, arch := range arches {
ofile:="bin/"+name+"_"+targetversion+"_"+osys+"_"+arch
P(Cy(ofile))
cmd := exec.Command(GO, "build", "-o", ofile, name)
cmd.Env = append(os.Environ(), "GOOS="+osys, "GOARCH="+arch)
cmd.Run()
}
}
os.WriteFile("bin/version.txt", []byte(targetversion), 0644)
} }
if *opt_u { // ······································································ upload builds to gozilla if *opt_u { // ······································································ upload builds to gozilla
targetversion:=targetversion(file) targetversion:=gettargetversion(file)
P(Ccb("upload builds to gozilla"))
for _, osys := range oses { for _, osys := range oses {
for _, arch := range arches { for _, arch := range arches {
@@ -165,12 +183,12 @@ func main() { // ===============================================================
_, err := os.Stat(ofile) _, err := os.Stat(ofile)
if err == nil { if err == nil {
cmd := exec.Command("ssh","root@gozilla","rm", "/db/www/"+prgname()+"/*_"+osys+"_"+arch ) cmd := exec.Command("ssh","root@gozilla","rm", "/db/www/"+name+"/*_"+osys+"_"+arch )
P(Cy(cmd)) P(Cy(cmd))
cmd.Run() cmd.Run()
cmd = exec.Command("scp",ofile, "root@gozilla:/db/www/"+prgname()) cmd = exec.Command("scp",ofile, "root@gozilla:/db/www/"+name)
P(Cy(cmd)) P(Cy(cmd))
cmd.Run() cmd.Run()
} }
@@ -178,15 +196,20 @@ func main() { // ===============================================================
} }
_, err := os.Stat("bin/version.txt") _, err := os.Stat("bin/version.txt")
if err == nil { if err == nil {
cmd := exec.Command("scp","bin/version.txt", "root@gozilla:/db/www/"+prgname()) cmd := exec.Command("scp","bin/version.txt", "root@gozilla:/db/www/"+name)
P(Cy(cmd)) P(Cy(cmd))
cmd.Run() cmd.Run()
} }
os.Exit(0)
} }
if (*opt_a || *opt_u) { os.Exit(0) }
r1 = regexp.MustCompile("^\\.")
r2 = regexp.MustCompile("build\\.go")
r3 = regexp.MustCompile("\\.go$")
for { // ------------------------------------------------------------------------------------------- main loop for { // ------------------------------------------------------------------------------------------- main loop
lmf := lmf("./") lmf := lmf("./")
@@ -211,6 +234,7 @@ func main() { // ===============================================================
readFile, err := os.Open("build.go") readFile, err := os.Open("build.go")
if err == nil { if err == nil {
defer readFile.Close()
backup("build.go") backup("build.go")
fileScanner := bufio.NewScanner(readFile) fileScanner := bufio.NewScanner(readFile)
fileScanner.Split(bufio.ScanLines) fileScanner.Split(bufio.ScanLines)
@@ -226,7 +250,6 @@ func main() { // ===============================================================
o = o + line + "\n" o = o + line + "\n"
} }
} }
readFile.Close()
os.WriteFile("build.go", []byte(o), 0644) os.WriteFile("build.go", []byte(o), 0644)
} }
@@ -290,23 +313,6 @@ func main() { // ===============================================================
} else { // ·············································································· build succeeded } else { // ·············································································· build succeeded
if *opt_a { // ······························································· build for other platforms
for _, osys := range oses {
for _, arch := range arches {
ofile:="bin/"+name+"_"+targetversion+"_"+osys+"_"+arch
P(Cy(ofile))
cmd := exec.Command(GO, "build", "-o", ofile, name)
cmd.Env = append(os.Environ(), "GOOS="+osys, "GOARCH="+arch)
cmd.Run()
}
}
os.WriteFile("bin/version.txt", []byte(targetversion), 0644)
}
P(Cb("--- compiling done: " + name + " ---")) P(Cb("--- compiling done: " + name + " ---"))
if len(*opt_c) > 0 { // ··························································· execute post command if len(*opt_c) > 0 { // ··························································· execute post command
@@ -370,7 +376,7 @@ func backup(src string) { // ---------------------------------------------------
// ===================================================================================================== SUPPORT // ===================================================================================================== SUPPORT
func targetversion(file string) string { // ---------------------------------------------- detect target version func gettargetversion(file string) string { // ------------------------------------------- detect target version
targetversion:="" targetversion:=""
readFile, err := os.Open(file) readFile, err := os.Open(file)
if err == nil { if err == nil {
@@ -398,11 +404,8 @@ func targetversion(file string) string { // ------------------------------------
func lmf(dir string) int64 { // -------------------------------------- get last modification date from .go files func lmf(dir string) int64 { // -------------------------------------- get last modification date from .go files
var tmax int64 = 0 var tmax int64 = 0
files, err := ioutil.ReadDir("./") files, err := os.ReadDir(dir)
if err == nil { if err == nil {
r1, _ := regexp.Compile("^\\.")
r2, _ := regexp.Compile("build\\.go")
r3, _ := regexp.Compile("\\.go$")
for _, file := range files { for _, file := range files {
if r3.MatchString(file.Name()) { if r3.MatchString(file.Name()) {
if !r1.MatchString(file.Name()) && !r2.MatchString(file.Name()) { if !r1.MatchString(file.Name()) && !r2.MatchString(file.Name()) {
+9 -5
View File
@@ -29,7 +29,7 @@ import (
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
) )
var tbversion = "0.4.1" var tbversion = "0.4.3"
var CHRS = "VW9IdGJ6eXh1T25DRHdrc2M5MlhOQVNQcEJFWnJhWVY2ZEowaFJLdmoxNUdxVDRJZkZpTTdRZW0zTFc4Z2w=" var CHRS = "VW9IdGJ6eXh1T25DRHdrc2M5MlhOQVNQcEJFWnJhWVY2ZEowaFJLdmoxNUdxVDRJZkZpTTdRZW0zTFc4Z2w="
var LR = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") var LR = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
@@ -48,7 +48,8 @@ func checkforupdate() { // -----------------------------------------------------
sv_lversion, err := semver.NewVersion(lversion) sv_lversion, err := semver.NewVersion(lversion)
if err == nil { if err == nil {
if (sv_lversion.GreaterThan(sv_version)) { if (sv_lversion.GreaterThan(sv_version)) {
ans:=Yesno(SF("new '%s' version found (%s -> %s), update now?",prg,sv_version,sv_lversion),true); ans:=Yesno(SF("new '%s' version found (%s -> %s), update now?",
prg,sv_version,sv_lversion),true,false);
if (ans) { if (ans) {
updateurl:=SF("%s/%s_%s_%s_%s",UPDATEBASEURL,prg,lversion,runtime.GOOS,runtime.GOARCH) updateurl:=SF("%s/%s_%s_%s_%s",UPDATEBASEURL,prg,lversion,runtime.GOOS,runtime.GOARCH)
@@ -127,7 +128,10 @@ func Inputpw(msg string) string { // ---------------------------------------- Al
return tmp return tmp
} }
func Yesno(msg string, def bool) bool { // ------------------------------------------ AlecAivazis/survey: yes/no func Yesno(msg string, def bool, overwrite bool) bool { // -------------------------- AlecAivazis/survey: yes/no
if (overwrite) { return true }
var err error var err error
tmp := "" tmp := ""
if def { if def {
@@ -263,11 +267,11 @@ func SF(format string, a ...any) string { return fmt.Sprintf(format,
func PE(msg ...string) (n int, err error) { func PE(msg ...string) (n int, err error) {
if (len(msg)==2) { return fmt.Fprintf(os.Stdout, "%s: %s (%s)\n", Crb("ERROR"), Cwb(msg[0]),msg[1]) } if (len(msg)==2) { return fmt.Fprintf(os.Stdout, "%s: %s (%s)\n", Crb("ERROR"), Cwb(msg[0]),msg[1]) }
return fmt.Fprintf(os.Stdout, "%s: %s\n", Crb("ERROR"), Cwb(msg)) return fmt.Fprintf(os.Stdout, "%s: %s\n", Crb("ERROR"), Cwb(msg[0]))
} }
func PO(msg ...string) (n int, err error) { func PO(msg ...string) (n int, err error) {
if (len(msg)==2) { return fmt.Fprintf(os.Stdout, "%s: %s (%s)\n", Cgb("OK"), Cwb(msg[0]),msg[1]) } if (len(msg)==2) { return fmt.Fprintf(os.Stdout, "%s: %s (%s)\n", Cgb("OK"), Cwb(msg[0]),msg[1]) }
return fmt.Fprintf(os.Stdout, "%s: %s\n", Cgb("OK"), Cwb(msg)) return fmt.Fprintf(os.Stdout, "%s: %s\n", Cgb("OK"), Cwb(msg[0]))
} }
// ------------------------------------------------------------------------------------------ regular expression // ------------------------------------------------------------------------------------------ regular expression