#! /bin/bash -e

# Copyright (C) 2014-2015 uib GmbH
# http://www.uib.de
# All rights reserved.

VERSION=19
VERBOSE=true

. /usr/share/univention-join/joinscripthelper.lib
joinscript_init

TFTPROOT="/var/lib/univention-client-boot"
SERVER_ROLE=$(ucr get server/role)
OPSI_ROLE="configserver"
ROOT_DN=$(ucr get ldap/base)
LDAP_MASTER=$(ucr get ldap/master)
LDAP_USER=$(ucr get ldap/hostdn)
LDAP_SECRET=$(cat /etc/machine.secret)
HOSTNAME=$(uname -n)
DOMAIN=$(ucr get domainname)
FQDN=$(hostname --fqdn)
IPADDRESS=$(getent hosts $FQDN | head -n1 | cut -d' ' -f1)
NETMASK=""
GATEWAY=""
SUBNET=""
BROADCAST=""
WINDOMAIN=$(ucr get windows/domain)
UCS_VERSION=$(ucr get version/version)
UCS_PATCHLEVEL=$(ucr get version/patchlevel)

if   [ "$SERVER_ROLE" = "domaincontroller_master" ]; then
	$VERBOSE && echo -e "\nRunning on UCS Master"
elif [ "$SERVER_ROLE" = "domaincontroller_slave" ]; then
	$VERBOSE && echo -e "\nRunning on UCS Slave"
elif [ "$SERVER_ROLE" = "domaincontroller_backup" ]; then
	$VERBOSE && echo -e "\nRunning on UCS Backup"
else
	$VERBOSE && echo -e "\nRunning on $SERVER_ROLE"
fi

if [ -e "/etc/init.d/univention-dhcp"  ]; then
	DHCPSERVER=1
else
	DHCPSERVER=0
fi

SAMBA_INIT_SCRIPT="/etc/init.d/samba"
eval "$(ucr shell samba4/role)"
if [ -n "$samba4_role" ]; then
	echo "The local UCS is configured as Samba/AD $samba4_role"
	if [ "$UCS_VERSION" = "3.1" -o "$UCS_VERSION" = "3.2" ]; then
		SAMBA_INIT_SCRIPT="/etc/init.d/samba4"
	fi
fi

LDAP_PORT=$(ucr get ldap/master/port)

# --- Test ldap connection ------------------------------------------------------------------------------------------------------
$VERBOSE && echo "Testing ldap connection to $LDAP_MASTER"
set +e
if [ $SERVER_ROLE = "memberserver" ]; then
	univention-ldapsearch -D "$LDAP_USER" -w "$LDAP_SECRET" -s base > /dev/null
else
	univention-ldapsearch -x userPassword | grep "^userPassword:" >/dev/null
fi
ret=$?
set -e
if [ $ret != 0 ]; then
	echo "" 1>&2
	echo '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' 1>&2
	echo " Connect to ldap master $LDAP_MASTER as $LDAP_USER failed" 1>&2
	echo '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' 1>&2
	echo "" 1>&2
	exit 1
fi


# --- Get network config --------------------------------------------------------------------------------------------------------
for iface in `ifconfig -a | grep "^[[:alnum:]]" | cut -d " " -f 1`; do
	ip=`ifconfig $iface | grep "\:[[:digit:]]*\." | sed "s/:/ /g" | awk '{ printf $3}'`
	NETMASK=`ifconfig $iface | grep "\:[[:digit:]]*\." | sed "s/:/ /g" | awk '{ printf $7}'`
	GATEWAY=`route -n | grep ^0.0.0.0 | awk '{ printf $2}'`
	if [ "$ip" != "" ]; then
		if [ "$IPADDRESS" = "" ]; then
			IPADDRESS="$ip"
		fi
		[ "$IPADDRESS" = "$ip" ] && break
	fi
done

[ "$NETMASK" = "" ] && NETMASK="255.255.255.0"

if [ "$IPADDRESS" != "" ]; then
	for part in 1 2 3 4; do
		I[$part]=$(echo $IPADDRESS | cut -d . -f $part)
		M[$part]=$(echo $NETMASK | cut -d . -f $part)
	done

	for part in 1 2 3 4; do
		N[$part]=$((${I[$part]} & ${M[$part]}))
		B[$part]=$((${N[$part]} | $((${M[$part]} ^255))))
	done

	SUBNET="${N[1]}.${N[2]}.${N[3]}.${N[4]}"
	BROADCAST="${B[1]}.${B[2]}.${B[3]}.${B[4]}"
