v_change_user_shell 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash
  2. # info: change user shell
  3. # options: user shell
  4. #
  5. # The function changes system shell of a user. Shell gives abilty to use ssh.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. user=$1
  11. shell=$2
  12. # Importing variables
  13. source $VESTA/conf/vesta.conf
  14. source $VESTA/func/shared.sh
  15. #----------------------------------------------------------#
  16. # Verifications #
  17. #----------------------------------------------------------#
  18. # Checking arg number
  19. check_args '2' "$#" 'user shell'
  20. # Checking argument format
  21. validate_format 'user' 'shell'
  22. # Checking user
  23. is_object_valid 'user' 'USER' "$user"
  24. # Checking user is active
  25. is_object_unsuspended 'user' 'USER' "$user"
  26. #----------------------------------------------------------#
  27. # Action #
  28. #----------------------------------------------------------#
  29. # Get shell full path
  30. shell_path=$(/usr/bin/chsh --list-shells | grep -w "$shell" )
  31. # Changing passwd file
  32. /usr/bin/chsh -s "$shell_path" "$user" &>/dev/null
  33. #----------------------------------------------------------#
  34. # Vesta #
  35. #----------------------------------------------------------#
  36. # Changing user shell
  37. update_user_value "$user" '$SHELL' "$shell"
  38. # Logging
  39. log_event "$OK" "$EVENT"
  40. exit