#!/bin/sh
# Copy this file, install-offline.sh, update-offline.sh
# addons-0.8.5a_full.tar.gz, addons-0.8.5a_update.tar.gz,
# addons-0.8.6_update.tar.gz and addons-0.8.6a_update.tar.gz
# to the /tmp directory of your fonera. (or call this file with
# 0.8.6a http://your_server/path/to/files

echo "Starting install of 0.8.6a"

$server="$1"

if [ -n $server ]; then
	wget -O /tmp/addons-0.8.5_full.tar.gz "$server"/addons-0.8.5_full.tar.gz
	if [ $? -ne 0 ]; then
		echo "Download of 0.8.5_full failed"
		exit 1
	fi
	wget -O /tmp/addons-0.8.5a_update.tar.gz "$server"/addons-0.8.5a_update.tar.gz
	if [ $? -ne 0 ]; then
		echo "Download of 0.8.5a_update failed"
		exit 1
	fi
	wget -O /tmp/addons-0.8.6_update.tar.gz "$server"/addons-0.8.6_update.tar.gz
	if [ $? -ne 0 ]; then
		echo "Download of 0.8.6_update failed"
		exit 1
	fi
	wget -O /tmp/addons-0.8.6a_update.tar.gz "$server"/addons-0.8.6a_update.tar.gz
	if [ $? -ne 0 ]; then
		echo "Download of 0.8.6a_update failed"
		exit 1
	fi
	wget -O /tmp/install_offline.sh "$server"/install_offline.sh
	if [ $? -ne 0 ]; then
		echo "Download of 0.8.5a_update failed"
		exit 1
	fi
	wget -O /tmp/update_offline.sh "$server"/update_offline.sh
	if [ $? -ne 0 ]; then
		echo "Download of 0.8.5a_update failed"
		exit 1
	fi
fi

echo "Starting install..."

chmod 755 /tmp/install-offline.sh
chmod 755 /tmp/update-offline.sh

/tmp/install-offline.sh 0.8.5
if [ $? -ne 0 ]; then
	echo "Install of 0.8.5 failed"
	exit 1
fi
/tmp/update-offline.sh 0.8.5a
if [ $? -ne 0 ]; then
	echo "Update to 0.8.5a failed"
	exit 1
fi
/tmp/update-offline.sh 0.8.6
if [ $? -ne 0 ]; then
	echo "Update to 0.8.6 failed"
	exit 1
fi
/tmp/update-offline.sh 0.8.6a
if [ $? -ne 0 ]; then
	echo "Update to 0.8.6a failed"
	exit 1
fi

rm -f /tmp/update.offline.sh
rm -f /tmp/0.8.6a_install.sh

echo "Install of 0.8.6a done!"
echo "You should reboot now."
exit 0

