Last active
May 29, 2018 18:04
-
-
Save maxpoletaev/f36f4dc0283000f8248bbde8fdcb6950 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Environment variables: | |
# REMOTE_USER, REMOTE_HOST — obviously | |
# Read more about deployment over SSH: | |
# https://confluence.atlassian.com/bitbucket/access-remote-hosts-via-ssh-847452940.html | |
set -e # automatic exit on error | |
REMOTE_DIR="~/www" | |
DIST_FILE="/tmp/dist.tar.gz" | |
SSH_USER="$REMOTE_USER@$REMOTE_HOST" | |
SSH_OPTIONS="" | |
echo "creating an archive of project files" | |
tar -czf $DIST_FILE --exclude .git --exclude dist.tar.gz ./ | |
echo "uploading the archive on the remote host" | |
scp $SSH_OPTIONS $DIST_FILE $SSH_USER:~/dist.tar.gz | |
echo "unpacking the archive and restart the servcies" | |
ssh $SSH_USER $SSH_OPTIONS << EOF | |
mkdir -p ~/dist | |
mkdir -p $REMOTE_DIR | |
tar xf ~/dist.tar.gz -C ~/dist | |
if [[ -d $REMOTE_DIR ]]; then | |
rm -rf $REMOTE_DIR | |
fi | |
mv ~/dist $REMOTE_DIR | |
EOF | |
rm $DIST_FILE | |
echo "Done" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment