Skip to content

Instantly share code, notes, and snippets.

@pantoniotti
Last active June 2, 2016 01:00
Show Gist options
  • Save pantoniotti/6029951 to your computer and use it in GitHub Desktop.
Save pantoniotti/6029951 to your computer and use it in GitHub Desktop.
Installation script
#!/usr/bin/env bash
# 1- Copy to the remote machine
# (cat server_setup.sh | ssh [email protected] 'cat >> ~/server_setup.sh')
# 2- Chmod to make it excecutable
# chmod a+x server_setup.sh
# 3- Run it
# sudo ./server_setup.sh
RUBY=2.2.4
# Deployer user (for Capistrano)
echo "#-> Creating Deployers Group and deployer user"
sudo groupadd deployers
sudo useradd -G deployers deployer
sudo usermod -a -G deployers deployer
sudo chown -R deployer:deployers /var/www
sudo chmod -R g+w /var/www
# To update to latest version of ubuntu
echo "#-> Installing Ubuntu Updates"
apt-get -y update
apt-get -y upgrade
# Librairies
echo "#-> Installing Dev Librairies"
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline-dev libyaml-dev libcurl4-openssl-dev
# Curl, Git and more
echo "#-> Installing Git, Curl, Python-Software"
apt-get -y install curl git-core python-software-properties
# Gcc compiler used by rbenv
echo "#-> Installing Gcc"
apt-get install gcc build-essential
# For nokogiri
echo "#-> Installing Nokogiri Librairies"
apt-get install libxslt-dev libxml2-dev
# ImageMagick
echo "#-> Installing Image Magick"
apt-get -y install imagemagick
# Ngnix
echo "#-> Installing Nginx"
if aptitude search '~i ^nginx$' | grep -q nginx; then
echo "--> nginx already installed, skipping."
else
add-apt-repository ppa:nginx/stable
apt-get update
apt-get -y install nginx
service nginx start
fi
# Passenger + Nginx extras
# Install our PGP key and add HTTPS support for APT
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
apt-get install -y apt-transport-https ca-certificates
# Add the repo
sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main > /etc/apt/sources.list.d/passenger.list'
apt-get update
apt-get install -y nginx-extras passenger
# Postgresql
if aptitude search '~i ^postgresql$' | grep -q postgresql; then
echo "postgresql already installed."
else
echo "#-> Installing Postgresql"
apt-get install postgresql postgresql-contrib
fi
# MySql
echo "#-> Installing MySql"
if aptitude search '~i ^mysql-server$' | grep -q mysql-server; then
echo "--> mysql already installed, skipping."
else
echo "#-> Installing MySql2 Librairies"
apt-get install libmysql-ruby libmysqlclient-dev
aptitude -y install mysql-server mysql-client libmysqlclient-dev libmysql-ruby php5-mysql
fi
# # MongoDB
# echo "#-> Installing MongoDb"
# if aptitude search '~i ^mongodb' | grep -q mongodb; then
# echo "--> mongodb already installed, skipping."
# else
# apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
# echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
# apt-get update
# apt-get -y install mongodb-10gen
# fi
# Node.js
echo "#-> Installing Node.js"
if aptitude search '~i ^nodejs$' | grep -q nodejs; then
echo "--> nodejs already installed, skipping."
else
add-apt-repository ppa:chris-lea/node.js
apt-get update
apt-get -y install nodejs
fi
# # Redis server
# echo "#-> Installing Redis"
# if aptitude search '~i ^redis-server$' | grep -q redis-server; then
# echo "--> redis-server already installed, skipping."
# else
# add-apt-repository ppa:chris-lea/redis-server
# apt-get update
# apt-get install redis-server
# redis-server /etc/redis/redis.conf
# fi
#
# # RVM And Ruby (Latest)
# echo "#-> Installing RVM"
# if env | egrep -v '^PATH' | egrep '^rvm_path'; then
# echo "--> rvm already installed"
# else
# gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
# curl -sSL https://get.rvm.io | bash -s stable --ruby
# sudo apt-get install ruby-dev
# fi
# Rbenv
echo "#-> Installing Rbenv"
if test -x ~/.rbenv/bin/rbenv; then
echo "--> rbenv already installed"
else
# Short version
# apt-get -y install rbenv
# Long version
# git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
# Change path in the bash_profile
# echo -e 'export PATH="$HOME/.rbenv/bin:$PATH"' | tee -a ~/.bash_profile
# echo -e 'eval "$(rbenv init -)"' | tee -a ~/.bash_profile
#
# # Install ruby build as a rbenv plug-in (recommended)
# git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
# # Restart your shell as a login shell so the path changes take effect.
# source ~/.bash_profile
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
# Change user and group to deployer to allow gem installs
chown -R deployer:deployer .rbenv/
fi
# Install Ruby via rbenv
echo "#-> Installing Ruby Via Rbenv"
if [ -d "~/.rbenv/versions/$RUBY" ]; then
echo "--> ruby $RUBY already installed"
else
rbenv install -v $RUBY
rbenv global $RUBY
fi
# Bundler
echo "#-> Installing Bundler Via Gem"
if gem list | grep -q bundler; then
echo "--> bundler already installed, skipping."
else
gem install bundler --no-rdoc --no-ri
rbenv rehash
fi
# Create mysql root password and new user
# mysql -u root -p
# CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
# GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
# FLUSH PRIVILEGES;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment