56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
|
|
_ "github.com/codingsince1985/checksum"
|
|
)
|
|
|
|
func main() {
|
|
var source_dir = flag.String("source_dir", "./", "Path to image folder (/srv/fwuploads-tmp/)")
|
|
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")
|
|
flag.Parse()
|
|
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)
|
|
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())
|
|
}
|
|
|
|
}
|
|
}
|