added function to check versions
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Stefan Hoffmann 2023-06-01 22:30:57 +02:00
parent 991d8a9977
commit 7029d039a3
Signed by: stefan
GPG Key ID: 8EFC7042BF8D5CDD
3 changed files with 51 additions and 11 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
target*
source*

View File

@ -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)
}
}

View File

@ -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() {
}