Advertisement
Guest User

keychainmatches

a guest
Jan 25th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3.  
  4. #Find out who's logged in
  5. USER=`who | grep console | awk '{print $1}'`
  6.  
  7. #Get the name of the users keychain - some messy sed and awk to set up the correct name for security to like
  8. KEYCHAIN=`su $USER -c "security list-keychains" | grep login | sed -e 's/\"//g' | sed -e 's/\// /g' | awk '{print $NF}'`
  9.  
  10. #Go delete the keychain in question...
  11. su $USER -c "security delete-keychain $KEYCHAIN"
  12.  
  13. #Ask the user for their login password to create a new keychain
  14. PASSWORD="$(/usr/bin/osascript -e 'Tell application "System Events" to display dialog "Please enter your login password:" default answer "" with title "Login Password" with text buttons {"Ok"} default button 1 with hidden answer' -e 'text returned of result')"
  15.  
  16.  
  17. #Create the new login keychain
  18. expect <<- DONE
  19. set timeout -1
  20. spawn su $USER -c "security create-keychain login.keychain"
  21. # Look for prompt
  22. expect "*?chain:*"
  23. # send user entered password from CocoaDialog
  24. send "$PASSWORD\n"
  25. expect "*?chain:*"
  26. send "$PASSWORD\r"
  27. expect EOF
  28. DONE
  29.  
  30. #Set the newly created login.keychain as the users default keychain
  31. su $USER -c "security default-keychain -s login.keychain"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement