Added dryrun and folder check
This commit is contained in:
parent
c4546b210a
commit
aaa1cb8ff3
62
main.go
62
main.go
@ -2,15 +2,19 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
_ "github.com/codingsince1985/checksum"
|
_ "github.com/codingsince1985/checksum"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var source_dir = flag.String("source_dir", "./", "Path to image folder (/srv/fwuploads-tmp/)")
|
var source_dir = flag.String("s", "", "Path to image folder (/srv/fwuploads-tmp/)")
|
||||||
var target_dir = flag.String("target_dir", "./", "Path to image folder in public (/srv/fwuploads/troisdorf)")
|
var target_dir = flag.String("t", "", "Path to image folder in public (/srv/fwuploads/troisdorf)")
|
||||||
var branch = flag.String("branch", "", "Branch to work with")
|
var branch = flag.String("b", "", "Branch to work with")
|
||||||
|
var dryrun = flag.Bool("d", false, "Dryrun, just show changes on filesystem")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
sdir := *source_dir
|
sdir := *source_dir
|
||||||
tdir := *target_dir
|
tdir := *target_dir
|
||||||
@ -19,10 +23,52 @@ func main() {
|
|||||||
var source_dir_branch string = sdir + br + "/"
|
var source_dir_branch string = sdir + br + "/"
|
||||||
var target_dir_branch string = tdir + br + "/"
|
var target_dir_branch string = tdir + br + "/"
|
||||||
|
|
||||||
//generate manifest file for branch
|
if is_firmware_folder(source_dir_branch) {
|
||||||
err := generate_manifest(source_dir_branch)
|
//generate manifest file for branch
|
||||||
if err != nil {
|
if !(*dryrun) {
|
||||||
log.Println("Error generating Manifest file: ", err)
|
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, *dryrun)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func is_firmware_folder(s string) bool {
|
||||||
|
|
||||||
|
// check files in source_folder
|
||||||
|
files, err := os.ReadDir(s)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Fehler beim Lesen des Verzeichnisses:", err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
sysupgradeCount := 0
|
||||||
|
factoryCount := 0
|
||||||
|
otherCount := 0
|
||||||
|
|
||||||
|
// look for folders
|
||||||
|
for _, file := range files {
|
||||||
|
if file.IsDir() {
|
||||||
|
// check name
|
||||||
|
switch file.Name() {
|
||||||
|
case "sysupgrade":
|
||||||
|
sysupgradeCount++
|
||||||
|
case "factory":
|
||||||
|
factoryCount++
|
||||||
|
case "other":
|
||||||
|
otherCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if there only the 3 folders then continue
|
||||||
|
if sysupgradeCount == 1 && factoryCount == 1 && otherCount == 1 {
|
||||||
|
log.Println("this looks like a gluon folder! Go on!")
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
log.Println("the source folder does not look like a gluon firmware output.")
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
release_branch(*branch, source_dir_branch, target_dir_branch)
|
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ func split_filenames(files []fs.FileInfo, dir string) []Files {
|
|||||||
current_name := files[i].Name()
|
current_name := files[i].Name()
|
||||||
split := strings.Split(current_name, "-")
|
split := strings.Split(current_name, "-")
|
||||||
if split[0] != "gluon" {
|
if split[0] != "gluon" {
|
||||||
fmt.Println("skipping ", current_name)
|
log.Println("skipping ", current_name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
split_name := len(split) - 1
|
split_name := len(split) - 1
|
||||||
|
24
release.go
24
release.go
@ -1,12 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func release_branch(branch string, source_dir string, target_dir string) {
|
func release_branch(branch string, source_dir string, target_dir string, dryrun bool) {
|
||||||
checkOldFolder, _ := os.ReadDir(source_dir)
|
checkOldFolder, _ := os.ReadDir(source_dir)
|
||||||
checkNewFolder, _ := os.ReadDir(target_dir)
|
checkNewFolder, _ := os.ReadDir(target_dir)
|
||||||
var newImages bool = false
|
var newImages bool = false
|
||||||
@ -17,19 +16,26 @@ func release_branch(branch string, source_dir string, target_dir string) {
|
|||||||
if newImages {
|
if newImages {
|
||||||
// delete old firmware files in public folder
|
// delete old firmware files in public folder
|
||||||
for _, file := range checkNewFolder {
|
for _, file := range checkNewFolder {
|
||||||
err := os.Remove(target_dir + file.Name())
|
if !(dryrun) {
|
||||||
if err != nil {
|
err := os.RemoveAll(target_dir + file.Name())
|
||||||
log.Println("error deleting file: ", err)
|
if err != nil {
|
||||||
|
log.Println("error deleting file: ", err)
|
||||||
|
} else {
|
||||||
|
log.Println("removed file: ", file.Name())
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Println("removed file: ", file.Name())
|
log.Println("DRYRUN: delete folder :", file.Name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//move new files to folder
|
//move new files to folder
|
||||||
for _, file := range checkOldFolder {
|
for _, file := range checkOldFolder {
|
||||||
os.Rename(source_dir+file.Name(), target_dir+file.Name())
|
if !(dryrun) {
|
||||||
fmt.Println("moved file: ", file.Name())
|
os.Rename(source_dir+file.Name(), target_dir+file.Name())
|
||||||
|
log.Println("moved file: ", file.Name())
|
||||||
|
} else {
|
||||||
|
log.Println("DRYRUN: move folder: ", file.Name())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user