v-change-user-php-cli 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. source $HESTIA/func/main.sh
  18. source $HESTIA/conf/hestia.conf
  19. #----------------------------------------------------------#
  20. # Verifications #
  21. #----------------------------------------------------------#
  22. # Reading user values
  23. source $USER_DATA/user.conf
  24. FILE=$HOMEDIR/$user/.bash_aliases
  25. is_format_valid 'user'
  26. is_object_valid 'user' 'USER' "$user"
  27. is_object_unsuspended 'user' 'USER' "$user"
  28. # Verify php version format
  29. if [[ ! $version =~ ^[0-9]\.[0-9]+ ]]; then
  30. echo "The php version format is invalid, it should look like [0-9].[0-9]..."
  31. exit
  32. fi
  33. # Check if php version is supported
  34. if [ ! -f "$HESTIA_INSTALL_DIR/multiphp/$WEB_SYSTEM/PHP-${version//.}.sh" ]; then
  35. echo "Version is currently not supported or does not exist..."
  36. exit
  37. fi
  38. #create .bash_aliases is not exsists
  39. if [ ! -f "$FILE" ]; then
  40. touch "$FILE"
  41. fi
  42. if grep -q "alias php='env php$version'" "$FILE"; then
  43. echo "PHP CLI Already defined"
  44. exit;
  45. fi
  46. # Perform verification if read-only mode is enabled
  47. check_hestia_demo_mode
  48. #----------------------------------------------------------#
  49. # Action #
  50. #----------------------------------------------------------#
  51. sed -i "/alias php='env/d" "$FILE"
  52. echo "alias php='env php$version'" >> $FILE
  53. update_user_value "$user" '$PHPCLI' "$version"
  54. #----------------------------------------------------------#
  55. # Hestia #
  56. #----------------------------------------------------------#
  57. exit