blogker/aux/pull-n-build.sh

43 lines
846 B
Bash
Executable File

#!/bin/sh
# stop on error
set -e -v
{
# Log date
date
# check if initial git run
if [ "$REPO_URL" == "" ]; then
# no repo URL set.
# most likely the repo is passed through as volume
# do not pull, treat the repo as-is
true
else
# repo URL set
if [ ! -d /repo ]; then
# repo needs to be cloned
git clone --recurse-submodules $REPO_URL /repo
else
# no - pull existing repo
cd /repo && git pull --recurse-submodules
fi
fi
# create temporary working directory
tmpdir=$(mktemp --directory)
# copy over into temporary directory
cp -r /repo/* $tmpdir
# build and copy over
cd $tmpdir && \
hugo && \
rm -rf /usr/share/nginx/html/* && \
cp -R $tmpdir/public/* /usr/share/nginx/html && \
chown nginx:nginx -R /usr/share/nginx/html
# cleanup
rm -rf $tmpdir
} 2>&1 | tee /var/log/blogker-pull-n-build.log