-
-
Notifications
You must be signed in to change notification settings - Fork 600
feat(extras/scripts): update Transmission peer port #2611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
juanlufont
wants to merge
9
commits into
passteque:master
Choose a base branch
from
juanlufont:script-transmission
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+134
−0
Open
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
905ad67
Add script to update Transmission peer port
juanlufont 22c148b
Merge branch 'master' into script-transmission
juanlufont c6d0efd
Merge branch 'master' into script-transmission
juanlufont 3ee4da7
Add script improvements
juanlufont d839868
Add script Transmission script to Dockerfile
juanlufont f509be0
Merge branch 'master' into script-transmission
juanlufont 2d6ab23
Improve error message
juanlufont f8be206
Remove redundant exit 0
juanlufont 08a18a1
Move --quiet out of WGET_OPTS
juanlufont File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| #!/bin/sh | ||
|
|
||
| # Description: This script updates the peer port for the Transmission torrent | ||
| # client using its RPC API. | ||
| # Author: Juan Luis Font | ||
|
|
||
| # default values | ||
| DEFAULT_URL="http://localhost:9091/transmission/rpc" | ||
| WGET_OPTS="--quiet" | ||
|
qdm12 marked this conversation as resolved.
Outdated
|
||
|
|
||
| usage() { | ||
| echo "Usage: $0 [OPTIONS]" | ||
| echo | ||
| echo "Options:" | ||
| echo " -h, --help Show this help message and exit." | ||
| echo " -u, --user USER Specify the Transmission RPC user name." | ||
| echo " (Omit if not required)" | ||
| echo " -p, --pass PASS Specify the Transmission RPC password." | ||
| echo " (Omit if not required)" | ||
| echo " -P, --port PORT Specify the Transmission Peer Port." | ||
| echo " REQUIRED" | ||
|
qdm12 marked this conversation as resolved.
|
||
| echo " -U, --url URL Specify the Transmission RPC URL." | ||
| echo " DEFAULT: ${DEFAULT_URL}" | ||
| echo "Example:" | ||
| echo " $0 -u admin -p **** 40409" | ||
| exit 1 | ||
| } | ||
|
|
||
| while [ $# -gt 0 ]; do | ||
| case "$1" in | ||
| -h | --help) | ||
| usage | ||
| ;; | ||
| -u | --user) | ||
| USERNAME="$2" | ||
| _USECRED=true | ||
| shift 2 | ||
| ;; | ||
| -p | --pass) | ||
| PASSWORD="$2" | ||
| _USECRED=true | ||
| shift 2 | ||
| ;; | ||
| -P | --port) | ||
| PORT="$2" | ||
| shift 2 | ||
| ;; | ||
| -U | --url) | ||
| RPC_URL="$2" | ||
| shift 2 | ||
| ;; | ||
| *) | ||
| echo "Unknown option: $1" | ||
| usage | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| if [ -z "${PORT}" ]; then | ||
| echo "ERROR: No PORT provided!" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ "${_USECRED}" ]; then | ||
| # make sure username AND password were provided | ||
| if [ -z "${USERNAME}" ] || [ -z "${PASSWORD}" ]; then | ||
| echo "ERROR: Username or password not provided." | ||
| exit 1 | ||
|
juanlufont marked this conversation as resolved.
|
||
| else | ||
|
juanlufont marked this conversation as resolved.
Outdated
|
||
| # basic auth options, --auth-no-challenge avoids 409 Conflict | ||
| WGET_OPTS=" | ||
| ${WGET_OPTS} | ||
|
juanlufont marked this conversation as resolved.
Outdated
|
||
| --auth-no-challenge | ||
| --user=${USERNAME} | ||
| --password=${PASSWORD} | ||
| " | ||
| fi | ||
| fi | ||
|
|
||
| if [ -z "${RPC_URL+x}" ]; then | ||
| RPC_URL="${DEFAULT_URL}" | ||
| fi | ||
|
|
||
| # get the X-Transmission-Session-Id | ||
| SESSION_ID=$( | ||
| wget \ | ||
| ${WGET_OPTS} \ | ||
| --server-response \ | ||
| "$RPC_URL" 2>&1 | | ||
| grep 'X-Transmission-Session-Id:' | | ||
| awk '{print $2}' | ||
| ) | ||
|
Comment on lines
+92
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider wrapping this in a loop, which fails after some retries: |
||
|
|
||
| # generate payload string | ||
| PAYLOAD=$(printf '{ | ||
| "method": "session-set", | ||
| "arguments": { | ||
| "peer-port": %s | ||
| } | ||
| }' "$PORT") | ||
|
|
||
| # update peer host via API | ||
| RES=$( | ||
| wget \ | ||
| ${WGET_OPTS} \ | ||
| --header="Content-Type: application/json" \ | ||
| --header="X-Transmission-Session-Id: $SESSION_ID" \ | ||
| --post-data="${PAYLOAD}" \ | ||
| "$RPC_URL" \ | ||
| -O - | ||
| ) | ||
|
|
||
| # check string returned by wget | ||
| SUCCESS='{"arguments":{},"result":"success"}' | ||
| if [ "$RES" = "$SUCCESS" ]; then | ||
| echo "Success! Peer port updated to ${PORT}" | ||
| exit 0 | ||
| else | ||
|
juanlufont marked this conversation as resolved.
Outdated
|
||
| echo "ERROR: Could not update peer port" | ||
| exit 1 | ||
| fi | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.