[root@arm-1 join-dir]# cat entering_to_domain.sh
#!/bin/bash
NEW_HOSTNAME=$(hostname -s)
OU=$(curl http://172.16.150.168/cgi_scripts/search_ou.sh?hostname="$NEW_HOSTNAME" -s)
DOMAIN='pkk.local'
echo "Selected division - $OU"
# Entering in domain
echo "Setting a new hostname for this computer: $NEW_HOSTNAME"
while true; do
if [[ -z "$ADMIN_PASS" ]]
then
read -p "Input domain admin login: " ADMIN_USER
read -sp "Input domain admin password: " ADMIN_PASS
else
read -p 'Select the desired item:
1. - Input domain credentials again;
2. - Change hostname;
3. - NO GOD! PLEASE! NO! NOOOOOOOO!;
Any value to continue entering to domain;' ANSWER
case $ANSWER in
1)
read -p "Input domain admin login: " ADMIN_USER
read -sp "Input domain admin password: " ADMIN_PASS
;;
2)
read -p "Input new hostname without domain prefix (exp. arm-r01, minzdrav-r01): " NEW_HOSTNAME
hostnamectl set-hostname "$NEW_HOSTNAME.$DOMAIN"
echo "New name for computer: $(hostname -s).$DOMAIN"
;;
3)
break
;;
*)
echo "Continue executing the script..."; echo
;;
esac
fi
cat > /root/join-dir/.domain_creds << EOF
{
"username":"$ADMIN_USER",
"password":"$ADMIN_PASS"
}
EOF
# Joining a domain
if join-to-domain -d "$DOMAIN" -n "$NEW_HOSTNAME" -u "$ADMIN_USER" -p "$ADMIN_PASS" --ou "$OU" -y; then
break
fi
done