summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile7
-rw-r--r--argv.go3
-rw-r--r--doEverything.go6
-rw-r--r--doNewest.go14
-rw-r--r--doWalk.go2
-rw-r--r--find.go92
-rw-r--r--main.go15
-rw-r--r--makePackagesFile.go77
8 files changed, 195 insertions, 21 deletions
diff --git a/Makefile b/Makefile
index 7adfe4d..c11fb7e 100644
--- a/Makefile
+++ b/Makefile
@@ -7,10 +7,10 @@ BUILDTIME = $(shell date +%s)
all: install
mirrors
-everything:
+everything: install
mirrors
find /home/mirrors/wit/dists
- false
+ mirrors verify
mirrors everything
apt update
sleep 1
@@ -18,6 +18,9 @@ everything:
find /home/mirrors/wit/dists
cat /var/lib/apt/lists/mirrors.wit.com_wit_dists_sid_InRelease
+find:
+ find find /var/lib/apt/lists/mi* /home/mirrors/wit/dists
+
build: goimports
GO111MODULE=off go build \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
diff --git a/argv.go b/argv.go
index 7866848..23a9486 100644
--- a/argv.go
+++ b/argv.go
@@ -28,6 +28,7 @@ type args struct {
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"`
+ Create bool `arg:"--create" help:"create a new .pb file"`
}
type EmptyCmd struct {
@@ -54,7 +55,7 @@ func (args) Appname() string {
}
func (a args) DoAutoComplete(pb *prep.Auto) {
- base := []string{"--version", "oldway", "--dry-run", "--force", "incoming", "walk", "list", "makedists", "verify", "newest"}
+ base := []string{"--version", "oldway", "--dry-run", "--force", "incoming", "walk", "list", "makedists", "verify", "newest", "--create"}
if pb.Cmd == "" {
pb.Autocomplete3(base)
diff --git a/doEverything.go b/doEverything.go
index 9e24644..66bc887 100644
--- a/doEverything.go
+++ b/doEverything.go
@@ -81,8 +81,10 @@ func doEverything() (string, error) {
log.Info("make debInfo file error", err)
panic("deb error")
}
- log.Info(controlfile)
- myshit += controlfile + "\n"
+ // log.Info(controlfile)
+ myshit += controlfile
+ myshit += log.Sprintf("Installed-Size: %s\n", "234234234")
+ myshit += "\n"
}
fullname := "/home/mirrors/wit/dists/sid/main/binary-amd64/Packages"
diff --git a/doNewest.go b/doNewest.go
index 224163f..7744499 100644
--- a/doNewest.go
+++ b/doNewest.go
@@ -44,21 +44,13 @@ func doNewest(arch string) (string, error) {
}
newest.SortPackage()
- var myshit string
- for p := range newest.IterAll() {
- controlfile, err := p.GetDebianControlFile()
- if err != nil {
- log.Info("make debInfo file error", err)
- panic("deb error")
- }
- log.Info(controlfile)
- myshit += controlfile + "\n"
- }
+ thefile := doMakePackagesFile(newest)
fullname := "/home/mirrors/wit/dists/sid/main/binary-amd64/Packages"
- if err := os.WriteFile(fullname, []byte(myshit), 0644); err != nil {
+ if err := os.WriteFile(fullname, []byte(thefile), 0644); err != nil {
return fullname, err
}
+ panic("file is: " + fullname)
r, err := shell.RunVerbose([]string{"gzip", "-k", fullname})
log.Info(r, err)
diff --git a/doWalk.go b/doWalk.go
index b02a0d0..516345a 100644
--- a/doWalk.go
+++ b/doWalk.go
@@ -28,7 +28,7 @@ func doWalk() (string, error) {
newdeb.Filename = deb.Filename
newdeb.DebInfo.Filename = deb.Filename
newdeb.DebInfo.MD5SUM = deb.MD5Sum
- newdeb.DebInfo.SHA1 = deb.SHA1Sum
+ // newdeb.DebInfo.SHA1 = deb.SHA1Sum
newdeb.DebInfo.SHA256 = deb.SHA256Sum
// log.Info("len(CONTROLDATA)", len(deb.ControlData))
diff --git a/find.go b/find.go
index 31e581c..58260bc 100644
--- a/find.go
+++ b/find.go
@@ -1,8 +1,14 @@
package main
import (
+ "fmt"
"os"
"path/filepath"
+
+ "go.wit.com/lib/config"
+ "go.wit.com/log"
+ "google.golang.org/protobuf/proto"
+ "google.golang.org/protobuf/reflect/protoreflect"
)
func FindFiles(lookhere string) ([]string, error) {
@@ -21,3 +27,89 @@ func FindFiles(lookhere string) ([]string, error) {
return allfiles, err
}
+
+// this is terrible and I regret making this
+func printDebInfoStrings(pb proto.Message, fallback bool) (string, error) {
+ var verbose bool
+ var controlfile string
+ // 1. Get the reflection interface for the top-level message.
+ msg := pb.ProtoReflect()
+ descriptor := msg.Descriptor()
+
+ // 2. Find the FieldDescriptor for the nested "debInfo" message.
+ // Note: Protobuf field names like "deb_info" are often canonicalized
+ // to "debInfo" in Go code, but reflection should use the name from the .proto file.
+ // We'll check for both common variations for robustness.
+
+ debInfoFieldDesc := descriptor.Fields().ByName("debInfo")
+ if debInfoFieldDesc == nil {
+ debInfoFieldDesc = descriptor.Fields().ByName("deb_info")
+ }
+
+ if debInfoFieldDesc == nil {
+ return controlfile, fmt.Errorf("field 'debInfo' or 'deb_info' not found in message %s", descriptor.FullName())
+ }
+
+ // 3. Get the actual nested message object from the parent.
+ debInfoValue := msg.Get(debInfoFieldDesc)
+ debInfoMsg := debInfoValue.Message()
+
+ // 4. Check if the nested message is valid and has been set.
+ if !debInfoMsg.IsValid() {
+ fmt.Printf("--- Field '%s' in [%s] is not set. --- \n", debInfoFieldDesc.Name(), descriptor.FullName())
+ return controlfile, nil // Not an error, just nothing to print.
+ }
+
+ // 5. Now, iterate over the fields of the nested debInfo message.
+ debInfoDescriptor := debInfoMsg.Descriptor()
+ fields := debInfoDescriptor.Fields()
+
+ if verbose {
+ fmt.Printf("--- Listing String Fields in '%s' --- \n", debInfoFieldDesc.Name())
+ }
+ foundStrings := false
+ for i := 0; i < fields.Len(); i++ {
+ fieldDesc := fields.Get(i)
+
+ // 6. Check if the field's kind is a string.
+ if fieldDesc.Kind() == protoreflect.StringKind {
+ var value string
+ var fieldName protoreflect.Name
+ // Get the value from the debInfo message object.
+ value = debInfoMsg.Get(fieldDesc).String()
+ fieldName = fieldDesc.Name()
+ if value == "" {
+ if verbose {
+ log.Info(string(fieldName), "is blank")
+ }
+ newval, err := config.GetString(pb, string(fieldName))
+ if err != nil {
+ if verbose {
+ log.Info("GetString() failed", newval, err)
+ }
+ continue
+ } else {
+ if verbose {
+ log.Info("GetString() worked:", newval)
+ }
+ value = newval
+ }
+ }
+ if value == "" {
+ // still blank after backup lookup
+ continue
+ }
+
+ // Print the result.
+ fmt.Printf("%s: \"%s\"\n", string(fieldName), value)
+ controlfile += fmt.Sprintf("%s: %s\n", string(fieldName), value)
+ foundStrings = true
+ }
+ }
+
+ if !foundStrings {
+ fmt.Println(" (No string fields found)")
+ }
+
+ return controlfile, nil
+}
diff --git a/main.go b/main.go
index b2de137..bcd8290 100644
--- a/main.go
+++ b/main.go
@@ -6,7 +6,6 @@ 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"
@@ -30,13 +29,21 @@ func main() {
me.pb = zoopb.NewPackages()
me.pb.Filename = "/home/mirrors/wit/mirrors.wit.com.pb"
if err := me.pb.Load(); err != nil {
- if argv.Force {
- config.Save(me.pb)
+ if argv.Create {
+ me.pb.BaseDir = "/home/mirrors/wit"
+ me.pb.Save()
+ me.sh.GoodExit("created new pb file: " + me.pb.Filename)
} else {
- me.sh.BadExit("no config found. use --force to create one", err)
+ me.sh.BadExit("no config found. use --create to create one", err)
}
}
+ if me.pb.BaseDir == "" {
+ me.pb.BaseDir = "/home/mirrors/wit"
+ me.pb.Save()
+ me.sh.BadExit("pb.BaseDir is bank", nil)
+ }
+
if err := os.Chdir(me.pb.BaseDir); err != nil {
me.sh.BadExit("no '"+me.pb.BaseDir+"' directory", err)
}
diff --git a/makePackagesFile.go b/makePackagesFile.go
new file mode 100644
index 0000000..9f28e46
--- /dev/null
+++ b/makePackagesFile.go
@@ -0,0 +1,77 @@
+package main
+
+import (
+ "strings"
+
+ "go.wit.com/lib/cobol"
+ "go.wit.com/lib/protobuf/zoopb"
+ "go.wit.com/log"
+)
+
+func getDebianControlFile(p *zoopb.Package, varname string) (string, string) {
+ switch varname {
+ case "Package":
+ return "Package", p.Package
+ case "Filename":
+ return "Filename", p.Filename
+ case "Version":
+ return "Version", p.Version
+ case "Architecture":
+ return "Architecture", p.Architecture
+ case "Maintainer":
+ return "Maintainer", p.DebInfo.Maintainer
+ // return "Maintainer", p.Author
+ case "Source":
+ return "Source", p.DebInfo.Source
+ case "Conflicts":
+ return "Conflicts", p.DebInfo.Conflicts
+ case "Packager":
+ return "Packager", p.DebInfo.Packager
+ // return "Packager", p.Packager
+ case "Depends":
+ return "Depends", p.DebInfo.Depends
+ case "BuildDepends":
+ return "Build-Depends", p.DebInfo.BuildDepends
+ case "InstalledSize":
+ return "Installed-Size", "222222222"
+ case "URL":
+ return "Homepage", p.DebInfo.URL
+ case "Size":
+ return "Size", "22222222"
+ case "BuildDate":
+ return "Build-Date", cobol.Time(p.BuildDate)
+ // case "SHA1":
+ // return "SHA1", p.DebInfo.SHA1
+ case "MD5SUM":
+ return "MD5Sum", p.DebInfo.MD5SUM
+ case "SHA256":
+ return "SHA256", p.DebInfo.SHA256
+ case "SHA512":
+ return "SHA512", "" // todo: implement or totally rediculously overkill ?
+ }
+ log.Info("DebInfo sent a field we didn't have. fix the code above", varname)
+ return "", ""
+}
+
+// make a list of the newest .deb files
+func doMakePackagesFile(all *zoopb.Packages) string {
+ var pfile string
+ for p := range all.IterAll() {
+ var controlfile string
+ parts, err := zoopb.GetDebInfoFields(p)
+ if err != nil {
+ log.Info(err)
+ }
+ for _, varname := range parts {
+ varname, varval := getDebianControlFile(p, varname)
+ varval = strings.TrimSpace(varval)
+ if varval == "" {
+ continue
+ }
+ controlfile += log.Sprintf("%s: %s\n", varname, varval)
+ }
+ controlfile += log.Sprintf("\n")
+ pfile += controlfile
+ }
+ return pfile
+}