Skip to content

Instantly share code, notes, and snippets.

@vfsoraki
Created November 7, 2019 08:54
Show Gist options
  • Save vfsoraki/7cd8b54a5065ef4fa9434a8d40dee840 to your computer and use it in GitHub Desktop.
Save vfsoraki/7cd8b54a5065ef4fa9434a8d40dee840 to your computer and use it in GitHub Desktop.
Simple bash script to facilitate deploying projects to shared hosting using git
#!/usr/bin/env bash
## This is a simple bash script to help deploy git-based projects to shared hostings.
## It work by tracking last deployed commit in a file (see below for file name).
## When you run this script, all files changed since last deployed commit up to now
## are put into a .tar.gz file (see below for file name), so you can easily upload and
## unzip it on shared hosting.
LAST_COMMIT_FILE=.last.deploy
OUTPUT_FILE=file.tar.gz
LAST_DEPLOYED_COMMIT=$(cat $LAST_COMMIT_FILE 2>/dev/null || git rev-list --max-parents=0 HEAD)
CURRENT_COMMIT=$(git rev-parse HEAD)
if [ "$LAST_DEPLOYED_COMMIT" = "$CURRENT_COMMIT" ]
then
echo "Current commit already deployed"
exit
fi
if [ -f $OUTPUT_FILE ]
then
echo "Output file '$OUTPUT_FILE' already exists, please remove it first"
exit
fi
git diff --name-only $LAST_DEPLOYED_COMMIT $CURRENT_COMMIT | tar -zcT - -f $OUTPUT_FILE
echo -n $CURRENT_COMMIT > $LAST_COMMIT_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment