[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
var build = "305"
var build = "339"
+38 -35
View File
@@ -8,7 +8,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -19,7 +18,7 @@ import (
"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 UPDATEBASEURL = "http://gozilla.fhi.mpg.de/gbld"
@@ -31,7 +30,7 @@ var GO string
var GOIMPORTS string
var done chan bool
var r1, r2, r3 *regexp.Regexp
func main() { // ========================================================================================== main
@@ -77,16 +76,16 @@ func main() { // ===============================================================
info()
P()
P(Cw("Usage:"))
P(Cy(" gbld [-b] [-1] [-i] [-a] [-c <CMD>] [-o <OPTIONS>] [build name]"))
P(Cy(" gbld -u"))
P(Cy(" gbld [-b] [-1] [-i] [-c <CMD>] [-o <OPTIONS>] [build name]"))
P(Cy(" gbld [-a] [-u]"))
P(Cw(" -b build only"))
P(Cw(" -1 run only once"))
P(Cw(" -i run gpimports before build"))
P(Cw(" -a build for all platforms"))
P(Cw(" -o <OPTIONS> exec options"))
P(Cw(" -c <CMD> run command after build"))
P(Cw(" -v show version"))
P(Cw(" -h show help"))
P(Cw(" -a build for all platforms"))
P(Cw(" -u upload builds to gozilla"))
P()
P(Cw(" · if build is supplied the current directory name will be used"))
@@ -150,14 +149,33 @@ func main() { // ===============================================================
var st int = 1
var xmd *exec.Cmd = nil
if (!*opt_1) {
if (!*opt_1 && !*opt_a && !*opt_u) {
PN("\033[2J\033[1;1H")
}
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
targetversion:=targetversion(file)
targetversion:=gettargetversion(file)
P(Ccb("upload builds to gozilla"))
for _, osys := range oses {
for _, arch := range arches {
@@ -165,12 +183,12 @@ func main() { // ===============================================================
_, err := os.Stat(ofile)
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))
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))
cmd.Run()
}
@@ -178,15 +196,20 @@ func main() { // ===============================================================
}
_, err := os.Stat("bin/version.txt")
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))
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
lmf := lmf("./")
@@ -211,6 +234,7 @@ func main() { // ===============================================================
readFile, err := os.Open("build.go")
if err == nil {
defer readFile.Close()
backup("build.go")
fileScanner := bufio.NewScanner(readFile)
fileScanner.Split(bufio.ScanLines)
@@ -226,7 +250,6 @@ func main() { // ===============================================================
o = o + line + "\n"
}
}
readFile.Close()
os.WriteFile("build.go", []byte(o), 0644)
}
@@ -290,23 +313,6 @@ func main() { // ===============================================================
} 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 + " ---"))
if len(*opt_c) > 0 { // ··························································· execute post command
@@ -370,7 +376,7 @@ func backup(src string) { // ---------------------------------------------------
// ===================================================================================================== SUPPORT
func targetversion(file string) string { // ---------------------------------------------- detect target version
func gettargetversion(file string) string { // ------------------------------------------- detect target version
targetversion:=""
readFile, err := os.Open(file)
if err == nil {
@@ -398,11 +404,8 @@ func targetversion(file string) string { // ------------------------------------
func lmf(dir string) int64 { // -------------------------------------- get last modification date from .go files
var tmax int64 = 0
files, err := ioutil.ReadDir("./")
files, err := os.ReadDir(dir)
if err == nil {
r1, _ := regexp.Compile("^\\.")
r2, _ := regexp.Compile("build\\.go")
r3, _ := regexp.Compile("\\.go$")
for _, file := range files {
if r3.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"
)
var tbversion = "0.4.1"
var tbversion = "0.4.3"
var CHRS = "VW9IdGJ6eXh1T25DRHdrc2M5MlhOQVNQcEJFWnJhWVY2ZEowaFJLdmoxNUdxVDRJZkZpTTdRZW0zTFc4Z2w="
var LR = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
@@ -48,7 +48,8 @@ func checkforupdate() { // -----------------------------------------------------
sv_lversion, err := semver.NewVersion(lversion)
if err == nil {
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) {
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
}
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
tmp := ""
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) {
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) {
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