fi


# --- Determine opsi role -------------------------------------------------------------------------------------------------------
set +e
# old version
# config_server=$(ldapsearch -x -L -s sub -b "$ROOT_DN" "(objectClass=opsiConfigserver)" | grep -i '^opsiHostId:' | head -n1 | cut -d ':' -f2 | tr -d ' ' 2>/dev/null)
config_server="$(univention-ldapsearch -x -L -s sub -b "$ROOT_DN" "(univentionService=OpsiConfigserver)" | grep -i '^cn:' | head -n1 | cut -d ':' -f2 | tr -d ' ' 2>/dev/null).$DOMAIN"
$VERBOSE && echo "Found configserver: $config_server"
set -e
if [ "$config_server" == ".$DOMAIN" ]; then
	$VERBOSE && echo "No Server marked as OpsiConfigserver, trying to set $FQDN as OpsiConfigserver for $ROOT_DN"
	udm computers/$SERVER_ROLE modify "$@" --dn $(ucr get ldap/hostdn) --append service=OpsiConfigserver
	$VERBOSE && echo "Creating Service Entry for UMC."
	udm settings/service create "$@" --ignore_exists --position "cn=services,cn=univention,$ROOT_DN" --set name=OpsiConfigserver

elif [ "$config_server" != ".$DOMAIN" -a "$config_server" != "$FQDN" ]; then
	OPSI_ROLE="depotserver"
fi


# --- Show system information ---------------------------------------------------------------------------------------------------
$VERBOSE && echo -e "\nSystem information"
$VERBOSE && echo "     UCS version      : $UCS_VERSION"
$VERBOSE && echo "     UCS patchlevel   : $UCS_PATCHLEVEL"
$VERBOSE && echo "     TFTP root        : $TFTPROOT"
$VERBOSE && echo "     UCS role         : $SERVER_ROLE"
$VERBOSE && echo "     Opsi server role : $OPSI_ROLE"
$VERBOSE && echo "     Root dn          : $ROOT_DN"
$VERBOSE && echo "     LDAP master      : $LDAP_MASTER"
$VERBOSE && echo "     LDAP user        : $LDAP_USER"
$VERBOSE && echo "     Hostname         : $HOSTNAME"
$VERBOSE && echo "     Domain           : $DOMAIN"
$VERBOSE && echo "     FQDN             : $FQDN"
$VERBOSE && echo "     IP-Address       : $IPADDRESS"
$VERBOSE && echo "     Netmask          : $NETMASK"
$VERBOSE && echo "     Gateway          : $GATEWAY"
$VERBOSE && echo "     Subnet           : $SUBNET"
$VERBOSE && echo "     Broadcast        : $BROADCAST"
$VERBOSE && echo "     Windomain        : $WINDOMAIN"

## --- Deleting existing opsi extended-attribute ------------------------------------------------------------------------
udm settings/extended_attribute remove $@ \
	--dn="cn=opsiHostId,cn=custom attributes,cn=univention,$ROOT_DN" 2>/dev/null || true

# --- Add users and groups ------------------------------------------------------------------------------------------------------
$VERBOSE && echo "Adding system users and groups..."

fileadmingroup="opsifileadmins"
set +e
grep "pcpatch" /etc/opsi/opsi.conf 2>/dev/null || true
if [ $? = 0 ]; then
	sed -i "s/pcpatch/opsifileadmins/g" /etc/opsi/opsi.conf
fi

udm groups/group list "$@" --filter "(name=OPSI Depot Servers)" | grep '^DN:' 1>/dev/null
ret=$?
set -e
if [ $ret != 0 ]; then
	$VERBOSE && echo "Adding group OPSI Depot Servers"
	udm groups/group create "$@" \
		--position="cn=groups,$ROOT_DN" \
		--set name="OPSI Depot Servers" \
		--set description="opsi depot servers" \
		--ignore_exists
fi
udm groups/group modify "$@" \
	--dn "cn=OPSI Depot Servers,cn=groups,$ROOT_DN" \
	--append hosts="$LDAP_USER" \
	--ignore_exists

