#!/bin/sh
#######################################################
#
#  automate-025-tune-cl
#
#######################################################
#
# License: GPL
# Author: Fabian Herschel 2016
# (c) 2016 SUSE Linux GmbH, Nuremberg, Germany
#
# To be called at primary node
#
# Syntax:
# automate-025-tune-cl [--group=<group NR>] [--nodeNr=1|2] 
# Next Automation Script
#
# TODO Tunables :)
# Tune SBD on disk parameters
# Tune SBD deamon parameters
# Tune/Check Watchdog
# Tune/Check STONITH (Fencing)
# Tune/Check Corosync basic setting (udpu, two_nodes, ...)
# 
#
#######################################################
#
set -u
source /etc/sysconfig/Landscape

FILES=$LandscapeRoot/LandscapeCore/automate-SAPHanaSR/files
PATH="$PATH:$LandscapeRoot/bin"


while [ $# -gt 0 ]; do
    case "$1" in
        --group=* ) GROUP=${1#--group=}
                   ;;
        --nodeNr=* ) nodeNr=${1#--nodeNr=}
                   ;;
        --node=* ) nodeNr=${1#--node=}
                   ;;
    esac
    shift
done

if [ -z "$GROUP" ]; then
	echo "Welcome... I am just doing some SLES automation tasks"
	echo "If any question comes along during the auto installation process, just say 'yes'"
	echo ""
	echo -n "Please enter your group number: "
	read GROUP
	echo ""
	echo "Your group number is $GROUP"
	echo "Press <enter>"
	read
	echo ""
	echo "Installing SAP HOSTAGENT and SAP HANA on both nodes..."
	echo ""
fi
echo "Doing tasks for group $GROUP ..."
echo ""

export GROUP

nodes=""
for system in "${LandscapeSystems[@]}"
do
    read hypervisor VM OWNER REST <<< $system
    if [ "$OWNER" = "$GROUP" ]; then
        nodes="$nodes $VM"
    fi
done
array_nodes=( x $nodes )

# TODO: NET_IF as configurable param
# TODO: ADD UseCase for SLES11

#
# Do some 'initial' things like sleha_init does...
#
case "$LandscapeSLES" in
    SLES11* | 11* )
        NET_IF="eth1"
        SBD="/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi0-0-0-part1"
	rcopenais stop
	bash createCorosyncConf $LandscapeSLES
	bash createSysconfigSBD $LandscapeSLES
	rcopenais start
        ;;
    SLES12* | 12* )
        NET_IF="eth0"
        SBD="/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi0-0-0-part1"
	systemctl stop pacemaker
	systemctl stop corosync
	bash createCorosyncConf $LandscapeSLES $LandscapeUseCase
	bash createSysconfigSBD $LandscapeSLES $LandscapeUseCase
	systemctl start corosync
	systemctl start pacemaker
        ;;
esac


# TODO: PRIO1: Get good sbd timing parameters from lars
# TODO: PRIO1: Get good tune parameters from lars for corosync.conf

