#!/bin/bash
##################################################
# HA-Lizard noSAN Installer version 2.1.4
##################################################
#################################################################################################
#
# HA-Lizard - Open Source High Availability Framework for Xen Cloud Platform and XenServer
#
# Copyright 2021 Salvatore Costantino
# ha@pulsesupply.com
#
# This file is part of HA-Lizard.
#
#    HA-Lizard is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    HA-Lizard is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with HA-Lizard.  If not, see <http://www.gnu.org/licenses/>.
#
##################################################################################################

INSTALL_LOG=/tmp/ha-lizard-deps-install.log
#####################################
# Check for connection to internet
#####################################
HALIZARD_MIRROR_URL='http://halizard.org/release'
wget -q --tries=10 --timeout=20 --spider $HALIZARD_MIRROR_URL
if [ $? -ne 0 ]
then
	echo "No internet access detected. An internet connection"
	echo "is required to download the required components"
	exit 1
fi

#######################################
# Create repos required for installing
# DRBD init, DRBD userland tools, tgt
#######################################
echo '#######################
## Base CentOS7 Repo ##
#######################
[ha-lizard-base]
name=CentOS-$releasever - ha-lizard
mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=os&infra=$infra
baseurl=http://mirror.centos.org/centos/7/os/$basearch/
enabled=0
gpgcheck=0

#######################
## epel CentOS7 Repo ##
#######################
[ha-lizard-epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=0
gpgcheck=0

#########################
## elrepo CentOS7 Repo ##
#########################
### Name: ELRepo.org Community Enterprise Linux Repository for el7
### URL: http://elrepo.org/

[ha-lizard-elrepo]
name=ELRepo.org Community Enterprise Linux Repository - el7
baseurl=http://elrepo.org/linux/elrepo/el7/$basearch/
        http://mirrors.coreix.net/elrepo/elrepo/el7/$basearch/
        http://jur-linux.org/download/elrepo/elrepo/el7/$basearch/
        http://repos.lax-noc.com/elrepo/elrepo/el7/$basearch/
        http://mirror.ventraip.net.au/elrepo/elrepo/el7/$basearch/
mirrorlist=http://mirrors.elrepo.org/mirrors-elrepo.el7
enabled=0
gpgcheck=0
protect=0' > /etc/yum.repos.d/ha-lizard.repo

######################################
# Install DRBD
# Set chkconfig to off
######################################
echo "Installing DRBD packages"
yum install drbd84-utils --enablerepo=ha-lizard-elrepo -y >> $INSTALL_LOG
yum install drbd84-utils-sysvinit --enablerepo=ha-lizard-elrepo -y >> $INSTALL_LOG
systemctl disable drbd

####################################
# Install iSCSI Target Framework
# and make sure it does not start
# automatically
####################################
echo "Installing iSCSI Target Framework"
yum install scsi-target-utils --enablerepo=ha-lizard-epel,ha-lizard-base -y >> $INSTALL_LOG
systemctl disable tgtd


