#!/bin/bash

if [[ $(/usr/bin/id -u) -ne 0 ]]; then
    echo "Not running as root"
    exit
fi

# modify common configs
sed -i 's/installonly_limit=5/installonly_limit=2/' /etc/yum.conf
sed -i 's/GRUB_DEFAULT=saved/GRUB_DEFAULT=0/' /etc/default/grub
sed -i 's/#hostonly="yes"/hostonly="no"/' /etc/dracut.conf
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

# clean up before install
yum clean all

# update whole system
yum -y update --skip-broken

# install development tools
yum -y groupinstall "Development Tools"

# SpaceWalk Remote Management
yum -y copr enable @spacewalkproject/spacewalk-2.8-client
yum -y install rhn-client-tools rhn-check rhn-setup rhnsd m2crypto
#Fedora: yum -y install dnf-plugin-spacewalk
#RHEL: yum -y install yum-rhn-plugin

# Icinga Monitoring
rpm --import https://packages.icinga.com/icinga.key
curl https://packages.icinga.com/fedora/ICINGA-release.repo -o /etc/yum.repos.d/ICINGA-release.repo
yum -y install icinga2 icinga2-bin icinga2-common
yum -y install nagios-plugins-*

# FreeIPA Access Management
yum -y install freeipa-client

# write new boot config
grub2-mkconfig -o /boot/grub2/grub.cfg

# enable or disable (un)needed services
systemctl daemon-reload

systemctl stop firewalld
systemctl mask firewalld
systemctl disable firewalld

systemctl enable haveged
systemctl enable fail2ban
systemctl enable ntpd
systemctl enable fstrim.timer

# set current time
ntpdate ptbtime1.ptb.de

# sync fs and reboot
sync
reboot