set +e
$VERBOSE && echo "Adding system users and group: $fileadmingroup"
$VERBOSE && echo "Checking if pcpatch group exists"
PCPATCH_DN=$(udm groups/group list "$@" --filter "(name=pcpatch)" | grep '^DN:' | cut -d " " -f2)
if [ "$PCPATCH_DN" != "" ]; then
	$VERBOSE && echo "Group pcpatch found, renaming to opsifileadmins"
	udm groups/group modify --dn "$PCPATCH_DN" --set name="$fileadmingroup"
fi
udm groups/group list "$@" --filter "(name=$fileadmingroup)" | grep '^DN:' 1>/dev/null
ret=$?
$VERBOSE && echo "Result: $ret"
set -e

if [ $ret != 0 ]; then
	$VERBOSE && echo "Adding group $fileadmingroup"
	udm groups/group create $@ \
		--position="cn=groups,$ROOT_DN" \
		--set name="$fileadmingroup" \
		--set description="opsi file admin group" \
		--ignore_exists
fi

set +e
udm groups/group list "$@" --filter "(name=opsiadmin)" | grep '^DN:' 1>/dev/null
ret=$?
set -e
if [ $ret != 0 ]; then
	$VERBOSE && echo "Adding group opsiadmin"
	udm groups/group create "$@" \
		--position="cn=groups,$ROOT_DN" \
		--set name="opsiadmin" \
		--set description="opsi config admin group" \
		--ignore_exists
fi

set +e
udm users/user list "$@" --filter "(uid=pcpatch)" | grep '^DN:' 1>/dev/null
ret=$?
set -e
if [ $ret != 0 ]; then
	# User pcpatch does not exist in ldap
	$VERBOSE && echo "Adding user pcpatch"

	pass=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c12`

	udm users/user create "$@" \
		--position="cn=users,$ROOT_DN" \
		--set username="pcpatch" \
		--set description="opsi-pseudo user" \
		--set unixhome="/var/lib/opsi" \
		--set primaryGroup="cn=$fileadmingroup,cn=groups,$ROOT_DN" \
		--set lastname="pcpatch" \
		--set password="${pass}" \
		--set overridePWLength=1 \
		--ignore_exists
fi

set +e
udm users/user list "$@" --filter "(uid=opsiconfd)" | grep '^DN:' 1>/dev/null
ret=$?
set -e
if [ $ret != 0 ]; then
	# User opsiconfd does not exist in ldap
	$VERBOSE && echo "Adding user opsiconfd"

	pass=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c12`

	udm users/user create "$@" \
		--position="cn=users,$ROOT_DN" \
		--set username="opsiconfd" \
		--set description="opsi configuration daemon user" \
		--set unixhome="/var/lib/opsi" \
		--set primaryGroup="cn=$fileadmingroup,cn=groups,$ROOT_DN" \
		--set lastname="opsiconfd" \
		--set password="${pass}" \
		--set overridePWLength=1 \
		--ignore_exists
fi

udm groups/group modify "$@" \
	--dn "cn=opsiadmin,cn=groups,$ROOT_DN" \
	--append users="uid=opsiconfd,cn=users,$ROOT_DN"

# Remove users/groups from passwd/group
userdel pcpatch >/dev/null 2>/dev/null || true
userdel opsiconfd >/dev/null 2>/dev/null || true
[ -e /tmp/.group.tmp.opsi4ucs ] && rm /tmp/.group.tmp.opsi4ucs
cp /etc/group /tmp/.group.tmp.opsi4ucs
cat /tmp/.group.tmp.opsi4ucs | grep -v '^pcpatch:' | grep -v '^opsiadmin:' | grep -v '^opsiconfd' >/etc/group || true
rm /tmp/.group.tmp.opsi4ucs


udm groups/group modify "$@" \
	--dn "cn=opsiadmin,cn=groups,$ROOT_DN" \
	--append users="uid=Administrator,cn=users,$ROOT_DN"



# --- Add samba shares ----------------------------------------------------------------------------------------------------------
$VERBOSE && echo "Creating container for samba shares"
udm container/cn create "$@" \
	--ignore_exists \
	--position="cn=shares,$ROOT_DN" \
	--set name=$FQDN

