v-change-user-php-cli 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. # info: add php version alias to .bash_aliases
  3. # options: USER VERSION
  4. # labels: hestia
  5. #
  6. # example: v-change-user-php-cli user php7.4
  7. #
  8. # add line to .bash_aliases to set default php command line
  9. # version when multi-php is enabled.
  10. #----------------------------------------------------------#
  11. # Variable&Function #
  12. #----------------------------------------------------------#
  13. # Argument definition
  14. user=$1
  15. version=$2
  16. # Includes
  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. FILE=$HOMEDIR/$user/.bash_aliases
  25. check_args '2' "$#" 'USER PHPVERSION'
  26. is_format_valid 'user'
  27. is_object_valid 'user' 'USER' "$user"
  28. is_object_unsuspended 'user' 'USER' "$user"
  29. # Reading user values
  30. source $USER_DATA/user.conf
  31. # Verify php version format
  32. if [[ ! $version =~ ^[0-9]\.[0-9]+ ]]; then
  33. echo "The php version format is invalid, it should look like [0-9].[0-9]..."
  34. exit
  35. fi
  36. # Check if php version is supported
  37. if [ ! -f "$HESTIA_INSTALL_DIR/multiphp/$WEB_SYSTEM/PHP-${version//.}.sh" ]; then
  38. echo "Version is currently not supported or does not exist..."
  39. exit
  40. fi
  41. # Create .bash_aliases is not exsists
  42. if [ ! -f "$FILE" ]; then
  43. touch $FILE
  44. chown $user:$user $FILE
  45. fi
  46. if grep -q "alias php='env php$version'" "$FILE"; then
  47. echo "PHP CLI Already defined"
  48. exit;
  49. fi
  50. # Perform verification if read-only mode is enabled
  51. check_hestia_demo_mode
  52. #----------------------------------------------------------#
  53. # Action #
  54. #----------------------------------------------------------#
  55. sed -i "/alias php='env/d" "$FILE"
  56. echo "alias php='env php$version'" >> $FILE
  57. update_user_value "$user" '$PHPCLI' "$version"
  58. #----------------------------------------------------------#
  59. # Hestia #
  60. #----------------------------------------------------------#
  61. $BIN/v-log-action "system" "Info" "Users" "Default PHP CLI version changed (User: $user, Version: $version)."
  62. exit