#!/bin/bash
set -eux
set -o pipefail

ironic_http_port=$(hiera ironic::drivers::deploy::http_port)

# Create the apache vHOST for Ironic
mkdir -p /etc/httpd/conf.d
sed "s/IRONIC_HTTP_PORT/$ironic_http_port/" $(dirname $0)/ipxe-vhost.template \
    > /etc/httpd/conf.d/10-ipxe_vhost.conf

systemctl restart httpd || :

[ -x /usr/sbin/semanage ] || exit 0

semanage fcontext -a -t httpd_sys_content_t "/httpboot(/.*)?"
restorecon -Rv /httpboot/

# Try to delete port if present
semanage port -d -t http_port_t -p tcp $ironic_http_port || true

# Add port
semanage port -a -t http_port_t -p tcp $ironic_http_port
