v-change-user-shell 2.0 KB

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