04-create-default-user 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/bash
  2. # Licence : GPL v3
  3. # Author: Laurent HUBERT
  4. #
  5. # Creates a new user for administrative purposes (in sudo group)
  6. #
  7. cat <<EOF
  8. +---------------------------------------------+
  9. | Creating default user |
  10. +---------------------------------------------+
  11. EOF
  12. read -p "Please enter default user name: " the_user
  13. if [ -n "$the_user" ]
  14. then
  15. echo Creating user $the_user
  16. # Creates the user but disable the login to set the password later:
  17. adduser --gecos ,,,, --disabled-login $the_user
  18. status=$?
  19. else
  20. # Exit with non zero status
  21. exit 1
  22. fi
  23. if [ 0 -ne "$status" ]
  24. then
  25. echo "### Error creating $the_user ###"
  26. echo "### Please try again by rebooting your system ###"
  27. exit 1
  28. else
  29. # Adds new user to sudo group
  30. adduser $the_user sudo
  31. fi
  32. status=1
  33. while [ 0 -ne "$status" ]
  34. do
  35. passwd $the_user
  36. status=$?
  37. if [ 0 -ne "$status" ]
  38. then
  39. echo "# Error changing $the_user password #"
  40. echo "Please try again"
  41. else
  42. echo "> $the_user : created successfully <"
  43. exit 0
  44. fi
  45. done
  46. echo "### An error occurred changing $the_user password ###"
  47. exit $status