-
-
Save dieppon/ff9ec92d8faa292a123a17bc1bbfee2a to your computer and use it in GitHub Desktop.
spx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# https://github.com/NoiseByNorthwest/php-spx | |
# | |
# @author Djamil Legato http://github.com/w00fz/spx-osx | |
# @modified Victor Dieppa Garriga - https://github.com/NoiseByNorthwest/php-spx convertion | |
# @license MIT | |
# @version 1.0 | |
app="$(basename "$0")" | |
command="$1" | |
options="$2" | |
php_version_dot=$(php -r "\$v=explode('.', phpversion() ); echo implode('.', array_splice(\$v, 0, -1));") | |
php_version="${php_version_dot//./}" | |
spx_conf_path="$(brew --prefix)/etc/php/$php_version_dot/conf.d" | |
spx_conf_file="ext-spx.ini" | |
spx_conf=$spx_conf_path/$spx_conf_file | |
if [ ! -f "$spx_conf" ] && [ ! -f "$spx_conf.disabled" ]; then | |
echo "" | |
echo "The ini file for spx was not found at '$spx_conf_path'" | |
echo "" | |
exit 1 | |
else | |
STATUS="enabled" | |
IS_PHP_FPM=false | |
SERVER_NAME="apache" | |
if [ -f "$spx_conf" ] && [ -f "$spx_conf.disabled" ]; then | |
echo "" | |
echo "Detected both enabled and disabled spx ini files. Deleting the disabled one." | |
echo "" | |
rm -rf "$spx_conf.disabled" | |
STATUS="enabled" | |
elif [ -f "$spx_conf.disabled" ]; then | |
STATUS="disabled" | |
fi | |
if [ $# -ge 1 ] && [ "$command" == "on" ] || [ "$command" == "off" ]; then | |
if [ "$command" == "on" ]; then | |
mv "$spx_conf.disabled" "$spx_conf" 2> /dev/null | |
STATUS="enabled" | |
elif [ "$command" == "off" ]; then | |
mv "$spx_conf" "$spx_conf.disabled" 2> /dev/null | |
STATUS="disabled" | |
fi | |
if [ -f ~/Library/LaunchAgents/homebrew.mxcl.php"${php_version}".plist ]; then | |
IS_PHP_FPM=true | |
SERVER_NAME="php-fpm" | |
fi | |
if [ "$options" == '--no-server-restart' ]; then | |
echo "" | |
echo "spx has been $STATUS. Will not restart $SERVER_NAME" | |
else | |
if [ "$IS_PHP_FPM" == true ]; then | |
echo "" | |
echo "spx has been $STATUS, restarting $SERVER_NAME" | |
brew services restart php"${php_version}" | |
else | |
echo "" | |
echo "spx has been $STATUS, restarting $SERVER_NAME" | |
brew services restart httpd | |
fi | |
fi | |
else | |
echo "" | |
echo "Usage: ${app} <on | off> [--no-server-restart]" | |
fi | |
echo "" | |
echo "You are running PHP v$php_version_dot with spx $STATUS" | |
echo "" | |
php -v | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment