Created
October 3, 2017 21:15
-
-
Save samacs/8b74597d5058a33f0915da23eac9ceee 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/bash | |
RUBY_VERSION=2.4.1 | |
RAILS_VERSION=5.1.4 | |
PB_VERSION=9.6 | |
curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - | |
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7 | |
apt-add-repository multiverse | |
add-apt-repository https://deb.nodesource.com/node_0.12/ | |
add-apt-repository https://oss-binaries.phusionpassenger.com/apt/passenger | |
apt-get install -y apt-transport-https ca-certificates | |
apt-get update -y | |
apt-get upgrade -y | |
apt-get install -y build-essential curl gdb git-core htop libcurl4-openssl-dev \ | |
libffi-dev libreadline-dev libsqlite3-dev libssl-dev libxml2-dev libxslt1-dev \ | |
libyaml-dev libz-dev linux-tools-generic lsb-release openssl python-software-properties \ | |
rar rlwrap screen scrot silversearcher-ag sqlite3 subversion systemtap tree unrar \ | |
unzip valgrind vim zip zlib1g zlib1g-dev zsh | |
add-apt-repository -y ppa:webupd8team/java | |
apt-get update -y | |
execute_with_rbenv () { | |
`cat >/home/ubuntu/temp-script.sh <<\EOF | |
export HOME=/home/ubuntu | |
if [ -d $HOME/.rbenv ]; then | |
export PATH="$HOME/.rbenv/bin:$PATH" | |
eval "$(rbenv init -)" | |
fi | |
EOF` | |
echo $1 >> /home/ubuntu/temp-script.sh | |
chmod +x /home/ubuntu/temp-script.sh | |
su ubuntu -c "bash -c /home/ubuntu/temp-script.sh" | |
rm /home/ubuntu/temp-script.sh | |
} | |
install_ruby_and_bundler () { | |
execute_with_rbenv "rbenv install $1" | |
execute_with_rbenv "rbenv local $1" | |
execute_with_rbenv "gem install bundler" | |
} | |
`cat >/home/ubuntu/install_rbenv.sh <<\EOF | |
git clone https://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"' >> ~/.bash_profile | |
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile | |
EOF` | |
chmod +x /home/ubuntu/install_rbenv.sh | |
su ubuntu -c "bash -c /home/ubuntu/install_rbenv.sh" | |
rm /home/ubuntu/install_rbenv.sh | |
install_ruby_and_bundler "$RUBY_VERSION" | |
execute_with_rbenv "rbenv global $RUBY_VERSION" | |
apt-get -y install nodejs | |
npm install npm -g | |
echo 'deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main 9.6' | sudo tee -a '/etc/apt/sources.list.d/postgresql.list' | |
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - | |
apt-get update | |
apt-get install -y postgresql postgresql-contrib-9.5 postgresql-client-9.6 libpq-dev | |
sudo -u postgres pg_dropcluster --stop $PG_VERSION main | |
sudo -u postgres pg_createcluster --start $PG_VERSION main | |
sudo -u postgres createuser -d -R -w -S ubuntu | |
perl -i -p -e 's/local all all peer/local all all trust/' /etc/postgresql/$PG_VERSION/main/pg_hba.conf | |
service postgresql restart | |
apt-get install -y passenger nginx-extras | |
`cat >/etc/nginx/sites-available/rails-solr <<\EOF | |
server { | |
server_name *.lvh.me; | |
listen 3000; | |
listen 3443 ssl; | |
ssl_certificate /vagrant/certificate/nginx.crt; | |
ssl_certificate_key /vagrant/certificate/nginx.key; | |
client_max_body_size 10M; | |
passenger_enabled on; | |
rails_env development; | |
root /vagrant/rails-solr/public; | |
# redirect server error pages to the static page /50x.html | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root html; | |
} | |
} | |
EOF | |
` | |
perl -i -p -e 's/# passenger_root \/usr\/lib\/ruby\/vendor_ruby\/phusion_passenger\/locations\.ini\;\n/passenger_root \/usr\/lib\/ruby\/vendor_ruby\/phusion_passenger\/locations.ini;\n\tpassenger_ruby \/home\/ubuntu\/.rbenv\/shims\/ruby;\n/' /etc/nginx/nginx.conf | |
ln -s /etc/nginx/sites-available/rails-solr /etc/nginx/sites-enabled/rails-solr | |
rm /etc/nginx/sites-enabled/default | |
service nginx restart | |
`cat >/home/ubuntu/.environment.sh <<\EOF | |
export LANG="en_US.UTF-8" | |
export CLICOLOR="YES" | |
if [ -f ~/.secret_keys.sh ]; then | |
source ~/.secret_keys.sh | |
EOF | |
fi` | |
echo 'source ~/.environment.sh' >> /home/ubuntu/.bash_profile | |
touch /home/ubuntu/.secret_keys.sh | |
chown ubuntu:ubuntu /home/ubuntu/.environment.sh | |
chowh ubuntu:ubuntu /home/ubuntu/.secret_keys.sh | |
apt-get -y autoremove | |
apt-get -y autoclean | |
apt-get -y clean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment