Create a gist now

Instantly share code, notes, and snippets.

Make transmission turn on the alternate bandwidth limits (turtle mode) when you login over ssh and turn back on when you log out of the last ssh connection.
#!/bin/sh
# Usage: transmission-turtle [true|false]
ENDPOINT=http://localhost:9091
CRED='admin:coolpassword'
################################################################################
ENDPOINT=$ENDPOINT/transmission/rpc
HEADER=`curl -s -u "$CRED" -I $ENDPOINT | tr -d "\015" | egrep ^X-Transmission-Session-Id `
curl -s -H "$HEADER" -u "$CRED" \
$ENDPOINT -d "{\"method\": \"session-set\",\"arguments\":{\"alt-speed-enabled\":$1}}" | sed -e 's/.*:/ /g; s/["}]//g;'
#!/bin/sh
# If we're the last ssh login deselect the turtle icon in tranmission
if [ -f `which tranmission-turtle 2> /dev/null` ]; then
ps ax | egrep "^ *$PPID *.*ssh" > /dev/null
if [ $? -eq 0 ]; then
# We're in an ssh login
MY_TTY=`tty | sed 's#.*/##' `
who | grep -v $MY_TTY |grep \( > /dev/null
if [ $? -ne 0 ]; then
# We're the last ssh connection
echo -n "🐢De-Turtling Transmission... "
transmission-turtle false
fi
fi
fi
# If we're a fresh ssh login click the turtle icon in tranmission
if [ -f `which tranmission-turtle 2> /dev/null` ]; then
MY_TTY=`tty | sed 's#.*/##' `
who | grep $MY_TTY |grep \( > /dev/null
if [ $? -eq 0 ]; then
echo -n "🐢Turtling Transmission... "
transmission-turtle true
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment