Skip to content

Instantly share code, notes, and snippets.

@ericgibb
Created May 1, 2012 19:21
Show Gist options
  • Save ericgibb/2570664 to your computer and use it in GitHub Desktop.
Save ericgibb/2570664 to your computer and use it in GitHub Desktop.
Installs Brew, Ruby, MySql, and other helpful utilities
# if ask "Do you want to do something?"; then
# echo "Yes"
# else
# echo "No"
# fi
#
# # Default to No if the user presses enter without giving an answer:
# if ask "Do you want to do something?" N; then
# echo "Yes"
# else
# echo "No"
# fi
# Only do something if you say Yes
# if ask "Do you want to do only yes?" Y; then
# echo "said yes"
# fi
# Only do something if you say No
# if ! ask "Do you want to do only no?"; then
# echo "said no"
# fi
function ask {
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
default=N
else
prompt="y/n"
default=
fi
# Ask the question
read -p "$1 [$prompt] " REPLY
# Default?
if [ -z "$REPLY" ]; then
REPLY=$default
fi
# Check if the reply is valid
case "$REPLY" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac
done
}
echo "######################################################"
echo "# Brew Setup & Extras #"
echo "######################################################"
######################################################
# Install Xcode #
######################################################
if ask "Have you installed Xcode yet?"; then
echo "Make sure to install the command line tools under Xcode's Preferences > Downloads"
else
echo "You should probably go and install Xcode first and then install the command line tools under Xcode's Preferences > Downloads"
fi
######################################################
# Install Utilities #
######################################################
############### Helpful Utilities ###############
# brew install ack
# brew install curl
# brew install colordiff
if ask "Do you want to install wget?"; then
brew install wget
fi
if ask "Do you want to install imagemagick?"; then
brew install imagemagick
fi
############### Install DNS Masq ###############
if ask "Do you want to install DnsMasq?"; then
brew install dnsmasq
echo "address=/.dev/127.0.0.1" >> /usr/local/etc/dnsmasq.conf
echo "listen-address=127.0.0.1" >> /usr/local/etc/dnsmasq.conf
echo "no-hosts" >> /usr/local/etc/dnsmasq.conf
sudo cp /usr/local/Cellar/dnsmasq/2.60/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
sudo -i
mkdir /etc/resolver
echo "nameserver 127.0.0.1" > /etc/resolver/dev
exit
fi
############### Install Brew ###############
if ask "Do you want to install brew?"; then
echo "SETUP: Installing Brew ..."
echo "note: Brew installs under /usr/local/Cellar/"
/usr/bin/ruby -e "$(/usr/bin/curl -fksSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"
fi
############### Install Git ###############
if ask "Do you want to install git?"; then
echo "SETUP: Installing Git ..."
echo "note: http://mac.github.com/ is a nice Git interface"
brew install git
if ask "Do you want to install git-flow?"; then
echo "SETUP: Installing Git-flow ..."
brew install git-flow
fi
fi
######################################################
# Install Languages #
######################################################
############### Install Ruby ###############
if ask "Do you want to do install ruby?"; then
brew install ruby
fi
# TODO: add ruby to export PATH=/usr/local/Cellar/ruby/1.9.3-p???????????/bin:$PATH
############### Install Rails ###############
if ask "Do you want to do install rails?"; then
brew install rails
##### Install Common Gems #####
# gem install bundler
# gem install mysql2
# gem install rails
# gem install bundler
# gem install mysql2
# gem install capistrano
# gem install capistrano-ext
fi
############### Install Node.js ###############
if ask "Do you want to install Node.js?"; then
brew install node
if ask "Do you want to install NPM?"; then
curl http://npmjs.org/install.sh | sh
fi
if ask "Do you want to install ender?"; then
npm install ender -g
fi
fi
######################################################
# Install Databases #
######################################################
############### Install MySQL ###############
if ask "Do you want to install MySQL?"; then
brew install mysql
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
if ask "Do you want to create launch agents for MySQL?" Y; then
mkdir -p ~/Library/LaunchAgents
# hopefully the plist name doesn't change
find /usr/local/Cellar/mysql/ -name "homebrew.mxcl.mysql.plist" -exec cp {} ~/Library/LaunchAgents/ \;
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
fi
echo "Note: $ mysql.server {start,stop,restart}"
fi
# if you have problems with mysql "cannot connect to /tmp/mysql.sock"
# then create a file /usr/local/etc/my.cnf and add this:
#
# [client]
# port = 3306
# socket = /tmp/mysql.sock
# [mysqld]
# bind-address = 127.0.0.1
# port = 3306
# socket = /tmp/mysql.sock
############### Install Mongo DB ###############
if ask "Do you want to install MongoDB?"; then
brew install mongodb
if ask "Do you want to create the default db path?" Y; then
sudo mkdir -p /data/db/
sudo chown `id -u` /data/db
fi
fi
############### Install Redis ###############
if ask "Do you want to install redis?"; then
brew install redis
if ask "Do you want to create launch agents for redis?" Y; then
mkdir -p ~/Library/LaunchAgents
find /usr/local/Cellar/redis/ -name "homebrew.mxcl.redis.plist" -exec cp {} ~/Library/LaunchAgents/ \;
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
fi
fi
############### Install sqlite ###############
# brew install sqlite
############### Install Memcache ###############
if ask "Do you want to install memcached?"; then
brew install memcached
if ask "Do you want to make launch agents for memcached?" Y; then
mkdir -p ~/Library/LaunchAgents
find /usr/local/Cellar/memcached/ -name "homebrew.mxcl.memcached.plist" -exec cp {} ~/Library/LaunchAgents/ \;
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist
fi
fi
######################################################
# Install Servers #
######################################################
# brew install nginx
######################################################
# To Install #
######################################################
# Notes: $ sudo apachectl {star,stop,restart}
# brew install libmemcached
# brew install libxml2
# brew install libxslt
# brew install readline
# brew install v8
# brew install rsync
# brew install sphinx # A Ruby connector between Sphinx and ActiveRecord. http://freelancing-god.github.com/ts/en/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment