Knowledge Base

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

Deploy my nikola site

So after I have built the site with nikola, I send up a tarball over ssh and extract it on the site. There's probably a million ways to do this, and I picked a simple one off the top of my head.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh
# File: deploy.sh
# Locations:
#    server1:/var/server1/shares/public/Support/Programs/nikola/scripts/deploy.sh
# Author: bgstack15
# Startdate: 2021-08-29
# Title: Deploy static site to bgstack15.ddns.net/blog/
# Purpose: Automation of updating the blog
# History:
# Usage:
#    deploy-kb2.sh
# Reference:
# Improve:
# Dependencies:
#   wireguard vpn to doc7-01a
#   output of `nikola build` in /mnt/public/Support/Programs/nikola/kb2-output/
# Documentation:
#    /mnt/public/Support/Programs/nikola/blog-README.md
INDIR=/mnt/public/Support/Programs/nikola/blog
OUTDIR=/var/www/blog
TARFILE=/tmp/kb2.blog.$( date "+%FT%H%M%S" ).tgz
if test "$( hostname -s )" != "server1" ;
then
   echo "Connecting to server1..."
   ssh server1 /mnt/public/Support/Programs/nikola/scripts/deploy.sh
else
   echo "Now on server1."
   if test "${USER}" != "blog" ;
   then
      sudo su blog <<-EOF
      chmod -R g=rwX "${INDIR}" 2>/dev/null
      tar -zcf "${TARFILE}" -C "$( dirname "${INDIR}" )" blog
      scp -p "${TARFILE}" blog@doc7-01a:/tmp
      ssh -i ~/.ssh/id_rsa blog@doc7-01a /usr/local/bin/deploy-part2.sh "${TARFILE}"
EOF
   else
      # already user blog
      chmod -R g=rwX "${INDIR}" 2>/dev/null
      tar -zcf "${TARFILE}" -C "$( dirname "${INDIR}" )" blog
      scp -p "${TARFILE}" blog@doc7-01a:/tmp
      ssh -i ~/.ssh/id_rsa blog@doc7-01a /usr/local/bin/deploy-part2.sh "${TARFILE}"
   fi
fi

Just like that build script, this script can be run from anywhere in my infrastructure because it will ssh to server1 first, if necessary.

Comments