#!/bin/bash
# to be sourced

ENABLED=yes
[ "$ENABLED" != "yes" ] && exit 0

. /usr/lib/ublinux/os-config

SOURCE=${SYSCONF}/config; [ -f "${SOURCE}" ] && . ${SOURCE} 2>/dev/null

if [ ! -z "$ADSERVER" ] ;then

    export PATH=$PATH:/usr/lib/ublinux/scripts:/opt/secretnet/sbin:/opt/secretnet/bin:/usr/lib/qt4/bin

   # Time synchronization
   systemctl stop ntpd
   /usr/sbin/ntpdate $ADSERVER >/dev/null 2>&1
   systemctl start ntpd

   if ! echo -e "\n\n\n" | net ads testjoin ;then
      /usr/share/ublinux/ad_join/ad_join.pl
   fi

   xsetroot -cursor_name left_ptr
   systemctl restart smb
   systemctl restart winbind

   # launch some rc scripts
   for a in /usr/lib/ublinux/rc.domain/* ;do
      [ -x $a ] && $a
   done
   for a in /usr/lib/ublinux/rc.domain.d/* ;do
      [ -x $a ] && $a &
   done
fi
