1
0

composer.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. Install_composer() {
  11. if [ -e "${php_install_dir}/bin/phpize" ]; then
  12. if [ -e "/usr/local/bin/composer" ]; then
  13. echo "${CWARNING}PHP Composer already installed! ${CEND}"
  14. else
  15. pushd ${oneinstack_dir}/src > /dev/null
  16. # get the IP information
  17. PUBLIC_IPADDR=$(../include/get_public_ipaddr.py)
  18. IPADDR_COUNTRY=$(../include/get_ipaddr_state.py ${PUBLIC_IPADDR})
  19. if [ "${IPADDR_COUNTRY}"x == "CN"x ]; then
  20. wget -c https://mirrors.aliyun.com/composer/composer.phar -O /usr/local/bin/composer > /dev/null 2>&1
  21. ${php_install_dir}/bin/php /usr/local/bin/composer config -g repo.packagist composer https://packagist.phpcomposer.com
  22. else
  23. wget -c https://getcomposer.org/composer.phar -O /usr/local/bin/composer > /dev/null 2>&1
  24. fi
  25. chmod +x /usr/local/bin/composer
  26. if [ -e "/usr/local/bin/composer" ]; then
  27. echo; echo "${CSUCCESS}PHP Composer installed successfully! ${CEND}"
  28. else
  29. echo; echo "${CFAILURE}PHP Composer install failed, Please try again! ${CEND}"
  30. fi
  31. popd > /dev/null
  32. fi
  33. fi
  34. }
  35. Uninstall_composer() {
  36. if [ -e "/usr/local/bin/composer" ]; then
  37. rm -f /usr/local/bin/composer
  38. echo; echo "${CMSG}Composer uninstall completed${CEND}";
  39. else
  40. echo; echo "${CWARNING}Composer does not exist! ${CEND}"
  41. fi
  42. }