Skip to content

Instantly share code, notes, and snippets.

@josuecau
Last active March 17, 2019 12:16
Show Gist options
  • Save josuecau/bb176d1eb65e8992ada92333a329a3cd to your computer and use it in GitHub Desktop.
Save josuecau/bb176d1eb65e8992ada92333a329a3cd to your computer and use it in GitHub Desktop.
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 <[email protected]>
# 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