Last active
January 29, 2018 18:12
-
-
Save arzzen/552c8550b9941d2ba82aa26a0df5b574 to your computer and use it in GitHub Desktop.
Download torrent
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 | |
# Install transmission dependences | |
# sudo apt-get install transmission-cli transmission-daemon transmission-common | |
# chmod +x download.sh | |
DOWNLOAD_DIR=${HOME}"/download" | |
TRANS_CLI="transmission-cli" | |
TRANS_SHOW="transmission-show" | |
TRANS_NOTIFY=${HOME}"/notify.sh" | |
TCONF=${HOME}"/.config/transmission" | |
MAX_UPLOAD=200 | |
TMP_NOHUP=${HOME}"/tmp.out" | |
TMP_TORRENT_FILE=${HOME}"/temp.torrent" | |
_help() | |
{ | |
echo "" | |
echo "Control transmission-cli via SSH with minimum typing." | |
echo | |
echo "OPTIONS:" | |
echo "--start=<URL> -- Starts transmission and download torrent file" | |
echo "--status -- Show current progress of download" | |
echo "--stop -- Stop transmission" | |
echo "--help -- Show this help message" | |
echo | |
echo "USAGE:" | |
echo "`basename $0` --start=http://itorrents.org/torrent/7B5FD54D7F69F6BB68B1AF7BE3FBFA2A4489786F.torrent" | |
echo "`basename $0` --status" | |
echo "`basename $0` --stop" | |
} | |
_log() | |
{ | |
logger "[TORRENT]: $1" | |
} | |
if [ $# -eq 0 ] | |
then _help | |
fi | |
while [ "$1" != "" ]; do | |
case $1 in | |
--start* ) | |
if [ -n "$1" ] | |
then | |
TORRENT_URL=$(echo $1 | cut --only-delimited --delimiter="=" --fields=2) | |
if [ -n "$TORRENT_URL" ] | |
then | |
wget $TORRENT_URL -q -O $TMP_TORRENT_FILE | |
nohup $TRANS_CLI -u $MAX_UPLOAD -f $TRANS_NOTIFY -w $DOWNLOAD_DIR $TMP_TORRENT_FILE > $TMP_NOHUP 2>&1 & | |
TORRENT_HASH=$($TRANS_SHOW $TMP_TORRENT_FILE | grep -Eo "Hash: (.*)" | tr -d "Hash: ") | |
TORRENT_NAME=$($TRANS_SHOW $TMP_TORRENT_FILE | head -n 1 | tr -d "Name: ") | |
shift | |
echo "pid $!" | |
_log "Start torrent; PID: ($!), HASH: ($TORRENT_HASH), URL: ($TORRENT_URL)" | |
else | |
echo "No torrent url specified!" | |
exit 1; | |
fi | |
else | |
echo "No torrent url specified!" | |
exit 1; | |
fi | |
;; | |
--status ) | |
tail $TMP_NOHUP | |
;; | |
--follow ) | |
tail -f $TMP_NOHUP | |
;; | |
--tail-syslog ) | |
tail -f /var/log/syslog | grep "TORRENT" | |
;; | |
--clean ) | |
rm -v ${TCONF}/torrents/*.torrent ${TCONF}/resume/*.resume $TMP_NOHUP | |
rm $TMP_TORRENT_FILE | |
_log "Clean torrent files" | |
;; | |
--stop ) | |
killall -u $USER -v $TRANS_CLI | |
_log "Kill transmission-cli" | |
;; | |
--help ) | |
_help | |
;; | |
* ) | |
echo "Unknown option: $1" | |
echo "`basename $0` --help for more info." | |
;; | |
esac | |
shift | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment