diff --git a/README.md b/README.md deleted file mode 100644 index e714f79..0000000 --- a/README.md +++ /dev/null @@ -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 -``` diff --git a/README.org b/README.org new file mode 100644 index 0000000..3b5f937 --- /dev/null +++ b/README.org @@ -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 \ No newline at end of file diff --git a/command/main.go b/command/main.go index 7242860..cc6f29c 100644 --- a/command/main.go +++ b/command/main.go @@ -5,6 +5,7 @@ import ( "flag" "fmt" "os" + "strconv" "codeberg.org/hyperreal/go-torrent-helper/almalinux" "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 { - 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 { return err } @@ -114,7 +132,24 @@ func (a *AddCmd) 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 { return err } @@ -158,7 +193,7 @@ type Runner interface { func Root(args []string) error { if len(args) < 1 { - return errors.New("You must pass a sub-command") + return errors.New("you must pass a sub-command") } cmds := []Runner{ @@ -179,7 +214,7 @@ func Root(args []string) error { var distro, relver string 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:]) @@ -187,7 +222,7 @@ func Root(args []string) error { if len(os.Args[4:]) == 0 && subcmd == "remove" { relver = "*" } 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 { relver = os.Args[5] } @@ -244,10 +279,10 @@ func Root(args []string) error { return cmd.Run(t) 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) } diff --git a/go-torrent-helper b/go-torrent-helper new file mode 100755 index 0000000..59e8a76 Binary files /dev/null and b/go-torrent-helper differ