Knowledge Base

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

Automatic build script for my static site

Building the site

As part of my nikola-powered static website, I have to actually "compile" or build the pages of the site.

The process for nikola is rather basic.

nikola build

Well, that sounds easy right? Well, you have to make sure you use the right python venv, and cd to the correct path. My entire logic consists of build.sh.

 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
#!/bin/sh
# Startdate: 2021-08-29 21:20
# Purpose: run `nikola build` for knowledgebase
# Dependencies:
#    nikola installed by pip for user blog on server1
INDIR=/var/server1/shares/public/Support/Programs/nikola/kb2
if test "$( hostname -s )" != "server1" ;
then
   echo "Connecting to server1..."
   ssh server1 /mnt/public/Support/Programs/nikola/scripts/build.sh
else
   echo "Now on server1."
   if test "${USER}" != "blog" ;
   then
      sudo su blog <<-EOF
      source ~/nikola/bin/activate
      cd $INDIR
      nikola build
EOF
   else
      source ~/nikola/bin/activate
      cd $INDIR
      nikola build
   fi # end-if-not-user-blog
fi # end-if-not-server1

The script sshes to the main file server, and then switches user, and then runs the nikola build command.

Comments