Rework on leaving domain and rejoin

Rework on leaving domain and rejoin
This commit is contained in:
PierreGode 2022-03-29 13:47:20 +02:00 committed by GitHub
parent d4dd9182f4
commit 4a8b13c352
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2384,52 +2384,34 @@ fi
Reauthenticate(){ Reauthenticate(){
export HOSTNAME export HOSTNAME
myhost=$( hostname | cut -d '.' -f1 ) myhost=$( hostname | cut -d '.' -f1 )
whoelse=$( who -ut | grep -v old | awk '{print $1}' | head -1 ) clear
homeshome=$( sudo realm list | grep domain-name | awk '{print $2}' ) SSSD=$( sudo cat /etc/sssd/sssd.conf | grep domain | awk '{print $3}' | head -1 ) < /dev/null > /dev/null 2>&1
homes=$( find /home/"$homeshome" -maxdepth 1 -mindepth 1 | head -1 | cut -d '/' -f4 ) DOMAINlower=$( echo "$DOMAIN" | tr '[:upper:]' '[:lower:]' ) < /dev/null > /dev/null 2>&1
if [ "$homes" = "$whoelse" ] if [ -f /etc/sssd/sssd.conf ]
then then
echo "" read -r -p "Do you really want to leave the domain: $SSSD (y/n)?" yn
echo "you are logged in as an AD user.. canceling request"
echo "only administrator has permissions"
echo ""
exit
else
LEFT=$(sudo realm discover | grep configured | awk '{print $2}')
DOMAIN=$(realm discover | grep -i realm.name | awk '{print $2}')
SSSD=$( sudo grep domain /etc/sssd/sssd.conf | awk '{print $3}' | head -1 )
DOMAINlower=$( echo "$DOMAIN" | tr '[:upper:]' '[:lower:]' )
if [ "$DOMAINlower" = "$SSSD" ]
then
echo "Detecting realm $SSSD"
else
if [ "$LEFT" = "no" ]
then
echo ""
echo "$DOMAIN has not been configured"
echo "you could try to leave manually with, sudo realm leave $SSSD"
echo ""
exit
fi
fi
read -r -p "Do you really want to leave the domain: $DOMAIN (y/n)?" yn
case $yn in case $yn in
[Yy]* ) echo "Listing domain" [Yy]* ) echo "Listing domain"
sudo realm discover "$DOMAIN" sudo realm discover "$SSSD" | grep realm | head -1
sudo realm leave "$DOMAIN" if ! sudo realm leave "$SSSD"
then
echo "failed Nothing to leave"
exit 0
else
LEFT=$(sudo realm discover | grep configured | awk '{print $2}') LEFT=$(sudo realm discover | grep configured | awk '{print $2}')
if [ "$LEFT" = "no" ] if [ "$LEFT" = "no" ]
then then
echo "" echo ""
sudo echo "" | sudo tee /etc/sssd/sssd.conf sudo echo "" | sudo tee /etc/sssd/sssd.conf
echo "$DOMAIN has been left" echo "has left $SSSD"
echo "" echo ""
notify-send ADconnection "Left $DOMAIN " notify-send ADconnection "Left $SSSD "
linuxclient
else else
echo "something went wrong, try to leave manually" echo "something went wrong, try to leave manually"
read -r DOMAIN echo ""
sudo realm leave "$DOMAIN" echo "Please type domain you wish to leave"
read -r DOMAIN
sudo realm leave "$DOMAIN"
left=$(sudo realm discover | grep configured | awk '{print $2}') left=$(sudo realm discover | grep configured | awk '{print $2}')
if [ "$left" = "no" ] if [ "$left" = "no" ]
then then
@ -2437,20 +2419,22 @@ read -r -p "Do you really want to leave the domain: $DOMAIN (y/n)?" yn
sudo echo "" | sudo tee /etc/sssd/sssd.conf sudo echo "" | sudo tee /etc/sssd/sssd.conf
echo "$DOMAIN has been left" echo "$DOMAIN has been left"
echo "" echo ""
notify-send ADconnection "Left $DOMAIN " notify-send ADconnection "Left $SSSD "
linuxclient PRECHECK_FN
else else
echo "something went wrong" echo "something went wrong"
fi fi
fi fi
fi
;; ;;
[Nn]* ) echo "Bye" [Nn]* ) echo "Not leaving $SSSD"
exit exit
;; ;;
* ) echo 'Please answer yes or no.';; * ) echo 'Please answer yes or no.';;
esac esac
exit exit
fi fi
exit
} }
######################### Leave Realm ################################ ######################### Leave Realm ################################