v-change-user-php-cli 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/bash
  2. # info: add php version alias to .bash_aliases
  3. # options: USER VERSION
  4. #
  5. # example: v-change-user-php-cli user 7.4
  6. #
  7. # add line to .bash_aliases to set default php command line
  8. # version when multi-php is enabled.
  9. #----------------------------------------------------------#
  10. # Variables & Functions #
  11. #----------------------------------------------------------#
  12. # Argument definition
  13. user=$1
  14. version=$2
  15. # Includes
  16. # shellcheck source=/etc/hestiacp/hestia.conf
  17. source /etc/hestiacp/hestia.conf
  18. # shellcheck source=/usr/local/hestia/func/main.sh
  19. source $HESTIA/func/main.sh
  20. # load config file
  21. source_conf "$HESTIA/conf/hestia.conf"
  22. #----------------------------------------------------------#
  23. # Verifications #
  24. #----------------------------------------------------------#
  25. FILE=$HOMEDIR/$user/.bash_aliases
  26. check_args '2' "$#" 'USER PHPVERSION'
  27. is_format_valid 'user'
  28. is_object_valid 'user' 'USER' "$user"
  29. is_object_unsuspended 'user' 'USER' "$user"
  30. # Perform verification if read-only mode is enabled
  31. check_hestia_demo_mode
  32. # Reading user values
  33. source $USER_DATA/user.conf
  34. versions=$($BIN/v-list-sys-php plain);
  35. support=0;
  36. for v in $versions; do
  37. if [ "$v" == "$version" ]; then
  38. support=1;
  39. fi
  40. done
  41. if [ "$support" = 0 ]; then
  42. echo "Version is currently not supported or does not exist..."
  43. exit 2;
  44. fi
  45. # Create .bash_aliases is not exsists
  46. if [ ! -f "$FILE" ]; then
  47. touch $FILE
  48. chown $user:$user $FILE
  49. fi
  50. if grep -q "alias php='env php$version'" "$FILE"; then
  51. echo "PHP CLI Already defined"
  52. exit;
  53. fi
  54. #----------------------------------------------------------#
  55. # Action #
  56. #----------------------------------------------------------#
  57. sed -i "/alias php='env/d" $FILE
  58. echo "alias php='env php$version'" >> $FILE
  59. update_user_value "$user" '$PHPCLI' "$version"
  60. #----------------------------------------------------------#
  61. # Hestia #
  62. #----------------------------------------------------------#
  63. $BIN/v-log-action "system" "Info" "Users" "Default PHP CLI version changed (User: $user, Version: $version)."
  64. exit