diff --git a/src/go.mod b/src/go.mod new file mode 100644 index 0000000..e32e4bb --- /dev/null +++ b/src/go.mod @@ -0,0 +1,5 @@ +module ppp/v2 + +go 1.21.0 + +require github.com/ulikunitz/xz v0.5.11 diff --git a/src/go.sum b/src/go.sum new file mode 100644 index 0000000..996da64 --- /dev/null +++ b/src/go.sum @@ -0,0 +1,2 @@ +github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8= +github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= diff --git a/src/main.go b/src/main.go new file mode 100644 index 0000000..e706ed2 --- /dev/null +++ b/src/main.go @@ -0,0 +1,74 @@ +package main + +import ( + "bufio" + "io" + "log" + "net/http" + "os" + "strings" + + "github.com/ulikunitz/xz" +) + +func main() { + base := os.Args[1] + target := os.Args[2] + + basePackages := processFile(base) + targetPackages := processFile(target) + + compare(basePackages, targetPackages) +} + +func processFile(url string) map[string]string { + + resp, err := http.Get(url) + if err != nil { + panic(err) + } + defer resp.Body.Close() + rdr := io.Reader(resp.Body) + if strings.HasSuffix(url, ".xz") { + r, err := xz.NewReader(resp.Body) + if err != nil { + log.Fatalf("xz error %s", err) + } + rdr = r + } + + packages := make(map[string]string) + var currentPackage string + scanner := bufio.NewScanner(rdr) + for scanner.Scan() { + line := scanner.Text() + + if line == "" { + currentPackage = "" + } + + if currentPackage == "" { + if strings.HasPrefix(line, "Package: ") { + currentPackage = strings.TrimPrefix(line, "Package: ") + } + } else { + if strings.HasPrefix(line, "Version: ") { + packages[currentPackage] = strings.TrimPrefix(line, "Version: ") + } + } + } + return packages + +} + +func compare(basePackages map[string]string, targetPackages map[string]string) { + for pack, version := range targetPackages { + if baseVersion, ok := basePackages[pack]; ok { + if baseVersion != version { + println(pack) + } + } else { + println(pack) + } + } +}