Guest User

Untitled

a guest
Mar 27th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #################################
  4. # OSX Machine auth for 802.1x profile with Active Directory
  5. # get AD machine user/pass and put into 802.1x profile template
  6. # install the profile
  7. #
  8. # sed has it's own uses for '&' and '\' in replacements
  9. # and the randomly generated password sometimes has them
  10. # So, trap and escape them before feeding into sed
  11. #
  12. # put the host name in 'host/computername.domain.com' format
  13. ##
  14. # Originally by DP ~2012
  15. # added traps and host name modification
  16. # thp 7/16/14
  17. #################################
  18.  
  19. DOMAIN="mydomain.com"
  20. FOREST="MYFOREST"
  21. PASS=$(sudo /usr/bin/security find-generic-password -s "/Active Directory/${FOREST}" -w /Library/Keychains/System.keychain)
  22. USER=$(/usr/sbin/dsconfigad -show | /usr/bin/awk '/Computer *Account/ { print $4 }')
  23.  
  24. # trap '\' and escape them
  25. if [[ ${PASS} =~ '\' ]]; then
  26. PASS=$(/bin/echo "$PASS" | /usr/bin/sed 's/\\/\\\\/g')
  27. fi
  28.  
  29. # trap '&' and escape them
  30. if [[ ${PASS} =~ '&' ]]; then
  31. PASS=$(/bin/echo "$PASS" | /usr/bin/sed 's/&/\\&/g')
  32. fi
  33.  
  34. # format username as hostname
  35. USER=$(/bin/echo $USER | /usr/bin/tr -d '$')
  36. USER="host\/${USER}.${DOMAIN}"
  37.  
  38. # change template file
  39. PROPATH='/path/to/profile/directory'
  40. PROFILE='PROFILENAME.mobileconfig'
  41.  
  42. /usr/bin/sed -i .bak 's/TESTPASS/'${PASS}'/' ${PROPATH}/${PROFILE}
  43. /usr/bin/sed -i .bak 's/TESTUSER/'${USER}'/' ${PROPATH}/${PROFILE}
  44.  
  45. /usr/bin/profiles -I -F ${PROPATH}/${PROFILE}
  46. RESULT=$(/bin/echo $?)
  47.  
  48. /bin/rm -f ${PROPATH}/${PROFILE}.bak
  49.  
  50. # If profile successfully installed, delete it
  51. if [ "$RESULT" = 0 ]; then
  52. /bin/rm -rf ${PROPATH}/${PROFILE}
  53. fi
  54.  
  55. exit
Add Comment
Please, Sign In to add comment