Skip to content

Instantly share code, notes, and snippets.

@Tronix117
Created July 17, 2012 05:42
Show Gist options
  • Save Tronix117/3127441 to your computer and use it in GitHub Desktop.
Save Tronix117/3127441 to your computer and use it in GitHub Desktop.
Rails 3 and Ruby 1.9.2, Installation development environment on Mac OSX Lion. Require: https://github.com/kennethreitz/osx-gcc-installer/downloads
#!/bin/bash
# Configuration (to edit)
RCPATH=~/.bashrc
PROJECT_DIRECTORY=~/Sites/myproject # project directoy (if it doesn't exist, the project will be installed here)
PROJECT_GIT_REPOSITORY='[email protected]:myname/myproject.git' # git repository of the project
DBPASS='123456' # root pass
# Your current Rails configuration (fill it with config/database.yml)
RAILS_BASE='myproject_dev'
RAILS_BASE_TEST='myproject_test'
RAILS_USER='myproject_dev'
RAILS_PASS='123456'
RAILS_SOCKET=/var/run/mysqld/mysqld.sock # if mysql is already installed, some command will change the place of the socket, if it's a problem with some applications, better have to change the socket path in the config/database.yml in the rails application, and not commit this modification
RAILS_PORT=3306
# Initialisation
SQLCONFIG=$( cat <<EOF
[client]
password = $DBPASS
port = $RAILS_PORT
socket = $RAILS_SOCKET
[mysqld]
port = $RAILS_PORT
socket = $RAILS_SOCKET
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K
server-id = 1
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
[mysqlhotcopy]
interactive-timeout
EOF
)
# Installations & Configurations
# Install gcc standalone, if XCode is not installed
if ! command -v gcc >/dev/null 2>&1
then
echo "== GCC not found, Installing GCC"
curl -O http://cloud.github.com/downloads/kennethreitz/osx-gcc-installer/GCC-10.7-v2.pkg
sudo installer -pkg ./GCC-10.7-v2.pkg -target /
rm -f ./GCC-10.7-v2.pkg;
fi
# RVM allow us to load a different ruby / rails version than the default one
echo "== RVM Installation"
# at the end press Q to continue
bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
echo "[[ -s \"$HOME/.rvm/scripts/rvm\" ]] && source \"$HOME/.rvm/scripts/rvm\"" >> $RCPATH
source "$HOME/.rvm/scripts/rvm"
# Ruby installation
echo "== Ruby 1.9 Installation"
rvm install 1.9.2
rvm --default use 1.9.2
# Brew is a package manager, easiest way to set up rails on mac
echo "== Brew Installation"
/usr/bin/ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go)
sudo mkdir -p /usr/local/Cellar
sudo chown -R $(whoami) /usr/local/Cellar
# Don't know the behavior of following commands on already existing mysql configurations
echo "== MySQL Installation"
brew install mysql
brew link mysql
sudo chown -R $(whoami) /usr/local/lib /usr/local/include
unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
echo "== MySQL Configuration"
sudo mkdir /var/run/mysqld
sudo chmod 777 /var/run/mysqld
sudo echo "$SQLCONFIG" > /etc/my.cnf
mysql.server start
/usr/local/Cellar/mysql/5.5.25a/bin/mysqladmin -u root password $DBPASS
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/mysql/5.5.25a/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
# Configure some database to work with the rails app
echo "== Create Database and Users"
echo "CREATE DATABASE $RAILS_BASE;CREATE DATABASE $RAILS_BASE_TEST;GRANT ALL PRIVILEGES ON $RAILS_BASE.* TO '$RAILS_USER'@'localhost' IDENTIFIED BY '$RAILS_PASS';GRANT ALL PRIVILEGES ON $RAILS_BASE_TEST.* TO '$RAILS_USER'@'localhost';FLUSH PRIVILEGES;" | mysql -u root -p$DBPASS
echo "== Fill Database with server dump (may take some minutes)"
#ssh ruby@dev-srv1 "mysqldump -u $RAILS_USER -p'$RAILS_PASS' $RAILS_BASE | mysql -u $RAILS_USER -p$RAILS_PASS $RAILS_BASE"
ssh ruby@dev-srv1 "mysqldump -u $RAILS_USER -p$RAILS_PASS $RAILS_BASE --result-file=./tmpsqldump.sql"
scp ruby@dev-srv1:./tmpsqldump.sql ./tmpsqldump.sql
cat ./tmpsqldump.sql | mysql -u $RAILS_USER -p$RAILS_PASS $RAILS_BASE
ssh ruby@dev-srv1 rm -f ./tmpsqldump.sql
rm -f ./tmpsqldump.sql
# GEMs are module for rails, those are the default ones, bundler will handle installation of every other needed
echo "== GEMs Installation"
gem install bundler
gem install capistrano
gem install powder
# Retrieve the rails application for github if the project directory doesn't exist
if [ ! -d "$PROJECT_DIRECTORY" ]; then
echo "== Project Installation"
mkdir -p $PROJECT_DIRECTORY
git clone $PROJECT_GIT_REPOSITORY $PROJECT_DIRECTORY
fi
# set the ruby version + configure powder, which is a rails server working correctly with rails
echo "== Project Configuration"
cd $PROJECT_DIRECTORY
bundle install
powder install
rvm env -- `rvm current` > .powenv
powder respawn
powder default
echo "== Project Launch"
powder link
echo "Sources files are in $PROJECT_DIRECTORY"
echo "To restart the rails app go to $PROJECT_DIRECTORY and enter: powder restart"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment