blogker/aux/pull-n-build.sh

53 lines
1.1 KiB
Bash
Raw Normal View History

2023-07-26 20:22:25 +00:00
#!/bin/sh
# stop on error
set -e -v
2023-07-28 07:18:39 +00:00
{
# Log date
date
2023-07-26 20:22:25 +00:00
2023-07-28 07:18:39 +00:00
# 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
2023-07-28 07:18:39 +00:00
else
# repo URL set
2023-10-14 13:31:43 +00:00
if [ -d /repo ]; then
# repo already exists, try to pull
cd /repo && git pull --recurse-submodules
if [ "$?" -ne 0 ]; then
# pull failed, clean and retry to clone
echo "Pull failed, attempting to clean clone"
rm -rf /repo
fi
fi
if [ ! -d /repo ]; then
# repo needs to be cloned
2023-09-09 17:35:43 +00:00
# check if there is a specific branch to clone
if [ ! "$REPO_BRANCH" == "" ]; then
BRANCHCMD="--branch $REPO_BRANCH"
fi
git clone --recurse-submodules $BRANCHCMD $REPO_URL /repo
fi
2023-07-28 07:18:39 +00:00
fi
2023-07-26 20:22:25 +00:00
# create temporary working directory
tmpdir=$(mktemp --directory)
# copy over into temporary directory
cp -r /repo/* $tmpdir
2023-07-28 07:18:39 +00:00
# build and copy over
cd $tmpdir && \
2023-07-28 07:18:39 +00:00
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
2023-07-28 07:18:39 +00:00
} 2>&1 | tee /var/log/blogker-pull-n-build.log