v_change_user_shell 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/vars.conf
  14. source $V_CONF/vesta.conf
  15. source $V_FUNC/shared.func
  16. #----------------------------------------------------------#
  17. # Verifications #
  18. #----------------------------------------------------------#
  19. # Checking arg number
  20. check_args '2' "$#" 'user shell'
  21. # Checking argument format
  22. format_validation 'user' 'shell'
  23. # Checking user
  24. is_user_valid
  25. # Checking user is active
  26. is_user_suspended
  27. #----------------------------------------------------------#
  28. # Action #
  29. #----------------------------------------------------------#
  30. # Get shell full path
  31. shell_path=$(/usr/bin/chsh --list-shells | grep -w "$shell" )
  32. # Changing passwd file
  33. /usr/bin/chsh -s "$shell_path" "$user" >/dev/null 2>&1
  34. #----------------------------------------------------------#
  35. # Vesta #
  36. #----------------------------------------------------------#
  37. # Changing user shell
  38. update_user_value "$user" '$SHELL' "$shell"
  39. # Logging
  40. log_event 'system' "$V_EVENT"
  41. exit