summaryrefslogtreecommitdiff
path: root/doDistro.go
diff options
context:
space:
mode:
Diffstat (limited to 'doDistro.go')
-rw-r--r--doDistro.go94
1 files changed, 94 insertions, 0 deletions
diff --git a/doDistro.go b/doDistro.go
new file mode 100644
index 0000000..f63b20e
--- /dev/null
+++ b/doDistro.go
@@ -0,0 +1,94 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+ "strings"
+
+ "go.wit.com/log"
+)
+
+func doDistro() error {
+ log.Println("--- Starting Debian repository generation in Go ---")
+
+ // 1. Clean and create directory structure
+ distPath := filepath.Join(distsDir, dist)
+ log.Printf("Cleaning up old dists directory: %s\n", distPath)
+ if err := os.RemoveAll(distPath); err != nil {
+ return err
+ }
+
+ log.Println("Creating new directory structure...")
+ for _, arch := range architectures {
+ binPath := filepath.Join(distPath, component, "binary-"+arch)
+ if err := os.MkdirAll(binPath, 0755); err != nil {
+ log.Printf("Failed to create directory %s: %v\n", binPath, err)
+ return err
+ }
+ }
+
+ // 2. Scan pool directory for .deb files and gather info
+ log.Printf("Scanning for .deb files in %s/ જુ\n", poolDir)
+ debInfos, err := scanDebs(poolDir)
+ if err != nil {
+ log.Printf("Failed to scan .deb files: %v\n", err)
+ return err
+ }
+ log.Printf("Found %d total .deb packages.", len(debInfos))
+
+ // 3. Group packages by architecture
+ debsByArch := make(map[string][]DebInfo)
+ for _, deb := range debInfos {
+ arch := deb.ControlData["Architecture"]
+ debsByArch[arch] = append(debsByArch[arch], deb)
+ }
+ // Add the 'all' packages to each specific architecture list as well, as is standard.
+ for _, arch := range architectures {
+ if arch != "all" {
+ debsByArch[arch] = append(debsByArch[arch], debsByArch["all"]...)
+ }
+ }
+
+ // 4. Generate Packages files
+ log.Println("Generating Packages files...")
+ for _, arch := range architectures {
+ binPath := filepath.Join(distPath, component, "binary-"+arch)
+ packagesFile := filepath.Join(binPath, "Packages")
+
+ var content strings.Builder
+ for _, deb := range debsByArch[arch] {
+ for key, val := range deb.ControlData {
+ fmt.Fprintf(&content, "%s: %s\n", key, val)
+ }
+ fmt.Fprintf(&content, "Filename: %s\n", deb.Filename)
+ fmt.Fprintf(&content, "Size: %d\n", deb.Size)
+ fmt.Fprintf(&content, "MD5sum: %s\n", deb.MD5Sum)
+ fmt.Fprintf(&content, "SHA1: %s\n", deb.SHA1Sum)
+ fmt.Fprintf(&content, "SHA256: %s\n", deb.SHA256Sum)
+ fmt.Fprintln(&content)
+ }
+
+ if err := os.WriteFile(packagesFile, []byte(content.String()), 0644); err != nil {
+ return err
+ }
+
+ // Compress the Packages file
+ if err := compressFile(packagesFile, "gz"); err != nil {
+ return err
+ }
+ if err := compressFile(packagesFile, "bz2"); err != nil {
+ return err
+ }
+ }
+
+ // 5. Generate and sign the Release file
+ log.Println("Generating and signing Release file...")
+ if err := generateAndSignReleaseFile(distPath); err != nil {
+ log.Printf("Failed to generate or sign Release file: %v\n", err)
+ return err
+ }
+
+ log.Println("--- Repository generation complete! ---")
+ return nil
+}