#!/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.

# Sudo is not setup by default on Fedora/CentOS/RHEL

SUDO=""

install_cms_prereq_packages()
{
  $SUDO yum install -y openssh-server openssh-clients python-devel xen socat dnsmasq tunctl python-paramiko gcc mysql-devel mysql-server
}   


# Make the innodb default engine
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
}

# additional setup
additional_setup_mysql()
{
   /etc/init.d/mysqld start
   chkconfig --level 345 mysqld on

###  Automating this is not working because of stty error. 
##   TBD: try it with pexpect sometime.
###   if [ -e /usr/bin/mysql_secure_installation ]; then
###      ## Create response file for running secure installation script
###      # Change password ? Y
###      # Enter new password : convirt.
###      # Remove anonymous user : Y
###      # Disallow root login remotely : Y
###      # Remove test database ? Y
###      # Reload privilege tables now ? Y
###
###      MYSQL_SECURE_INST_RESP_FILE=`mktemp -t mysql_secure_inst.resp.XXXXXXXXXX`
###      cat  <<EOF > $MYSQL_SECURE_INST_RESP_FILE
###Y
###convirt
###Y
###Y
###Y
###Y
###EOF
###
###      # run the command with the response file.
###      /usr/bin/mysql_secure_installation < $MYSQL_SECURE_INST_RESP_FILE
###      rm -f $MYSQL_SECURE_INST_RESP_FILE	
###   fi
   if [ -e /usr/bin/mysql_secure_installation ]; then
      echo "Running mysql_secure_installation."
      echo "Current root password for fresh installation is blank. So simple press enter."
      /usr/bin/mysql_secure_installation
   fi
   return 0
}

# service name is different
restart_mysql()
{
   $SUDO /etc/init.d/mysqld restart
}
# service name is different
start_mysql()
{
   $SUDO /etc/init.d/mysqld start
}

# service name is different
status_mysql()
{
   $SUDO /etc/init.d/mysqld status
}


