v_change_user_shell 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. # Includes
  13. source $VESTA/conf/vesta.conf
  14. source $VESTA/func/main.sh
  15. #----------------------------------------------------------#
  16. # Verifications #
  17. #----------------------------------------------------------#
  18. check_args '2' "$#" 'user shell'
  19. validate_format 'user' 'shell'
  20. is_object_valid 'user' 'USER' "$user"
  21. is_object_unsuspended 'user' 'USER' "$user"
  22. #----------------------------------------------------------#
  23. # Action #
  24. #----------------------------------------------------------#
  25. # Get shell full path
  26. shell_path=$(/usr/bin/chsh --list-shells | grep -w "$shell" |head -n1)
  27. # Changing passwd file
  28. /usr/bin/chsh -s "$shell_path" "$user" &>/dev/null
  29. shell=$(basename $shell_path)
  30. #----------------------------------------------------------#
  31. # Vesta #
  32. #----------------------------------------------------------#
  33. # Changing user shell
  34. update_user_value "$user" '$SHELL' "$shell"
  35. # Logging
  36. log_event "$OK" "$EVENT"
  37. exit