Last active
November 11, 2017 11:47
-
-
Save bonan/5493167cbb574cfdb5f07ec1ac3ebba6 to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
# | |
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED | |
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR | |
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | |
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
# | |
DELUGE_URL=http://localhost:8112 | |
DELUGE_PW=deluge | |
DELUGE_JAR=/tmp/.deluge-cookiejar | |
DELUGE_NGINX_CONF=/etc/nginx/deluge_session_include | |
if [ -f /etc/environment/deluge ]; then | |
. /etc/environment/deluge | |
fi | |
DELUGE_CURL="curl --compressed --silent -b $DELUGE_JAR -c $DELUGE_JAR -H 'Accept: application/json' -H 'Content-Type: application/json'" | |
AUTH_CHECK='{"method":"auth.check_session","params":[],"id":1}' | |
AUTH_LOGIN="{\"method\":\"auth.login\",\"params\":[\"${DELUGE_PW}\"],\"id\":2}" | |
if [ ! -f $DELUGE_JAR ]; then | |
touch $DELUGE_JAR || exit 1 | |
fi | |
LASTCOOKIE=$(grep _session_id $DELUGE_JAR | cut -f 7-) | |
${DELUGE_CURL} -d ${AUTH_CHECK} ${DELUGE_URL}/json | grep -E '"result": *true' | |
if [ $? -gt 0 ]; then | |
${DELUGE_CURL} -d ${AUTH_LOGIN} ${DELUGE_URL}/json || exit 1 | |
COOKIE=$(grep '_session_id' $DELUGE_JAR | cut -f 7-) | |
if [ "$COOKIE" != "$LASTCOOKIE" ]; then | |
echo "proxy_set_header Cookie _session_id=$COOKIE;" > $DELUGE_NGINX_CONF | |
echo "Updated session_id" | |
systemctl reload nginx | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment