2023-05-29 19:33:50 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2023-05-29 20:18:37 +00:00
|
|
|
"fmt"
|
2023-05-29 19:33:50 +00:00
|
|
|
"log"
|
2023-05-29 20:18:37 +00:00
|
|
|
"os"
|
2023-05-29 19:33:50 +00:00
|
|
|
|
|
|
|
_ "github.com/codingsince1985/checksum"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var source_dir = flag.String("source_dir", "./", "Path to image folder (/srv/fwuploads-tmp/)")
|
2023-05-29 20:18:37 +00:00
|
|
|
var target_dir = flag.String("target_dir", "./", "Path to image folder in public (/srv/fwuploads/troisdorf)")
|
|
|
|
var branch = flag.String("branch", "", "Branch to work with")
|
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
|
|
|
|
var source_dir_branch string = sdir + br + "/"
|
|
|
|
var target_dir_branch string = tdir + br + "/"
|
|
|
|
err := generate_manifest(source_dir_branch)
|
2023-05-29 19:33:50 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Println("Error generating Manifest file: ", err)
|
|
|
|
}
|
2023-05-29 20:18:37 +00:00
|
|
|
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())
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-05-29 19:33:50 +00:00
|
|
|
}
|