Skip to content

Instantly share code, notes, and snippets.

@sean-e-dietrich
Created March 23, 2018 19:24
Show Gist options
  • Save sean-e-dietrich/0ce334573d43d59f4dc1d07b4a91d4c4 to your computer and use it in GitHub Desktop.
Save sean-e-dietrich/0ce334573d43d59f4dc1d07b4a91d4c4 to your computer and use it in GitHub Desktop.
Deploy Script
#!/usr/bin/env bash
if [ ! -d ~/.ssh ]; then
mkdir ~/.ssh
fi
# Move SSH Config to not ask about host
cp ./.circleci/ssh_config ~/.ssh/config
ENV=${1:-DEV}
SSH_PORT=${SSH_PORT:-22}
varname=${ENV}_HOST
eval "ENV_HOST=\$$varname"
varname=${ENV}_USER
eval "ENV_USER=\$$varname"
varname=${ENV}_PORT
eval "ENV_PORT=\$$varname"
varname=${ENV}_PATH
eval "ENV_PATH=\$$varname"
# SSH_HOST: The host of the end machine to connect to
SSH_HOST="${ENV_HOST}"
# SSH_USER: Who should we connect as
SSH_USER="${ENV_USER}"
# SSH_PORT: The SSH Port to connect to
SSH_PORT="${ENV_PORT}"
# SSH_PATH: The location to rsync the files to
SSH_PATH="${ENV_PATH}"
if [[ "${SSH_HOST}" != "" ]] && [[ "${SSH_USER}" != "" ]] && [[ "${SSH_PORT}" != "" ]] && [[ "${SSH_PATH}" != "" ]]; then
# Remove .git directory and do not transfer over.
rm -rf .git
# Rsync Folder Over
ssh -p ${SSH_PORT} -l ${SSH_USER} ${SSH_HOST} "sudo chown -R ${SSH_CURRENT_USER}:${SSH_CURRENT_GROUP} ${SSH_PATH}"
rsync -avzI -e "ssh -p ${SSH_PORT}" . ${SSH_USER}@${SSH_HOST}:${SSH_PATH}
ssh -p ${SSH_PORT} -l ${SSH_USER} ${SSH_HOST} "sudo chown -R ${SSH_WEB_USER}:${SSH_WEB_GROUP} ${SSH_PATH}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment