mirror of
https://codeberg.org/hyperreal/go-torrent-helper
synced 2024-11-01 08:43:10 +01:00
Refactor; update README
This commit is contained in:
parent
841120a26b
commit
51ef14ac54
34
README.md
34
README.md
@ -1,34 +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:
|
|
||||||
|
|
||||||
``` bash
|
|
||||||
export TRANSMISSION_RPC_URL=10.0.0.42
|
|
||||||
```
|
|
||||||
|
|
||||||
Install with Go:
|
|
||||||
|
|
||||||
``` bash
|
|
||||||
go install git.hyperreal.coffee/go-torrent-helper@latest
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
``` bash
|
|
||||||
# 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
|
|
||||||
```
|
|
31
README.org
Normal file
31
README.org
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
* go-torrent-helper
|
||||||
|
|
||||||
|
This is a helper program to add and remove torrents from a transmission-daemon instance.
|
||||||
|
|
||||||
|
** Installation
|
||||||
|
#+BEGIN_SRC shell
|
||||||
|
go install codeberg.org/hyperreal/go-torrent-helper@latest
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
** Usage
|
||||||
|
#+BEGIN_SRC shell
|
||||||
|
export TX_RPC_URL=localhost
|
||||||
|
export TX_RPC_USER="cat"
|
||||||
|
export TX_RPC_PASS="meow"
|
||||||
|
export TX_RPC_PORT="9091"
|
||||||
|
export TX_RPC_USE_HTTPS="True"
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
*** Add torrents
|
||||||
|
#+BEGIN_SRC shell
|
||||||
|
go-torrent-helper add -distro fedora -relver 50
|
||||||
|
go-torrent-helper add -distro nixos -relver *
|
||||||
|
go-torrent-helper add -distro almalinux -relver 12.4
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
*** Remove torrents
|
||||||
|
#+BEGIN_SRC shell
|
||||||
|
go-torrent-helper remove -distro almalinux -relver 12.4
|
||||||
|
go-torrent-helper remove -distro nixos -relver *
|
||||||
|
go-torrent-helper remove -distro fedora -relver 50
|
||||||
|
#+END_SRC
|
@ -5,6 +5,7 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"codeberg.org/hyperreal/go-torrent-helper/almalinux"
|
"codeberg.org/hyperreal/go-torrent-helper/almalinux"
|
||||||
"codeberg.org/hyperreal/go-torrent-helper/debian"
|
"codeberg.org/hyperreal/go-torrent-helper/debian"
|
||||||
@ -101,7 +102,24 @@ func (l *ListCmd) Init(args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *AddCmd) Run(d Distro) error {
|
func (a *AddCmd) Run(d Distro) error {
|
||||||
client, err := transmissionrpc.New(os.Getenv("TRANSMISSION_RPC_URL"), os.Getenv("TRANSMISSION_RPC_USER"), os.Getenv("TRANSMISSION_RPC_PASSWD"), nil)
|
txRpcUrl := os.Getenv("TX_RPC_URL")
|
||||||
|
txRpcUser := os.Getenv("TX_RPC_USER")
|
||||||
|
txRpcPass := os.Getenv("TX_RPC_PASS")
|
||||||
|
txRpcPort, err := strconv.ParseUint(os.Getenv("TX_RPC_PORT"), 10, 16)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
txRpcUseHTTPS, err := strconv.ParseBool(os.Getenv("TX_RPC_USE_HTTPS"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := transmissionrpc.New(txRpcUrl, txRpcUser, txRpcPass,
|
||||||
|
&transmissionrpc.AdvancedConfig{
|
||||||
|
HTTPS: txRpcUseHTTPS,
|
||||||
|
Port: uint16(txRpcPort),
|
||||||
|
},
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -114,7 +132,24 @@ func (a *AddCmd) Run(d Distro) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *RemoveCmd) Run(d Distro) error {
|
func (r *RemoveCmd) Run(d Distro) error {
|
||||||
client, err := transmissionrpc.New(os.Getenv("TRANSMISSION_RPC_URL"), os.Getenv("TRANSMISSION_RPC_USER"), os.Getenv("TRANSMISSION_RPC_PASSWD"), nil)
|
txRpcUrl := os.Getenv("TX_RPC_URL")
|
||||||
|
txRpcUser := os.Getenv("TX_RPC_USER")
|
||||||
|
txRpcPass := os.Getenv("TX_RPC_PASS")
|
||||||
|
txRpcPort, err := strconv.ParseUint(os.Getenv("TX_RPC_PORT"), 10, 16)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
txRpcUseHTTPS, err := strconv.ParseBool(os.Getenv("TX_RPC_USE_HTTPS"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := transmissionrpc.New(txRpcUrl, txRpcUser, txRpcPass,
|
||||||
|
&transmissionrpc.AdvancedConfig{
|
||||||
|
HTTPS: txRpcUseHTTPS,
|
||||||
|
Port: uint16(txRpcPort),
|
||||||
|
},
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -158,7 +193,7 @@ type Runner interface {
|
|||||||
|
|
||||||
func Root(args []string) error {
|
func Root(args []string) error {
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
return errors.New("You must pass a sub-command")
|
return errors.New("you must pass a sub-command")
|
||||||
}
|
}
|
||||||
|
|
||||||
cmds := []Runner{
|
cmds := []Runner{
|
||||||
@ -179,7 +214,7 @@ func Root(args []string) error {
|
|||||||
var distro, relver string
|
var distro, relver string
|
||||||
|
|
||||||
if len(os.Args[2:]) == 0 {
|
if len(os.Args[2:]) == 0 {
|
||||||
return fmt.Errorf("See -h for usage options")
|
return fmt.Errorf("see -h for usage options")
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Init(os.Args[2:])
|
cmd.Init(os.Args[2:])
|
||||||
@ -187,7 +222,7 @@ func Root(args []string) error {
|
|||||||
if len(os.Args[4:]) == 0 && subcmd == "remove" {
|
if len(os.Args[4:]) == 0 && subcmd == "remove" {
|
||||||
relver = "*"
|
relver = "*"
|
||||||
} else if len(os.Args[4:]) == 0 && subcmd == "add" {
|
} else if len(os.Args[4:]) == 0 && subcmd == "add" {
|
||||||
return fmt.Errorf("Please enter a release version")
|
return fmt.Errorf("please enter a release version")
|
||||||
} else {
|
} else {
|
||||||
relver = os.Args[5]
|
relver = os.Args[5]
|
||||||
}
|
}
|
||||||
@ -244,10 +279,10 @@ func Root(args []string) error {
|
|||||||
return cmd.Run(t)
|
return cmd.Run(t)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Unknown distro: %s", distro)
|
return fmt.Errorf("unknown distro: %s", distro)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf("Unknown subcommand: %s", subcmd)
|
return fmt.Errorf("unknown subcommand: %s", subcmd)
|
||||||
}
|
}
|
||||||
|
BIN
go-torrent-helper
Executable file
BIN
go-torrent-helper
Executable file
Binary file not shown.
Loading…
Reference in New Issue
Block a user