commit 7548d1d8e816c1c0d471548f38bab7ef009332af
parent 911a3082c22dac3e8bc6670a200683e4b9d9b21d
Author: Paco Esteban <paco@e1e0.net>
Date: Mon, 2 Mar 2020 19:50:35 +0100
rewrite of Daniel's python script
Diffstat:
5 files changed, 148 insertions(+), 0 deletions(-)
diff --git a/showvictims/.gitignore b/showvictims/.gitignore
@@ -0,0 +1 @@
+port-showvictims
diff --git a/showvictims/LICENSE b/showvictims/LICENSE
@@ -0,0 +1,13 @@
+Copyright (c) 2020 Paco Esteban <paco@e1e0.net>
+
+Permission to use, copy, modify, and distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/showvictims/Makefile b/showvictims/Makefile
@@ -0,0 +1,23 @@
+BINARY=port-showvictims
+
+VERSION=v0.1.0
+PREFIX=/usr/local
+OS=`uname | tr "[:upper:]" "[:lower:]"`
+ARCH="amd64"
+
+LDFLAGS=-ldflags "-X main.Version=${VERSION} -w"
+
+.DEFAULT: ${BINARY}
+
+${BINARY}: main.go
+ @echo "Build for ${OS}(${ARCH})"
+ GOOS=${OS} GOARCH=${ARCH} \
+ go build ${LDFLAGS} -o ${BINARY}
+
+.PHONY: clean install
+clean:
+ rm -rf ${BINARY}
+
+install: ${BINARY}
+ install -m 0755 ${BINARY} ${PREFIX}/bin/
+ install -m 0644 ${BINARY}.1 ${PREFIX}/share/man/man1/
diff --git a/showvictims/main.go b/showvictims/main.go
@@ -0,0 +1,71 @@
+// Look for consumers of a given OpenBSD port.
+// reimplementation of Daniel Jakots' python script of the same purpose
+package main
+
+import (
+ "database/sql"
+ "flag"
+ "fmt"
+ "log"
+ "os"
+ "strings"
+
+ _ "github.com/mattn/go-sqlite3"
+)
+
+var Version string
+
+func main() {
+ ver := flag.Bool("v", false, "Shows version and exists")
+ depType := flag.String("t", "run,test,lib,build", "Dependencies to look for")
+ flag.Parse()
+
+ if *ver {
+ fmt.Printf("%s\n", Version)
+ os.Exit(0)
+ }
+
+ if len(flag.Args()) < 1 {
+ flag.Usage()
+ os.Exit(1)
+ }
+
+ db, err := sql.Open("sqlite3", "/usr/local/share/sqlports")
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer db.Close()
+
+ // TODO: better deal with this ... it goes directly to an SQL query.
+ // run to the hills ! run for your lives !
+ var dependencies []string
+ deps := strings.Split(*depType, ",")
+ for _, x := range deps {
+ dependencies = append(dependencies, strings.ToUpper(x)+"_DEPENDS")
+ }
+
+ pkg := flag.Args()[0]
+ fmt.Printf("Consumers for %s:\n", pkg)
+
+ for _, d := range dependencies {
+ baseQuery := "SELECT FULLPKGPATH FROM Ports where "
+ rows, err := db.Query(baseQuery+d+" like ?", "%"+pkg+"%")
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer rows.Close()
+
+ fmt.Printf("%s\n", d)
+ for rows.Next() {
+ var pkgpath string
+ if err := rows.Scan(&pkgpath); err != nil {
+ log.Fatal(err)
+ }
+ fmt.Printf(" > %s\n", pkgpath)
+ }
+ if err := rows.Err(); err != nil {
+ log.Fatal(err)
+ }
+ }
+
+}
diff --git a/showvictims/port-showvictims.1 b/showvictims/port-showvictims.1
@@ -0,0 +1,40 @@
+.Dd March 1, 2020
+.Dt PORT-SHOWVICTIMS 1
+.Os
+.Sh NAME
+.Nm port-showvictims
+.Nd finds consumers of a given port
+.Sh SYNOPSYS
+.Nm
+.Op Fl v
+.Op Fl t Ar dep_type
+.Op Ar port
+.Sh DESCRIPTION
+.Nm
+uses the sqlite3 database from databases/sqlports to search for consumers on
+a given port.
+.Pp
+The options are as follows:
+.Bl -tag -width Ds
+.It Fl v
+Prints version and exits.
+.It Fl t Ar dep_type
+This is a comma separated list of dependency types to look for.
+They can be
+.Ar run ,
+.Ar test ,
+.Ar lib ,
+.Ar build .
+By default it looks for all.
+.It Ar port
+Port to check consumers, this is mandatory.
+.El
+.Sh EXIT STATUS
+.Ex -std
+.Sh AUTHORS
+.An Paco Esteban
+.Mt paco@e1e0.net
+.Sh BUGS
+Probably many.
+If you find one and want to send a patch, please to so to:
+.Mt patches@e1e0.net