Guest User

Untitled

a guest
May 9th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. SCRIPT="$( cd "$(dirname "$0")" ; pwd -P )/$(basename "$0")"
  4. CRED_FILE="$HOME/.ad_cred"
  5. MNT_POINT="$HOME/.ad_mnt"
  6. MOUNT_AD="sudo mount -t cifs //prhwinad03/NETLOGON -o domain=UP,credentials=$CRED_FILE $MNT_POINT"
  7.  
  8. USER_PROMPT="To be able to access the internet you need to login with your UP"
  9. USER_PROMPT+=" (not CS-website) credentials. Please enter your student number:"
  10.  
  11. PASS_PROMPT="Please enter your UP password"
  12.  
  13. ERR_PROMPT="Unable to mount AD. The provided username and password is probably "
  14. ERR_PROMPT+="incorrect. Trying again..."
  15.  
  16. MNT_TIMEOUT=20
  17.  
  18. while ! [[ -f $CRED_FILE ]]; do
  19. username=$(zenity --entry --title="Username" --text="$USER_PROMPT")
  20. [[ $? -ne 0 ]] && break
  21. password=$(zenity --password --title="Password" --text="$PASS_PROMPT")
  22. [[ $? -ne 0 ]] && break
  23.  
  24. echo "username=$username" > "$CRED_FILE"
  25. echo "password=$password" >> "$CRED_FILE"
  26. done
  27.  
  28. if ! [[ -f $CRED_FILE ]]; then
  29. zenity --error --title="Error" --text="Couldn't get username and password, cancelling"
  30. exit 1
  31. fi
  32.  
  33. mkdir -p "$MNT_POINT"
  34.  
  35. while [[ $MNT_TIMEOUT -ge 0 ]] && ! mount | grep -q "$MNT_POINT"; do
  36. $MOUNT_AD || break
  37. ((MNT_TIMEOUT-=1))
  38. sleep 5
  39. done
  40.  
  41. if ! mount | grep -q "$MNT_POINT"; then
  42. zenity --error --title="Error" --text="$ERR_PROMPT"
  43. rm "$CRED_FILE"
  44. "$SCRIPT"
  45. fi
Add Comment
Please, Sign In to add comment