#!/bin/bash
#
#   ConVirt   -  Copyright (c) 2008 Convirture Corp.
#   ======
#
# ConVirt is a Virtualization management tool with a graphical user
# interface that allows for performing the standard set of VM operations
# (start, stop, pause, kill, shutdown, reboot, snapshot, etc...). It
# also attempts to simplify various aspects of VM lifecycle management.
#
#
# This software is subject to the GNU General Public License, Version 2 (GPLv2)
# and for details, please consult it at:
#
#    http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
# 
#
# author : Jd <jd_jedi@users.sourceforge.net>
#

# Distribution and version specific code can go here.
# Assume that common functions are included
# Assme the DIST and the VER to be set here.


install_cms_prereq_packages()
{
   zypper -n in wget make xen xen-libs xen-tools socat dnsmasq tunctl gcc mysql mysql-client   
   ret=$?
   if [ $ret != 0 ]; then
      echo "ERROR: Installing required packages."
      return $ret
   fi
   zypper in python-devel libmysqlclient-devel python-paramiko
   ret=$?
   if [ $ret != 0 ]; then
      echo "ERROR: Installing required packages. Please make sure that you have ConVirt repository setup done."
      return $ret
   fi
}

install_ez_setup()
{
   # tweak dist utils
   if [ -e /usr/lib64/python/distutils/distutils.cfg ]; then
      $SUDO sed -i.bak 's/prefix=\/usr\/local/prefix=\/usr/' /usr/lib64/python/distutils/distutils.cfg
   fi
   if [ -e /usr/lib/python/distutils/distutils.cfg ]; then
      $SUDO sed -i.bak 's/prefix=\/usr\/local/prefix=\/usr/' /usr/lib/python/distutils/distutils.cfg
   fi
   $SUDO wget http://peak.telecommunity.com/dist/ez_setup.py
   $SUDO python ez_setup.py
}

set_default_to_innodb()
{
   if [ `grep -v '#' /etc/my.cnf | grep -c default-storage-engine=innodb` == 0 ]; then
      $SUDO sed -i.bak '/\[mysqld\]/ a\
default-storage-engine=innodb
' /etc/my.cnf
   fi
}

fix_xen_in_tg2env()
{
   # Link xen libraries
   if [ ! -e $VIRTUAL_ENV_DIR/lib/python2.*/site-packages/xen ]; then
      ln -s /usr/lib64/python/site-packages/xen $VIRTUAL_ENV_DIR/lib/python2.*/site-packages/
   fi
}

additional_setup_mysql()
{
    
    echo "Starting MySQL service."
    $SUDO /etc/init.d/mysql start
    echo "Setting mysql root password to convirt."
    echo "Enter mysql password given at the time of installation."
    echo "For blank password press Enter key."
    mysqladmin -u root -p password convirt
}
