summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--argv.go2
-rw-r--r--doIncoming.go76
-rw-r--r--doWalk.go75
-rw-r--r--main.go82
-rw-r--r--stuff.go2
5 files changed, 161 insertions, 76 deletions
diff --git a/argv.go b/argv.go
index ddbea91..5f99c69 100644
--- a/argv.go
+++ b/argv.go
@@ -18,7 +18,7 @@ var argv args
type args struct {
List *EmptyCmd `arg:"subcommand:list" help:"show the packages"`
- Walk *EmptyCmd `arg:"subcommand:scan" help:"walk the filesystem for new .deb files"`
+ Walk *EmptyCmd `arg:"subcommand:walk" help:"walk the filesystem for new .deb files"`
Update *EmptyCmd `arg:"subcommand:update" help:"update the apt repo"`
Incoming *EmptyCmd `arg:"subcommand:incoming" help:"handle the incoming directory"`
DryRun bool `arg:"--dry-run" help:"only show what would be packaged"`
diff --git a/doIncoming.go b/doIncoming.go
new file mode 100644
index 0000000..f077db7
--- /dev/null
+++ b/doIncoming.go
@@ -0,0 +1,76 @@
+package main
+
+import (
+ "crypto/md5"
+ "os"
+ "path/filepath"
+ "strings"
+
+ "go.wit.com/lib/config"
+ "go.wit.com/lib/gui/shell"
+ "go.wit.com/log"
+)
+
+func doIncoming() (string, error) {
+ os.Chdir(me.mirrorsDir)
+
+ for p := range me.pb.IterAll() {
+ log.Info(p.Package, p.Filename)
+ }
+
+ err := filepath.Walk("pool", func(path string, info os.FileInfo, err error) error {
+ if err != nil {
+ return err
+ }
+
+ if !info.IsDir() && strings.HasSuffix(info.Name(), ".deb") {
+ found := me.pb.FindByFilename(path)
+ if found == nil {
+ log.Printf("new file %s\n", path)
+ return nil
+ }
+ 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)
+ 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)
+ log.Fatal("Failed to create destination directory: %v", err)
+ }
+ if config.Exists(newfilename) {
+ olddata, _ := os.ReadFile(path)
+ newdata, _ := os.ReadFile(newfilename)
+ oldmd5 := md5.Sum(olddata)
+ newmd5 := md5.Sum(newdata)
+ if oldmd5 == newmd5 {
+ log.Info("files are the same", md5.Sum(olddata), md5.Sum(newdata))
+ } else {
+ shell.RunVerbose([]string{"dpkg", "-I", path})
+ shell.RunVerbose([]string{"dpkg", "-I", newfilename})
+ log.Printf("different checksums: %s %s\n", path, newfilename)
+ log.Printf("md5sum old %x vs new %x\n", md5.Sum(olddata), md5.Sum(newdata))
+ }
+ me.sh.BadExit("file already exists", nil)
+ }
+ os.Rename(path, newfilename)
+ log.Printf("%s moved incoming oldname %s newname: %s\n", found.Package, path, newfilename)
+ me.sh.GoodExit("file moved")
+ return nil
+ }
+ log.Info("already processed", path)
+
+ // Get control info
+ // cmd := exec.Command("dpkg-deb", "-I", path)
+ // var out bytes.Buffer
+ // cmd.Stdout = &out
+ // if err := cmd.Run(); err != nil {
+ // return fmt.Errorf("failed to run dpkg-deb on %s: %v", path, err)
+ // }
+
+ }
+ return nil
+ })
+
+ return "scanned incoming", err
+}
diff --git a/doWalk.go b/doWalk.go
new file mode 100644
index 0000000..bc2d999
--- /dev/null
+++ b/doWalk.go
@@ -0,0 +1,75 @@
+package main
+
+import (
+ "os"
+
+ "go.wit.com/lib/config"
+ "go.wit.com/lib/debian"
+ "go.wit.com/lib/protobuf/zoopb"
+ "go.wit.com/log"
+)
+
+func doWalk() (string, error) {
+ os.Chdir(me.mirrorsDir)
+
+ // 2. Scan pool directory for .deb files and gather info
+ log.Printf("Scanning for .deb files in %s\n", poolDir)
+ debInfos, err := scanDebs(poolDir, 35)
+ if err != nil {
+ log.Printf("Failed to scan .deb files: %v\n", err)
+ me.sh.BadExit("scan pool scan dir", err)
+ }
+
+ var counter int
+ for _, deb := range debInfos {
+ newdeb := new(zoopb.Package)
+ newdeb.Filename = deb.Filename
+ newdeb.MD5SUM = deb.MD5Sum
+ newdeb.SHA1 = deb.SHA1Sum
+ newdeb.SHA256 = deb.SHA256Sum
+
+ // log.Info("len(CONTROLDATA)", len(deb.ControlData))
+ // log.Sprintf("VAR='%s' VAL='%s'\n", varname, varvalue)
+ // log.Info("%v", deb.ControlData)
+ for varname, varvalue := range deb.ControlData {
+ switch varname {
+ case "Package":
+ newdeb.Package = varvalue
+ case "Version":
+ newdeb.Version = varvalue
+ case "Git-Tag-Date":
+ log.Info("CONVERT THIS TO TIME", varvalue)
+ case "Depends":
+ newdeb.Depends = varvalue
+ case "Build-Depends":
+ newdeb.BuildDepends = varvalue
+ case "Architecture":
+ newdeb.Architecture = varvalue
+ case "Packager":
+ newdeb.Packager = varvalue
+ case "Package-Build-Date":
+ varvalue = "PackageBuildDate"
+ case "URL":
+ newdeb.URL = varvalue
+ default:
+ if ok, err := debian.SetString(newdeb, varname, varvalue); ok {
+ continue
+ } else if err != nil {
+ log.Printf("%v VAR='%s' VAL='%s'\n", err, varname, varvalue)
+ }
+ // todo: add to protomap
+ }
+ }
+ counter += 1
+ me.pb.AppendByFilename(newdeb)
+ config.PrintStrings(newdeb)
+ // arch := deb.ControlData["Architecture"]
+ }
+
+ // footer := me.pb.PrintTable()
+ // log.Info("found so far:", footer)
+
+ config.Save(me.pb)
+ log.Printf("add %d new packages. Total packages.Len()=%d\n", counter, me.pb.Len())
+ return "/home/mirrors/wit/ has been scanned for ne files", nil
+}
diff --git a/main.go b/main.go
index fb8187e..cf777e0 100644
--- a/main.go
+++ b/main.go
@@ -2,10 +2,8 @@ package main
import (
"embed"
- "os"
"go.wit.com/lib/config"
- "go.wit.com/lib/debian"
"go.wit.com/lib/gui/prep"
"go.wit.com/lib/protobuf/zoopb"
"go.wit.com/log"
@@ -38,6 +36,13 @@ func main() {
}
}
+ if me.sh.Cmd == "" {
+ // default behavior when no argv
+ s := log.Sprintf("You have %d packages in %s", me.pb.Len(), me.mirrorsDir)
+ me.sh.GoodExit(s)
+ }
+
+ // default handling of argv subcommands
var s string
var err error
if argv.Incoming != nil {
@@ -56,82 +61,11 @@ func main() {
}
if argv.Update != nil {
- if err = doDistro(); err != nil {
- me.sh.BadExit("boo", err)
- }
- me.sh.GoodExit("")
+ err = doDistro()
}
- log.Printf("You have %d packages in %s\n", me.pb.Len(), me.mirrorsDir)
if err != nil {
me.sh.BadExit(s, err)
}
me.sh.GoodExit(s)
}
-
-func doIncoming() (string, error) {
-
- return "", nil
-}
-
-func doWalk() (string, error) {
- os.Chdir(me.mirrorsDir)
-
- // 2. Scan pool directory for .deb files and gather info
- log.Printf("Scanning for .deb files in %s\n", poolDir)
- debInfos, err := scanDebs(poolDir, 35)
- if err != nil {
- log.Printf("Failed to scan .deb files: %v\n", err)
- me.sh.BadExit("scan pool scan dir", err)
- }
-
- for _, deb := range debInfos {
- newdeb := new(zoopb.Package)
- newdeb.Filename = deb.Filename
- newdeb.MD5SUM = deb.MD5Sum
- newdeb.SHA1 = deb.SHA1Sum
- newdeb.SHA256 = deb.SHA256Sum
-
- // log.Info("len(CONTROLDATA)", len(deb.ControlData))
- // log.Sprintf("VAR='%s' VAL='%s'\n", varname, varvalue)
- // log.Info("%v", deb.ControlData)
- for varname, varvalue := range deb.ControlData {
- switch varname {
- case "Package":
- newdeb.Package = varvalue
- case "Version":
- newdeb.Version = varvalue
- case "Git-Tag-Date":
- log.Info("CONVERT THIS TO TIME", varvalue)
- case "Depends":
- newdeb.Depends = varvalue
- case "Build-Depends":
- newdeb.BuildDepends = varvalue
- case "Architecture":
- newdeb.Architecture = varvalue
- case "Packager":
- newdeb.Packager = varvalue
- case "Package-Build-Date":
- varvalue = "PackageBuildDate"
- case "URL":
- newdeb.URL = varvalue
- default:
- if ok, err := debian.SetString(newdeb, varname, varvalue); ok {
- continue
- } else if err != nil {
- log.Printf("%v VAR='%s' VAL='%s'\n", err, varname, varvalue)
- }
- // todo: add to protomap
- }
- }
- me.pb.AppendByFilename(newdeb)
- // arch := deb.ControlData["Architecture"]
- }
-
- footer := me.pb.PrintTable()
- log.Info("found so far:", footer)
-
- config.Save(me.pb)
- log.Info("len", me.pb.Len())
- return "/home/mirrors/wit/ has been scanned for ne files", nil
-}
diff --git a/stuff.go b/stuff.go
index 7fdc531..faf4cbb 100644
--- a/stuff.go
+++ b/stuff.go
@@ -29,7 +29,7 @@ func scanDebs(root string, count int) ([]DebInfo, error) {
if !info.IsDir() && strings.HasSuffix(info.Name(), ".deb") {
found := me.pb.FindByFilename(path)
if found != nil {
- log.Info("already processed", path)
+ // log.Info("already processed", path)
return nil
}
if count == -1 {