v-change-user-shell 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/bash
  2. # info: change user shell
  3. # options: USER SHELL
  4. # labels: panel
  5. #
  6. # example: v-change-user-shell admin nologin
  7. #
  8. # The function changes system shell of a user. Shell gives ability to use ssh.
  9. #----------------------------------------------------------#
  10. # Variable&Function #
  11. #----------------------------------------------------------#
  12. # Argument definition
  13. user=$1
  14. shell=$2
  15. # Includes
  16. source $HESTIA/func/main.sh
  17. source $HESTIA/conf/hestia.conf
  18. #----------------------------------------------------------#
  19. # Verifications #
  20. #----------------------------------------------------------#
  21. check_args '2' "$#" 'USER SHELL'
  22. is_format_valid 'user' 'shell'
  23. is_object_valid 'user' 'USER' "$user"
  24. is_object_unsuspended 'user' 'USER' "$user"
  25. # Perform verification if read-only mode is enabled
  26. check_hestia_demo_mode
  27. #----------------------------------------------------------#
  28. # Action #
  29. #----------------------------------------------------------#
  30. # Get shell full path
  31. shell_path=$(grep -w "$shell" /etc/shells | head -n1)
  32. # Changing passwd file
  33. /usr/bin/chsh -s "$shell_path" "$user" >/dev/null 2>&1
  34. shell=$(basename $shell_path)
  35. # Adding jailed sftp env
  36. if [[ "$shell" =~ nologin ]] || [[ "$shell" =~ rssh ]]; then
  37. $BIN/v-add-user-sftp-jail $user >/dev/null 2>&1
  38. else
  39. $BIN/v-delete-user-sftp-jail $user >/dev/null 2>&1
  40. fi
  41. #----------------------------------------------------------#
  42. # Hestia #
  43. #----------------------------------------------------------#
  44. # Changing user shell
  45. update_user_value "$user" '$SHELL' "$shell"
  46. # Logging
  47. log_history "changed $user shell to $shell" '' 'admin'
  48. log_event "$OK" "$ARGUMENTS"
  49. exit