v-change-user-shell 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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_history "changed $user shell to $shell" '' 'admin'
  37. log_event "$OK" "$EVENT"
  38. exit