Skip to content

Instantly share code, notes, and snippets.

@MuhammetDilmac
Last active May 25, 2016 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MuhammetDilmac/fb9d6eee47c72c6efa04d12f2f2fedc4 to your computer and use it in GitHub Desktop.
Save MuhammetDilmac/fb9d6eee47c72c6efa04d12f2f2fedc4 to your computer and use it in GitHub Desktop.
FFA Deployment Server Prepare Script
#!/usr/bin/env bash
# Information output
info(){
printf "\e[1;34m[*] %s\e[0m\n" "$1"
}
user_path=/home/deploy
info "Change work path to deploy"
cd
info "Installing rbenv..."
git clone git://github.com/sstephenson/rbenv.git $user_path/.rbenv 1>/dev/null
info "Writing rbenv path to bashrc ..."
echo 'export PATH=\"$HOME/.rbenv/bin:$PATH\"' >> $user_path/.bashrc
echo 'eval "$(rbenv init -)"' >> $user_path/.bashrc
info "Exporting rbenv path..."
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
info "Preparing rbenv plugins..."
mkdir -p $user_path/.rbenv/plugins
git clone https://github.com/sstephenson/ruby-build.git $user_path/.rbenv/plugins/ruby-build 1>/dev/null
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> $user_path/.bashrc
git clone https://github.com/sstephenson/rbenv-gem-rehash.git $user_path/.rbenv/plugins/rbenv-gem-rehash 1>/dev/null
## Ruby environment
RUBY_VERSION="2.3.1"
info "Installing Ruby $RUBY_VERSION ..."
rbenv install $RUBY_VERSION 1>/dev/null
rbenv rehash 1>/dev/null
rbenv global $RUBY_VERSION 1>/dev/null
info "Ruby Version: $(ruby -v)"
info "Gem update system ..."
gem update --system 1>/dev/null
info "Echo .gemrc..."
echo 'gem: --no-rdoc --no-ri' >> $user_path/.gemrc
gem install bundler 1>/dev/null
gem install backup 1>/dev/null
rbenv rehash 1>/dev/null
info "Export path ..."
echo "export PATH="$PATH:/usr/bin"" >> $user_path/.bashrc
ssh-keygen -b 2048 -t rsa -f $user_path/.ssh/id_rsa -q -N ""
info "Public Key: $(cat $user_path/.ssh/id_rsa.pub)"
exec $SHELL
#!/usr/bin/env bash
# Config
public_key="SSH_KEY"
# Information output
info(){
printf "\e[1;34m[*] %s\e[0m\n" "$1"
}
# Error output
error(){
printf "\e[1;31m[*] %s\e[0m\n" "$1"
exit 1
}
# Success output
success(){
printf "\e[1;32m[*] %s\e[0m\n" "$1"
}
# Warning output
warning(){
printf "\e[1;33m[*] %s\e[0m\n" "$1"
}
RELEASE="$(lsb_release -r | cut -d$'\t' -f2)"
DISTRIBUTOR="$(lsb_release -i | cut -d$'\t' -f2)"
info "Your relase is $DISTRIBUTOR $RELEASE"
if [[ $DISTRIBUTOR != "Ubuntu" ]]; then
error "This script only available for Ubuntu"
fi
if [[ $RELEASE != "14.04" ]]; then
warning "This script only tested Ubuntu 14.04"
fi
if [[ $EUID -ne 0 ]]; then
error "You must be a root user"
fi
info "Change work path to root"
cd
info "Get latest repo index"
apt-get -y update 1>/dev/null
info "Get system upgrade"
apt-get -y upgrade 1>/dev/null
info "Exporting language"
export LANGUAGE=en_US.UTF-8 && export LANG=en_US.UTF-8 && export LC_ALL=en_US.UTF-8 && locale-gen en_US.UTF-8 && dpkg-reconfigure
info "Installing ruby dependencies..."
apt-get -y install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev 1>/dev/null
info "Installing nodejs ..."
add-apt-repository -y ppa:chris-lea/node.js 1>/dev/null
apt-get -y update 1>/dev/null
apt-get -y install nodejs 1>/dev/null
info "Installing imagemagick ..."
apt-get install -y imagemagick 1>/dev/null
info "Installing nginx ..."
add-apt-repository -y ppa:nginx/stable 1>/dev/null
apt-get -y update 1>/dev/null
apt-get -y install nginx 1>/dev/null
service nginx start 1>/dev/null
info "Installing postgresql ..."
apt-get -y install postgresql libpq-dev 1>/dev/null
info "Creating deploy user and group"
deploy_group=deploy
deploy_user=deploy
info "Check user is exist"
id -u $deploy_user &> /dev/null
if [ $? -ne 0 ]
then
info "* Add $deploy_group group"
groupadd $deploy_group 1>/dev/null
info "* Creating user $deploy_user"
useradd -m -g $deploy_group -s /bin/bash $deploy_user 1>/dev/null
info "* Adding user $deploy_user to sudoers"
chmod +w /etc/sudoers 1>/dev/null
echo "$deploy_user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
chmod -w /etc/sudoers 1>/dev/null
else
warning "* $deploy_user user already exists"
fi
info "Check user is exist, maybe some errors occured"
id -u $deploy_user &> /dev/null
if [ $? -ne 0 ]
then
warning "* $deploy_user user does not exists"
else
info "* Add .ssh directory to $deploy_user"
test -d /home/$deploy_user/.ssh
if [ $? -ne 0 ]
then
mkdir /home/$deploy_user/.ssh
# change user permisisions
# 700 => (owner read/write/execute, group none, other none)
chmod 700 /home/$deploy_user/.ssh
chown $deploy_user /home/$deploy_user/.ssh
chgrp $deploy_group /home/$deploy_user/.ssh
fi
info "* Adding $deploy_user authorized_keys"
echo $public_key >> /home/$deploy_user/.ssh/authorized_keys
# change user permisisions
# 600 => (owner read/write, group none, other none)
chmod 600 /home/$deploy_user/.ssh/authorized_keys
chown $deploy_user /home/$deploy_user/.ssh/authorized_keys
chgrp $deploy_group /home/$deploy_user/.ssh/authorized_keys
info "* Completed..."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment