added release.go

This commit is contained in:
Stefan Hoffmann 2023-05-29 22:27:28 +02:00
parent 6a0baa278c
commit 923f606076
Signed by: stefan
GPG Key ID: 8EFC7042BF8D5CDD
3 changed files with 43 additions and 34 deletions

33
main.go
View File

@ -2,9 +2,7 @@ package main
import (
"flag"
"fmt"
"log"
"os"
_ "github.com/codingsince1985/checksum"
)
@ -17,39 +15,14 @@ func main() {
sdir := *source_dir
tdir := *target_dir
br := *branch
var source_dir_branch string = sdir + br + "/"
var target_dir_branch string = tdir + br + "/"
//generate manifest file for branch
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)
}
func release_branch(branch string, source_dir string, target_dir string) {
checkOldFolder, _ := os.ReadDir(source_dir)
checkNewFolder, _ := os.ReadDir(target_dir)
var newImages bool = false
if len(checkOldFolder) > 0 {
newImages = true
}
if newImages {
// delete old firmware files in public folder
for _, file := range checkNewFolder {
err := os.Remove(target_dir + file.Name())
if err != nil {
log.Println("error deleting file: ", err)
} else {
log.Println("removed file: ", file.Name())
}
}
//move new files to folder
for _, file := range checkOldFolder {
os.Rename(source_dir+file.Name(), target_dir+file.Name())
fmt.Println("moved file: ", file.Name())
}
}
}

View File

@ -14,13 +14,14 @@ import (
)
func generate_manifest(dir string) error {
files, err := get_files(dir)
sysdir := dir + "sysupgrade/"
files, err := get_files(sysdir)
if err != nil {
log.Println("Error reading Image Files in folder: ", dir)
log.Println("Error reading Image Files in folder: ", sysdir)
return err
}
file_struct := split_filenames(files, dir)
build_manifest(file_struct, dir)
file_struct := split_filenames(files, sysdir)
build_manifest(file_struct, sysdir)
return err
}

35
release.go Normal file
View File

@ -0,0 +1,35 @@
package main
import (
"fmt"
"log"
"os"
)
func release_branch(branch string, source_dir string, target_dir string) {
checkOldFolder, _ := os.ReadDir(source_dir)
checkNewFolder, _ := os.ReadDir(target_dir)
var newImages bool = false
if len(checkOldFolder) > 0 {
newImages = true
}
if newImages {
// delete old firmware files in public folder
for _, file := range checkNewFolder {
err := os.Remove(target_dir + file.Name())
if err != nil {
log.Println("error deleting file: ", err)
} else {
log.Println("removed file: ", file.Name())
}
}
//move new files to folder
for _, file := range checkOldFolder {
os.Rename(source_dir+file.Name(), target_dir+file.Name())
fmt.Println("moved file: ", file.Name())
}
}
}