user.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/sh
  2. echo -e '
  3. _ _
  4. | | | |___ ___ _ _
  5. | |_| (_-</ -_) ._|
  6. \___//__/\___|_|
  7. '
  8. echo -e "Create new user (you will be asked a user name and a password)"
  9. . bin/checkroot.sh
  10. sleep 3
  11. echo -n "Enter user name: "
  12. read user
  13. while [ "$user" = "" ]
  14. do
  15. read -p "enter a user name ? " user
  16. if [ "$user" != "" ]; then
  17. # check if user already exists
  18. if id "$user" >/dev/null 2>&1; then
  19. echo "user $user alreday exists, you must provide a non existing user name."
  20. user=""
  21. else
  22. read -p "is user name $user correcte [y|n] " validated
  23. if [ "$validated" = "y" ]; then
  24. break
  25. else
  26. user=""
  27. fi
  28. fi
  29. fi
  30. done
  31. # read -p "Continue? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
  32. adduser "$user"
  33. sed -i "s/$user:\/bin\/ash/$user:\/bin\/bash/g" /etc/passwd
  34. usermod -a -G www "$user"
  35. # TODO limiting su to the admin group
  36. yn="reset"
  37. while [ "$yn" != "y" ] && [ "$yn" != "n" ]
  38. do
  39. echo -n "Should we allow $user to su? [y|n] "
  40. read yn
  41. done
  42. if [ "$yn" = "y" ]; then
  43. echo "adding $user to admin group"
  44. # admin group is created by misc
  45. usermod -a -G admin "$user"
  46. fi
  47. echo -e "user $user configured"