summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-05 07:35:57 -0500
committerJeff Carr <[email protected]>2025-10-05 07:35:57 -0500
commite8857d62d91538e0760c50c5e1a68eaa16caf309 (patch)
treeed5a5a2526ed0025a450e28c7d177f8bfbd7b5d0
parentb65fe9b53c549ba63ec390b2fb2950345ed1fdb9 (diff)
a binary to replace aptly
-rw-r--r--Makefile2
-rw-r--r--argv.go50
-rwxr-xr-xbuild10
-rw-r--r--control2
-rw-r--r--doDistro.go94
-rw-r--r--main.go119
-rw-r--r--resources/wit-sid.asc (renamed from wit-sid.asc)0
-rw-r--r--resources/wit.list (renamed from wit.list)0
-rw-r--r--structs.go38
9 files changed, 210 insertions, 105 deletions
diff --git a/Makefile b/Makefile
index 0e253ca..ac6bb13 100644
--- a/Makefile
+++ b/Makefile
@@ -28,8 +28,6 @@ go-deb:
goimports:
goimports -w *.go
- # // to globally reset paths:
- # // gofmt -w -r '"go.wit.com/gui/gadgets" -> "go.wit.com/lib/gadgets"' *.go
clean:
rm -f go.*
diff --git a/argv.go b/argv.go
new file mode 100644
index 0000000..346dc5d
--- /dev/null
+++ b/argv.go
@@ -0,0 +1,50 @@
+// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
+// Use of this source code is governed by the GPL 3.0
+
+package main
+
+/*
+ this parses the command line arguements
+ this enables command line options from other packages like 'gui' and 'log'
+*/
+
+import (
+ "os"
+
+ "go.wit.com/lib/gui/prep"
+)
+
+var argv args
+
+type args struct {
+ Update *EmptyCmd `arg:"subcommand:update" help:"update the apt repo"`
+ DryRun bool `arg:"--dry-run" help:"only show what would be packaged"`
+ Verbose bool `arg:"--verbose" help:"be loud about it"`
+ Force bool `arg:"--force" help:"rebuild everything"`
+}
+
+type EmptyCmd struct {
+}
+
+func (args) Buildtime() (string, string) {
+ return BUILDTIME, VERSION
+}
+
+func (args) Version() string {
+ return ARGNAME + " " + VERSION + " Built on " + BUILDTIME
+}
+
+func (args) Appname() string {
+ return ARGNAME
+}
+
+func (a args) DoAutoComplete(pb *prep.Auto) {
+ base := []string{"--version", "update", "--dry-run", "--force"}
+
+ if pb.Cmd == "" {
+ pb.Autocomplete3(base)
+ } else {
+ pb.SubCommand(pb.Goargs...)
+ }
+ os.Exit(0)
+}
diff --git a/build b/build
index eba7c70..4dfcd69 100755
--- a/build
+++ b/build
@@ -1,4 +1,14 @@
#!/bin/bash -x
+# these are the keys and files you need
+#
+# to be able to apt install packages from mirrors.wit.com
+
+mkdir -p files/etc/apt/trusted.gpg.d/
+cp resources/wit-sid.asc files/etc/apt/trusted.gpg.d/
+
+mkdir -p files/etc/apt/sources.list.d/
+cp resources/wit.list files/etc/apt/sources.list.d/
+
mkdir -p files/usr/share/bash-completion/completions/
mirrors --bash > files/usr/share/bash-completion/completions/mirrors
diff --git a/control b/control
index 9974c56..ea80ad8 100644
--- a/control
+++ b/control
@@ -7,6 +7,6 @@ Architecture: all
Depends:
URL: https://mirrors.wit.com/
Recommends:
-Version: 0.0.7
+Version: 0.0.8
Description: apt keys and source file
This was packaged with go-deb from go.wit.com
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
+}
diff --git a/main.go b/main.go
index 5c6846b..3e0f080 100644
--- a/main.go
+++ b/main.go
@@ -1,115 +1,30 @@
package main
import (
- "fmt"
- "log"
- "os"
- "path/filepath"
- "strings"
-)
+ "embed"
-// --- Configuration ---
-// !!! IMPORTANT: Set your GPG Key ID here!
-// Find it with: gpg --list-secret-keys --keyid-format=long
-const gpgKeyID = "5D7C9BE47836D2FA48F83C2B4A854AEAF7E0E16D"
+ "go.wit.com/lib/gui/prep"
+)
-const dist = "sid"
-const component = "main"
-const poolDir = "pool"
-const distsDir = "dists"
+// sent via -ldflags
+var VERSION string
+var BUILDTIME string
-var architectures = []string{"amd64", "riscv64", "arm64", "all"}
+// used for shell auto completion
+var ARGNAME string = "mirrors" // todo: get this from $0 ?
-// DebInfo holds the control information for a single .deb package.
-type DebInfo struct {
- ControlData map[string]string
- Filename string
- Size int64
- MD5Sum string
- SHA1Sum string
- SHA256Sum string
-}
+//go:embed resources/*
+var resources embed.FS
func main() {
- log.Println("--- Starting Debian repository generation in Go ---")
-
- if gpgKeyID == "YOUR_GPG_KEY_ID" || gpgKeyID == "" {
- log.Fatal("ERROR: Please set the 'gpgKeyID' constant at the top of the script.")
- }
-
- // 1. Clean and create directory structure
- distPath := filepath.Join(distsDir, dist)
- log.Printf("Cleaning up old dists directory: %s", distPath)
- if err := os.RemoveAll(distPath); err != nil {
- log.Fatalf("Failed to remove old dists directory: %v", err)
- }
+ me = new(mainType)
+ me.sh = prep.Bash3(&argv) // add support for bash autocomplete with go-arg
- 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.Fatalf("Failed to create directory %s: %v", binPath, err)
- }
- }
-
- // 2. Scan pool directory for .deb files and gather info
- log.Printf("Scanning for .deb files in %s/ જુ", poolDir)
- debInfos, err := scanDebs(poolDir)
- if err != nil {
- log.Fatalf("Failed to scan .deb files: %v", 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"]...)
+ if argv.Update != nil {
+ if err := doDistro(); err != nil {
+ me.sh.BadExit("boo", err)
}
+ me.sh.GoodExit("")
}
-
- // 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 {
- log.Fatalf("Failed to write Packages file for %s: %v", arch, err)
- }
-
- // Compress the Packages file
- if err := compressFile(packagesFile, "gz"); err != nil {
- log.Fatalf("Failed to gzip Packages file for %s: %v", arch, err)
- }
- if err := compressFile(packagesFile, "bz2"); err != nil {
- log.Fatalf("Failed to bzip2 Packages file for %s: %v", arch, err)
- }
- }
-
- // 5. Generate and sign the Release file
- log.Println("Generating and signing Release file...")
- if err := generateAndSignReleaseFile(distPath); err != nil {
- log.Fatalf("Failed to generate or sign Release file: %v", err)
- }
-
- log.Println("--- Repository generation complete! ---")
+ me.sh.GoodExit("nothing to do")
}
diff --git a/wit-sid.asc b/resources/wit-sid.asc
index 8648d6c..8648d6c 100644
--- a/wit-sid.asc
+++ b/resources/wit-sid.asc
diff --git a/wit.list b/resources/wit.list
index f1b6db6..f1b6db6 100644
--- a/wit.list
+++ b/resources/wit.list
diff --git a/structs.go b/structs.go
new file mode 100644
index 0000000..c0d5cb1
--- /dev/null
+++ b/structs.go
@@ -0,0 +1,38 @@
+package main
+
+import (
+ "sync"
+
+ "go.wit.com/lib/gui/prep"
+)
+
+// --- Configuration ---
+// !!! IMPORTANT: Set your GPG Key ID here!
+// Find it with: gpg --list-secret-keys --keyid-format=long
+const gpgKeyID = "5D7C9BE47836D2FA48F83C2B4A854AEAF7E0E16D"
+
+const dist = "sid"
+const component = "main"
+const poolDir = "pool"
+const distsDir = "dists"
+
+var architectures = []string{"amd64", "riscv64", "arm64", "all"}
+
+// DebInfo holds the control information for a single .deb package.
+type DebInfo struct {
+ ControlData map[string]string
+ Filename string
+ Size int64
+ MD5Sum string
+ SHA1Sum string
+ SHA256Sum string
+}
+
+var me *mainType
+
+// this app's variables
+type mainType struct {
+ once sync.Once // one-time initialized data
+ sh *prep.Auto // more experiments for bash handling
+ // forge *forgepb.Forge // your customized repo preferences and settings
+}