You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.8 KiB

  1. #! /bin/bash
  2. # NOTE: At the moment, this has only been confirmed to work with PHP 7
  3. PHP_VERSION=$2 # Without dot
  4. # Grab full name of workspace container
  5. WORKSPACE_CONTAINER=$(docker ps | grep workspace${PHP_VERSION} | awk '{print $1}')
  6. if [[ -z "${WORKSPACE_CONTAINER}" ]]; then
  7. echo "Unable to find workspace container: workspace${PHP_VERSION}"
  8. exit 1
  9. fi
  10. # Grab OS type
  11. if [[ "$(uname)" == "Darwin" ]]; then
  12. OS_TYPE="OSX"
  13. else
  14. OS_TYPE=$(expr substr $(uname -s) 1 5)
  15. fi
  16. xdebug_status ()
  17. {
  18. echo 'xDebug status'
  19. # If running on Windows, need to prepend with winpty :(
  20. if [[ $OS_TYPE == "MINGW" ]]; then
  21. winpty docker exec -it $WORKSPACE_CONTAINER bash -c 'php -v'
  22. else
  23. docker exec -it $WORKSPACE_CONTAINER bash -c 'php -v'
  24. fi
  25. }
  26. xdebug_start ()
  27. {
  28. echo 'Start xDebug'
  29. # And uncomment line with xdebug extension, thus enabling it
  30. ON_CMD="sed -i 's/^;zend_extension=/zend_extension=/g' \
  31. /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"
  32. # If running on Windows, need to prepend with winpty :(
  33. if [[ $OS_TYPE == "MINGW" ]]; then
  34. winpty docker exec -it $WORKSPACE_CONTAINER bash -c "${ON_CMD}"
  35. docker restart $WORKSPACE_CONTAINER
  36. winpty docker exec -it $WORKSPACE_CONTAINER bash -c 'php -v'
  37. else
  38. docker exec -it $WORKSPACE_CONTAINER bash -c "${ON_CMD}"
  39. docker restart $WORKSPACE_CONTAINER
  40. docker exec -it $WORKSPACE_CONTAINER bash -c 'php -v'
  41. fi
  42. }
  43. xdebug_stop ()
  44. {
  45. echo 'Stop xDebug'
  46. # Comment out xdebug extension line
  47. OFF_CMD="sed -i 's/^zend_extension=/;zend_extension=/g' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"
  48. # If running on Windows, need to prepend with winpty :(
  49. if [[ $OS_TYPE == "MINGW" ]]; then
  50. # This is the equivalent of:
  51. # winpty docker exec -it laradock_php-fpm_1 bash -c 'bla bla bla'
  52. # Thanks to @michaelarnauts at https://github.com/docker/compose/issues/593
  53. winpty docker exec -it $WORKSPACE_CONTAINER bash -c "${OFF_CMD}"
  54. docker restart $WORKSPACE_CONTAINER
  55. #docker-compose restart php-fpm
  56. winpty docker exec -it $WORKSPACE_CONTAINER bash -c 'php -v'
  57. else
  58. docker exec -it $WORKSPACE_CONTAINER bash -c "${OFF_CMD}"
  59. # docker-compose restart php-fpm
  60. docker restart $WORKSPACE_CONTAINER
  61. docker exec -it $WORKSPACE_CONTAINER bash -c 'php -v'
  62. fi
  63. }
  64. case $1 in
  65. stop|STOP)
  66. xdebug_stop
  67. ;;
  68. start|START)
  69. xdebug_start
  70. ;;
  71. status|STATUS)
  72. xdebug_status
  73. ;;
  74. *)
  75. echo "xDebug [Stop | Start | Status] in the ${WORKSPACE_CONTAINER} container."
  76. echo "xDebug must have already been installed."
  77. echo "Usage:"
  78. echo " .php-fpm/xdebug stop|start|status"
  79. esac
  80. exit 1