{% if recipe %}
{% set anamon_url = anamon|default('http://' + lab_controller.fqdn + '/beaker/anamon') %}

if command -v python3 >/dev/null ; then
    fetch /usr/local/sbin/anamon {{ (anamon_url + '3')|shell_quoted }}
elif [ -f /usr/libexec/platform-python ] && \
     /usr/libexec/platform-python --version 2>&1 | grep -q "Python 3" ; then
    fetch /usr/local/sbin/anamon {{ (anamon_url + '3')|shell_quoted }}
    sed -i 's/#!\/usr\/bin\/python3/#!\/usr\/libexec\/platform-python/' /usr/local/sbin/anamon
else
    fetch /usr/local/sbin/anamon {{ anamon_url|shell_quoted }}
fi
chmod 755 /usr/local/sbin/anamon

# OS without `initscripts` need to use systemd
if [ -e /etc/init.d/functions ]; then
    fetch /etc/rc.d/init.d/anamon {{ (anamon_url + '.init')|shell_quoted }}

    chmod 755 /etc/rc.d/init.d/anamon
    if selinuxenabled &>/dev/null ; then
        restorecon /etc/rc.d/init.d/anamon /usr/local/sbin/anamon
    fi

    chkconfig --add anamon
else
    fetch /etc/systemd/system/anamon.service {{ (anamon_url + '.service')|shell_quoted }}
    systemctl enable anamon
fi

cat << __EOT__ > /etc/sysconfig/anamon
XMLRPC_URL="http://{{ lab_controller.fqdn }}:8000/RPC2"
RECIPE_ID="{{ recipe.id }}"
LOGFILES="/var/log/boot.log /var/log/messages /var/log/dmesg"
__EOT__

{% endif %}
