#!/bin/sh
set -e
set -x
echo "This script helps you migrate your existing launch-control installation to LAVA"

if  [ `id -u` != 0 ]; then
    echo "Invoke with sudo please"
    exit
fi

echo "Adding new Linaro Validation PPA"
add-apt-repository ppa:linaro-validation/ppa
apt-get update
echo "Upgrading to latest version of Launch Control"
apt-get dist-upgrade --yes


echo "Shutting down apache to prevent modifications to the database"
service apache2 stop
echo "Moving launch-control settings to lava-server"
mv /etc/launch-control /etc/lava-server
mv /etc/dbconfig-common/launch-control.conf /etc/dbconfig-common/lava-server.conf
sed -i -e 's/launch-control/lava-server/g' /etc/dbconfig-common/lava-server.conf /etc/lava-server/default_database.conf

echo "Moving launch-control files to lava-server"
mv /var/lib/launch-control /var/lib/lava-server

echo "Installing lava-dashboard"
sudo apt-get install lava-dashboard --yes

echo "Starting apache"
sudo service apache2 start
