#!/bin/bash

function install_drbl()
{
  echo "Installing Diskless Remote Boot in Linux ...."
  echo "deb http://free.nchc.org.tw/drbl-core drbl stable" > drbl.list
  sudo mv drbl.list /etc/apt/sources.list.d/
  wget http://drbl.nchc.org.tw/GPG-KEY-DRBL
  sudo apt-key add GPG-KEY-DRBL
  rm GPG-KEY-DRBL
  sudo apt-get update
  sudo apt-get install drbl
  sudo /opt/drbl/sbin/drblsrv -i
  sudo /opt/drbl/sbin/drblpush -i
}

function install_ganglia()
{
  echo "Installing Ganglia ...."
  sudo apt-get install gmetad ganglia-monitor
  sudo apt-get install rrdtool librrds-perl librrd-dev apache2 libapache2-mod-php5 php5-gd apache2-mpm-prefork apache2-utils apache2.2-common libapr1 libaprutil1 libmysqlclient15off libpq5 mysql-common openssl-blacklist ssl-cert
  echo "deb http://free.nchc.org.tw/debian testing main" > testing.list
  sudo mv testing.list /etc/apt/sources.list.d/
  sudo apt-get update
  sudo apt-get install ganglia-webfrontend
  sudo rm /etc/apt/sources.list.d/testing.list
  sudo apt-get update
}

function configure_gmetad()
{
  echo "Configuring gmetad ..."
}

function configure_gmom()
{
  echo "Configuring gmom ..."
}

if [ ! -d /opt/drbl ]; then
  install_drbl
fi

if [ ! -f /usr/sbin/gmond ] || [ ! -f /usr/sbin/gmetad ]; then
  install_ganglia
fi
