summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mirrorsSupport.go162
-rw-r--r--printDebInfo.go36
2 files changed, 32 insertions, 166 deletions
diff --git a/mirrorsSupport.go b/mirrorsSupport.go
deleted file mode 100644
index aade2b8..0000000
--- a/mirrorsSupport.go
+++ /dev/null
@@ -1,162 +0,0 @@
-package zoopb
-
-// makes dists/ directores for 'apt update'
-
-import (
- "bytes"
- "errors"
- "fmt"
- "io"
- "os"
- "path"
- "path/filepath"
- "strings"
-
- "go.wit.com/lib/gui/shell"
- "go.wit.com/log"
- "google.golang.org/protobuf/encoding/prototext"
-)
-
-var verbose bool
-
-// remove and return the pb varname
-func (pb *Package) DeleteString(varname string) string {
- return "todo"
-}
-
-func (pb *Package) Print() {
- shell.RunVerbose([]string{"dpkg", "-I", pb.Filename})
- log.Info("\nNEW PB START")
- log.Info(strings.TrimSpace(prototext.Format(pb)))
- log.Info("NEW PB END\n")
-
- log.Info("Attempt to walk pb.DebInfo")
- if err := printDebInfoStrings(pb, true); err != nil {
- log.Info("pb.walk error:", err)
- }
-
-}
-
-// makes /home/mirrors/debian/dists/ for use by 'apt update'
-func (pb *Packages) MakeDists() (string, error) {
- log.Printf("Attempting to make dists/ in %s with %d .deb files\n", pb.BaseDir, pb.Len())
- os.Chdir(pb.BaseDir)
-
- var s string
- var err error
- var archpb *Packages
- archpb, s, err = pb.doNormalArch("all")
- log.Printf("arch all found %5d packages. %s err=(%v)\n", archpb.Len(), filepath.Join(pb.BaseDir, s), err)
- archpb, s, err = pb.doNormalArch("riscv64")
- log.Printf("arch riscv64 found %5d packages. %s err=(%v)\n", archpb.Len(), filepath.Join(pb.BaseDir, s), err)
-
- // archpb, s, err = pb.doNormalArch("amd64")
- // log.Printf("arch amd64 found %5d packages. %s err=(%v)\n", archpb.Len(), filepath.Join(pb.BaseDir, s), err)
-
- // archpb, s, err = pb.doNormalArch("arm64")
- // log.Printf("arch arm64 found %5d not as cool as riscv packages. msg='%s' err=(%v)\n", archpb.Len(), s, err)
-
- return s, nil
-}
-
-func (pb *Packages) doNormalArch(arch string) (*Packages, string, error) {
- packageDir := filepath.Join("dists", "sid", "main", "binary-"+arch)
- archpb, s, err := pb.MakePackageFile(packageDir, arch)
- if err != nil {
- log.Info("MakePackageFile() failed", s, err)
- } else {
- if verbose {
- log.Info("MakePackageFile() for", arch, "worked")
- }
- }
-
- /*
- // 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
- }
- */
- return archpb, filepath.Join(packageDir, "Packages"), err
-}
-
-// similar to "dpkg -I moonbuggy.deb"
-// destroys the pb so send a copy
-func (pb *Package) writeDebInfo(w io.Writer) {
- fmt.Fprintf(w, "Package: %s\n", pb.Package)
- fmt.Fprintf(w, "Filename: %s\n", pb.Filename)
- fmt.Fprintf(w, "MD5sum: %s\n", pb.DeleteString("md5sum"))
- fmt.Fprintf(w, "SHA1: %s\n", pb.DeleteString("SHA1"))
- fmt.Fprintf(w, "SHA256: %s\n", pb.DeleteString("sha256"))
-}
-
-// makes the file "dists/sid/main/binary-riscv64/Packages"
-// then compresses it as .gz & .bz2 files
-func (pb *Packages) MakePackageFile(packageDir string, arch string) (*Packages, string, error) {
- if verbose {
- log.Printf("Attempting to make Package file for arch=%s\n", arch)
- }
- if err := os.Chdir(pb.BaseDir); err != nil {
- return nil, "", err
- }
-
- fullpath := path.Join(pb.BaseDir, packageDir)
- if err := os.MkdirAll(fullpath, 0755); err != nil {
- return nil, "", err
- }
-
- // made a new PB in memory of just the matching riscv64.deb files
- matcharch := NewPackages()
-
- // goes through each .deb file and writes out the entry in the Packages file
- for debPB := range pb.IterAll() {
- if verbose {
- log.Info("Adding package", debPB.Architecture, debPB.Filename)
- }
- if debPB.Architecture != arch {
- continue
- }
- matcharch.Append(debPB)
- }
-
- if matcharch.Len() == 0 {
- return matcharch, "found no files", errors.New("no " + arch + " files found")
- }
-
- var data bytes.Buffer
- for debPB := range matcharch.IterByFilename() {
- if verbose {
- log.Info("Adding package", debPB.Filename)
- }
- debPB.writeDebInfo(&data)
- fmt.Fprintf(&data, "\n")
- }
-
- // write out the "Packages" file
- filename := filepath.Join(packageDir, "Package")
- fullname := filepath.Join(pb.BaseDir, filename)
- if len(data.String()) == 0 {
- return matcharch, fullname, errors.New("something is wrong. Package file would be empty")
- }
- log.Info("Going to write file", fullname, "with string length", len(data.String()))
- if err := os.WriteFile(fullname, []byte(data.String()), 0644); err != nil {
- return matcharch, fullname, err
- }
-
- log.Info(data.String())
-
- /*
- // Create "Packages.gz"
- if err := compressFile(filepath.Join(fullfile, "Package.gz"); err != nil {
- return err
- }
-
- // Create "Packages.gz"
- if err := compressFile(filepath.Join(fullfile, "Package.bz2"); err != nil {
- return err
- }
- */
- s := log.Sprintf("Created %s", fullname)
- return matcharch, s, nil
-}
diff --git a/printDebInfo.go b/printDebInfo.go
index f0d9337..e87a3d2 100644
--- a/printDebInfo.go
+++ b/printDebInfo.go
@@ -2,17 +2,44 @@ package zoopb
import (
"fmt"
+ "strings"
"go.wit.com/lib/config"
+ "go.wit.com/lib/gui/shell"
"go.wit.com/log"
+ "google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
)
+func (pb *Package) Print() (string, error) {
+ shell.RunVerbose([]string{"dpkg", "-I", pb.Filename})
+ log.Info("\nNEW PB START")
+ log.Info(strings.TrimSpace(prototext.Format(pb)))
+ log.Info("NEW PB END\n")
+
+ log.Info("Attempt to walk pb.DebInfo")
+ if s, err := printDebInfoStrings(pb, true); err != nil {
+ return s, err
+ }
+ return "todo", nil
+}
+
+func (pb *Package) GetDebianControlFile() (string, error) {
+ var s string
+ var err error
+ if s, err = printDebInfoStrings(pb, true); err != nil {
+ return s, err
+ }
+ return s, err
+}
+
// if the varname isn't in the proto msg, then it'll try to read
// the same varname from the base message. This allows the
// .proto file to define the print order of the fields
-func printDebInfoStrings(pb proto.Message, fallback bool) error {
+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()
@@ -28,7 +55,7 @@ func printDebInfoStrings(pb proto.Message, fallback bool) error {
}
if debInfoFieldDesc == nil {
- return fmt.Errorf("field 'debInfo' or 'deb_info' not found in message %s", descriptor.FullName())
+ 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.
@@ -38,7 +65,7 @@ func printDebInfoStrings(pb proto.Message, fallback bool) error {
// 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 nil // Not an error, just nothing to print.
+ return controlfile, nil // Not an error, just nothing to print.
}
// 5. Now, iterate over the fields of the nested debInfo message.
@@ -83,6 +110,7 @@ func printDebInfoStrings(pb proto.Message, fallback bool) error {
// Print the result.
fmt.Printf("%s: \"%s\"\n", string(fieldName), value)
+ controlfile += fmt.Sprintf("%s: %s\n", string(fieldName), value)
foundStrings = true
}
}
@@ -91,7 +119,7 @@ func printDebInfoStrings(pb proto.Message, fallback bool) error {
fmt.Println(" (No string fields found)")
}
- return nil
+ return controlfile, nil
}
/*