diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3653b04 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +target* +source* diff --git a/main.go b/main.go index 0b4cb0f..bee419f 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,7 @@ 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() @@ -20,8 +21,8 @@ func main() { tdir := *target_dir br := *branch - var source_dir_branch string = sdir + br + "/" - var target_dir_branch string = tdir + br + "/" + 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 @@ -31,7 +32,7 @@ func main() { log.Println("Error generating Manifest file: ", err) } } - release_branch(*branch, source_dir_branch, target_dir_branch, *dryrun) + release_branch(*branch, source_dir_branch, target_dir_branch, *dryrun, *version) } } diff --git a/release.go b/release.go index 3e1704b..0e84576 100644 --- a/release.go +++ b/release.go @@ -1,23 +1,36 @@ package main import ( + "fmt" "log" "os" + "path/filepath" + "strings" ) -func release_branch(branch string, source_dir string, target_dir string, dryrun bool) { - checkOldFolder, _ := os.ReadDir(source_dir) - checkNewFolder, _ := os.ReadDir(target_dir) +func release_branch(b string, sDir string, tDir string, dryrun bool, v string) { + check_sDir, _ := os.ReadDir(sDir) + check_tDir, _ := os.ReadDir(tDir) var newImages bool = false - if len(checkOldFolder) > 0 { + if len(check_sDir) > 0 { newImages = true } + sVersion := GetGluonVersion(sDir) + tVersion := GetGluonVersion(tDir) + //check wanted version in target + if tVersion != v { + log.Println("published version is outdated, try to update from source folder") + if sVersion != v { + log.Println("wanted Version is not availible in source folder") + os.Exit(1) + } + } if newImages { // delete old firmware files in public folder - for _, file := range checkNewFolder { + for _, file := range check_tDir { if !(dryrun) { - err := os.RemoveAll(target_dir + file.Name()) + err := os.RemoveAll(tDir + file.Name()) if err != nil { log.Println("error deleting file: ", err) } else { @@ -29,9 +42,9 @@ func release_branch(branch string, source_dir string, target_dir string, dryrun } //move new files to folder - for _, file := range checkOldFolder { + for _, file := range check_sDir { if !(dryrun) { - os.Rename(source_dir+file.Name(), target_dir+file.Name()) + os.Rename(sDir+file.Name(), tDir+file.Name()) log.Println("moved file: ", file.Name()) } else { log.Println("DRYRUN: move folder: ", file.Name()) @@ -39,3 +52,27 @@ func release_branch(branch string, source_dir string, target_dir string, dryrun } } } + +func GetGluonVersion(path string) string { + image_folder := path + "sysupgrade/" + files, err := filepath.Glob(filepath.Join(image_folder, "gluon-tdf-*")) + if err != nil { + fmt.Println("Error reading directory: ", err) + os.Exit(1) + } + + if len(files) > 0 { + fileName := filepath.Base(files[0]) + parts := strings.Split(fileName, "-") + if len(parts) >= 4 { + version := parts[2] + return version + } + } + + return "" +} + +func check_Release() { + +}