17 november 2013

Your own Dropbox with a Raspberry Pi

Sparkleshare OS X client

Create your own Dropbox-like solution with a Raspberry Pi and the Sparkleshare open source solution.

SparkleShare creates a special folder, called a repository, on your computer. You can add remotely hosted folders (or "projects") to this folder. These projects will be automatically kept in sync with both the host and all of your peers when someone adds, removes or edits a file.

Raspberry Pi dropbox alternative Raspberry Pi dropbox alternative

The RPi is managed headless from within a SSH session. Follows the steps taken to install Sparkleshare and the web dashboard. Starting from a Pi having Raspbian Wheezy installed.

Here it is powered from the cable-modem USB port and connected to the modem's free Ethernet port. If you want to access your repository over the Net and not only on your LAN, setup port forwarding on your modem for ports 22, 80, 443 and optionally 8080 too.

SparkleShare installation:

# ------------
# SparkleShare
# ------------
pi$ curl https://raw.github.com/hbons/Dazzle/master/dazzle.sh \
> --output /usr/bin/dazzle && chmod +x /usr/bin/dazzle
pi$ sudo dazzle setup

# create your projects
pi$ sudo dazzle create private
pi$ sudo dazzle create public
pi$ sudo vi /home/storage/.ssh/authorized_keys
[add ssh key for each connected user@computer]

# Optionally edit the list of files to ignore (e.g. Mac OS X .DS_store and .lock files) or edit .gitignore, see git exclude files
pi$ sudo vi /.git/info/exclude
.DS_Store
.lock.*

Install NodeJS webserver:

# ------
# NodeJS
# ------
pi$ sudo mkdir /opt/node
pi$ sudo wget http://nodejs.org/dist/v0.10.2/node-v0.10.2-linux-arm-pi.tar.gz
pi$ sudo tar xvzf node-v0.10.2-linux-arm-pi.tar.gz
pi$ sudo cp -r node-v0.10.2-linux-arm-pi/* /opt/node

# add Node.JS to the path variable, before the 'export PATH' line
pi$ sudo vi /etc/profile
...
NODE_JS_HOME="/opt/node"
PATH="$PATH:$NODE_JS_HOME/bin"
export PATH
...

# copy nodejs.sh to /etc/init.d, using FTP
pi$ chmod 755 /etc/init.d/nodejs.sh
pi$ sudo update-rc.d nodejs.sh defaults

# The ‘server.js’ file is just a simple Node.JS server which will listen on
# port 8080 and display ‘Hello World’ and write some output to the console
pi$ mkdir /home/pi/app
pi$ put server.js into the app dir (using vi or Ftp)

# start the webserver
pi$ sudo /etc/init.d/nodejs.sh start

# and test it using a browser:
http://:8080 or http://:8080

Redis database server installation:

# -----
# Redis
# -----
pi$ cd ~
pi$ sudo wget http://download.redis.io/releases/redis-2.6.16.tar.gz
pi$ sudo tar xzf redis-2.6.16.tar.gz
pi$ cd redis-2.6.1616
pi$ sudo make
...
pi$ sudo make test
# have a coffee break (>25min) after all it's only a Pi

pi$ sudo make install
pi$ sudo cp redis.conf /etc/redis.conf
[ pi$ sudo cp src/redis-server /usr/local/bin/ ]
pi$ sudo vi /etc/redis.conf
...
#daemonize no
daemonize yes

# no log, to reduce SD card i/o
logfile stdout
#logfile /var/log/redis.log

# dump.rdb path
#dir ./
dir /home/pi/
...
# testrun
pi$ redis-server
pi$ redis-cli time

# copy the redis-server.sh script to /etc/init.d
pi$ chmod 755 /etc/init.d/redis-server.sh
pi$ sudo update-rc.d redis-server defaults 98 02

Network Package Manager:

# -----------------------------
# Network Package Manager (NPM)
# -----------------------------
pi$ cd ~
pi$ sudo curl https://npmjs.org/install.sh | sh

SparkleShare web interface installation:

# ----------------------
# SparkleShare-dashboard
# ----------------------

# install dependencies with NPM
pi$ npm install express@2.5 express-messages i18n jade connect-redis redis sass mime

pi$ cd ~
pi$ git clone https://github.com/tommyd3mdi/sparkleshare-dashboard.git
pi$ cd sparkleshare-dashboard
pi$ sudo /opt/node/bin/npm install express@2.5 express-messages i18n jade connect-redis redis sass mime

# install the node_modules
pi$ cd sparkleshare-dashboard
pi$ npm install -d

# copy the sparkleshare-dashboard.sh script to /etc/init.d
pi$ chmod 755 /etc/init.d/sparkleshare-dashboard.sh
pi$ sudo update-rc.d sparkleshare-dashboard defaults 98 02

# add user pi to the ‘storage’ group (to allow access via alias)
pi$ sudo adduser pi storage

# symlinks to the repo's
pi$ sudo ln -s /home/storage/private /home/pi/sparkleshare-dashboard/private_x
pi$ sudo ln -s /home/storage/public /home/pi/sparkleshare-dashboard/public_x

# edit (the alias to) the folders shown in the dashboard
pi$ sudo vi ~/sparkleshare-dashboard/config.js

{ type: 'git', name: 'Public GIT folder', path: '/home/pi/sparkleshare-dashboard/public_x', pub: true },
{ type: 'git', name: 'Private GIT folder', path: '/home/pi/sparkleshare-dashboard/private_x', pub: false }

# test (from within the ssh session)
pi$ sudo /etc/init.d/sparkleshare-dashboard start > /dev/null 2>&1 &

# if all went well, reboot the Pi
pi$ sudo shutdown -r now

# to conclude, if you have to switch off your Pi,
# switch it off gracefully
pi$ sudo shutdown -h now


Scripts and stylesheets

Links

Geplaatst op 17 november 2013 13:40 | Comments (0)