#!/bin/bash
# Navigate to install location
cd ~/HuboInstall

# Preparation of an Raspbian Jessie image.
echo Updating repository and installation. 
sudo apt-get -y update 
sudo apt-get -y upgrade

echo Installing latest version of GNU C++ compiler.
sudo apt-get -y install g++

echo Backing up old modules file and replacing it by new one.
sudo mv /etc/modules /etc/modules_original
sudo cp ~/HuboInstall/modules /etc/modules

echo Backing up old blacklist file and replacing it by new one.
sudo mv /etc/modprobe.d/raspi-blacklist.conf /etc/modprobe.d/raspi-blacklist.conf_original
sudo cp ~/HuboInstall/raspi-blacklist.conf /etc/modprobe.d/raspi-blacklist.conf

echo Copying library to lib space.
sudo cp ~/HuboDemo/libhubo.so /usr/lib/libhubo.so.1
sudo chmod 755 /usr/lib/libhubo.so.1

echo Preparing Python i2c
sudo apt-get -y install python-dev python-smbus
sudo adduser pi i2c

echo Preparing Python SPI
sudo apt-get -y install git
git clone https://github.com/doceme/py-spidev.git
cd py-spidev
sudo python setup.py install

echo Rebuilding Hubo demo files
cd ~/HuboDemo
./build

echo 
echo You are now prepared to run your first demo application. 
echo Change into ~/HuboDemo/DigitalInput1 and type sudo ./DigitalInput1.out.
echo
read -p "However, first you need to reboot. Press [Enter] key to reboot or [STRG+C] to cancel..."
sudo reboot
