#!/bin/sh -e

#
# ionoPi
#
#     Copyright (C) 2016 Sfera Labs S.r.l.
#
#     For information, see the Iono Pi web site:
#     http://www.sferalabs.cc/iono-pi
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Lesser Public License for more details.
#
# You should have received a copy of the GNU General Lesser Public
# License along with this program.  If not, see
# <http://www.gnu.org/licenses/lgpl-3.0.html>.
#

if [ x$1 = "xclean" ]; then
	echo "=== wiringPi ==="
	cd wiringPi
	./build clean
	echo "=== ionoPi ==="
	cd ../ionoPi
	make clean
	echo "Done."
	exit
fi

if [ x$1 = "xuninstall" ]; then
	echo "=== wiringPi ==="
	cd wiringPi
	./build uninstall
	echo "=== ionoPi ==="
	cd ../ionoPi
	sudo make uninstall
	echo "Done."
	exit
fi

if [ x$1 != "x" ]; then
	echo "Usage: $0 [clean | uninstall]"
	exit 1
fi

echo "=== wiringPi ==="
cd wiringPi
./build

echo "=== ionoPi ==="
cd ../ionoPi
sudo make uninstall
sudo make install

echo
echo Done.
echo 
echo "NOTE: To compile programs with ionoPi, you need to add:"
echo "    -lionoPi"
echo "  to your compile line(s)."
echo 
echo 
echo "Run 'iono' to test the installation"
echo 
