#!/bin/bash

source "/etc/asl/config"
export LANG="en_US.UTF-8"
WAIT=$(echo $RANDOM | cut -c1-3)


if [ "$CONFIGURED" ==  "yes" ]; then
  

  # Automatic Updates
  if [ "$AUTOMATIC_UPDATES" ==  "hourly" ]; then
	sleep $WAIT
    	/var/asl/bin/aum -u >/dev/null 2>&1
	
  else 
	sleep $WAIT
    	/var/asl/bin/aum -ck >/dev/null 2>&1
  fi

  # generate reports
  if [ -f /var/asl/bin/asl ]; then
	  if [ -f /var/asl/tmp/.upgrade ]; then
		/sbin/service tortixd restart >/dev/null 2>&1
		/var/asl/bin/asl -s -f >/dev/null 2>&1
		rm -f /var/asl/tmp/.upgrade
	  else
		/var/asl/bin/asl -s >/dev/null 2>&1
	  fi
  fi

  # Run rep report
  if [ "$REPUTATION_REPORT" == "yes" ]; then
  	if [ "$REPUTATION_FREQUENCY" == "hourly" ]; then
		/var/asl/bin/asl --rep_report >/dev/null 2>&1
	fi
  fi
  
else
  echo "Error: ASL has not been configured"
  exit 1
fi

