#!/usr/bin/env bash

scriptpath="`readlink -f \"$0\"`"
scriptbase="`dirname \"${scriptpath}\"`"

. "${scriptbase}/migrate-tools"

enforce_root

OS="`getos`"

if [ "${OS}" = "Ubuntu" ]; then
	if [ "`ls /var/cache/apt/archives/*.deb`" != "" ]; then
		dpkg -i /var/cache/apt/archives/*.deb
	fi
elif [ "${OS}" = "CentOS" ]; then
	if [ "`ls /var/lib/dosis2/rpm/archives/*.rpm`" != "" ]; then
		#rpm -Uvh /var/lib/dosis2/rpm/archives/*.rpm
		yum localinstall /var/lib/dosis2/rpm/archives/*.rpm
	fi
else
	echo "Unsupported OS: ${OS}"
fi

/opt/dosis2/bin/os-support-service restart postgresql-9.2
pushd /opt/dosis2/database > /dev/null 2>&1
./db_setup.bash
popd > /dev/null 2>&1
