go-gluon-publisher/main.go
Stefan 7029d039a3
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
added function to check versions
2023-06-01 22:30:57 +02:00

76 lines
1.8 KiB
Go

package main
import (
"flag"
"fmt"
"log"
"os"
_ "github.com/codingsince1985/checksum"
)
func main() {
var source_dir = flag.String("s", "", "Path to image folder (/srv/fwuploads-tmp/)")
var target_dir = flag.String("t", "", "Path to image folder in public (/srv/fwuploads/troisdorf)")
var branch = flag.String("b", "", "Branch to work with")
var version = flag.String("v", "", "which version should be released")
var dryrun = flag.Bool("d", false, "Dryrun, just show changes on filesystem")
flag.Parse()
sdir := *source_dir
tdir := *target_dir
br := *branch
var source_dir_branch string = sdir + br + "/images/"
var target_dir_branch string = tdir + br + "/images/"
if is_firmware_folder(source_dir_branch) {
//generate manifest file for branch
if !(*dryrun) {
err := generate_manifest(source_dir_branch)
if err != nil {
log.Println("Error generating Manifest file: ", err)
}
}
release_branch(*branch, source_dir_branch, target_dir_branch, *dryrun, *version)
}
}
func is_firmware_folder(s string) bool {
// check files in source_folder
files, err := os.ReadDir(s)
if err != nil {
fmt.Println("Fehler beim Lesen des Verzeichnisses:", err)
return false
}
sysupgradeCount := 0
factoryCount := 0
otherCount := 0
// look for folders
for _, file := range files {
if file.IsDir() {
// check name
switch file.Name() {
case "sysupgrade":
sysupgradeCount++
case "factory":
factoryCount++
case "other":
otherCount++
}
}
}
// if there only the 3 folders then continue
if sysupgradeCount == 1 && factoryCount == 1 && otherCount == 1 {
log.Println("this looks like a gluon folder! Go on!")
return true
} else {
log.Println("the source folder does not look like a gluon firmware output.")
return false
}
}