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

# Preparation of an Raspbian image for BPI M2+ EDU (and likely more flavors).
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/bpi_modules /etc/modules

echo Copying parameter list for w1_sunxi driver to load on correct pin.
sudo cp ~/HuboInstall/bpi_m2p_load_1wire.conf /etc/modprobe.d/bpi_m2p_load_1wire.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 ./bpi_DigitalInput1.out.
echo
read -p "However, first you need to reboot. Press [Enter] key to reboot or [STRG+C] to cancel..."
sudo reboot
