You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
160 lines
3.2 KiB
160 lines
3.2 KiB
#!/bin/sh |
|
# Execute Hugo website generation and log all output into log file |
|
# In error case, existing blog content will not be touched |
|
# |
|
|
|
# Print all commands to console |
|
set -x; |
|
|
|
# Version nr of this script. Just for logging |
|
VERSION=2 |
|
|
|
# Path to hugo executable on uberspace and local (for testing) |
|
HUGO=~/bin/hugo |
|
#HUGO=~/dierundestunde/hugo/hugo |
|
|
|
# Path to output destination on uberspace and local (for testing). Folder must exists. |
|
PUBLIC_WWW=~/html/dierundestunde |
|
# PUBLIC_WWW=/var/www/virtual/$USER/html/dierundestunde |
|
#PUBLIC_WWW=~/hugotest/html/dierundestunde |
|
|
|
# Working dir: here is the script and git's working dir |
|
GENDIR=~/dierundestundegen |
|
|
|
# Destination dir where hugo will genereate the content into |
|
TMPPUBLIC=$GENDIR/html |
|
|
|
# Path to persisted log file, e.g. in web folder |
|
LOG=$GENDIR/log.txt |
|
|
|
# Path to a temp log file for hugo's stdout |
|
TMPLOG=$GENDIR/tmplog.txt |
|
|
|
# Path to a temp log file for hugo's errout |
|
TMPERR=$GENDIR/tmperr.txt |
|
|
|
# Tmp file with timestamp string |
|
TMPDATE=$GENDIR/tmpdate.txt |
|
|
|
# Paths to the local gits |
|
TMPGIT_HUGO=$GENDIR/drs |
|
|
|
# Path to our repositories |
|
GIT_HUGO=https://kollegen.uber.space/gitea/webiste/drs.git |
|
|
|
# Log a text file content |
|
log_file () { |
|
cat $1 |
|
cat $1 >> $LOG |
|
} |
|
|
|
# log a string argument |
|
log () { |
|
echo $1 |
|
echo $1 >> $LOG |
|
} |
|
|
|
# Always produce a log file in the destination folder |
|
finish () { |
|
|
|
if [ -f $LOG ] |
|
then |
|
echo "Moving log.txt file to $LOG $PUBLIC_WWW/" |
|
mv -Z -v $LOG "$PUBLIC_WWW/" |
|
fi |
|
|
|
if [ -f $TMPLOG ] |
|
then |
|
rm $TMPLOG |
|
fi |
|
|
|
if [ -f $TMPERR ] |
|
then |
|
rm $TMPERR |
|
fi |
|
|
|
if [ -f $TMPDATE ] |
|
then |
|
rm $TMPDATE |
|
fi |
|
|
|
|
|
exit $1 |
|
} |
|
|
|
### MAIN ############################################### |
|
log "Version $VERSION" |
|
|
|
if [ -d $TMPPUBLIC ] |
|
then |
|
rm -r -f $TMPPUBLIC |
|
fi |
|
|
|
if [ -f $LOG ] |
|
then |
|
rm -v $LOG |
|
touch $LOG |
|
fi |
|
|
|
|
|
# Document actual time into log file |
|
date > $TMPDATE |
|
log_file $TMPDATE |
|
|
|
log "Using tmp dir $GENDIR" |
|
|
|
# For the very first time: create dir |
|
if [ ! -d $TMPGIT_HUGO ] |
|
then |
|
mkdir -v $TMPGIT_HUGO 2>&1 | tee -a $LOG |
|
fi |
|
|
|
# Check, if there is really the repro inside |
|
if [ ! -d $TMPGIT_HUGO/.git ] |
|
then |
|
# jetzt clonen wir das Repository in den temporären Ordner |
|
git clone $GIT_HUGO $TMPGIT_HUGO 2>&1 | tee -a $LOG |
|
else |
|
# env -i git -C $TMPGIT_HUGO pull 2>&1 | tee -a $LOG |
|
cd $TMPGIT_HUGO && git pull 2>&1 | tee -a $LOG |
|
fi |
|
|
|
# Hugo anschmeißen |
|
log "Starting hugo" |
|
|
|
cd $TMPGIT_HUGO && $HUGO --cacheDir=$HOME/tmp/hugo_cache --destination $TMPPUBLIC > $TMPLOG 2> $TMPERR |
|
|
|
if [ -f $TMPLOG ] |
|
then |
|
log_file $TMPLOG |
|
fi |
|
|
|
if [ -f $TMPERR ] |
|
then |
|
if grep -Fq "Error" $TMPERR |
|
then |
|
log "Hugo failed" |
|
log_file $TMPERR |
|
log "Generation canceled. Check the error and try to fix it. Then push again." |
|
finish 1 |
|
fi |
|
fi |
|
|
|
if [ -d $PUBLIC_WWW ] |
|
then |
|
log "Remove $PUBLIC_WWW" |
|
rm -r -f $PUBLIC_WWW 2>&1 | tee -a $LOG |
|
else |
|
log "Create $PUBLIC_WWW" |
|
mkdir -v $PUBLIC_WWW 2>&1 | tee -a $LOG |
|
|
|
fi |
|
|
|
# Publish now |
|
log "Copy $TMPPUBLIC to $PUBLIC_WWW" |
|
rm -r -f $PUBLIC_WWW |
|
mv -Z -v $TMPPUBLIC $PUBLIC_WWW 2>&1 | tee -a $LOG |
|
|
|
log "Ready, Blog created in $PUBLIC_WWW!" |
|
|
|
finish 0
|
|
|