#fileadminuserdn=$(udm users/user list "$@" --filter "(uid=opsiconfd)" | grep '^DN:' | cut -d ":" -f 2)
#fileadmingroupdn=$(udm groups/group list "$@" --filter "(cn=opsifileadmins)" | grep '^DN:' | cut -d ":" -f 2)

USERID=$(getent passwd opsiconfd | cut -d ":" -f 3)
GROUPID=$(getent group opsifileadmins | cut -d ":" -f 3)


set +e
udm shares/share list "$@" --filter "(name=opsi_depot_rw)" | grep '^DN:' | grep $FQDN 1>/dev/null
ret=$?
set -e
if [ $ret != 0 ]; then
	$VERBOSE && echo "Adding samba share opsi_depot_rw"
	udm shares/share create "$@" \
		--position="cn=$FQDN,cn=shares,$ROOT_DN" \
		--set name=opsi_depot_rw \
		--set host=$FQDN \
		--set path=/var/lib/opsi/depot \
		--set owner=$USERID \
		--set group=$GROUPID \
		--set directorymode=0755 \
		--set sambaName=opsi_depot_rw \
		--ignore_exists
fi

set +e
udm shares/share list "$@" --filter "(name=opsi_depot)" | grep '^DN:' | grep $FQDN 1>/dev/null
ret=$?
set -e
if [ $ret != 0 ]; then
	$VERBOSE && echo "Adding samba share opsi_depot"
	udm shares/share create "$@" \
		--position="cn=$FQDN,cn=shares,$ROOT_DN" \
		--set name=opsi_depot \
		--set host=$FQDN \
		--set path=/var/lib/opsi/depot \
		--set owner=$USERID \
		--set group=$GROUPID \
		--set sambaName=opsi_depot \
		--set sambaWriteable=0 \
		--set sambaBrowseable=1 \
		--set sambaPublic=0 \
		--set sambaOplocks=0 \
		--set sambaLevel2Oplocks=0 \
		--set sambaCustomSettings='"follow symlinks" yes' \
		--ignore_exists
fi
if [ ! -e "/var/lib/opsi/depot" -a ! -L "/var/lib/opsi/depot" -a -e "/opt/pcbin/install" ]; then
	ln -s /opt/pcbin/install /var/lib/opsi/depot
fi

set +e
udm shares/share list "$@" --filter "(name=opsi_workbench)" | grep '^DN:' | grep $FQDN 1>/dev/null
ret=$?
set -e
if [ $ret != 0 ]; then
	$VERBOSE && echo "Adding samba share opsi_workbench"
	udm shares/share create "$@" \
		--position="cn=$FQDN,cn=shares,$ROOT_DN" \
		--set name=opsi_workbench \
		--set host=$FQDN \
		--set path=/home/opsiproducts \
		--set owner=$USERID \
		--set group=$GROUPID \
		--set directorymode=0755 \
		--set sambaName=opsi_workbench \
		--set sambaWriteable=1 \
		--set sambaBrowseable=1 \
		--set sambaPublic=0 \
		--set sambaCreateMode=0774 \
		--set sambaDirectoryMode=0775 \
		--set sambaSecurityMode=0777 \
		--set sambaDirectorySecurityMode=0777 \
		--ignore_exists
fi

set +e
udm shares/share list "$@" --filter "(name=opsi_images)" | grep '^DN:' | grep $FQDN 1>/dev/null
ret=$?
set -e
if [ $ret != 0 ]; then
	$VERBOSE && echo "Adding samba share opsi_images"
	udm shares/share create "$@" \
		--position="cn=$FQDN,cn=shares,$ROOT_DN" \
		--set name=opsi_images \
		--set host=$FQDN \
		--set path=/var/lib/opsi/ntfs-images \
		--set owner=$USERID \
		--set group=$GROUPID \
		--set directorymode=0755 \
		--set sambaName=opsi_images \
		--set sambaWriteable=1 \
		--set sambaBrowseable=1 \
		--set sambaPublic=0 \
		--set sambaCreateMode=0774 \
		--set sambaDirectoryMode=0775 \
		--set sambaSecurityMode=0777 \
		--set sambaDirectorySecurityMode=0777 \
		--ignore_exists
fi

