echo "Downloading Prereqs"
sudo apt -y install realmd sssd sssd-tools libnss-sss libpam-sss adcli samba-common-bin oddjob oddjob-mkhomedir packagekit sendmail
echo "Testing Domain ds.tssn.services:"
realm discover ds.tssn.services
echo "Joining domain with account TSSN\svc.adjoin"
realm join --user svc.adjoin --computer-ou="ou=Linux Servers,ou=Servers,ou=Computers,ou=TSSN,ou=Organizations,dc=ds,dc=tssn,dc=services" ds.tssn.services
echo "Testing domain lookup"
id lucas.schwartz.sa@ds.tssn.services
echo "Adding TSSN\Global Linux Admins to the sudoers file"
echo "%Global_Linux_Admins ALL=(ALL) ALL" >> /etc/sudoers
echo "%${HOSTNAME}_Sudo_Users ALL=(ALL) ALL" >> /etc/sudoers
echo "Preparing Auto Creation of Home Dir on domain logon"
echo "session optional        pam_mkhomedir.so skel=/etc/skel umask=077" >> /etc/pam.d/common-session
echo "Modifying /etc/sssd/sssd.conf: use_fully_qualified_names = False"
systemctl stop sssd.service
cd /tmp
wget http://www.tssn.services/public/linux/adjoin/sssd.conf
wget http://www.tssn.services/public/linux/adjoin/sshd_config.conf
wget http://www.tssn.services/public/linux/adjoin/ds.tssn.services_banner.txt
wget http://www.tssn.services/public/linux/adjoin/sendmail.mc.txt
mv ds.tssn.services_banner.txt /etc/ssh/ds.tssn.services_banner
rm -rf /etc/mail/sendmail.mc
mv sendmail.mc.txt /etc/mail/sendmail.mc
rm -rf /etc/sssd/sssd.conf
rm -rf /etc/ssh/sshd_config
mv sssd.conf /etc/sssd/sssd.conf
mv sshd_config.conf /etc/ssh/sshd_config
chmod 0600 /etc/sssd/sssd.conf
chmod 0644 /etc/ssh/sshd_config
echo "Restartind sssd"
systemctl restart sssd.service
echo "Clearing sssd cache"
sss_cache -E
echo "Restarting SSH Service"
systemctl restart sshd.service
echo "Creating Working Dir"
mkdir /working
chmod +7777 /working
echo "Fixing Time to UTC"
timedatectl set-local-rtc 0