#!/bin/bash

# Enables automatic updates by default

#set arbitrarily high version 99.99 if no version provided
PREV_VERSION=${2:-99.99}

#Need to activate if new install or if they were previously running 3.3.2 or older
if [ "$1" == "new" -o `echo "${PREV_VERSION:0:3} < 3.4" | bc` -eq 1 ]; then
    echo "Enabling Automatic Updates"
    chkconfig --add yum-cron
    chkconfig yum-cron on
fi

#Handle updating configs here
grep "<service yum_cron>" /etc/perfsonar/toolkit/configdaemon.conf > /dev/null 2>&1
if [ $? != 0 ]; then
    sed -i '/<access>/a \\t<service yum_cron> \
		\t\trestart	\t\t 1 \
		\t\tstart \t\t 1 \
		\t\tstop \t\t 1 \
	\t</service>' /etc/perfsonar/toolkit/configdaemon.conf
fi