# Fix for Executable Bit problem but only for opsi-depot Share
# Changing ntacl-backend settings to native (default)
#

if [ -e /etc/init.d/samba4 ]; then
	/etc/init.d/samba4 force-reload
fi
if [ -e /etc/init.d/samba ]; then
	/etc/init.d/samba reload
fi

$VERBOSE && echo "Waiting for samba shares"
sleep 5
$VERBOSE && echo "Removing vfs objects = acl_xattr from shares"

grep -v "vfs objects = acl_xattr" /etc/samba/shares.conf.d/opsi_depot | grep -v "admin users" > /etc/samba/shares.conf.d/opsi_depot_tmp
echo admin users = administrator join-backup @$fileadmingroup >> /etc/samba/shares.conf.d/opsi_depot_tmp
mv /etc/samba/shares.conf.d/opsi_depot_tmp /etc/samba/shares.conf.d/opsi_depot
ucr commit /etc/samba/shares.conf.d/opsi_depot

ucr set samba4/ntacl/backend=native

# --- Configure dhcp ------------------------------------------------------------------------------------------------------------
if [ "$SERVER_ROLE" = "domaincontroller_master" ]; then
	set +e
	univention-ldapsearch -x -L -s base -b "cn=$DOMAIN,cn=dhcp,$ROOT_DN" | grep use-host-decl-names >/dev/null
	ret=$?
	set -e
	if [ $ret != 0 ]; then
		if [ $DHCPSERVER = "1" ]; then
			$VERBOSE && echo "Adding dhcpStatement: use-host-decl-names on"
			echo -e "dn: cn=$DOMAIN,cn=dhcp,$ROOT_DN\nadd: dhcpStatements\ndhcpStatements: use-host-decl-names on\n" \
				| ldapmodify -x -h "$LDAP_MASTER" -p $LDAP_PORT -ZZ -D "cn=admin,$ROOT_DN" -y "/etc/ldap.secret" >/dev/null
		else
			$VERBOSE && echo "DHCP-Server installation not found, skipping patching dhcp-server."
		fi
	fi
fi

# --- Configure tftp ------------------------------------------------------------------------------------------------------------
update-inetd --remove tftp
if [ ! -d "$TFTPROOT" ]; then
	$VERBOSE && echo "Creating $TFTPROOT"
	mkdir $TFTPROOT
	ln -sf /tftpboot/linux/pxelinux.0 $TFTPROOT/
	$VERBOSE && echo "Setting rights for $TFTPROOT"
	chmod 755 $TFTPROOT
	ln -sf /tftpboot/linux/pxelinux.cfg $TFTPROOT/
fi
TFTPLINE="tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd --tftpd-timeout 300 --retry-timeout 5 --verbose=5 $TFTPROOT"
update-inetd --add "${TFTPLINE}"
/etc/init.d/openbsd-inetd reload

$VERBOSE && echo "Linking tftpboot files into $TFTPROOT"
ln -sf /tftpboot/linux/install $TFTPROOT/
ln -sf /tftpboot/linux/install-x64 $TFTPROOT/
ln -sf /tftpboot/linux/menu.c32 $TFTPROOT/
ln -sf /tftpboot/linux/chain.c32 $TFTPROOT/
ln -sf /tftpboot/linux/miniroot.bz2 $TFTPROOT/
ln -sf /tftpboot/linux/miniroot-x64.bz2 $TFTPROOT/
if [ -e /tftpboot/linux/ldlinux.c32 ]; then
       ln -sf /tftpboot/linux/ldlinux.c32 $TFTPROOT/
fi
if [ -e /tftpboot/linux/libcom32.c32 ]; then
       ln -sf /tftpboot/linux/libcom32.c32 $TFTPROOT/
fi
if [ -e /tftpboot/linux/libutil.c32 ]; then
       ln -sf /tftpboot/linux/libutil.c32 $TFTPROOT/
fi

if [ ! -L $TFTPROOT/pxelinux.cfg ]; then
	find "$TFTPROOT/pxelinux.cfg" -mindepth 1 -maxdepth 1 -exec mv "{}" "/tftpboot/linux/pxelinux.cfg/" \;
	rmdir $TFTPROOT/pxelinux.cfg
	ln -sf /tftpboot/linux/pxelinux.cfg $TFTPROOT/
