From ef98499aa9587488f55f3776554481d5254c824c Mon Sep 17 00:00:00 2001 From: Jeffrey Serio <23226432+hyperreal64@users.noreply.github.com> Date: Fri, 29 Mar 2024 19:59:29 -0500 Subject: [PATCH] Add Kali; update repo url --- README.md | 2 +- README.org | 31 ------------------------ almalinux/main.go | 2 +- command/main.go | 26 ++++++++++++-------- debian/main.go | 2 +- devuan/main.go | 2 +- fedora/main.go | 2 +- freebsd/main.go | 2 +- go.mod | 2 +- kali/main.go | 62 +++++++++++++++++++++++++++++++++++++++++++++++ main.go | 2 +- nixos/main.go | 2 +- parrot/main.go | 2 +- qubes/main.go | 2 +- rocky/main.go | 2 +- tails/main.go | 2 +- 16 files changed, 91 insertions(+), 54 deletions(-) delete mode 100644 README.org create mode 100644 kali/main.go diff --git a/README.md b/README.md index 0563d2a..e714f79 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ export TRANSMISSION_RPC_URL=10.0.0.42 Install with Go: ``` bash -go install git.sr.ht/~hyperreal/go-torrent-helper@latest +go install git.hyperreal.coffee/go-torrent-helper@latest ``` ## Usage diff --git a/README.org b/README.org deleted file mode 100644 index a7ee9ba..0000000 --- a/README.org +++ /dev/null @@ -1,31 +0,0 @@ -* go-torrent-helper - -This is a helper program to add and remove torrents from a transmission-daemon instance. - -To use, make sure `TRANSMISSION_RPC_URL` is exported in the shell: -#+begin_src shell -export TRANSMISSION_RPC_URL=10.0.0.42 -#+end_src - -Install with Go: -#+begin_src shell -go install git.sr.ht/~hyperreal/go-torrent-helper@latest -#+end_src - -Example usage: -#+begin_src shell -# Add Fedora torrents -go-torrent-helper add -distro fedora -relver 38 - -# Remove NixOS torrents -go-torrent-helper remove -distro nixos - -# Add Rocky Linux torrents -go-torrent-helper add -distro rocky -relver 9.2 - -# Remove older Rocky Linux torrents -go-torrent-helper remove -distro rocky -relver 8.1 - -# If not -relver flag is supplied for the remove subcommand, remove all torrents for given distro -go-torrent-helper remove -distro debian -#+end_src diff --git a/almalinux/main.go b/almalinux/main.go index ca81402..e27e757 100644 --- a/almalinux/main.go +++ b/almalinux/main.go @@ -4,7 +4,7 @@ import ( "fmt" "log" - "git.sr.ht/~hyperreal/go-torrent-helper/common" + "git.hyperreal.coffee/go-torrent-helper/common" "github.com/hekmon/transmissionrpc" ) diff --git a/command/main.go b/command/main.go index cae52bd..c858aca 100644 --- a/command/main.go +++ b/command/main.go @@ -6,16 +6,17 @@ import ( "fmt" "os" - "git.sr.ht/~hyperreal/go-torrent-helper/almalinux" - "git.sr.ht/~hyperreal/go-torrent-helper/debian" - "git.sr.ht/~hyperreal/go-torrent-helper/devuan" - "git.sr.ht/~hyperreal/go-torrent-helper/fedora" - "git.sr.ht/~hyperreal/go-torrent-helper/freebsd" - "git.sr.ht/~hyperreal/go-torrent-helper/nixos" - "git.sr.ht/~hyperreal/go-torrent-helper/parrot" - "git.sr.ht/~hyperreal/go-torrent-helper/qubes" - "git.sr.ht/~hyperreal/go-torrent-helper/rocky" - "git.sr.ht/~hyperreal/go-torrent-helper/tails" + "git.hyperreal.coffee/go-torrent-helper/almalinux" + "git.hyperreal.coffee/go-torrent-helper/debian" + "git.hyperreal.coffee/go-torrent-helper/devuan" + "git.hyperreal.coffee/go-torrent-helper/fedora" + "git.hyperreal.coffee/go-torrent-helper/freebsd" + "git.hyperreal.coffee/go-torrent-helper/kali" + "git.hyperreal.coffee/go-torrent-helper/nixos" + "git.hyperreal.coffee/go-torrent-helper/parrot" + "git.hyperreal.coffee/go-torrent-helper/qubes" + "git.hyperreal.coffee/go-torrent-helper/rocky" + "git.hyperreal.coffee/go-torrent-helper/tails" "github.com/hekmon/transmissionrpc" ) @@ -131,6 +132,7 @@ func (l *ListCmd) Run(d Distro) error { "devuan", "fedora", "freebsd", + "kali", "nixos", "parrot", "qubes", @@ -211,6 +213,10 @@ func Root(args []string) error { fb := &freebsd.FreeBSD{NameSubstr: "FreeBSD", Relver: relver} return cmd.Run(fb) + case "kali": + k := &kali.Kali{NameSubstr: "kali-linux", Relver: relver} + return cmd.Run(k) + case "nixos": n := &nixos.Nixos{NameSubstr: "nixos"} return cmd.Run(n) diff --git a/debian/main.go b/debian/main.go index dd9b04d..948ea0e 100644 --- a/debian/main.go +++ b/debian/main.go @@ -4,7 +4,7 @@ import ( "fmt" "log" - "git.sr.ht/~hyperreal/go-torrent-helper/common" + "git.hyperreal.coffee/go-torrent-helper/common" "github.com/hekmon/transmissionrpc" ) diff --git a/devuan/main.go b/devuan/main.go index e263b02..8583b90 100644 --- a/devuan/main.go +++ b/devuan/main.go @@ -4,7 +4,7 @@ import ( "fmt" "log" - "git.sr.ht/~hyperreal/go-torrent-helper/common" + "git.hyperreal.coffee/go-torrent-helper/common" "github.com/hekmon/transmissionrpc" ) diff --git a/fedora/main.go b/fedora/main.go index a64422a..6810706 100644 --- a/fedora/main.go +++ b/fedora/main.go @@ -5,7 +5,7 @@ import ( "log" "strings" - "git.sr.ht/~hyperreal/go-torrent-helper/common" + "git.hyperreal.coffee/go-torrent-helper/common" "github.com/PuerkitoBio/goquery" "github.com/hekmon/transmissionrpc" ) diff --git a/freebsd/main.go b/freebsd/main.go index f27e8c0..701b8a0 100644 --- a/freebsd/main.go +++ b/freebsd/main.go @@ -6,7 +6,7 @@ import ( "log" "strings" - "git.sr.ht/~hyperreal/go-torrent-helper/common" + "git.hyperreal.coffee/go-torrent-helper/common" "github.com/hekmon/transmissionrpc" ) diff --git a/go.mod b/go.mod index 41cb3e0..26d4458 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module git.sr.ht/~hyperreal/go-torrent-helper +module git.hyperreal.coffee/go-torrent-helper go 1.20 diff --git a/kali/main.go b/kali/main.go new file mode 100644 index 0000000..5758db0 --- /dev/null +++ b/kali/main.go @@ -0,0 +1,62 @@ +package kali + +import ( + "fmt" + "log" + "strings" + + "git.hyperreal.coffee/go-torrent-helper/common" + "github.com/PuerkitoBio/goquery" + "github.com/hekmon/transmissionrpc" +) + +type Kali struct { + NameSubstr string + Relver string + URL string +} + +func (k Kali) AddNewTorrents(transmissionbt *transmissionrpc.Client) error { + // Send HTTP GET request and receive response + k.URL = fmt.Sprintf("https://cdimage.kali.org/kali-%s/", k.Relver) + respBody, err := common.GetResponse(k.URL) + if err != nil { + return err + } + + // Get a goquery doc from response body + doc, err := goquery.NewDocumentFromReader(respBody) + if err != nil { + return err + } + + // Extract torrent URLs from web page source + var torrentURLs []string + doc.Find("a").Each(func(i int, s *goquery.Selection) { + if strings.Contains(s.Text(), ".torrent") { + torrentURLs = append(torrentURLs, fmt.Sprintf("%s/kali-linux-%s-%s.torrent", k.URL, k.Relver, s.Text())) + } + }) + + // Add torrents to Transmission instance + for _, torrentURL := range torrentURLs { + torrent, err := transmissionbt.TorrentAdd(&transmissionrpc.TorrentAddPayload{ + Filename: &torrentURL, + }) + if err != nil { + return err + } + + log.Printf("%s added\n", *torrent.Name) + } + + return nil +} + +func (k Kali) RemoveOldTorrents(transmissionbt *transmissionrpc.Client) error { + if err := common.RemoveTorrents(k.NameSubstr, k.Relver, transmissionbt); err != nil { + return err + } + + return nil +} diff --git a/main.go b/main.go index 01ae222..bcf8907 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,7 @@ import ( "log" "os" - "git.sr.ht/~hyperreal/go-torrent-helper/command" + "git.hyperreal.coffee/go-torrent-helper/command" ) func main() { diff --git a/nixos/main.go b/nixos/main.go index 1c1fbcd..290fa10 100644 --- a/nixos/main.go +++ b/nixos/main.go @@ -6,7 +6,7 @@ import ( "io/ioutil" "log" - "git.sr.ht/~hyperreal/go-torrent-helper/common" + "git.hyperreal.coffee/go-torrent-helper/common" "github.com/hekmon/transmissionrpc" ) diff --git a/parrot/main.go b/parrot/main.go index 253fa6e..fc02204 100644 --- a/parrot/main.go +++ b/parrot/main.go @@ -5,7 +5,7 @@ import ( "log" "strings" - "git.sr.ht/~hyperreal/go-torrent-helper/common" + "git.hyperreal.coffee/go-torrent-helper/common" "github.com/PuerkitoBio/goquery" "github.com/hekmon/transmissionrpc" ) diff --git a/qubes/main.go b/qubes/main.go index 62ed17e..367bfd1 100644 --- a/qubes/main.go +++ b/qubes/main.go @@ -5,7 +5,7 @@ import ( "log" "strings" - "git.sr.ht/~hyperreal/go-torrent-helper/common" + "git.hyperreal.coffee/go-torrent-helper/common" "github.com/PuerkitoBio/goquery" "github.com/hekmon/transmissionrpc" ) diff --git a/rocky/main.go b/rocky/main.go index b88d19c..9d0107d 100644 --- a/rocky/main.go +++ b/rocky/main.go @@ -5,7 +5,7 @@ import ( "log" "strings" - "git.sr.ht/~hyperreal/go-torrent-helper/common" + "git.hyperreal.coffee/go-torrent-helper/common" "github.com/PuerkitoBio/goquery" "github.com/hekmon/transmissionrpc" ) diff --git a/tails/main.go b/tails/main.go index a6428e4..02d5506 100644 --- a/tails/main.go +++ b/tails/main.go @@ -4,7 +4,7 @@ import ( "fmt" "log" - "git.sr.ht/~hyperreal/go-torrent-helper/common" + "git.hyperreal.coffee/go-torrent-helper/common" "github.com/hekmon/transmissionrpc" )