diff --git a/ADconnection.sh b/ADconnection.sh index bf12421..17dda15 100755 --- a/ADconnection.sh +++ b/ADconnection.sh @@ -2458,47 +2458,33 @@ leaves(){ export HOSTNAME myhost=$( hostname | cut -d '.' -f1 ) clear -LEFT=$(sudo realm discover | grep configured | awk '{print $2}') < /dev/null > /dev/null 2>&1 -DOMAIN=$(realm discover | grep -i realm.name | awk '{print $2}') < /dev/null > /dev/null 2>&1 SSSD=$( sudo cat /etc/sssd/sssd.conf | grep domain | awk '{print $3}' | head -1 ) < /dev/null > /dev/null 2>&1 DOMAINlower=$( echo "$DOMAIN" | tr '[:upper:]' '[:lower:]' ) < /dev/null > /dev/null 2>&1 -if ! realm discover < /dev/null > /dev/null 2>&1 +if [ -f /etc/sssd/sssd.conf ] then -echo "" -echo "Realm not found, nothing to leave" -echo "" -else -if [ "$DOMAINlower" = "$SSSD" ] < /dev/null > /dev/null 2>&1 -then -echo "Detecting realm $SSSD" -else - if [ "$LEFT" = "no" ] < /dev/null > /dev/null 2>&1 - then - echo "" - echo "$DOMAIN has not been configured" - echo "" - exit - fi - fi -read -r -p "Do you really want to leave the domain: $DOMAIN (y/n)?" yn +read -r -p "Do you really want to leave the domain: $SSSD (y/n)?" yn case $yn in [Yy]* ) echo "Listing domain" - sudo realm discover "$DOMAIN" - sudo realm leave "$DOMAIN" + #sudo realm discover "$SSSD" + if ! sudo realm leave "$SSSD" + then + echo "failed Nothing to leave" + exit 0 + else LEFT=$(sudo realm discover | grep configured | awk '{print $2}') if [ "$LEFT" = "no" ] then echo "" sudo echo "" | sudo tee /etc/sssd/sssd.conf - echo "$DOMAIN has been left" + echo "has left $SSSD" echo "" - notify-send ADconnection "Left $DOMAIN " + notify-send ADconnection "Left $SSSD " else echo "something went wrong, try to leave manually" echo "" echo "Please type domain you wish to leave" - read -r DOMAIN - sudo realm leave "$DOMAIN" + read -r DOMAIN + sudo realm leave "$DOMAIN" left=$(sudo realm discover | grep configured | awk '{print $2}') if [ "$left" = "no" ] then @@ -2511,16 +2497,16 @@ read -r -p "Do you really want to leave the domain: $DOMAIN (y/n)?" yn echo "something went wrong" fi fi + fi ;; - [Nn]* ) echo "Bye" - exit - ;; + [Nn]* ) echo "Not leaving $SSSD" + exit + ;; * ) echo 'Please answer yes or no.';; esac exit fi exit -} ################################## encrypt pwd ############################### encrypt(){ echo "This will create 3 files public key, private key and encrypted file"