fi

# --- Configure opsi ------------------------------------------------------------------------------------------------------------
$VERBOSE && echo "Configuring opsi"
ln -sf /etc/opsi/backendManager/dispatch.conf.default /etc/opsi/backendManager/dispatch.conf
$VERBOSE && echo "Checking security options for opsi"

ucr set security/packetfilter/package/opsi4ucs/tcp/4447/all=ACCEPT
ucr set security/packetfilter/package/opsi4ucs/udp/69/all=ACCEPT
ucr set security/packetfilter/package/opsi4ucs/tcp/4447/all/en="Port for opsi-Webservice"
ucr set security/packetfilter/package/opsi4ucs/udp/69/all/en="Port for TFTPD"

$VERBOSE && echo "Cleanup old opsi local-Filterrules"

TEMPFILE=$(tempfile)

grep -v "dport 69"  /etc/security/packetfilter.d/50_local.sh | grep  -v "dport 4447" > $TEMPFILE
cat $TEMPFILE > /etc/security/packetfilter.d/50_local.sh
/etc/init.d/univention-firewall restart

if [ "$OPSI_ROLE" = "depotserver" -a "$SERVER_ROLE" != "domaincontroller_master" -a "$SERVER_ROLE" != "domaincontroller_backup" ]; then
	ln -sf /etc/opsi/backendManager/dispatch.conf.jsonrpc /etc/opsi/backendManager/dispatch.conf
	$VERBOSE && echo "Registering Server as OpsiDepotserver on $config_server"
	credentials="$@"
	opsi-setup --register-depot -l5 --binddata "--configserver $config_server $credentials"
else
	if [ "$OPSI_ROLE" = "depotserver" ]; then
		$VERBOSE && echo "Automatic Registration of Server as opsi-Depotserver could not be done, because serverole: $SERVER_ROLE was detected, please execute opsi-setup --register-depot after installation."
		ln -sf /etc/opsi/backendManager/dispatch.conf.default /etc/opsi/backendManager/dispatch.conf
	fi
	set +e
	$VERBOSE && echo "Check for opsi fileadmingroup."
	getent group $fileadmingroup >/dev/null 2>/dev/null
	if [ $? != 0 ]; then
		if [ -e "/usr/lib/univention-pam/ldap-group-to-file.py" ]; then
			python /usr/lib/univention-pam/ldap-group-to-file.py >/dev/null 2>/dev/null || true
		else
			sleep 20
		fi
	fi
	set -e
	opsi-setup --init-current-config
	opsi-setup --set-rights
fi

# --- Commit changes ------------------------------------------------------------------------------------------------------------
$VERBOSE && echo "Adding links to the UCS overview page"
ucr set ucs/web/overview/entries/admin/opsi-configed/description/de='Management-Interface für Client-Management mit <em>opsi</em> (Applet startet über Java-Webstart).'
ucr set ucs/web/overview/entries/admin/opsi-configed/description='Management Interface for Client-Management with <em>opsi</em> (Applet starts over Java-Webstart).'
ucr set ucs/web/overview/entries/admin/opsi-configed/icon=/icon/50x50/opsi-configed.png
ucr set ucs/web/overview/entries/admin/opsi-configed/label/de='opsi configed'
ucr set ucs/web/overview/entries/admin/opsi-configed/label='opsi configed'
ucr set ucs/web/overview/entries/admin/opsi-configed/link="https://${FQDN}:4447/configed.jnlp"
ucr set ucs/web/overview/entries/admin/opsi-configed/priority=50

$VERBOSE && echo "Commit changes"
ucr commit /var/www/ucs-overview/de.html
ucr commit /var/www/ucs-overview/en.html
ucr commit /etc/pam.d/opsi-auth
dpkg-reconfigure opsiconfd

$VERBOSE && echo "Restarting services"
if [ $DHCPSERVER = "1" ]; then
	/etc/init.d/univention-dhcp restart || true
elif [ -e "/etc/init.d/dhcp3-server" ]; then
	/etc/init.d/dhcp3-server restart || true
fi
$SAMBA_INIT_SCRIPT reload || true
/etc/init.d/opsiconfd restart || true
/etc/init.d/opsipxeconfd restart || true

joinscript_save_current_version
