user.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. # TODO limiting su to the admin group
  35. yn="reset"
  36. while [ "$yn" != "y" ] && [ "$yn" != "n" ]
  37. do
  38. echo -n "Should we allow $user to su? [y|n] "
  39. read yn
  40. done
  41. if [ "$yn" = "y" ]; then
  42. echo "adding $user to admin group"
  43. # admin group is created by misc
  44. usermod -a -G admin "$user"
  45. fi
  46. echo -e "user $user configured"