Raspberry Pi2 Raspbian

From Davical
Jump to: navigation, search

UNDER CONSTRUCTION

This guide is intended to people who want a lightweight calendar server at home, behind an internet box, up 24h/24h, with very low consumption, and chose a cheap Raspberry Pi. This guide has been written according to Raspberry Pi 2 model B but shall be working also with others versions. This guide explains how to install DaviCal calendar server and optionally InfCloud CalDAV/CardDAV web clients. It assume an other linux computer is available on the LAN with an Internet connexion.

Hardware tested:

  • 2015-11-07: Raspberry Pi 2 model B
  • 2015-06-18: Raspberry Pi 2 model B

System tested:

  • 2015-11-07: Raspbian jessie released on 2015-09-24
  • 2016-06-18: Raspbian jessie released on 2016-05-27

Software versions tested:

  • 2015-11-07: TBD DAViCal xxx, PostgreSql xxx, InfCloud xxx
  • 2016-06-18: TBD DAViCal 1.1.3.1, AWL 0.55, PostgreSql 9.4.8, InfCloud xxx

HW and network installation guide

Before starting, what you need

  • a Raspberry with RJ45 LAN connector (Pi 2 model B for example)
  • a Raspberry Pi Case (optional, but advised)
  • a 8 Go micro-SD card
  • a Raspberry Pi universal power supply (or equivalent)
  • an internet box with a free RJ45 connexion
  • an Ethernet cable (RJ45)
  • an other computer with an internet connexion and a micro-SD card adapter

See distributors on Raspberry shop page: https://www.raspberrypi.org/products/

What you don't need but can be useful

  • an USB keyboard
  • an USB mouse
  • an HDMI display

Preparing Raspberry Pi micro-SD card from a linux computer

wget https://downloads.raspberrypi.org/raspbian_lite_latest
openssl dgst -sha1 raspbian_lite_latest
# SHA1(raspbian_lite_latest)= 03b6ea33efc3bb4d475f528421d554fc1ef91944
unzip raspbian_lite_latest
# 2016-05-27-raspbian-jessie-lite.img
  • flash your micro-SD card (carefully identify micro-SD card device letter and replace sdX with correct drive!)
# before micro-SD card connexion, have a look to your computer drives (to preserve)
ls -l /dev/sd?
# after micro-SD card connexion, have a look to the new micro-SD card drive (to write to)
ls -l /dev/sd?
dd bs=2M if=2016-05-27-raspbian-jessie-lite.img of=/dev/sdX
sync
# if root required, you probably need to prefix dd and gparted commands with sudo
  • expand your raspberry / partition to full micro-SD card
gparted
# select micro-SD drive
# right click on / partition and expand it to full size
# click on apply
# remove micro-SD card from linux computer

Connecting Raspberry Pi to LAN and boot

Okay, you need a RJ45 cable between Raspberry and your box, insert micro-SD card into your Raspberry and plug on power supply. You can check:

  • near micro-SD card, red light ON
  • green light blinking few seconds and then OFF
  • near RJ45 connector yellow and red lights ON

If red and green lights are ON near micro-SD card, you may have a problem with your SD-card (missing, wrongly inserted, badly flashed, ...).

Now, you just have to guess your Raspberry Pi IP address! What you can try:

  • have a look to your box administration page
  • get your linux computer IP address
ifconfig
# inet addr: 192.168.x.y
  • try addresses 192.168.x.2 to 192.168.x.254 around y
  • connect to your Raspberry Pi
ssh -Y pi@192.168.x.z
# password: raspberry

If you fail guessing your Raspberry IP address:

  • connect USB mouse and Keyboard + HDMI display
  • launch a terminal

Then, you should write down a paper your Raspberry Mac address:

ifconfig
# HWaddr aa:bb:cc:dd:ee:ff

And configure your box router to assign a static local IP address to your Raspberry. Static DHCP reservation assigns a local IP address to a Mac HWaddr. Some boxes need a reboot to make static DHCP reservations active.

SW installation guide

DAViCal Install

(adapted and simplified from Debian_shared)

(858384 kb used on /)

Install current DAViCal version with Jessie dependencies:

sudo apt-get update
sudo apt-get install locales
export LANGUAGE="en_GB"
export LC_ALL="en_GB.UTF-8"
sudo dpkg-reconfigure locales              # select your locale with TUI
sudo apt-get install davical davical-doc

(1121108 kb used on /)

To be continued...


Prepare the DAViCal database values (please, for security reasons, choose your own values):

DatabaseName=mycaldb
DBUsername_dba=mycaluser_dba
DBUsername_app=mycaluser_app
DBPassword=12345
AdminPassword=1234

Add open permissions temporarily for the installation scripts:

MediumPgVersion="$(psql --version | grep -ie "sql" | tr -s " " "\n" | tail --lines=1 | cut -f 1,2 -d ".")"
PgConfig="/etc/postgresql/${MediumPgVersion}/main/pg_hba.conf"
sudo mv "$PgConfig" "${PgConfig}.davical-bak"
sudo cp -a "${PgConfig}.davical-bak" "$PgConfig"
echo "# Permissions for the DAViCal CMS" | sudo tee "$PgConfig"
echo "local $DatabaseName $DBUsername_dba trust" | sudo tee --append "$PgConfig"
echo "local $DatabaseName $DBUsername_app trust" | sudo tee --append "$PgConfig"
echo "" | sudo tee --append "$PgConfig"
sudo cat "${PgConfig}.davical-bak" | sudo tee --append "$PgConfig"
# Service name can be only "postgresql" or more:
sudo service postgresql reload

Apply a temporary patch to creation script:

