Guest User

Untitled

a guest
Dec 12th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. set -o errexit
  4. set -o pipefail
  5.  
  6. add_user() {
  7. local username="$1"
  8. local password="$2"
  9.  
  10. if id -u "${username}" &>/dev/null; then
  11. return
  12. fi
  13. useradd -m -U -G wheel -s /bin/bash "${username}"
  14. echo "${username}:${password}" | chpasswd
  15. }
  16.  
  17. add_sudoers() {
  18. local username="$1"
  19.  
  20. chmod u+w /etc/sudoers
  21. if [[ "$(grep -P "${username}\tALL=\(ALL\)\s+?ALL" "/etc/sudoers" 2>/dev/null)" != "" ]]; then
  22. return
  23. fi
  24. echo -e "${username}\tALL=(ALL)\tALL" >> "/etc/sudoers"
  25. chmod u-w /etc/sudoers
  26. }
  27.  
  28. main() {
  29. local username="$1"
  30. local password="$2"
  31.  
  32. add_user "${username}" "${password}"
  33. add_sudoers "${username}"
  34. }
  35.  
  36. main "$@"
Add Comment
Please, Sign In to add comment