Rails – Script de deploy in server ubuntu

echo “Configurando a linguagem”
sudo apt-get install language-pack-pt

echo “Configurando o relogio”
sudo apt-get update
sudo apt-get install tzdata
sudo dpkg-reconfigure tzdata

echo “Criando usuario deploy”
sudo adduser deploy

echo “Criando configuracoes SSH”
su deploy
ssh-keygen
ssh-copy-id deploy@SERVER_IP_ADDRESS
cat ~/.ssh/id_rsa.pub
exit
su – deploy
mkdir .ssh
chmod 700 .ssh
touch .ssh/authorized_keys
chmod 600 .ssh/authorized_keys
exit

echo “Liberando o SSH – PermitRootLogin yes | PasswordAuthentication yes”
sudo nano /etc/ssh/sshd_config
sudo service ssh restart
sudo usermod -a -G sudo deploy
exit

echo “Logando como deploy”
ssh deploy@SERVER_IP_ADDRESS

echo “Instalacoes”
sudo apt-get update
sudo apt-get install curl git-core nginx libpq-dev imagemagick -y

echo “Instalando o Ruby e Rails”
gpg –keyserver hkp://keys.gnupg.net –recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
\curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm requirements
rvm install VERSAO
gem install rails -v VERSAO
gem install bundler -V

echo “Instalando o NodeJS”

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash – sudo apt-get install -y nodejs

echo “SHH do Bitbucket”
ssh -T git@bitbucket.org
ssh-keygen -t rsa
echo “Olhar aqui: https://confluence.atlassian.com/display/BITBUCKET/Use+deployment+keys”

echo “git clone”
git clone git@bitbucket.org:infarma/ecommerce.git

echo “Estruturar o disparo do capistrano”
cat ~/.ssh/id_rsa.pub | ssh -p your_port_num deploy@your_server_ip ‘cat >> ~/.ssh/authorized_keys’

echo “Atualizando”
cap production deploy:initial

echo “Ajustes no Nginx”
sudo rm /etc/nginx/sites-enabled/default
sudo ln -nfs “/home/deploy/apps/appname/current/config/nginx.conf” “/etc/nginx/sites-enabled/appname”
sudo service nginx restart