Guest User

Untitled

a guest
Nov 17th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3.  
  4. #### Variables
  5. loggedInUser=`ls -l /dev/console | awk '{print $3}'`
  6. allusers=`sudo dscl . list /Users | grep -v '^_' | xargs | sed -e 's/ /", "/g' | awk '{ print "\""$0"\""}'`
  7. #####Change these Variables only
  8.  
  9. dirSearchBase="DC=risd,DC=net"
  10. dirHost="'risd.net'"
  11.  
  12. domnusr="'domin accountt'"
  13. dmnpass="'domain password'"
  14.  
  15. binduser="'domain join account'"
  16. bindpass="'password'"
  17. Domainname="'risd.net'"
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. oldusr=$loggedInUser
  30. #oldusr="$(osascript -e 'tell application "System Events" to activate' -e 'tell application "System Events" to return (choose from list {'"$allusers"'} with prompt "Choose your Account" with title "Account" OK button name "Select" cancel button name "Quit")')"
  31. adur=`dscl . -read /Users/$oldusr | grep OriginalAuthenticationAuthority`
  32.  
  33. if [ "$adur" != "" ]; then
  34. osascript -e 'Tell application "System Events" to display dialog "This user is already a network User" buttons {"Cancel"} cancel button "Cancel" default button "Cancel" with icon caution'
  35. exit 1
  36. fi
  37.  
  38. ######VErify User is same as AD USER
  39. ###This Does The Query for the CN of the User Account
  40.  
  41.  
  42. #ldapsearch -h "risd.net" -p 389 -x -D "domjoin" -w "Tms-k12J01n" -b "DC=risd,DC=net" -s sub sAMAccountName="hhorton"
  43. verifusr=`ldapsearch -h "risd.net" -p 389 -x -D "domain account" -w "domain password" -b "DC=risd,DC=net" -s sub sAMAccountName="$loggedInUser" | grep sAMAccountName | tail -1 | awk '{print $NF}' | tr '[:upper:]' '[:lower:]'`
  44. if [ $verifusr == $loggedInUser ]; then
  45. # The user pressed Cancel
  46. # exit 1 # exit with an error status
  47. #fi
  48.  
  49.  
  50. ###delete user but not Data
  51. sudo dscl . -delete /Users/$oldusr
  52.  
  53.  
  54. #######Fix Permissions and ownership of Files
  55. /System/Library/CoreServices/ManagedClient.app/Contents/Resources/createmobileaccount -n $loggedInUser
  56. sudo dscl . -append /Groups/admin GroupMembership $loggedInUser
  57. sleep 5
  58. chown -R $oldusr /Users/$oldusr &
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65. osascript -e 'Tell application "System Events" to display dialog "Please log out, and log in with your network credentials." buttons {"OK"} cancel button "OK" default button "OK" with icon caution'
  66.  
  67. else
  68. osascript -e 'Tell application "System Events" to display dialog "The user is not a network User. Please contact Helpdesk" buttons {"OK"} cancel button "OK" default button "OK" with icon caution'
  69. fi
Add Comment
Please, Sign In to add comment