diff options
| -rw-r--r-- | Makefile | 1 | ||||
| -rw-r--r-- | find.go | 23 | ||||
| -rw-r--r-- | main.go | 83 |
3 files changed, 105 insertions, 2 deletions
@@ -31,6 +31,7 @@ goimports: clean: rm -f go.* *.deb mirrors go-mod-clean purge + rm -f /home/mirrors/wit/dists/sid/* gpl: wit-test --witcom @@ -0,0 +1,23 @@ +package main + +import ( + "os" + "path/filepath" +) + +func FindFiles(lookhere string) ([]string, error) { + var allfiles []string + + err := filepath.Walk(lookhere, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + + if !info.IsDir() { + allfiles = append(allfiles, path) + } + return nil + }) + + return allfiles, err +} @@ -1,10 +1,14 @@ package main import ( + "crypto/sha256" "embed" "errors" + "fmt" "os" + "os/exec" "path/filepath" + "strings" "time" "go.wit.com/lib/cobol" @@ -143,7 +147,82 @@ func doNewest(arch string) (string, error) { return fullname, err } - // footer := newest.PrintTable() - // log.Info("newest packages ?", footer, counter) + shell.RunVerbose([]string{"gzip", "-f", "-k", fullname}) + shell.RunVerbose([]string{"bzip2", "-f", "-k", fullname}) + + allfiles, _ := FindFiles("dists/sid/main") + for i, filename := range allfiles { + log.Info(i, filename) + } + + releasePath := filepath.Join("/home/mirrors/wit/dists/sid", "Release") + + rfile, _ := os.OpenFile(releasePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) + fmt.Fprintf(rfile, "Origin: WIT.COM Debian Sid\n") + fmt.Fprintf(rfile, "Label: WIT.COM Debian Sid\n") + fmt.Fprintf(rfile, "Suite: sid\n") + fmt.Fprintf(rfile, "Codename: sid\n") + fmt.Fprintf(rfile, "Date: %s\n", time.Now().UTC().Format(time.RFC1123Z)) + fmt.Fprintf(rfile, "Architectures: riscv64 amd64 arm64 all\n") + fmt.Fprintf(rfile, "Components: main\n") + fmt.Fprintf(rfile, "Description: Tooling for RiscV, Semiconductor Designs & Private Clouds\n") + + /* + fmt.Fprintf(rfile, "MD5SUM:\n") + for i, filename := range allfiles { + log.Info(i, filename) + fileBytes, _ := os.ReadFile(filename) + sum := fmt.Sprintf("%x", md5.Sum(fileBytes)) // deprecated + newfile := strings.TrimPrefix(filename, "dists/sid/") + fmt.Fprintf(rfile, " %s %d %s\n", sum, len(fileBytes), newfile) + } + fmt.Fprintf(rfile, "SHA1:\n") + for i, filename := range allfiles { + log.Info(i, filename) + fileBytes, _ := os.ReadFile(filename) + sum := fmt.Sprintf("%x", sha1.Sum(fileBytes)) + newfile := strings.TrimPrefix(filename, "dists/sid/") + fmt.Fprintf(rfile, " %s %d %s\n", sum, len(fileBytes), newfile) + } + */ + fmt.Fprintf(rfile, "SHA256:\n") + for i, filename := range allfiles { + log.Info(i, filename) + fileBytes, _ := os.ReadFile(filename) + sum := fmt.Sprintf("%x", sha256.Sum256(fileBytes)) + newfile := strings.TrimPrefix(filename, "dists/sid/") + fmt.Fprintf(rfile, " %s %d %s\n", sum, len(fileBytes), newfile) + } + // fmt.Fprintf(rfile, "SHA1:\n") + // fmt.Fprintf(rfile, "SHA256:\n") + rfile.Close() + + // Sign the file + log.Println("Signing with GPG key:", gpgKeyID) + + distPath := "/home/mirrors/wit/dists/sid" + // Create InRelease + cmdClearSign := exec.Command("gpg", "--default-key", gpgKeyID, "--clearsign", "-o", filepath.Join(distPath, "InRelease"), releasePath) + if err := runCommand(cmdClearSign); err != nil { + log.Printf("failed to create InRelease: %v\n", err) + } + + // Create Release.gpg + cmdDetachedSign := exec.Command("gpg", "--default-key", gpgKeyID, "-abs", "-o", filepath.Join(distPath, "Release.gpg"), releasePath) + if err := runCommand(cmdDetachedSign); err != nil { + log.Printf("failed to create Release.gpg: %v\n", err) + } + /* + var sum string + switch name { + case "MD5Sum": + sum = fmt.Sprintf("%x", md5.Sum(fileBytes)) + case "SHA1": + sum = fmt.Sprintf("%x", sha1.Sum(fileBytes)) + case "SHA256": + // FIX 3: Use the correct sha256.Sum256 function. + sum = fmt.Sprintf("%x", sha256.Sum256(fileBytes)) + */ + return "doNewest", nil } |
