Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

Deploy my Nikola site, part 2

So file deploy-part2.sh executes on the web server. It's called by the first script from the first server.

#!/bin/sh
# File: deploy-part2.sh
# Locations:
#    doc7-01a:/usr/local/bin/
#    server1:/var/server1/shares/public/Support/Programs/nikola/scripts/
# Author: bgstack15
# Startdate: 2021-08-29 16:56
# Title: Script that extracts tarfile of static site for knowledgebase
# Purpose: Automation of updating the blog
# History:
# Usage:
#    depoy-part2.sh /tmp/kb2.blog.2021-08-29T165805.tgz
#    called by deploy-kb2.sh
# Reference:
# Improve:
# Dependencies:
#    tarball of knowledgebase blog
# Documentation: /mnt/public/Suppot/Programs/nikola/blog-README.md
set -x
OUTDIR=/var/www/blog
TARFILE="${1}" # should be similar to /tmp/kb2.blog.2021-08-29T165805.tgz
if ! test -f "${TARFILE}" ;
then
   echo "Unable to find tarfile ${TARFILE}. Aborted."
   exit 1
fi
test "${USER}" != "blog" && { sudo mkdir -p "${OUTDIR}" ; sudo chown blog.nginx "${OUTDIR}" ; sudo chmod 0775 "${OUTDIR}" ; }
cd "$( dirname "${OUTDIR}" )"
{
   {
      tar -zxf "${TARFILE}"
      # for some reason we cannot utime, even though this is xfs. Whatever. Don't care.
   } 2>&1 1>&3 | grep -viE 'Cannot utime|Exiting with failure status' 1>&2
} 3>&1
test "${USER}" != "blog" && { sudo chown -R blog.nginx "${OUTDIR}" ; }
chmod -R u=rwX,g=rwX,o=rX "${OUTDIR}"
/usr/local/bin/generate-tag-cloud.sh

Walkthrough

I'm so pleased that I don't have to trigger nginx to reload or anything! That's the beauty of a static site: the contents are served from disk, and that is all (well, minus the javascript comments stuff).

I ran into some weird problem where tar was throwing extraneous errors about cannot utime. And I didn't care enough to fix it, so I just wrap around it and exclude that error message.

And then I call generate-tag-cloud.sh which makes the nifty tag cloud you see in the right sidebar.

Comments