Jekyll Deploy Script

When I began using Jekyll to build my websites with I started developing this script to help me manage the build, and upload of new posts.

This script uses the following variables:

  • Location of the key
  • Location of the local Jekyll Website Files
  • Remote username
  • Remote server address
  • Remote path to to the files on the server
  • Port number to connect to.

The script checks for an existing _site directory and deletes it before building the website again. The rsync command looks at md5sums to determine if files have changed, and does not move them over if the content has changed.

The script is available from My Github Account

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#! /bin/bash

KEYLOCATION="$HOME/.ssh/id_rsa"
LOCALWEBSITEFILES="$HOME/excalibursheath.com/_site/"
REMOTEUSERNAME="jordan"
REMOTESERVER="sylara.excalibursheath.com"
REMOTEWEBPATH="/home/$REMOTEUSERNAME/www/excalibursheath.com/public_html/"

#Check if the _site directory exists and delete it
if [ -d "$LOCALWEBSITEFILES" ]; then
        rm -rf $LOCALWEBSITEFILES
fi

#Source .profile to run Jekyll
source $HOME/.profile

#Build the Jekyll Site
jekyll build

#Copy the Jekyll Site To the Server
rsync -avz --checksum -e "ssh -p 4242 -i $KEYLOCATION" $LOCALWEBSITEFILES $REMOTEUSERNAME@$REMOTESERVER:$REMOTEWEBPATH
Written on September 15, 2016