Created
June 3, 2015 23:50
-
-
Save monkseal/0fcc813f951e136bdc82 to your computer and use it in GitHub Desktop.
Ruby on Rails Centos 6.6 provision.sh
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 | |
# Install dependent packages | |
sudo yum update | |
sudo yum install -y apr-devel apr-util-devel autoconf automake curl-devel \ | |
g++ gcc gcc-c++ git glibc-headers httpd-devel libxml2 \ | |
libxml2-devl libxslt libxslt-devel libyaml-devel make \ | |
mysql-devel mysql-server openssl-devel patch readline \ | |
readline-devel zlib zlib-devel | |
if ! [ -d /home/vagrant/.rbenv ]; then | |
echo "Installing rbenv" | |
git clone git://github.com/sstephenson/rbenv.git ~/.rbenv | |
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build | |
echo "export PATH=\$HOME/.rbenv/bin:\$PATH" >> /home/vagrant/.bash_profile | |
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile | |
source ~/.bash_profile | |
rbenv install 2.2.2 | |
rbenv rehash | |
rbenv global 2.2.2 | |
gem update --system | |
gem install bundler | |
fi | |
echo "Gem home is $GEM_HOME" | |
echo "Path is $PATH" | |
MYSQL_RUNNING=$(service mysqld status | egrep "mysql.*running" | wc -l) | |
if [ "$MYSQL_RUNNING" -ne 1 ]; then | |
echo 'Starting Mysql' | |
sudo /sbin/service mysqld start | |
sudo /sbin/chkconfig mysqld on | |
fi | |
DATABASE_YML="/vagrant/config/database.yml" | |
APP_DB_USERNAME="blog_user" | |
APP_DB_PASSWORD="blog_user91x91x" | |
if [ -f $DATABASE_YML ]; | |
then | |
echo "File $DATABASE_YML exists." | |
else | |
echo "File $DATABASE_YML does not exist, creating." | |
read -r -d '' CREATE_USER_SQL <<_EOF_ | |
CREATE USER '$APP_DB_USERNAME'@'localhost' IDENTIFIED BY '$APP_DB_PASSWORD'; | |
CREATE USER '$APP_DB_USERNAME'@'%' IDENTIFIED BY '$APP_DB_PASSWORD'; | |
GRANT ALL PRIVILEGES ON *.* TO '$APP_DB_USERNAME'@'localhost' WITH GRANT OPTION; | |
GRANT ALL PRIVILEGES ON *.* TO '$APP_DB_USERNAME'@'%' WITH GRANT OPTION; | |
_EOF_ | |
echo "Creating mysql user:" | |
echo $CREATE_USER_SQL | |
mysql -uroot -e "$CREATE_USER_SQL" | |
cat > $DATABASE_YML <<_EOF_ | |
default: &default | |
adapter: mysql2 | |
encoding: utf8 | |
reconnect: false | |
pool: 5 | |
username: $APP_DB_USERNAME | |
password: $APP_DB_PASSWORD | |
host: localhost | |
development: | |
<<: *default | |
database: blog_development | |
test: | |
<<: *default | |
database: blog_test | |
production: | |
<<: *default | |
database: blog_production | |
_EOF_ | |
fi | |
echo "Installing gems" | |
cd /vagrant | |
bundle install | |
bundle exec rake db:create:all --trace | |
bundle exec rake db:migrate --trace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment