Last active
August 29, 2015 14:06
-
-
Save deetergp/3f73d7e6de77e9500cde to your computer and use it in GitHub Desktop.
This file contains 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/sh | |
if [ -z $1 ] | |
then | |
echo 'Please enter which version you want to switch to (e.g. `phps 55`, or `phps 53`)' | |
exit | |
fi | |
etc="/Users/deetergp/etc" | |
version=$1 | |
### | |
# Decides whether or not to switch the php version. | |
## | |
function php_switch() { | |
case ${version} in | |
53|55) | |
set_new_php_version; | |
break;; | |
*) | |
echo "Not a supported version"; | |
break;; | |
esac | |
} | |
### | |
# Returns a shorthand of the current PHP version. | |
## | |
function get_current_version() { | |
local current_version=$(php --version) | |
case ${current_version} in | |
'PHP 5.3'*) | |
local result=53; | |
break;; | |
'PHP 5.5'*) | |
local result=55; | |
break;; | |
*) | |
exit;; | |
esac | |
echo ${result} | |
} | |
### | |
# Returns true if the requested version is the same as the current version. | |
## | |
function get_version_difference() { | |
local current_version=$(get_current_version) | |
if [ ${version} == ${current_version} ] | |
then | |
echo 0 | |
else | |
echo 1 | |
fi | |
} | |
### | |
# Does the actual switching of the PHP version. | |
## | |
function set_new_php_version() { | |
local version_difference=$(get_version_difference) | |
local current_version=$(get_current_version) | |
if [ ${version_difference} == 0 ] | |
then | |
echo "You are currently on php${version}." | |
exit | |
fi | |
echo "Switching to php${version}" | |
# I keep a version of my .zshrc & httpd.conf files where the path for each | |
# version of the homebrew/josegonzalez PHP package. | |
sudo cp ${etc}/httpd.conf.php${version} /etc/apache2/httpd.conf | |
sudo cp ${etc}/zshrc.php${version} /Users/deetergp/.zshrc | |
# Changes the links for which version of PHP Homebrew should use. | |
brew unlink php${current_version} | |
brew link php${version} | |
# Restarts the OS X Apache server and refreshes the .zhsrc file. | |
sudo apachectl restart | |
exec zsh | |
} | |
php_switch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment