<commit_before># Start here:

## DISCLAIMER!
### These instructions are correct as of April 1st 2016

Start by flashing a SD card with the latest Raspbian Jessie Lite image.
You can get it from [Raspberry Pi website](https://www.raspberrypi.org/downloads/raspbian/)

# Do this in your Raspberry Pi as 'pi' user

Boot it, launch *raspi-config* to perform (at least) the following configurations:
```
# as 'pi' user
sudo raspi-config
```

* 1) expand filesystem 
* 2) change default user password
* A3) setup memory split as you wish (I recommend 16Mb for GPU)

Optionally:
* 8) setup overclocking.

# Secure your installation

Delete generated SSH keys and recreate them.
(why this matters? [read it here](https://www.raspberrypi.org/forums/viewtopic.php?t=126892))
```
# as 'pi' user
sudo rm -v /etc/ssh/ssh_host_*
sudo dpkg-reconfigure openssh-server
sudo reboot
```

After the previous step you've created new SSH keys. 

Update installed packages
```
# as 'pi' user
sudo apt update
sudo apt upgrade
```

# Install additional packages

(needs validation if all packages are recent enough)
```
# as 'pi' user
sudo apt install -y python-virtualenv python-pip git uwsgi uwsgi-plugin-python
sudo pip install -U click
sudo reboot
```

# Meanwhile, go get the goodies while Raspberry Pi is rebootting



(We assume you know about ssh keys and have one "at hand", you'll need to copy it)

Clone [piku repo](https://github.com/rcarmo/piku) somewhere and copy files to your Raspberry Pi
```
# as yourself in your desktop/laptop computer
scp piku.py uwsgi-piku.service pi@your_machine:/tmp
scp your_public_ssh_key.pub    pi@your_machine:/tmp
```

# Back to the Pi

Prepare uWSGI (part one):
```
# as 'pi' user
sudo ln -s `which uwsgi` /usr/local/bin/uwsgi-piku
sudo systemctl disable uwsgi
sudo cp /tmp/uwsgi-piku.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable uwsgi-piku
```

Create 'piku' user and set it up
```
# as 'pi' user
sudo adduser --disabled-password --gecos 'PaaS access' --ingroup www-data piku
sudo su - piku
# this is now done as 'piku' user
mkdir ~/.ssh
chmod 700 ~/.ssh<commit_msg>Readability<commit_after># Setting up a Raspberry Pi Piku Server from Scratch

## DISCLAIMER!

### These instructions are correct as of April 1st 2016

Start by flashing a SD card with [the latest Raspbian Jessie Lite image](https://www.raspberrypi.org/downloads/raspbian/).

# Do this in your Raspberry Pi as 'pi' user

Boot it, launch *raspi-config* to perform (at least) the following configuration:

```bash
# as 'pi' user
sudo raspi-config
```

* 1) expand filesystem 
* 2) change default user password
* 3) set up memory split as you wish (for a headless server, 16MB for GPU)

Optionally:

* 4) set up over-clocking.

# Secure your install

Delete the existing SSH keys and recreate them (why? [read this](https://www.raspberrypi.org/forums/viewtopic.php?t=126892)).

```bash
# as 'pi' user
sudo rm -v /etc/ssh/ssh_host_*
sudo dpkg-reconfigure openssh-server
sudo reboot
```

This will recreate the server keys. Next, update your system:

```bash
# as 'pi' user
sudo apt update
sudo apt upgrade
```

# Install required packages

As of April 2016, the shipping versions with Raspbian are recent enough to run `piku`:

```bash
# as 'pi' user
sudo apt install -y python-virtualenv python-pip git uwsgi uwsgi-plugin-python
sudo pip install -U click
sudo reboot
```

# Meanwhile, go get the goodies while Raspberry Pi is rebooting

(We assume you know about ssh keys and have one "at hand", you'll need to copy it)

Clone [piku repo](https://github.com/rcarmo/piku) somewhere and copy files to your Raspberry Pi
```
# as yourself in your desktop/laptop computer
scp piku.py uwsgi-piku.service pi@your_machine:/tmp
scp your_public_ssh_key.pub    pi@your_machine:/tmp
```

# Back to the Pi

Prepare uWSGI (part one):
```
# as 'pi' user
sudo ln -s `which uwsgi` /usr/local/bin/uwsgi-piku
sudo systemctl disable uwsgi
sudo cp /tmp/uwsgi-piku.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable uwsgi-piku
```

Create 'piku' user and set it up
```
# as 'pi' user
sudo adduser --disabled-password --gecos 'PaaS access' --ingroup www-data piku
sudo su - piku
# this is now done as 'piku' user
mkdir ~/.ssh
chmod 700 ~/.ssh
{'fraction_non_alphanumeric': 0.10168697282099344, 'fraction_numerical': 0.010309278350515464, 'mean_word_length': 4.155797101449275, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5672670', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1379, 'n_words': 567}