#!/bin/bash -ex

# set localhost to be always be first nameserver
echo "nameserver 127.0.0.1" >> /etc/resolvconf/resolv.conf.d/head
echo "search domain.lan" >> /etc/resolvconf/resolv.conf.d/head
echo "domain domain.lan" >> /etc/resolvconf/resolv.conf.d/head

# symlink for samba documentation
ln -s /usr/share/doc/samba-doc/htmldocs /var/www/samba

# setup cups certificate
/usr/lib/inithooks/firstboot.d/16cups-sslcert

# tweak tkl-webcp
sed -i "s|padding: 5pt 8px;|padding: 5pt 8px 25pt 8px;|" /var/www/css/base.css

# disable Lighty "unconfigured" site and enable tkl-webcp
lighttpd-disable-mod unconfigured
lighttpd-enable-mod tkl-webroot

# disable standalone samba services - samba-ad-dc will start if required
# note: they won't start anyway, this just keeps the logs cleaner
systemctl disable smbd.service
systemctl disable nmbd.service
systemctl disable winbind.service

# enable samba-ad-dc service
systemctl unmask samba-ad-dc
systemctl enable samba-ad-dc

# adjust Webmin so it uses the correct service
webmin_conf=/etc/webmin/samba/config
for comm in start restart stop; do
    sed -i "\|^${comm}_cmd=| s|=.*|=service samba-ad-dc ${comm}|" $webmin_conf
done

# Disable CUPS by default
systemctl disable --now cups.service
