Skip to content

Instantly share code, notes, and snippets.

@fstanis
Last active March 29, 2021 21:06
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save fstanis/02d6b6888519f9d1f11bb24a3af3fba1 to your computer and use it in GitHub Desktop.
Save fstanis/02d6b6888519f9d1f11bb24a3af3fba1 to your computer and use it in GitHub Desktop.
Upspin server backed by Google Drive on a Raspberry Pi

Set up an Upspin server backed by Google Drive

Overview

The purpose of this document is to explain how to deploy an Upspin server on a Debian or Ubuntu based machine - which can be a Raspberry Pi - and, optionally, use Google Drive to back the data.

Effectively, this will give you all the nifty advantages Upspin gives you in terms of file sharing without requiring a costly server.

Requirements

  • You understand what Upspin is - and that all is this is in early days, so don't put data you're not prepared to lose on it.

  • You should have a domain that you control.

    • (Optional) To make things easier, this guide assumes you're using CloudFlare to manage it.
  • You should already have completed Upspin - Signing up a new user

    • If you're signing up now, choose Skip configuring my servers; I’ll use Upspin in read-only mode for now. when prompted.
  • If you're storing data locally on a Raspberry Pi, it's strongly recommended to have an external storage, such as an external HDD or a USB flash.

  • You may want to have a separate user on your server for Upspin. If you decide to do this, just create the user via sudo useradd -m upspin and proceed with the rest of this guide logged in as that user.

Presumptions

Throughout this guide, these presumptions are made. Replace the values with your own:

  • Your domain is example.com

  • The subdomain you'll use will be upspin.example.com

  • Your external storage on a Raspberry Pi is mounted on /mnt/external

  • The email you used to signup for Upspin is you@gmail.com

Guide

Install the latest version of Go

  1. Remove any existing Go installation:
sudo apt-get remove golang*
  1. Go to the Downloads section of the Go website.

  2. Find the latest version of Go for your platform and copy the download link.

    If you're using a Raspberry Pi, the platform you're looking for is ARMv6 and, at time of writing, the latest package is go1.9.4.linux-armv6l.tar.gz

  3. Install Go to /usr/local:

wget https://dl.google.com/go/go1.9.4.linux-armv6l.tar.gz
sudo tar -C /usr/local -xzf go1.9.4.linux-armv6l.tar.gz
mkdir -p "$HOME/go"
echo 'PATH="/usr/local/go/bin:$HOME/go/bin:$PATH"' >> ~/.profile
  1. Re-login or reboot for the changes to take effect.

  2. Make sure the installation was a success:

go version  # should output "go version go1.9.4 linux/arm"

Install Upspin

  1. Make sure git is installed:
sudo apt-get install git
  1. Download and build Upspin and (optionally) Drive support for Upspin:
go get -v upspin.io/cmd/...
go get -v drive.upspin.io/cmd/...
  1. Make sure Upspin works:
upspin -version  # should output "devel"
  1. Give your user permission to bind to ports 80 and 443:
sudo setcap cap_net_bind_service=+ep "$HOME/go/bin/upspinserver"
sudo setcap cap_net_bind_service=+ep "$HOME/go/bin/upspinserver-drive"

Move your config to the server

If you've already signed up on a different machine, you'll need to move your keys and create a placeholder config on the server.

  1. Create a simple placeholder config:
mkdir "$HOME/upspin"

cat > "$HOME/upspin/config" << EOF
username: you@gmail.com
dirserver: none
storeserver: none
packing: ee
EOF
  1. Copy the directory ~/.ssh/you@gmail.com from the machine where you completed signup to your server.

Setup your domain to use with Upspin

  1. Make sure curl, dnsutils and python are all installed:
sudo apt-get install curl dnsutils python
  1. Run setupdomain:
upspin setupdomain -domain=example.com
  1. Follow the instructions provided to add the required TXT record to your domain. For Cloudflare, instructions are available here: How do I add a TXT record?

  2. Wait a bit and verify that the TXT record has been added before you proceed:

host -t TXT example.com
  1. Find out the external IP address of your network:
curl ipv4.icanhazip.com
curl ipv6.icanhazip.com  # if you have IPv6 support
  1. Create an A record (if using IPv4) or an AAAA record (if using IPv6) on your domain. For Cloudflare, instructions are available here: How do I add A records? and How do I add AAAA records?

    1. Set the name to upspin
    2. Set the IP address to the IP address you learned from the previous step.
    3. Set the TTL to 1 hour.
  2. If your IP address is not static, this might be a good time to setup Dynamic DNS. For Cloudflare, you may use ddclient or DNS-O-Matic.

  3. If your Raspberry Pi is behind a router, set up port forwarding for ports 80 and 443. See How To Port Forward a Router for more information.

  4. Time to check and make sure everything is working correctly. Run a simple HTTP server:

sudo python -m SimpleHTTPServer 80
  1. In a web browser on another machine, try to navigate to http://upspin.example.com - if you get a response, your domain and port forwarding are both set up correctly.

  2. Terminate the python server from the previous step.

Setup storage

At this stage, you can decide to either use the local storage mounted on your server or Google Drive.

Keep in mind that Google Drive support is highly experimental at this stage.

Use local storage

  1. Decide on a directory you'd like to use for local storage. It's strongly recommended to use an external HDD or USB flash. In this guide, we'll use /mnt/external/upspin

  2. Create this directory and set the correct permissions:

sudo mkdir /mnt/external/upspin
sudo chown $(id -u):$(id -g) /mnt/external/upspin
  1. Run setupstorage:
upspin setupstorage -domain=example.com -path=/mnt/external/upspin
  1. Start the Upspin server:
upspinserver
  1. Make sure the output contains "Configuration file not found. Running in setup mode." and continue to the next section.

Use Google Drive

  1. On another machine, navigate to drive.google.com and make sure you're logged in with the Google Account you're planning to use.

  2. Back on your server, run setupstorage-drive:

upspin setupstorage-drive -domain=example.com
  1. Open the provided link on the machine where you're logged in to Google and copy the generated token back where requested.

  2. Start the Upspin server:

upspinserver-drive
  1. Make sure the output contains "Configuration file not found. Running in setup mode." and continue to the next section.

Setup the Upspin server

  1. With the server still running, in another terminal, run serversetup:
upspin setupserver -domain=example.com -host=upspin.example.com
  1. You should see output like this:

    Successfully put "upspin@example.com" to the key server.
    Configured upspinserver at "upspin.example.com:443".
    Created root "you@gmail.com".
    

    On the server, you should see:

    Store and Directory servers initialized.
    
  2. If the Created root "you@gmail.com" message is not present and your server displays no root for user, you need to create the root manually:

upspin mkdir @/
  1. Test to make sure everything works:
echo 'Hello, Upspin' | upspin put you@gmail.com/hello
upspin ls  # should output "you@gmail.com/hello"
upspin get you@gmail.com/hello  # should output "Hello, Upspin"
  1. Go back to the terminal where the server is running and stop it.

Setup the Upspin server to run on startup

  1. Make sure your system supports systemd:
pidof systemd > /dev/null && echo "systemd"  # should output "systemd"
  1. Create a service definition (if using Google Drive, replace which upspinserver with which upspinserver-drive):
sudo bash -c "cat > /etc/systemd/system/upspinserver.service" << EOF
[Unit]
Description=Upspin server

[Service]
ExecStart=$(which upspinserver)
User=$(id -u)
Group=$(id -g)
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF
  1. Start the service:
sudo systemctl start upspinserver
  1. Check the logs to ensure the server started successfully:
journalctl -f -u upspinserver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment