summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-14 06:18:38 -0500
committerJeff Carr <[email protected]>2025-10-14 06:33:14 -0500
commit37e10c58d67cb1abb15c2f345f4e6800ab7065b2 (patch)
treee5676c7c5bc20c09dce2c31a72fc01174175da02
parenta7d9ba18a64d53010c08285c14804c07b4e8c8fb (diff)
hammering it into form
-rw-r--r--Makefile13
-rw-r--r--config.text25
-rw-r--r--doDistro.go87
-rw-r--r--doIncoming.go24
-rw-r--r--doRelease.go5
-rw-r--r--doVerify.go32
-rw-r--r--main.go17
-rw-r--r--structs.go2
8 files changed, 81 insertions, 124 deletions
diff --git a/Makefile b/Makefile
index bf9c4e6..6010aad 100644
--- a/Makefile
+++ b/Makefile
@@ -4,8 +4,10 @@ VERSION = $(shell git describe --tags)
GUIVERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%s)
-all: reset goimports vet install
- mirrors everything
+all: goimports vet build
+ cp ~/.config/mirrors/config.text .
+ rm -f ~/go/bin/mirrors
+ ./mirrors newest
find:
find /var/lib/apt/lists/mi* /home/mirrors/wit/dists -type f |xargs ls -l
@@ -22,8 +24,6 @@ build: goimports
build-verbose:
GO111MODULE=off go build -v -x \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
-reset:
- reset
install: goimports
GO111MODULE=off go install \
@@ -42,10 +42,7 @@ goimports:
clean:
rm -f go.* *.deb mirrors
go-mod-clean purge
- rm -rf /home/mirrors/wit/dists/
-
-gpl:
- wit-test --witcom
+ # rm -rf /home/mirrors/wit/dists/
check-git-clean:
@git diff-index --quiet HEAD -- || (echo "Git repository is dirty, please commit your changes first"; exit 1)
diff --git a/config.text b/config.text
new file mode 100644
index 0000000..dfbf1a9
--- /dev/null
+++ b/config.text
@@ -0,0 +1,25 @@
+#
+# This is our WIT mirrors config file
+# ~/.config/mirrors/config.text
+#
+uuid: "3135d0f9-82a9-40b6-8aa1-b683ebe7bedd"
+version: "v0.0.2 go.wit.com/lib/config"
+configs: {
+ key: "example config var"
+ value: "protobufs are neat"
+}
+configs: {
+ key: "mirrors.pb"
+ value: "/home/mirrors/wit/mirrors.wit.com.pb"
+}
+configs: {
+ key: "distPath"
+ value: "/home/mirrors/wit/dists/sid"
+}
+# YOUR GPG KEY
+# Find it with: gpg --list-secret-keys --keyid-format=long
+configs: {
+ key: "gpgKeyID"
+ value: "5D7C9BE47836D2FA48F83C2B4A854AEAF7E0E16D"
+}
+filename: "/root/.config/mirrors/config.text"
diff --git a/doDistro.go b/doDistro.go
deleted file mode 100644
index f8034cd..0000000
--- a/doDistro.go
+++ /dev/null
@@ -1,87 +0,0 @@
-package main
-
-/*
-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, -1)
- 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/doIncoming.go b/doIncoming.go
index ed5b4a0..33aab32 100644
--- a/doIncoming.go
+++ b/doIncoming.go
@@ -25,19 +25,25 @@ func doIncoming(pb *zoopb.Packages) (string, error) {
if !info.IsDir() && strings.HasSuffix(info.Name(), ".deb") {
counter += 1
- found := me.pb.FindByFilename(path)
- if found == nil {
- log.Printf("new file %s\n", path)
- newcount += 1
+ if found := me.pb.FindByFilename(path); found != nil {
+ // log.Printf("not new file %s\n", path)
return nil
}
+ newcount += 1
if strings.HasPrefix(path, "pool/main/incoming") {
- letteredDir := log.Sprintf("%1.1s", found.Package)
_, filename := filepath.Split(path)
- newfilename := filepath.Join("pool/main", letteredDir, found.Package, filename)
+ parts := strings.Split(filename, "_")
+ if len(parts) != 3 {
+ // todo: add more filename checking here (check for ".deb")
+ log.Println("bad filenae", filename)
+ return nil
+ }
+ packageName := parts[0]
+ letteredDir := log.Sprintf("%1.1s", filename)
+ newfilename := filepath.Join("pool/main", letteredDir, packageName, filename)
destDir := filepath.Dir(newfilename)
- if err := os.MkdirAll(destDir, 0755); err != nil {
- log.Printf("%s move incoming oldname %s newname: %s\n", found.Package, path, newfilename)
+ if err := os.MkdirAll(destDir, os.ModePerm); err != nil {
+ log.Printf("%s move incoming oldname %s newname: %s\n", packageName, path, newfilename)
log.Fatal("Failed to create destination directory: %v", err)
}
if !argv.Force {
@@ -59,7 +65,7 @@ func doIncoming(pb *zoopb.Packages) (string, error) {
}
}
os.Rename(path, newfilename)
- log.Printf("%s moved incoming oldname %s newname: %s\n", found.Package, path, newfilename)
+ log.Printf("%s moved incoming oldname %s newname: %s\n", packageName, path, newfilename)
incount += 1
if incount > 100 {
me.sh.GoodExit("file moved")
diff --git a/doRelease.go b/doRelease.go
index 887dab9..c436e70 100644
--- a/doRelease.go
+++ b/doRelease.go
@@ -11,6 +11,7 @@ import (
"strings"
"time"
+ "go.wit.com/lib/config"
"go.wit.com/lib/gui/shell"
"go.wit.com/log"
)
@@ -110,10 +111,12 @@ func doRelease() (string, error) {
// fmt.Fprintf(rfile, "SHA256:\n")
rfile.Close()
+ gpgKeyID := config.GetPanic("gpgKeyID")
// Sign the file
log.Println("Signing with GPG key:", gpgKeyID)
- distPath := "/home/mirrors/wit/dists/sid"
+ // distPath := "/home/mirrors/wit/dists/sid"
+ distPath := config.GetPanic("distPath")
// Create InRelease
cmdClearSign := exec.Command("gpg", "--default-key", gpgKeyID, "--clearsign", "-o", filepath.Join(distPath, "InRelease"), releasePath)
if err := runCommand(cmdClearSign); err != nil {
diff --git a/doVerify.go b/doVerify.go
index 3a8029c..0f2a7e3 100644
--- a/doVerify.go
+++ b/doVerify.go
@@ -6,7 +6,6 @@ import (
"path/filepath"
"strings"
- "go.wit.com/lib/cobol"
"go.wit.com/lib/gui/shell"
"go.wit.com/lib/protobuf/zoopb"
"go.wit.com/log"
@@ -111,13 +110,28 @@ func doVerify() (string, error) {
counter += 1
continue
}
- // verify constructed filename
- constructedFilename := p.Package + "_" + p.Version + "_" + p.Architecture + ".deb"
- _, fname := filepath.Split(p.Filename)
- if constructedFilename != fname {
- log.Info("filename mismatch", constructedFilename, fname, cobol.Since(p.Ctime))
- return moveToBroken(p)
- }
+ /*
+ // verify constructed filename
+ constructedFilename := p.Package + "_" + p.Version + "_" + p.Architecture + ".deb"
+ _, fname := filepath.Split(p.Filename)
+ if constructedFilename != fname {
+ log.Info("filename mismatch", constructedFilename, fname, cobol.Since(p.Ctime))
+ counter += 1
+ moveToBroken(p)
+ continue
+ }
+ // verify constructed filepath
+ firstletter := fmt.Sprintf("%1.1s", p.Package)
+ fpath := filepath.Join("pool", "main", firstletter, p.Package)
+ constructedFullname := filepath.Join(fpath, constructedFilename)
+ if p.Filename != constructedFullname {
+ log.Info("bad fullname", p.Filename)
+ log.Info("new fullname", constructedFullname)
+ counter += 1
+ moveToBroken(p)
+ continue
+ }
+ */
// deprecate this and Delete(p) instead?
// log.Info("Package", p.Package)
@@ -147,7 +161,7 @@ func moveToBroken(p *zoopb.Package) (string, error) {
return "no '" + me.pb.BaseDir + "' directory", err
}
brokendir := filepath.Join(me.pb.BaseDir, "broken")
- if err := os.MkdirAll(brokendir, 0755); err != nil {
+ if err := os.MkdirAll(brokendir, os.ModePerm); err != nil {
return "mkdir " + brokendir, err
}
_, fname := filepath.Split(p.Filename)
diff --git a/main.go b/main.go
index 60f7480..c977ed0 100644
--- a/main.go
+++ b/main.go
@@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
+ "go.wit.com/lib/config"
"go.wit.com/lib/gui/prep"
"go.wit.com/lib/gui/shell"
"go.wit.com/lib/protobuf/zoopb"
@@ -28,10 +29,11 @@ func main() {
// read in protobuf file
me.pb = zoopb.NewPackages()
- me.pb.Filename = "/home/mirrors/wit/mirrors.wit.com.pb"
+ me.pb.Filename = config.GetPanic("mirrors.pb")
if err := me.pb.Load(); err != nil {
if argv.Create {
- me.pb.BaseDir = "/home/mirrors/wit"
+ // me.pb.BaseDir = "/home/mirrors/wit"
+ me.pb.BaseDir = config.GetPanic("BaseDir")
me.pb.Save()
me.sh.GoodExit("created new pb file: " + me.pb.Filename)
} else {
@@ -40,7 +42,7 @@ func main() {
}
if me.pb.BaseDir == "" {
- me.pb.BaseDir = "/home/mirrors/wit"
+ me.pb.BaseDir = config.GetPanic("BaseDir")
me.pb.Save()
me.sh.BadExit("pb.BaseDir is bank", nil)
}
@@ -106,16 +108,13 @@ func main() {
}
if argv.Everything != nil {
- s, err = doWalk()
- if err != nil {
- me.sh.BadExit(s, err)
- }
+ // move files to the right place
s, err = doIncoming(me.pb)
if err != nil {
me.sh.BadExit(s, err)
}
- // a second time, files from incoming should have
- // been moved now
+
+ // add the filenames to the .pb
s, err = doWalk()
if err != nil {
me.sh.BadExit(s, err)
diff --git a/structs.go b/structs.go
index be576d2..71643b5 100644
--- a/structs.go
+++ b/structs.go
@@ -11,7 +11,7 @@ import (
// --- Configuration ---
// !!! IMPORTANT: Set your GPG Key ID here!
// Find it with: gpg --list-secret-keys --keyid-format=long
-const gpgKeyID = "5D7C9BE47836D2FA48F83C2B4A854AEAF7E0E16D"
+// const gpgKeyID = "5D7C9BE47836D2FA48F83C2B4A854AEAF7E0E16D"
const dist = "sid"
const component = "main"