Skip to content

Instantly share code, notes, and snippets.

@eporama
Last active October 1, 2016 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eporama/e1a0e01c87814c6300e5d6aa886369df to your computer and use it in GitHub Desktop.
Save eporama/e1a0e01c87814c6300e5d6aa886369df to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# This script will be run to install multiple versions of Drupal related software
# in building up a VirtualMachine for NEDCamp 2016
# The original basis of this script was a gist written by Jonathan Webb to install
# multiple versions of PHP using phpevn and brew
# https://gist.github.com/webbj74/4151020ef4f642fa80a6
# Check OS
if [ "${OSTYPE//[0-9.]/}" != "darwin" ]; then
echo "This script is intended for OSX users."
exit
fi
# Make sure Xcode License is accepted
sudo xcodebuild -license
# Install homebrew
function install_homebrew() {
if [ -z "$(which brew)" ]; then
echo "Installing Hombrew by following curl instructions from http://brew.sh"
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
echo "\nInstalled brew successfully."
else
echo "Homebrew already successfully installed."
fi
}
# Configure Homebrew
function configure_homebrew() {
# Intall taps
echo "Installing brew taps"
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
# Update/upgrade everything
echo "Updating and upgrading homebrew"
brew update
brew upgrade --all
}
# Install multiple versions of php
function install_php() {
# install_php55
install_php56
install_php70
}
function install_php55() {
echo "Installing php 5.5"
brew install php55
brew link php55
echo "date.timezone = UTC" > /usr/local/etc/php/5.5/conf.d/date.ini
brew install php55-memcache
brew install php55-xdebug
brew install php55-xhprof
brew unlink php55
}
function install_php56() {
echo "Installing php 5.6"
brew install php56
brew link php56
echo "date.timezone = UTC" > /usr/local/etc/php/5.6/conf.d/date.ini
brew install php56-memcache
brew install php56-xdebug
brew install php56-xhprof
brew unlink php56
}
function install_php70() {
echo "Installing php 7.0"
brew install php70
brew link php70
brew install --HEAD homebrew/php/php70-memcached
brew install php70-xdebug
brew unlink php70
}
function install_phpenv() {
# Setup phpenv
echo "Installing phpenv via brew"
brew install phpenv
if [ ! -d "${HOME}/.phpenv" ]; then
echo "Running phpenv-install.sh"
phpenv-install.sh
export PATH="$HOME/.phpenv/bin:$PATH"
eval "$(phpenv init -)"
fi
if [ ! -d "${HOME}/.phpenv/versions" ]; then
echo "Making directory for phpenv versions"
mkdir -p "${HOME}/.phpenv/versions"
fi
echo "Cleaning out previous entries"
find "${HOME}/.phpenv/versions" -maxdepth 1 -mindepth 1 -type l -delete
# Create symlinks for new versions
phpenv_versions
}
# Set up phpenv versions
function phpenv_versions() {
echo "Finding all brew installed versions of PHP and extracting major and minor version numbers and creating two symlinks one for major and one for minor"
for version in $(find $(find /usr/local/Cellar -maxdepth 1 -mindepth 1 -name 'php??' ) -maxdepth 1 -mindepth 1 -type d 2>/dev/null); do
ln -s ${version} ${HOME}/.phpenv/versions/ 2>/dev/null
ln -s ${version} ${HOME}/.phpenv/versions/$(echo "${version}" | perl -p -e "s/.*(\d+\.\d+)\.(.+)$/\1/") 2>/dev/null
done
echo "Rehashing phpenv"
phpenv rehash
}
# Let's actually do these things now
install_homebrew
configure_homebrew
install_php
install_phpenv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment