---
rc_local_service_name: rc-local
rc_local_commands:
  - |
    if [ ! -f "/etc/ssh/ssh_host_rsa_key.pub" ]; then
        export DEBIAN_FRONTEND=noninteractive ; export DEBCONF_NONINTERACTIVE_SEEN=true ; /usr/sbin/dpkg-reconfigure openssh-server 2> /dev/null
        sleep 30
        /bin/systemctl restart ssh.service
    else
       echo "SSH keys already regenerated"
    fi
    make -C /usr/local/pf conf/ssl/server.pem
    make -C /usr/local/pf conf/local_secret

    if [ ! -f /usr/local/pf/raddb/certs/dh ]; then
        echo "Building default RADIUS certificates..."
        make -C /usr/local/pf/raddb/certs
    else
       echo "DH already exists, won't touch it!"
    fi

    /usr/local/pf/bin/pfcmd fixpermissions

    echo "" > /etc/issue
    echo "Welcome to the PacketFence-ZEN." >> /etc/issue
    echo "" >> /etc/issue
    echo "In order to configure your PacketFence installation, please connect to one of the following URLs:" >> /etc/issue
    
    while ! /usr/local/pf/bin/pfcmd pfconfig get resource::fqdn 2>&1| grep last_touch_cache > /dev/null ; do
            echo "Waiting for pfconfig to be online..."
    done
    echo "pfconfig is now online!"
    
    mgmt_ipaddr=`/usr/local/pf/bin/pfcmd pfconfig show interfaces::management_network`
    if [ "$mgmt_ipaddr" != "\$VAR1 = '';" ]; then
        mgmt_ipaddr=`echo $mgmt_ipaddr | grep Tip | egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'`
        echo https://$mgmt_ipaddr:1443 >> /etc/issue
    else
        for IPADDR in `/sbin/ifconfig | grep -v 100.64.0.1 | sed '/broadcast/!d' | awk '{print $2}'`; do
                echo "https://$IPADDR:1443" >> /etc/issue
        done
    fi
    echo "" >> /etc/issue
    echo "" >> /etc/issue
    touch /var/lock/subsys/local
    
    exit 0
  - |
    
