First Commit: Build Manifest files
This commit is contained in:
commit
13bc0dad2e
10
go.mod
Normal file
10
go.mod
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
module fftdf.de/go-gluon-publish
|
||||||
|
|
||||||
|
go 1.20
|
||||||
|
|
||||||
|
require github.com/codingsince1985/checksum v1.3.0
|
||||||
|
|
||||||
|
require (
|
||||||
|
golang.org/x/crypto v0.6.0 // indirect
|
||||||
|
golang.org/x/sys v0.5.0 // indirect
|
||||||
|
)
|
7
go.sum
Normal file
7
go.sum
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
github.com/codingsince1985/checksum v1.3.0 h1:kqqIqWBwjidGmt/pO4yXCEX+np7HACGx72EB+MkKcVY=
|
||||||
|
github.com/codingsince1985/checksum v1.3.0/go.mod h1:QfRskdtdWap+gJil8e5obw6I8/cWJ0SwMUACruWDSU8=
|
||||||
|
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
||||||
|
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
|
||||||
|
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
|
||||||
|
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
|
||||||
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
18
main.go
Normal file
18
main.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
_ "github.com/codingsince1985/checksum"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var source_dir = flag.String("source_dir", "./", "Path to image folder (/srv/fwuploads-tmp/)")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
err := generate_manifest(*source_dir)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Error generating Manifest file: ", err)
|
||||||
|
}
|
||||||
|
}
|
104
manifest.go
Normal file
104
manifest.go
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/codingsince1985/checksum"
|
||||||
|
)
|
||||||
|
|
||||||
|
func generate_manifest(dir string) error {
|
||||||
|
files, err := get_files(dir)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Error reading Image Files in folder: ", dir)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
file_struct := split_filenames(files, dir)
|
||||||
|
build_manifest(file_struct, dir)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func get_files(dir string) ([]fs.FileInfo, error) {
|
||||||
|
files, err := ioutil.ReadDir(dir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return files, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func split_filenames(files []fs.FileInfo, dir string) []Files {
|
||||||
|
var data []Files
|
||||||
|
for i := range files {
|
||||||
|
current_name := files[i].Name()
|
||||||
|
split := strings.Split(current_name, "-")
|
||||||
|
split_name := len(split) - 1
|
||||||
|
// Routername
|
||||||
|
router_name := strings.Join(split[5:split_name], "-")
|
||||||
|
//RELEASE
|
||||||
|
router_release := strings.Join(split[3:5], "-")
|
||||||
|
//Checksum
|
||||||
|
sha256, _ := checksum.SHA256sum(dir + "/" + current_name)
|
||||||
|
//FileSize
|
||||||
|
filesize := files[i].Size()
|
||||||
|
//Build Struct
|
||||||
|
data = append(data, Files{Model: router_name, Name: current_name, Release: router_release, Checksum: sha256, Size: filesize})
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
func build_manifest(files []Files, dir string) error {
|
||||||
|
// Datei zum Schreiben öffnen
|
||||||
|
release := strings.Split(files[0].Release, "-")
|
||||||
|
file, err := os.Create(dir + release[0] + ".manifest")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("error creating manifest file")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
// Aktuelles Datum und Uhrzeit abrufen
|
||||||
|
now := time.Now()
|
||||||
|
// Datum im gewünschten Format formatieren
|
||||||
|
formatted := now.Format("2006-01-02 15:04:05-07:00")
|
||||||
|
|
||||||
|
branch_line := "BRANCH=" + release[0] + "\n"
|
||||||
|
date_line := "DATE=" + formatted + "\n"
|
||||||
|
prio_line := "PRIORITY=0" + "\n"
|
||||||
|
|
||||||
|
// Zeilen Schreiben
|
||||||
|
// Header
|
||||||
|
_, err = file.WriteString(branch_line)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = file.WriteString(date_line)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = file.WriteString(prio_line)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = file.WriteString("\n")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Router Lines
|
||||||
|
for i := range files {
|
||||||
|
size_str := strconv.Itoa(int(files[i].Size))
|
||||||
|
line := files[i].Model + " " + files[i].Release + " " + files[i].Checksum + " " + size_str + " " + files[i].Name + "\n"
|
||||||
|
_, err := file.WriteString(line)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Println("Manifest file " + release[0] + ".manifest" + " generated")
|
||||||
|
return err
|
||||||
|
}
|
6
testfiles/stable.manifest
Normal file
6
testfiles/stable.manifest
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
BRANCH=stable
|
||||||
|
DATE=2023-05-29 21:26:35+02:00
|
||||||
|
PRIORITY=0
|
||||||
|
|
||||||
|
avm-fritz-wlan-repeater-300e stable-3.7.0 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 0 gluon-lo-snw-stable-3.7.0-avm-fritz-wlan-repeater-300e-sysupgrade.bin
|
||||||
|
tp-link-tl-wdr3600-v1 stable-3.7.0 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 0 gluon-lo-snw-stable-3.7.0-tp-link-tl-wdr3600-v1-sysupgrade.bin
|
Loading…
Reference in New Issue
Block a user