user.sh 1.1 KB

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