Skip to content

Instantly share code, notes, and snippets.

@ramontayag
Last active June 10, 2016 10:51
Show Gist options
  • Save ramontayag/6308461 to your computer and use it in GitHub Desktop.
Save ramontayag/6308461 to your computer and use it in GitHub Desktop.
Raspberry Pi setup with BitTorrent Sync

First boot

  • Expand storage
  • Start desktop
  • Reboot

Continue by plugging the LAN cable, then in the router admin panel, find the IP address of the pi. Connect:

ssh pi@ipaddress

Type in raspberry as the password.

CLI

sudo apt-get install tmux -y
curl https://gist.github.com/ramontayag/5079630/raw/ba4be5de45fa77a725e5396695a997de427c8c08/gistfile1.txt > ~/.tmux.conf
tmux
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install htop vim monit zsh git-core -y

ZSH

Follow these instructions. Then log out, and log back in.

vim ~/.zshrc:

bindkey -v
bindkey "^R" history-incremental-search-backward

Network

To connect to the wifi, follow this blog post

sudo apt-get install raspberrypi-bootloader

BitTorrent Sync

mkdir -p ~/Downloads/btsync
cd ~/Downloads/btsync
wget http://btsync.s3-website-us-east-1.amazonaws.com/btsync_arm.tar.gz
tar zxvf btsync_arm.tar.gz
cd ..
sudo mv btsync /opt
/opt/btsync/btsync --dump-sample-config > ~/.btsync.conf

Open the btsync config (vim ~/.btsync.conf) and change the following:

  • "My Sync Device" to the what you want your Raspberry Pi to be known as in the BitTorrent Sync network
  • Uncomment the pid file line "pid_file" : "/var/run/btsync/btsync.pid", and change it to "pid_file" : "/var/run/btsync.pid"
  • In the webui section, "password" : "password" to set the password (change the one on the right) that you need to enter when opening the web app.
  • Change /home/user to /home/pi

Monit

sudo vim /etc/monit/conf.d/btsync.monitrc

Paste the ff:

check process btsync with pidfile /var/run/btsync.pid
  start program = "/bin/bash -c '/opt/btsync/btsync --config /home/pi/.btsync.conf'"
  stop program = "/bin/bash -c '/bin/kill -9 `cat /var/run/btsync.pid`'"
  if failed host 127.0.0.1 port 8888 then restart
  if cpu is greater than 90% for 2 cycles then alert
  if cpu > 95% for 30 cycles then restart

sudo vim /etc/monit/monitrc

uncomment the httpd part, with and pick a password

Then reload monit:

sudo monit reload

USB Auto Mount

Instructions from here

Find out where in /dev/sd* your disk is (probably /dev/sda1):

sudo fdisk -l

You should create the directory where you want it to be mounted: sudo mkdir /mount/storage

Format

If you need format the drive, see this. I followed the format portion only, not the mount.

Knowing your Pi's Dynamic IP

One thing you can use BitTorrent Sync for is to update (you're most likely using a dynamic IP) the public IP address of the connection your Pi is using. This is helpful if you port forward to your Pi.

Make a script that we can run:

mkdir ~/about
mkdir ~/scripts
vim ~/scripts/public_ip_dump

Paste:

#!/bin/bash

IP=`curl -s checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'`
echo $IP > /home/pi/about/ip.txt

Make it executable:

chmod +x ~/scripts/public_ip_dump

Now set it to run every 30 minutes:

crontab -e

Paste:

30 * * * * /home/pi/scripts/public_ip_dump

Then add that folder to BitTorrent sync through the WebUI. Keep that in sync with your computer so you know what the IP address even if the Pi's public IP changes.

@Yohoa
Copy link

Yohoa commented Jun 10, 2016

When I setup the Monit part, I find that the Sync is always started as a root user. I think it is unsafe, but what should I do to change it? (Sync process is used to run as the user "pi")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment