From b73be5b5b19c19c6d8f5de8a4adca783144e9659 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 14 Oct 2025 10:02:53 -0500 Subject: riscv64 might work now (?) --- argv.go | 2 +- doRelease.go | 171 ---------------------------------------------------- main.go | 34 ++++++++++- makePackagesFile.go | 163 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 196 insertions(+), 174 deletions(-) delete mode 100644 doRelease.go create mode 100644 makePackagesFile.go diff --git a/argv.go b/argv.go index e7078a1..192ce81 100644 --- a/argv.go +++ b/argv.go @@ -53,7 +53,7 @@ func (args) Appname() string { } func (a args) DoAutoComplete(pb *prep.Auto) { - base := []string{"--dry-run", "--force", "incoming", "walk", "list", "everything", "verify", "newest", "--create", "--verbose"} + base := []string{"--dry-run", "--force", "incoming", "walk", "list", "everything", "verify", "newest", "--create", "--verbose", "release"} if pb.Cmd == "" { pb.Autocomplete3(base) diff --git a/doRelease.go b/doRelease.go deleted file mode 100644 index f99e9e4..0000000 --- a/doRelease.go +++ /dev/null @@ -1,171 +0,0 @@ -package main - -import ( - "bytes" - "crypto/sha256" - "errors" - "fmt" - "os" - "os/exec" - "path/filepath" - "strings" - "time" - - "go.wit.com/lib/config" - "go.wit.com/lib/debian" - "go.wit.com/lib/gui/shell" - "go.wit.com/log" -) - -func doRelease() (string, error) { - // all paths should be relative to this BaseDir path - if err := os.Chdir(config.GetPanic("BaseDir")); err != nil { - log.Info("could not change to dir", config.GetPanic("BaseDir"), err) - panic("could not change to dir") - } - shell.RunVerbose([]string{"rm", "-rf", "dists"}) - - if err := os.MkdirAll("dists/sid/main/binary-amd64", 0755); err != nil { - log.Info("did not work", err) - } else { - log.Info("did work") - } - - if err := os.Chdir(me.pb.BaseDir); err != nil { - me.sh.BadExit("no '"+me.pb.BaseDir+"' directory", err) - } - - if !shell.IsDir("pool/") { - me.sh.BadExit("no "+filepath.Join(me.pb.BaseDir, "pool")+" directory", errors.New("mount -a ? missing wit/pool/")) - } - - log.Info("Processing dir", filepath.Join(me.pb.BaseDir, "pool")) - - // arch := "amd64" - - newest := doGetNewest("amd64") - newest.SortPackage() - thefile := debian.MakePackagesFile(newest) - fullname := "dists/sid/main/binary-amd64/Packages" - if err := os.WriteFile(fullname, []byte(thefile), os.ModePerm); err != nil { - return fullname, err - } - - r, err := shell.RunVerbose([]string{"gzip", "-k", fullname}) - log.Info(r, err) - // r, err := shell.RunVerbose([]string{"gzip", fullname}) - // panic("blah") - // shell.RunVerbose([]string{"bzip2", "-k", fullname}) - // shell.RunVerbose([]string{"bzip2", fullname}) - - allfiles, _ := FindFiles("dists/sid/main") - for i, filename := range allfiles { - log.Info(i, filename) - } - - releasePath := filepath.Join("dists/sid", "Release") - - rfile, _ := os.OpenFile(releasePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) - fmt.Fprintf(rfile, "Origin: WIT.COM Debian Sid\n") - fmt.Fprintf(rfile, "Label: WIT.COM Debian Sid\n") - fmt.Fprintf(rfile, "Suite: sid\n") - fmt.Fprintf(rfile, "Codename: sid\n") - fmt.Fprintf(rfile, "Date: %s\n", time.Now().UTC().Format(time.RFC1123Z)) - fmt.Fprintf(rfile, "Architectures: riscv64 amd64 arm64 all\n") - fmt.Fprintf(rfile, "Components: main\n") - fmt.Fprintf(rfile, "Description: Tooling for RiscV, Semiconductor Designs & Private Clouds\n") - - /* - fmt.Fprintf(rfile, "MD5SUM:\n") - for i, filename := range allfiles { - log.Info(i, filename) - fileBytes, _ := os.ReadFile(filename) - sum := fmt.Sprintf("%x", md5.Sum(fileBytes)) // deprecated - newfile := strings.TrimPrefix(filename, "dists/sid/") - fmt.Fprintf(rfile, " %s %d %s\n", sum, len(fileBytes), newfile) - } - fmt.Fprintf(rfile, "SHA1:\n") - for i, filename := range allfiles { - log.Info(i, filename) - fileBytes, _ := os.ReadFile(filename) - sum := fmt.Sprintf("%x", sha1.Sum(fileBytes)) - newfile := strings.TrimPrefix(filename, "dists/sid/") - fmt.Fprintf(rfile, " %s %d %s\n", sum, len(fileBytes), newfile) - } - */ - fmt.Fprintf(rfile, "SHA256:\n") - for i, filename := range allfiles { - log.Info(i, filename) - fileBytes, _ := os.ReadFile(filename) - sum := fmt.Sprintf("%x", sha256.Sum256(fileBytes)) - newfile := strings.TrimPrefix(filename, "dists/sid/") - fmt.Fprintf(rfile, " %s %d %s\n", sum, len(fileBytes), newfile) - } - // fmt.Fprintf(rfile, "SHA1:\n") - // fmt.Fprintf(rfile, "SHA256:\n") - rfile.Close() - - gpgKeyID := config.GetPanic("gpgKeyID") - // Sign the file - log.Println("Signing with GPG key:", gpgKeyID) - - 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 { - log.Printf("failed to create InRelease: %v\n", err) - } - - // Create Release.gpg - cmdDetachedSign := exec.Command("gpg", "--default-key", gpgKeyID, "-abs", "-o", filepath.Join(distPath, "Release.gpg"), releasePath) - if err := runCommand(cmdDetachedSign); err != nil { - log.Printf("failed to create Release.gpg: %v\n", err) - } - /* - var sum string - switch name { - case "MD5Sum": - sum = fmt.Sprintf("%x", md5.Sum(fileBytes)) - case "SHA1": - sum = fmt.Sprintf("%x", sha1.Sum(fileBytes)) - case "SHA256": - // FIX 3: Use the correct sha256.Sum256 function. - sum = fmt.Sprintf("%x", sha256.Sum256(fileBytes)) - */ - - log.Info("Package file:", fullname) - log.Info("Release file:", releasePath) - log.Info("InRelease file:", filepath.Join(distPath, "InRelease")) - cmd := []string{"apt-get", "update"} - cmd = append(cmd, "-o", "Dir::Etc::sourcelist=/etc/apt/sources.list.d/wit.list") - cmd = append(cmd, "-o", "Dir::Etc::sourceparts=/dev/null") - cmd = append(cmd, "-o", "APT::Get::List-Cleanup=0") - log.Info("apt update :", cmd) - log.Info("") - log.Info("Finished Everything") - log.Info("") - - if config.Verbose() { - log.Info("") - shell.RunVerbose(cmd) - log.Info("") - log.Info("") - log.Info("Local file:", "/var/lib/apt/lists/mirrors.wit.com_wit_dists_sid_main_binary-amd64_Packages") - log.Info("") - shell.RunVerbose([]string{"head", "-n", "15", "/var/lib/apt/lists/mirrors.wit.com_wit_dists_sid_main_binary-amd64_Packages"}) - log.Info("apt install :", "apt install wit-tools") - log.Info("") - } - - return "did everything", nil -} - -func runCommand(cmd *exec.Cmd) error { - var stderr bytes.Buffer - cmd.Stderr = &stderr - err := cmd.Run() - if err != nil { - return fmt.Errorf("command '%s' failed: %v\nStderr: %s", cmd.String(), err, stderr.String()) - } - return nil -} diff --git a/main.go b/main.go index 0995076..89435e0 100644 --- a/main.go +++ b/main.go @@ -97,7 +97,9 @@ func main() { } if argv.SignRelease != nil { - s, err = doRelease() + err = doPurge() + s, err = makePackagesFile("riscv64") + err = doSignRelease() } if argv.Everything != nil { @@ -124,10 +126,38 @@ func main() { s = "newest .deb files table: " + all.PrintTable() log.Info("newest files are:", s) + err = doPurge() + if err != nil { + me.sh.BadExit("could not purge dists/", err) + } + // make and GPG sign the Release files - s, err = doRelease() + s, err = makePackagesFile("riscv64") + s, err = makePackagesFile("amd64") + s, err = makePackagesFile("arm64") + err = doSignRelease() } + /* + add --update + cmd := []string{"apt-get", "update"} + cmd = append(cmd, "-o", "Dir::Etc::sourcelist=/etc/apt/sources.list.d/wit.list") + cmd = append(cmd, "-o", "Dir::Etc::sourceparts=/dev/null") + cmd = append(cmd, "-o", "APT::Get::List-Cleanup=0") + log.Info("apt update :", cmd) + if argv.Update { + log.Info("") + shell.RunVerbose(cmd) + log.Info("") + log.Info("") + // log.Info("Local file:", "/var/lib/apt/lists/mirrors.wit.com_wit_dists_sid_main_binary-"+arch+"_Packages") + // log.Info("") + // shell.RunVerbose([]string{"head", "-n", "15", "/var/lib/apt/lists/mirrors.wit.com_wit_dists_sid_main_binary-" + arch + "_Packages"}) + // log.Info("apt install :", "apt install wit-tools") + // log.Info("") + } + */ + if err != nil { me.sh.BadExit(s, err) } diff --git a/makePackagesFile.go b/makePackagesFile.go new file mode 100644 index 0000000..650a12c --- /dev/null +++ b/makePackagesFile.go @@ -0,0 +1,163 @@ +package main + +import ( + "bytes" + "crypto/sha256" + "errors" + "fmt" + "os" + "os/exec" + "path/filepath" + "strings" + "time" + + "go.wit.com/lib/config" + "go.wit.com/lib/debian" + "go.wit.com/lib/gui/shell" + "go.wit.com/log" +) + +func doPurge() error { + // all paths should be relative to this BaseDir path + if err := os.Chdir(config.GetPanic("BaseDir")); err != nil { + log.Info("could not change to dir", config.GetPanic("BaseDir"), err) + panic("could not change to dir") + } + var err error + _, err = shell.RunVerbose([]string{"rm", "-rf", "dists"}) + + return err +} + +func makePackagesFile(arch string) (string, error) { + os.Chdir(config.GetPanic("BaseDir")) + + if err := os.MkdirAll("dists/sid/main/binary-"+arch, 0755); err != nil { + log.Info("did not work", err) + } else { + log.Info("did work") + } + + if err := os.Chdir(me.pb.BaseDir); err != nil { + me.sh.BadExit("no '"+me.pb.BaseDir+"' directory", err) + } + + if !shell.IsDir("pool/") { + me.sh.BadExit("no "+filepath.Join(me.pb.BaseDir, "pool")+" directory", errors.New("mount -a ? missing wit/pool/")) + } + + log.Info("Processing dir", filepath.Join(me.pb.BaseDir, "pool")) + + newest := doGetNewest(arch) + newest.SortPackage() + thefile := debian.MakePackagesFile(newest) + fullname := "dists/sid/main/binary-" + arch + "/Packages" + if err := os.WriteFile(fullname, []byte(thefile), 0644); err != nil { + return fullname, err + } + + r, err := shell.RunVerbose([]string{"gzip", "-k", fullname}) + log.Info(r, err) + + return fullname + " is created", err +} + +// r, err := shell.RunVerbose([]string{"gzip", fullname}) +// panic("blah") +// shell.RunVerbose([]string{"bzip2", "-k", fullname}) +// shell.RunVerbose([]string{"bzip2", fullname}) + +func doSignRelease() error { + allfiles, _ := FindFiles("dists/sid/main") + for i, filename := range allfiles { + log.Info(i, filename) + } + + releasePath := filepath.Join("dists/sid", "Release") + + rfile, _ := os.OpenFile(releasePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) + fmt.Fprintf(rfile, "Origin: WIT.COM Debian Sid\n") + fmt.Fprintf(rfile, "Label: WIT.COM Debian Sid\n") + fmt.Fprintf(rfile, "Suite: sid\n") + fmt.Fprintf(rfile, "Codename: sid\n") + fmt.Fprintf(rfile, "Date: %s\n", time.Now().UTC().Format(time.RFC1123Z)) + fmt.Fprintf(rfile, "Architectures: riscv64 amd64 arm64 all\n") + fmt.Fprintf(rfile, "Components: main\n") + fmt.Fprintf(rfile, "Description: Tooling for RiscV, Semiconductor Designs & Private Clouds\n") + + /* + fmt.Fprintf(rfile, "MD5SUM:\n") + for i, filename := range allfiles { + log.Info(i, filename) + fileBytes, _ := os.ReadFile(filename) + sum := fmt.Sprintf("%x", md5.Sum(fileBytes)) // deprecated + newfile := strings.TrimPrefix(filename, "dists/sid/") + fmt.Fprintf(rfile, " %s %d %s\n", sum, len(fileBytes), newfile) + } + fmt.Fprintf(rfile, "SHA1:\n") + for i, filename := range allfiles { + log.Info(i, filename) + fileBytes, _ := os.ReadFile(filename) + sum := fmt.Sprintf("%x", sha1.Sum(fileBytes)) + newfile := strings.TrimPrefix(filename, "dists/sid/") + fmt.Fprintf(rfile, " %s %d %s\n", sum, len(fileBytes), newfile) + } + */ + fmt.Fprintf(rfile, "SHA256:\n") + for i, filename := range allfiles { + log.Info(i, filename) + fileBytes, _ := os.ReadFile(filename) + sum := fmt.Sprintf("%x", sha256.Sum256(fileBytes)) + newfile := strings.TrimPrefix(filename, "dists/sid/") + fmt.Fprintf(rfile, " %s %d %s\n", sum, len(fileBytes), newfile) + } + // fmt.Fprintf(rfile, "SHA1:\n") + // fmt.Fprintf(rfile, "SHA256:\n") + rfile.Close() + + gpgKeyID := config.GetPanic("gpgKeyID") + // Sign the file + log.Println("Signing with GPG key:", gpgKeyID) + + 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 { + log.Printf("failed to create InRelease: %v\n", err) + } + + // Create Release.gpg + cmdDetachedSign := exec.Command("gpg", "--default-key", gpgKeyID, "-abs", "-o", filepath.Join(distPath, "Release.gpg"), releasePath) + if err := runCommand(cmdDetachedSign); err != nil { + log.Printf("failed to create Release.gpg: %v\n", err) + } + /* + var sum string + switch name { + case "MD5Sum": + sum = fmt.Sprintf("%x", md5.Sum(fileBytes)) + case "SHA1": + sum = fmt.Sprintf("%x", sha1.Sum(fileBytes)) + case "SHA256": + // FIX 3: Use the correct sha256.Sum256 function. + sum = fmt.Sprintf("%x", sha256.Sum256(fileBytes)) + */ + + log.Info("Release file:", releasePath) + log.Info("InRelease file:", filepath.Join(distPath, "InRelease")) + log.Info("") + log.Info("Finished Everything") + log.Info("") + + return nil +} + +func runCommand(cmd *exec.Cmd) error { + var stderr bytes.Buffer + cmd.Stderr = &stderr + err := cmd.Run() + if err != nil { + return fmt.Errorf("command '%s' failed: %v\nStderr: %s", cmd.String(), err, stderr.String()) + } + return nil +} -- cgit v1.2.3