diff options
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | find.go | 25 | ||||
| -rw-r--r-- | makePackageFile.go | 90 | ||||
| -rw-r--r-- | package.proto | 57 | ||||
| -rw-r--r-- | tableDefault.go | 6 | ||||
| -rw-r--r-- | tablePackages.go | 8 | ||||
| -rw-r--r-- | wit.go | 20 |
7 files changed, 173 insertions, 36 deletions
@@ -4,3 +4,6 @@ protobuf definition files for zookeeper * zookeeper is similar to the apache zookeeper project * you can use it to maintain the systems in your cluster * zookeeper works with virtigo to maintain your private cloud + +This also helps generate the files needed in /home/mirrors/debian/dists +so one can 'apt update' the package lists. @@ -0,0 +1,25 @@ +package zoopb + +import ( + "errors" +) + +func (m *Machine) FindByPackageName(name string) (*Package, error) { + return m.Packages.FindByPackageName(name) +} + +// used when you want to inforce the protobuf only has one package per name +func (all *Packages) FindByPackageName(name string) (*Package, error) { + var found *Package + for p := range all.IterByPackage() { + if name == p.Package { + if found != nil { + return found, errors.New("duplicate package names in protobuf") + } + found = p + } + } + + // log.Info("package name not found", name) + return found, nil +} diff --git a/makePackageFile.go b/makePackageFile.go new file mode 100644 index 0000000..3926901 --- /dev/null +++ b/makePackageFile.go @@ -0,0 +1,90 @@ +package zoopb + +import ( + "bytes" + "fmt" + "io" + "os" + "path" + "path/filepath" +) + +// remove and return the pb varname +func (pb *Package) DeleteString(varname string) string { + return "todo" +} + +// makes /home/mirrors/debian/dists/ for use by 'apt update' +func (pb *Packages) MakeDists() (string, error) { + os.Chdir(pb.BaseDir) + + arch := "risc64" + packageDir := filepath.Join("dists", "sid", "main", "binary"+arch) + pb.MakePackageFile(packageDir, arch) + + /* + // 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 "--- Repository generation complete! ---", nil +} + +// 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) error { + if err := os.Chdir(pb.BaseDir); err != nil { + return err + } + + fullpath := path.Join(pb.BaseDir, packageDir) + os.MkdirAll(fullpath, 0755) + + // 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.IterByFilename() { + if debPB.Architecture != arch { + continue + } + matcharch.Append(debPB) + } + + var data bytes.Buffer + for debPB := range matcharch.IterByFilename() { + debPB.writeDebInfo(&data) + } + + // write out the "Packages" file + if err := os.WriteFile(filepath.Join(packageDir, "Package"), []byte(data.String()), 0644); err != nil { + return err + } + + /* + // 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 + } + */ + return nil +} diff --git a/package.proto b/package.proto index d3e6ae2..7c8436b 100644 --- a/package.proto +++ b/package.proto @@ -2,12 +2,15 @@ syntax = "proto3"; package gitpb; -// import "google/protobuf/duration.proto"; // Import the well-known type for Timestamp import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp -// global settings for autogenpb `autogenpb:mutex` +// Note: 'autogenpb' treats all .proto variable names as case insensitive -message Package { +// DebInfo has the information displayed by "dpkg -I moon-buggy.deb" +// The order here is the order they will be written into the +// /home/mirrors/debian/sid/main/binary-riscv64/Packages file + +message DebInfo { string Package = 1; // `autogenpb:unique` `autogenpb:sort` string Filename = 2; // `autogenpb:unique` `autogenpb:sort` string Namespace = 3; // path to the sources (go.wit.com/apps/zookeeper) @@ -15,28 +18,42 @@ message Package { string Architecture = 5; // string Depends = 6; // string Maintainer = 7; // - string Description = 8; // - string Packager = 9; // - string Source = 10; // - string Size = 11; // - string Conflicts = 12; // - string BuildDepends = 13; // - string URL = 14; // - string SHA1 = 15; // - string MD5SUM = 16; // - string SHA256 = 17; // - string SHA512 = 18; // - bool installed = 19; // if installed on your machine, this should be set to true - google.protobuf.Timestamp BuildDate = 20; // - google.protobuf.Timestamp GitDate = 21; // - google.protobuf.Timestamp ctime = 22; // create time on the mirrors - map<string, string> core = 23; // catch all for whatever is left over + string Homepage = 8; // + string Description = 9; // + string Packager = 10; // + string Source = 11; // + string Size = 12; // + string Conflicts = 13; // + string BuildDepends = 14; // + string URL = 15; // + string SHA1 = 16; // probably not used anymore + string MD5SUM = 17; // deprecate + string SHA256 = 18; // + string SHA512 = 19; // +} + +message Package { + string Package = 1; // `autogenpb:sort` + string Filename = 2; // `autogenpb:unique` `autogenpb:sort` + string Namespace = 3; // namespace path to the sources (go.wit.com/apps/zookeeper) + string Version = 4; // + string Architecture = 5; // + DebInfo debInfo = 6; // the information given by "dpkg -I pingus.deb" + bool installed = 7; // if installed on your machine, this should be set to true + google.protobuf.Timestamp ctime = 8; // the ctime of the file on the mirrors + google.protobuf.Timestamp buildDate = 9; // when the package was built + google.protobuf.Timestamp gitDate = 10; // the tiem of the last git commit + google.protobuf.Timestamp gitHash = 11; // the git hash it was built from + map<string, string> custom = 12; // for custom strings } message Packages { // `autogenpb:marshal` `autogenpb:gui` `autogenpb:http` string uuid = 1; // `autogenpb:uuid:2f26cc03-ea30-4481-a333-ad0acc86e1d3` - string version = 2; // `autogenpb:version:v0.0.2` + string version = 2; // `autogenpb:version:v0.0.3` repeated Package packages = 3; string filename = 4; // `autogenpb:save` -- this enables autogenerated pb.Load() and pb.Save() bool changed = 5; // only writes to disk on Save() if changed == true + string gpgKeyID = 6; // the gpg key used to sign the debian mirror Package files + string baseDir = 7; // where your mirrors repo starts "/home/mirrors/debian" + repeated string Errors = 8; // where your mirrors repo starts "/home/mirrors/debian" } diff --git a/tableDefault.go b/tableDefault.go index bc3ef86..a787540 100644 --- a/tableDefault.go +++ b/tableDefault.go @@ -107,8 +107,10 @@ func (m *Machine) makeSmartTable(pb *Packages) *PackagesTable { col = t.AddVersion() col.Width = 20 - col = t.AddMD5SUM() - col.Width = 8 + col = t.AddStringFunc("md5sum", func(p *Package) string { + return p.DebInfo.MD5SUM + }) + col.Width = 3 col = t.AddFilename() col.Width = -1 diff --git a/tablePackages.go b/tablePackages.go index a6968c1..c4ec53c 100644 --- a/tablePackages.go +++ b/tablePackages.go @@ -28,10 +28,14 @@ func (pb *Packages) MakeDefaultTable() *PackagesTable { }) col.Width = 3 - col = t.AddMD5SUM() + col = t.AddStringFunc("md5sum", func(p *Package) string { + return p.DebInfo.MD5SUM + }) col.Width = 6 - col = t.AddSHA256() + col = t.AddStringFunc("sha256", func(p *Package) string { + return p.DebInfo.SHA256 + }) col.Width = 6 col = t.AddArchitecture() @@ -22,6 +22,7 @@ func (m *Machine) IsInstalled(name string) bool { return false } +// this is a work in progress func (m *Machine) FindInstalledByName(name string) *Package { if m == nil { panic("m == nil") @@ -29,19 +30,14 @@ func (m *Machine) FindInstalledByName(name string) *Package { if m.Packages == nil { panic("m.Packages == nil") } - // log.Info("FindInstalledByName len=", m.Packages.Len()) - return m.Packages.FindByPackage(name) - /* - for p := range m.Packages.IterByName() { - if name == p.Package { - // log.Info("package installed:", p.Package, p.Version, p.PkgName) - return p - } - } - // log.Info("package not-installed:", name) - return nil - */ + for p := range m.Packages.IterByFilename() { + if name == p.Package { + // log.Info("package installed:", p.Package, p.Version, p.PkgName) + return p + } + } + return nil } // looks to see if any package matches a name and version |
