if command -v dnf >/dev/null ; then
   package_command="dnf"
else
   package_command="yum"
fi
$package_command{{ ' ' + yum_install_extra_opts if yum_install_extra_opts is defined else '' }} -y install {{ beah_rpm|default('beah') }} rhts-test-env
$package_command{{ ' ' + yum_install_extra_opts if yum_install_extra_opts is defined else '' }} -y install beakerlib
# This may fail if you are outside of Red Hat..
$package_command{{ ' ' + yum_install_extra_opts if yum_install_extra_opts is defined else '' }} -y install beakerlib-redhat

cp /etc/beah_beaker.conf{,.default}
cat << EOF > /etc/beah_beaker.conf
# see /etc/beah_beaker.conf.default for commented configuration

[DEFAULT]
# LAB_CONTROLLER: URI of Beaker's XML-RPC handler
LAB_CONTROLLER=http://{{ lab_controller.fqdn }}:8000
{% if system %}
#
# HOSTNAME: Pretend to be machine with given name.
# NOTE: This is mostly pointless as usually correct name is assigned by DHCP.
HOSTNAME={{ system.fqdn }}
{% endif %}
RECIPEID={{ recipe.id }}

# Turn on hard limits on upload sizes:
FILE_SIZE_LIMIT=200000000
TASK_SIZE_LIMIT=800000000

{% if beah_no_ipv6 is defined %}
IPV6_DISABLED=True
{% endif %}
EOF

cp /etc/beah.conf{,.default}
cat << EOF > /etc/beah.conf
# see /etc/beah.conf.default for commented configuration

[DEFAULT]
# Turn on more verbose logging. This is useful for debugging harness' problems.
LOG=Info
{# On systemd distros, systemd will capture all beah output and send it to the 
 # journal and the system console for us. #}
{% if has_systemd is undefined and beah_no_console_output is undefined %}
# Also send logs to /dev/console.
CONSOLE_LOG=Console
{% endif %}
# To turn on debug logging uncomment the following line. Warning: this is
# rather verbose! This also requires LOG to be Debug.
#DEVEL=True
{% if beah_no_ipv6 is defined %}
IPV6_DISABLED=True
{% endif %}

[TASK]
INTERFACE=

EOF

{% if has_systemd is defined %}
systemctl enable beah-srv.service
systemctl enable beah-beaker-backend.service
systemctl enable beah-fwd-backend.service
{% if beah_no_console_output is defined %}
mkdir /etc/systemd/system/beah-srv.service.d
cat >/etc/systemd/system/beah-srv.service.d/50-no-console.conf <<EOF
[Service]
StandardOutput=journal
EOF
mkdir /etc/systemd/system/beah-beaker-backend.service.d
cat >/etc/systemd/system/beah-beaker-backend.service.d/50-no-console.conf <<EOF
[Service]
StandardOutput=journal
EOF
mkdir /etc/systemd/system/beah-fwd-backend.service.d
cat >/etc/systemd/system/beah-fwd-backend.service.d/50-no-console.conf <<EOF
[Service]
StandardOutput=journal
EOF
restorecon -R /etc/systemd/system || :
{% endif %}
{% else %}
chkconfig --level 345 beah-srv on
chkconfig --level 345 beah-beaker-backend on
chkconfig --level 345 beah-fwd-backend on
{% endif %}
{% snippet 'default_rhts_compat' %}
