I am using Jekyll to generate this website for a half a year and Gandi for an even longer period of time so at the beginning of this year I revisited How to quickly download or upload directory tree over FTP post and created simple but useful shell script to automate build and upload process.
There is only one dependency – lftp utility.
$ sudo apt-get install lftp
Shell script uses lftp’s reverse mirror command to upload newly created and modified files to the server.
#!/bin/sh # Local - Blog directory local_directory="/home/milosz/Projects/blog" # Remote - SFTP hostname, username, password, directory hostname="sftp.dc0.gpaas.net" username="user" password="pass" remote_directory="/vhosts/blog.sleeplessbeastie.eu/htdocs" # execute only if directory exists if [ -d "$local_directory" ]; then # kill existing jekyll process pkill jekyll # wait for a while sleep 5 # build site LC_ALL=C.UTF-8 jekyll build --lsi # upload website # cd "${local_directory}/_site" && lftp -u ${username},${password} -e "mirror -R -p -P=10 -e --ignore-time -v ${local_directory}/_site/ ${remote_directory};quit" sftp://${hostname} fi
The following script output provides quite verbose output so the principle of operation should be easy to understand.
$ sh upload.sh Configuration file: /home/milosz/Projects/blog/_config.yml Source: /home/milosz/Projects/blog Destination: /home/milosz/Projects/blog/_site Generating... Populating LSI... Rebuilding index... done. Removing old file `atom.xml' Transferring file `atom.xml' Removing old file `2010/12/01/nginx-proxy-and-real-ip-address/index.html' Transferring file `2010/12/01/nginx-proxy-and-real-ip-address/index.html' Removing old file `2010/12/30/how-to-set-global-user-name-and-email-in-git/index.html' Transferring file `2010/12/30/how-to-set-global-user-name-and-email-in-git/index.html' Removing old file `2011/12/15/wordpress-disable-post-revisions/index.html' Transferring file `2011/12/15/wordpress-disable-post-revisions/index.html' Removing old file `2012/01/11/audible-ping/index.html' Transferring file `2012/01/11/audible-ping/index.html' Removing old file `2012/01/16/how-to-check-established-tcp-connections/index.html' Transferring file `2012/01/16/how-to-check-established-tcp-connections/index.html' Removing old file `2012/07/28/how-to-reboot-linksys-wag120n-router/index.html' Transferring file `2012/07/28/how-to-reboot-linksys-wag120n-router/index.html' Removing old file `2013/01/02/debian-how-to-monitor-battery-capacity/index.html' Transferring file `2013/01/02/debian-how-to-monitor-battery-capacity/index.html' Removing old file `2013/03/29/wordpress-as-a-personal-scrapbook/index.html' Transferring file `2013/03/29/wordpress-as-a-personal-scrapbook/index.html' Removing old file `2013/04/14/console-based-task-manager/index.html' Transferring file `2013/04/14/console-based-task-manager/index.html' Removing old file `2013/07/23/virtualbox-how-to-control-virtual-machine-using-command-line/index.html' Transferring file `2013/07/23/virtualbox-how-to-control-virtual-machine-using-command-line/index.html' Removing old file `2013/09/19/apt-cacher-ng-and-debian-minimal-cd/index.html' Transferring file `2013/09/19/apt-cacher-ng-and-debian-minimal-cd/index.html' Removing old file `2013/10/07/how-to-determine-whether-the-processor-supports-64-bit-instruction-set/index.html' Transferring file `2013/10/07/how-to-determine-whether-the-processor-supports-64-bit-instruction-set/index.html' Removing old file `2013/11/14/unattended-boot-grub-ubuntu-and-power-fail/index.html' Transferring file `2013/11/14/unattended-boot-grub-ubuntu-and-power-fail/index.html' Removing old file `2013/12/03/how-to-redirect-command-output-using-sudo/index.html' Transferring file `2013/12/03/how-to-redirect-command-output-using-sudo/index.html' Removing old file `2014/01/02/how-to-open-firefox-bookmarks-from-openbox-menu/index.html' Transferring file `2014/01/02/how-to-open-firefox-bookmarks-from-openbox-menu/index.html' Transferring file `assets/uploads/2014/01/openbox_specified_bookmarks.png' Transferring file `assets/uploads/2014/01/openbox_unsorted_bookmarks.png' Total: 1090 directories, 3000 files, 0 symlinks New: 2 files, 0 symlinks Modified: 16 files, 0 symlinks 234223 bytes transferred in 5 seconds (49.9K/s)
Check out manual page in case of any doubts as every used parameter in the above shell script is described there.