Last active
August 29, 2015 14:11
-
-
Save jubianchi/60d986d39b6f93ef8fd5 to your computer and use it in GitHub Desktop.
./php-brew.sh help
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
#!/bin/bash | |
if [[ "$1" = "-h" || "$1" = "--help" || $1 = "help" || $1 = "man" ]] | |
then | |
echo "A tiny script to run a command against PHP 5.3, 5.4, 5.5 and 5.6 using homebrew" | |
echo | |
echo -e "\033[34mUsage:\033[0m" | |
echo -e "\033[34m------\033[0m" | |
echo -e " \033[32m$0\033[0m \033[33m<command>\033[0m" | |
echo | |
echo -e " \033[33mcommand:\033[0m any command you want to run against all PHP versions" | |
exit 0 | |
fi | |
MIN_PHP_VERSION=3 | |
MAX_PHP_VERSION=6 | |
INIT_PHP_VERSION=$(php -v | head -n1 | sed 's/.*5\.\([0-9]\+\).*/\1/') | |
CURR_PHP_VERSION=$MIN_PHP_VERSION | |
OUTPUT=$(brew unlink php5$INIT_PHP_VERSION 2>&1) | |
if [ $? -ne 0 ] | |
then | |
echo $OUTPUT | |
fi | |
while [ $CURR_PHP_VERSION -le $MAX_PHP_VERSION ] | |
do | |
OUTPUT=$(brew link php5$CURR_PHP_VERSION 2>&1) | |
if [ $? -ne 0 ] | |
then | |
echo $OUTPUT | |
continue | |
fi | |
echo Running on PHP 5.$CURR_PHP_VERSION | |
php -v | head -n1 | |
OUTPUT=$($* 2>&1) | |
if [ $? -ne 0 ] | |
then | |
echo $OUTPUT | |
else | |
echo -e "\033[32mEverything is OK on PHP 5.$CURR_PHP_VERSION \\o/\033[0m" | |
fi | |
OUTPUT=$(brew unlink php5$CURR_PHP_VERSION 2>&1) | |
if [ $? -ne 0 ] | |
then | |
echo $OUTPUT | |
fi | |
(( CURR_PHP_VERSION=$CURR_PHP_VERSION+1 )) | |
done | |
OUTPUT=$(brew link php5$INIT_PHP_VERSION 2>&1) | |
if [ $? -ne 0 ] | |
then | |
echo $OUTPUT | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment