Skip to content

Instantly share code, notes, and snippets.

@anthonycastelli
Last active June 1, 2017 07:05
Show Gist options
  • Save anthonycastelli/7cbad0a248e762980c4cbbd5f49de73a to your computer and use it in GitHub Desktop.
Save anthonycastelli/7cbad0a248e762980c4cbbd5f49de73a to your computer and use it in GitHub Desktop.
Vapor Ubuntu setup script
# /bin/sh
#
# Vapor.sh
#
# Created by Anthony Castelli on 5/31/17
# Copyright © 2017 Anthony Castelli. All rights reserved.
#
print() {
echo "\033[1;36m$1 \033[0;36m$2"
}
green() {
echo "\033[0;32m$1"
}
echo "##########################"
echo "# VAPOR SETUP SCRIPT #"
echo "##########################"
echo ""
echo ""
# ---------------------
print "[NGINX]: " "Installing..."
sudo apt-get install nginx
print "[NGINX]: " "Make sure to setup your default site (/etc/nginx/sites-enabled/default)"
# ---------------------
echo "\n"
echo "\n"
# ---------------------
print "[GIT]: " "Installing..."
sudo apt-get install git
# ---------------------
echo "\n"
echo "\n"
# ---------------------
print "[Lets Encrypt]: " "Installing..."
sudo apt-get install letsencrypt
print "[Lets Encrypt]: " "A good place to follow along with setting up your certificate is https://www.linode.com/docs/security/ssl/install-lets-encrypt-to-create-ssl-certificates"
# ---------------------
print "\n"
print "\n"
# ---------------------
print "[Deploy Account]: " "Setting up a default deploy account (Password-less). Setup a default password for now, then we will remove it later on."
sudo adduser deploy
sudo adduser deploy sudo
sudo mkdir /home/deploy/.ssh
sudo chmod 700 /home/deploy/.ssh
sudo touch /home/deploy/.ssh/authorized_keys
sudo chmod 400 /home/deploy/.ssh/authorized_keys
sudo chown deploy:deploy /home/deploy -R
# su deploy
print "" "Don't forgot to disable root login and password authentication for SSH"
green "PermitRootLogin no"
green "PasswordAuthentication no"
print "" ""
echo "\n"
print "[Deploy Account]: " "Creating directories"
sudo mkdir /home/deploy/www
sudo mkdir /home/deploy/logs
sudo mkdir /home/deploy/www/letsencrypt/.well-known/acme-challenge
sudo chown deploy:deploy /home/deploy/www -R
sudo chown deploy:deploy /home/deploy/logs -R
sudo chown deploy:deploy /home/deploy/www/letsencrypt/.well-known/acme-challenge -R
# ---------------------
print "\n"
print "\n"
# ---------------------
print "[Swift & Vapor]: " "Installing..."
wget -q https://repo.vapor.codes/apt/keyring.gpg -O- | sudo apt-key add -
echo "deb https://repo.vapor.codes/apt $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/vapor.list
sudo apt-get update
sudo apt-get install swift vapor
# eval "$(curl -sL check.vapor.sh)"
print "[Swift & Vapor]: " "Testing Vapor..."
vapor version
# ---------------------
print "\n"
print "\n"
# ---------------------
green "[Notes]:"
green " NGINX: Don't forget to update your sites (/etc/nginx/sites-enabled/default)"
green " LETSENCRYPT: Don't forget to create your SSL Certifiate."
green " 1. Generate your SSL Cert via letsencrypt"
green " 2. Edit your crontab: \"sudo crontab -e\" (This must be done on the root account. EC2 Instance is ubuntu via the certificate from AWS)"
green " 3. Add this to your crontab"
green " # Lets Encrypt SSL Renewal every Monday at 2:30 AM"
green " 30 2 * * 1 sudo letsencrypt renew >> /home/deploy/logs/le-renew.log"
green " 35 2 * * 1 sudo service nginx reload"
green " SSH: Don't forget create an SSH key on your deploy account."
green " VAPOR DEPLOYMENT: Setup and use Flock (https://github.com/jakeheis/Flock). Once you setup your flock deploy targets, make sure to run \"flock tools\" using your root account, then for regular deployment, use the deploy account."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment