go-gluon-publisher/main.go

75 lines
1.7 KiB
Go
Raw Normal View History

2023-05-29 19:33:50 +00:00
package main
import (
"flag"
2023-05-30 17:57:42 +00:00
"fmt"
2023-05-29 19:33:50 +00:00
"log"
2023-05-30 17:57:42 +00:00
"os"
2023-05-29 19:33:50 +00:00
_ "github.com/codingsince1985/checksum"
)
func main() {
2023-05-30 17:57:42 +00:00
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 dryrun = flag.Bool("d", false, "Dryrun, just show changes on filesystem")
2023-05-29 19:33:50 +00:00
flag.Parse()
2023-05-29 20:18:37 +00:00
sdir := *source_dir
tdir := *target_dir
br := *branch
2023-06-02 17:04:31 +00:00
version := readVersions(*branch)
2023-06-01 20:30:57 +00:00
var source_dir_branch string = sdir + br + "/images/"
var target_dir_branch string = tdir + br + "/"
2023-05-29 20:27:28 +00:00
2023-05-30 17:57:42 +00:00
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)
}
}
2023-06-02 17:04:31 +00:00
release_branch(*branch, source_dir_branch, target_dir_branch, *dryrun, version)
2023-05-30 17:57:42 +00:00
}
}
func is_firmware_folder(s string) bool {
// check files in source_folder
files, err := os.ReadDir(s)
2023-05-29 19:33:50 +00:00
if err != nil {
2023-05-30 17:57:42 +00:00
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
2023-05-29 19:33:50 +00:00
}
2023-05-29 20:18:37 +00:00
}