Skip to content

Instantly share code, notes, and snippets.

@josuecau
Last active Mar 17, 2019
Embed
What would you like to do?
Select .torrent file to upload to seed box
#!/usr/bin/env bash
#
# Description: Select .torrent file to upload to seed box.
# Usage: $ seedbox
# Author: Josué CAU <me@josuecau.com>
# Version: v0.1.1
# Dependencies: fzf(1)
# Env: SEEDBOX_ADDRESS
set -e
if [ -z "$SEEDBOX_ADDRESS" ]; then
echo 'Environment variable SEEDBOX_ADDRESS must be set'
exit 1
fi
dir="$HOME/Downloads"
remote="$SEEDBOX_ADDRESS/watch"
listing () {
find "$dir" -type f -name '*.torrent' -print0 \
| xargs -0 basename -s '.torrent' \
| sort \
| fzf --exit-0
}
choice=$(listing)
torrent="$dir/$choice.torrent"
filetype=$(file -b --mime-type "$torrent")
if [ "$filetype" != 'application/x-bittorrent' ]; then
echo "Unexpected file type: $filetype"
exit 1
fi
scp "$torrent" "$remote"
mv "$torrent" "$torrent.backup"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment