Guest User

Untitled

a guest
May 20th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. if [[ `id -u` != 0 ]]; then
  4. echo "Must be root to run script"
  5. exit
  6. fi
  7.  
  8. read -p "Enter user name and press [ENTER]: " UserName
  9.  
  10. if [[ $UserName == `dscl . -list /Users UniqueID | awk '{print $1}' | grep -w $UserName` ]]; then
  11. echo "User already exists!"
  12. exit 0
  13. fi
  14.  
  15. read -p "Enter real name and press [ENTER]: " RealName
  16. read -p "Enter PrimaryGroupID (80 - admin, 20 - user) and press [ENTER]: " PrimaryGroupID
  17. LastID=`dscl . -list /Users UniqueID | awk '{print $2}' | sort -n | tail -1`
  18. NextID=$((LastID + 1))
  19.  
  20. . /etc/rc.common
  21. dscl . create /Users/$UserName
  22. dscl . create /Users/$UserName RealName $RealName
  23.  
  24. read -p "Enter password hint and press [ENTER]: " PasswordHint
  25. dscl . create /Users/$UserName hint $PasswordHint
  26. PasswordHint=0
  27.  
  28. echo " "
  29. read -s -p "Enter Account Password and press [ENTER]: " AccountPassword
  30. echo " "
  31. read -s -p "Enter Account Password again and press [ENTER]: " AccountPasswordRepeat
  32. if [[ $AccountPassword == $AccountPasswordRepeat ]]; then
  33. dscl . passwd /Users/$UserName $AccountPassword
  34. AccountPassword=0
  35. else
  36. echo "Passwords do not match!"
  37. exit 1
  38. fi
  39. echo " "
  40. dscl . create /Users/$UserName UniqueID $NextID
  41. dscl . create /Users/$UserName PrimaryGroupID $PrimaryGroupID
  42. dscl . create /Users/$UserName UserShell /bin/bash
  43. dscl . create /Users/$UserName NFSHomeDirectory /Users/$UserName
  44. createhomedir -u $UserName -c
  45.  
  46. echo " "
  47. echo "New user `dscl . -list /Users UniqueID | awk '{print $1}' | grep -w $UserName` has been created with unique ID `dscl . -list /Users UniqueID | grep -w $UserName | awk '{print $2}'`"
Add Comment
Please, Sign In to add comment