CScript="/usr/share/davical/dba/create-database.sh"
sudo mv "$CScript" "${CScript}.davical-bak"
sudo cp -a "${CScript}.davical-bak" "$CScript"
cat "${CScript}.davical-bak" | sed -e "s/DBNAME=.*/DBNAME=${DatabaseName}/g" | sed -e "s/AWL_DBAUSER=.*/AWL_DBAUSER=${DBUsername_dba}/g" | sed -e "s/AWL_APPUSER=.*/AWL_APPUSER=${DBUsername_app}/g" | sudo tee "$CScript"

Apply a temporary patch to update script:

UScript="/usr/share/davical/dba/update-davical-database"
sudo mv "$UScript" "${UScript}.davical-bak"
sudo cp -a "${UScript}.davical-bak" "$UScript"
cat "${UScript}.davical-bak" | sed -e "s/\$dbname = .*/\$dbname = \"${DatabaseName}\";/g" | sed -e "s/\$dbuser = .*/\$dbuser = \"${DBUsername_dba}\";/g" | sed -e "s/\$appuser = .*/\$appuser = \"${DBUsername_app}\";/g" | sed -e "s/\$dbpass = .*/\$dbpass = \"${DBPassword}\";/g" | sudo tee "$UScript"

(only fresh install) Run main installation script and take note of the shown password for the 'admin' user:

sudo su -l postgres -c "$CScript" "$DatabaseName" "$AdminPassword"

(only restoration of a backup) Restore data and run update script:

echo "DROP DATABASE IF EXISTS ${DatabaseName};" | sudo su -l postgres -c psql
echo "DROP USER IF EXISTS ${DBUsername_dba};" | sudo su -l postgres -c psql
sudo su -l postgres -c "psql --quiet --file ${DBUsername_dba}.pgdump"
echo "DROP USER IF EXISTS ${DBUsername_app};" | sudo su -l postgres -c psql
sudo su -l postgres -c "psql --quiet --file ${DBUsername_app}.pgdump"
sudo su -l postgres -c "psql --quiet --file ${DatabaseName}.pgdump"
sudo su -l postgres -c "$UScript"

Restore installation scripts to original:

sudo mv "${UScript}.davical-bak" "$UScript"
sudo mv "${CScript}.davical-bak" "$CScript"

(only fresh install) Set password authentication for the database:

echo "ALTER USER $DBUsername_dba WITH PASSWORD '${DBPassword}';" | sudo su -l postgres -c psql
echo "ALTER USER $DBUsername_app WITH PASSWORD '${DBPassword}';" | sudo su -l postgres -c psql

Allow these authenticated access to PostgreSql:

echo "# Permissions for the DAViCal CMS" | sudo tee "$PgConfig"
echo "local $DatabaseName $DBUsername_dba password" | sudo tee --append "$PgConfig"
echo "local $DatabaseName $DBUsername_app password" | sudo tee --append "$PgConfig"
echo "" | sudo tee --append "$PgConfig"
sudo cat "${PgConfig}.davical-bak" | sudo tee --append "$PgConfig"
# Service name can be only "postgresql" or more:
sudo service postgresql reload

Create or restore configuration file as /etc/davical/config.php (for default host example.net/davical) with its content as in the following example:

<?php
	$c->admin_email = 'admin@example.net';
	$c->system_name = "My CalDAV Server";
	$c->enable_row_linking = true;
	$c->default_locale = 'en_US.UTF-8';            # or something else: fr_FR.UTF-8, ...
	
	$c->pg_connect[] = 'dbname=mycaldb port=5432 user=mycaluser_app password=12345';

Avoid permissions issues:

sudo chmod a+r /etc/davical/config.php

Create or restore Apache virtualhost /etc/apache2/sites-available/000-default.conf with its profile content as in this example:

<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	DocumentRoot	/var/www/html
       ErrorLog ${APACHE_LOG_DIR}/error.log
       CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Enable Apache website (may be useless):

sudo a2ensite 000-default

Enable davical:

cd /var/www/html
sudo ln -s /usr/share/davical/htdocs/ davical

Now you should be able to browse to example.net/davical with your favourite web browser. If not, check example.net/davical/setup.php for details.


Login to DAViCal Admin

If all is going well you should now be able to browse to the site pages and log in as 'admin' with the password set during installation.

Apache2 setup for SSL access to DAViCal

Install SSL for apache2:

sudo apt-get install ssl-cert
sudo mkdir /etc/apache2/ssl
sudo make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem # (localhost + your box's public IP address)
sudo a2enmod ssl
sudo service apache2 restart
sudo a2ensite default-ssl
sudo service apache2 reload

Now, you can browse https://example.net/davical (you will probably have to add an exception in your browser because of self-signed certificate).

InfCloud setup (optional)

Check for InfCloud version at https://www.inf-it.com/open-source/clients/infcloud/

Download, unzip configure an run InfCloud:

cd
wget https://www.inf-it.com/InfCloud_0.13.1.zip
cd /usr/share
sudo unzip $HOME/InfCloud_0.13.1.zip
cd infcloud
sudo vi config.js # In globalNetworkCheckSettings=, change '/caldav.php/' with '/davical/caldav.php/'
sudo vi config.js # Check for globalInterfaceLanguage, globalDatepickerFirstDayOfWeek, globalDefaultAddressCountry
cd /var/www/html
sudo ln -s /usr/share/infcloud/ infcloud
sudo service apache2 reload

Now you should be able to browse to example.net/infcloud with your favourite web browser (and through https if apache2 configured for SSL) and login with davical account. Note: due to HTML5 browser caching, an update in config.js after browsing will probably need to delete browser cache manually.