Scripts to watch macOS ~/Downloads
folder for .torrent
files, upload them
to a seedbox, and download the resulting files.
Also has ability to automatically SCP .epub
files to an online Kindle running KOReader.
- To be a good citizen, and seed your torrents
- To remove the hassle of having to keep your laptop cracked open to do so
- To prevent snooping on your torrent downloads by your ISP
- To make downloading torrents as easy as any other file
- For books, to reduce the activation energy to reading as much as possible
-
macOS computer with Homebrew installed
-
Seedbox with SFTP access
-
Must be able to put SSH key on machine (This is doable with only
sftp
and no SSH access.) -
Must be running qBittorrent (Probably can make it work otherwise, but this is what I chose.)
-
This could be local, cloud self-run, or managed
-
This requires some manual configuration to work. I haven't tested this on setups that are not my own. If this doesn't work for you, please file an issue.
-
Generate SSH key:
ssh-keygen -t ed25519 -f ~/.ssh/id_seedbox
- Use a password manager to generate a secure passphrase. Save it.
-
Add key to SSH agent
ssh-add --apple-use-keychain ~/.ssh/id_seedbox
- This may fail. If so, either
brew unlink openssh
or call/usr/bin/ssh-add
instead. Homebrew's SSH doesn't work with the macOS keychain, which we need if we want to password-protect the key and be able to automate this.
- This may fail. If so, either
-
Write to your
~/.ssh/config
, filling in the values:Host seedbox HostName <HOSTNAME> User <USERNAME> Port <PORT> IdentityFile ~/.ssh/id_seedbox
This isn't necessary (the script generates its own config), but it's a solid quality-of-life improvement.
-
Add the public key to your seedbox. See here for instructions.
-
If you don't have SSH access, this can still be done over SFTP. It will look something like this:
$ cd ~/ $ sftp -P <PORT> <USERNAME>@<HOSTNAME> # This may be unnecessary if the directory already exists sftp> pwd Remote working directory: /home/<USERNAME> # If the above is not the home directory, cd into it. sftp> mkdir .ssh sftp> put .ssh/id_seedbox.pub .ssh/authorized_keys sftp> chmod 700 .ssh sftp> chmod 600 .ssh/authorized_keys
-
-
Restart the seedbox.
-
Run
sftp seedbox
. This should sign you in without needing a password.
- If this fails, try
ssh-add --apple-load-keychain
- Confirm you restarted the seedbox
- Make watch directories:
$ sftp seedbox
sftp> pwd
Remote working directory: /home/<USERNAME>
sftp> mkdir twatch
sftp> mkdir twatch_out
sftp> mkdir completed_torrents
-
Sign in to the web UI for qBittorrent
-
Go to Tools > Options
-
Check "Copy .torrent files for finished downloads to:" and set the value to
/home/<USERNAME>/completed_torrents
-
Under "Automatically add torrents from:" add a line with "Monitored Folder" being
/home/<USERNAME>/twatch
and "Override Save Location" being/home/<USERNAME>/twatch_out/
-
Scroll to the bottom and click "save"
-
Test this by
sftp
ing into the server, and copying a .torrent file to/home/<USERNAME>/twatch
. Wait for it to complete by watching the web UI, and then check that there is a.torrent
file for the download in/home/<USERNAME>/completed_torrents
, and the actual files are in/home/<USERNAME>/twatch_out
.
-
Install Homebrew if you haven't already.
-
Install this repo:
brew tap riley-martine/auto-seedbox brew install auto-seedbox
-
Set up your config in
~/.config/auto-seedbox/config.json
. All fields are required. It should look like this:{ "seedbox_user": "root", "seedbox_host": "website.address", "seedbox_port": "7777", "seedbox_key": "~/.ssh/id_seedbox", "send_to_kindle": true }
-
Run
brew services start auto-seedbox
. -
To test this is working,
tail -50 -f /opt/homebrew/var/log/auto-seedbox.log
. Add a torrent file to~/Downloads
, and watch the logs as it downloads.
At this point, you're probably done! Congratulations! However, if you're also trying to get your ebooks onto a Kindle, read on...
Note: This probably works with non-Kindle KOReader, but I haven't tried it.
-
Jailbreak your Kindle. Follow ALL instructions in the thread carefully. Do not connect to the internet. This may take a while, but do it right.
-
Install KUAL, gawk, KUAL+, KUAL Helper. See linked snapshots thread.
-
Install KOReader
-
Disable OTA updates through KUAL
-
If running FW >= 5.12.x, you MUST also disable OTA updates with method described here. You can do this through KOReader's shell in Top Menu > Tools Icon > More Tools > Terminal emulator > Open terminal session. Here is what I ran (the hosts stuff is a bit extra, but sue me I guess, I was working on this too long to get got by an update):
# mntroot rw # cd /usr/bin # mv otaupd otaupd.bck # mv otav3 otav3.bck # echo "/bin/true" > /usr/bin/otav3 # echo "/bin/true" > /usr/bin/otaupd # chmod +x /usr/bin/otav3 /usr/bin/otaupd # echo "127.0.0.1 firs-ta.g7g.amazon.com" >> /etc/hosts # echo "127.0.0.1 amazon.com" >> /etc/hosts # touch /var/local/system/DONT_DELETE_CONTENT_ON_DEREGISTRATION # exit
And then reboot the device.
-
-
Connect the device to WiFi. Pray you got everything right.
-
Launch KOReader. Go to
Top Menu > Gear Icon > SSH server
. Set the field "SSH port" to 2323. Enable "Login without password (DANGEROUS)". I was unable to make public key auth work, but I'll only be connecting to home WiFi, so I think it's probably fine. Check the box for "SSH server." This will tell you the IP address of the device. -
Test ssh access with
ssh -p 2323 root@<IP>
and just hit enter for the password. You should be logged in to the Kindle. -
You may need to change the download path in
auto_kindle/copy_to_kindle.sh
, on the line where it runsscp
. This should be KOReader's home folder, where you want the books to go. Add a file to your Kindle in the directory you want (I used/mnt/us/documents
because that's where Calibre was putting things) and run# ls /../../../mnt/us/documents/
to confirm you see your file; if not, correct the path and edit it incopy_to_kindle.sh
. -
Test
./copy_to_kindle.sh ~/Downloads/example.epub
. It may be slow the first time as it finds the Kindle. This should copy a file to the Kindle. -
Test the whole thing together. Find a torrent that has an epub in it, download it, and watch the logs (
tail -f /opt/homebrew/var/log/auto-seedbox.log
). If your Kindle is online, everything should work.
brew install --verbose --debug --HEAD ./Formula/auto-seedbox.rb
brew services restart auto-seedbox
tail -50 -f /opt/homebrew/var/log/auto-seedbox.log