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/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. # Changing user shell
  31. update_user_value "$user" '$SHELL' "$shell"
  32. # Get shell full path
  33. shell_path=$(/usr/bin/chsh --list-shells | grep -w "$shell" )
  34. # Changing passwd file
  35. /usr/bin/chsh -s "$shell_path" "$user" >/dev/null 2>&1
  36. #----------------------------------------------------------#
  37. # Vesta #
  38. #----------------------------------------------------------#
  39. # Logging
  40. log_event 'system' "$V_EVENT"
  41. exit