04-create-default-user 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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"
  27. else
  28. adduser $the_user sudo
  29. fi
  30. status=1
  31. while [ 0 -ne "$status" ]
  32. do
  33. passwd $the_user
  34. status=$?
  35. if [ 0 -ne "$status" ]
  36. then
  37. echo "Error changing $the_user password"
  38. echo "Please try again"
  39. else
  40. cat <<EOF
  41. ************************************
  42. * $the_user : created successfully *
  43. ************************************
  44. EOF
  45. exit 0
  46. fi
  47. done
  48. echo "An error occurred changing $the_user password"
  49. exit $status