#!/bin/sh
#
#Sample script for RED OS to use in postinstall tasks for domain join
#

while getopts "d:n:p:" option; do
   case $option in
	d) domain=$OPTARG;;
	n) username=$OPTARG;;
	p) password=$OPTARG;;
    \?) # Invalid option
         echo "Error: Invalid option"
         exit 1;;
   esac
done

compname=$(hostname | cut -d. -f1)
workgroup=$( cut -d. -f1 <<< "$domain" )

#echo $domain $compname $username $password >>/opt/vars.txt

#packages required to join with winbind
dnf install oddjob oddjob-mkhomedir samba-winbind samba-winbind-clients samba-common-tools -y
#packages required to join with sssd
dnf install realmd sssd adcli krb5-workstation -y

dnf update join-to-domain -y
hostnamectl set-hostname $compname.$domain
sh -c "echo '127.0.0.1  `hostname -f` `hostname -s`' >> /etc/hosts"
systemctl restart NetworkManager

join-to-domain.sh -d $domain -n $compname -u $username -p $password -y -f
net time set -S $domain

