Skip to content

Instantly share code, notes, and snippets.

@fur-q
Created August 27, 2015 19:22
Show Gist options
  • Save fur-q/7f83901c3cda0fd5e251 to your computer and use it in GitHub Desktop.
Save fur-q/7f83901c3cda0fd5e251 to your computer and use it in GitHub Desktop.
#!/bin/sh
ARIA2_URI=${ARIA2_URI:-127.0.0.1:6800}
[ -n "$ARIA2_SECRET" ] && SECRET='"secret":"$ARIA2_SECRET", '
die() {
[ -n "$1" ] && echo $1
cat << EOF
Usage: $(basename $0) OPTION (VALUE)
Available options:
bt-max-open-files (number)
download-result (download|full)
log (filename)
log-level (debug|info|notice|warn|error)
max-concurrent-downloads (number)
max-download-result (number)
max-overall-download-limit (size)
max-overall-upload-limit (size)
save-cookies (filename)
save-session (filename)
server-stat-of (filename)
EOF
exit 1
}
getOption() {
local out="$(curl -s -H 'Content-Type: application/json' -H 'Accept: application/json' \
--data-binary '{"jsonrpc":"2.0", "id":"asdf", "method":"aria2.getGlobalOption"}' \
$ARIA2_URI/jsonrpc)"
local err="$(echo "$out" | jq -r '.error.message')"
[ "$err" != "null" ] && die "Error: $err"
local res="$(echo "$out" | jq '.result["'$1'"]')"
[ "$res" = "null" ] && die "Error: No such option $1"
echo "$1: $res"
}
setOption() {
local out="$(curl -s -H 'Content-Type: application/json' -H 'Accept: application/json' \
--data-binary "{\"jsonrpc\":\"2.0\", \"id\":\"asdf\", \"method\":\"aria2.changeGlobalOption\", \"params\":[{\"$1\": \"$2\"}]}" \
$ARIA2_URI/jsonrpc)"
local err="$(echo "$out" | jq -r ".error.message")"
[ "$err" != "null" ] && die "Error: $err"
getOption "$1"
}
[ $# -eq 0 ] && die
[ $# -eq 1 ] && getOption "$1" || setOption "$1" "$2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment