#!/bin/bash set -e appSetup () { # Set variables DOMAIN=${DOMAIN:-SAMDOM.LOCAL} DOMAINPASS=${DOMAINPASS:-youshouldsetapassword} JOIN=${JOIN:-false} JOINSITE=${JOINSITE:-NONE} MULTISITE=${MULTISITE:-false} NOCOMPLEXITY=${NOCOMPLEXITY:-false} INSECURELDAP=${INSECURELDAP:-false} DNSFORWARDER=${DNSFORWARDER:-NONE} HOSTIP=${HOSTIP:-NONE} LDOMAIN=${DOMAIN,,} UDOMAIN=${DOMAIN^^} URDOMAIN=${UDOMAIN%%.*} # If multi-site, we need to connect to the VPN before joining the domain if [[ ${MULTISITE,,} == "true" ]]; then /usr/sbin/openvpn --config /docker.ovpn & VPNPID=$! echo "Sleeping 30s to ensure VPN connects ($VPNPID)"; sleep 30 fi # Set host ip option if [[ "$HOSTIP" != "NONE" ]]; then HOSTIP_OPTION="--host-ip=$HOSTIP" else HOSTIP_OPTION="" fi # Set up samba mv /etc/krb5.conf /etc/krb5.conf.orig echo "[libdefaults]" > /etc/krb5.conf echo " dns_lookup_realm = false" >> /etc/krb5.conf echo " dns_lookup_kdc = true" >> /etc/krb5.conf echo " default_realm = ${UDOMAIN}" >> /etc/krb5.conf # If the finished file isn't there, this is brand new, we're not just moving to a new container if [[ ! -f /etc/samba/external/smb.conf ]]; then mv /etc/samba/smb.conf /etc/samba/smb.conf.orig if [[ ${JOIN,,} == "true" ]]; then if [[ ${JOINSITE} == "NONE" ]]; then samba-tool domain join ${LDOMAIN} DC -U"${URDOMAIN}\administrator" --password="${DOMAINPASS}" --dns-backend=SAMBA_INTERNAL else samba-tool domain join ${LDOMAIN} DC -U"${URDOMAIN}\administrator" --password="${DOMAINPASS}" --dns-backend=SAMBA_INTERNAL --site=${JOINSITE} fi else samba-tool domain provision --use-rfc2307 --domain=${URDOMAIN} --realm=${UDOMAIN} --server-role=dc --dns-backend=SAMBA_INTERNAL --adminpass=${DOMAINPASS} ${HOSTIP_OPTION} if [[ ${NOCOMPLEXITY,,} == "true" ]]; then samba-tool domain passwordsettings set --complexity=off samba-tool domain passwordsettings set --history-length=0 samba-tool domain passwordsettings set --min-pwd-age=0 samba-tool domain passwordsettings set --max-pwd-age=0 fi fi sed -i "/\[global\]/a \ \\\tidmap_ldb:use rfc2307 = yes\\n\ wins support = yes\\n\ template shell = /bin/bash\\n\ winbind nss info = rfc2307\\n\ idmap config ${URDOMAIN}: range = 10000-20000\\n\ idmap config ${URDOMAIN}: backend = ad\ " /etc/samba/smb.conf if [[ $DNSFORWARDER != "NONE" ]]; then sed -i "/\[global\]/a \ \\\tdns forwarder = ${DNSFORWARDER}\ " /etc/samba/smb.conf fi if [[ ${INSECURELDAP,,} == "true" ]]; then sed -i "/\[global\]/a \ \\\tldap server require strong auth = no\ " /etc/samba/smb.conf fi # Once we are set up, we'll make a file so that we know to use it if we ever spin this up again cp /etc/samba/smb.conf /etc/samba/external/smb.conf else cp /etc/samba/external/smb.conf /etc/samba/smb.conf fi # Set up supervisor echo "[supervisord]" > /etc/supervisor/conf.d/supervisord.conf echo "nodaemon=true" >> /etc/supervisor/conf.d/supervisord.conf echo "" >> /etc/supervisor/conf.d/supervisord.conf echo "[program:samba]" >> /etc/supervisor/conf.d/supervisord.conf echo "command=/usr/sbin/samba -i" >> /etc/supervisor/conf.d/supervisord.conf if [[ ${MULTISITE,,} == "true" ]]; then if [[ -n $VPNPID ]]; then kill $VPNPID fi echo "" >> /etc/supervisor/conf.d/supervisord.conf echo "[program:openvpn]" >> /etc/supervisor/conf.d/supervisord.conf echo "command=/usr/sbin/openvpn --config /docker.ovpn" >> /etc/supervisor/conf.d/supervisord.conf fi appStart } appStart () { if [[ -f /etc/samba/external/smb.conf ]]; then cp /etc/samba/external/smb.conf /etc/samba/smb.conf /usr/bin/supervisord else echo "Config file is missing." fi } case "$1" in start) appStart ;; setup) # If the supervisor conf isn't there, we're spinning up a new container if [[ -f /etc/supervisor/conf.d/supervisord.conf ]]; then appStart else appSetup fi ;; esac exit 0