#!/bin/bash

# Script to update automatically Beta-hosts with cronjobs. To install it:
#    mkdir /root/bin
#    cp /root/elt/upate-puppet-beta.sh /root/bin
#    chmod +x /root/bin/update-puppet-beta.sh
#    crontab -e # add this line:
#	0 0 * * * bin/update-puppet-beta.sh > /tmp/update-puppet-beta.log 2>&1
#    systemctl enable crond
#    systemctl start crond

yum-config-manager --enable ESO-Beta-CentOS-8 >/dev/null 2>&1

yum -y update puppet-elt

ed /root/elt/puppet/modules/ESO/eltgeneral/manifests/init.pp << EOF >/dev/null
1
/ESO-Beta repository
/enabled
s/0/1/
w
q
EOF

cd /root/elt
./puppet-force-align

if ! grep -q BETA /etc/motd; then
  echo "                         BETA BETA BETA BETA BETA BETA BETA BETA!!!! " >> /etc/motd
  echo "" >> /etc/motd
fi

# On REALTIME hosts (env ELT_REALTIME=yes), crond might be disabled by puppet. 
# With no crond running this script will not be executed next time
/usr/bin/systemctl is-active crond >/dev/null 2>&1
if [ $? -ne 0 ]; then
  echo "Restoring crond"
  /usr/bin/systemctl enable crond
  /usr/bin/systemctl start crond
fi
