From 59293cc7c60688d5b34a038805a33dbdbd2133d3 Mon Sep 17 00:00:00 2001 From: Michael Reed Date: Sun, 9 Jul 2017 03:31:58 -0400 Subject: www/publish.sh: Make safe to run multiple instances concurrently Instead of always using the same file (temp.md), use a unique temporary file so that multiple instances of publish.sh do not clobber each other's work. --- www/publish.sh | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'www') diff --git a/www/publish.sh b/www/publish.sh index 264c95a1..40140728 100755 --- a/www/publish.sh +++ b/www/publish.sh @@ -2,6 +2,7 @@ # # Copyright (C) 2017 Alyssa Rosenzweig # Copyright (C) 2017 Leah Rowe +# Copyright (C) 2017 Michael Reed # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,8 +22,9 @@ set -e printf '%s\n' $1 FILE=${1%.md} +TMPFILE=$(mktemp -t libreboot_www.XXXXXXXXXX) -cat $1 > temp.md +cat "$1" > "$TMPFILE" OPTS="-T Libreboot" @@ -46,29 +48,29 @@ else fi if [[ $FILE = *suppliers ]]; then - printf '\n%s\n' "Edit this page -- Back to previous page" >> temp.md + printf '\n%s\n' "Edit this page -- Back to previous page" >> "$TMPFILE" fi if [ "${FILE}" != "./docs/fdl-1.3" ] && [ "${FILE}" != "./conduct" ]; then - cat footer.md >> temp.md + cat footer.md >> "$TMPFILE" fi # change out .md -> .html -sed -i -e 's/\.md\(#[a-z\-]*\)*)/.html\1)/g' temp.md -sed -i -e 's/\.md\(#[a-z\-]*\)*]/.html\1]/g' temp.md +sed -i -e 's/\.md\(#[a-z\-]*\)*)/.html\1)/g' "$TMPFILE" +sed -i -e 's/\.md\(#[a-z\-]*\)*]/.html\1]/g' "$TMPFILE" # change out .md -> .html -sed -i -e 's/\.md\(#[a-z\-]*\)*)/.html\1)/g' temp.md -sed -i -e 's/\.md\(#[a-z\-]*\)*]/.html\1]/g' temp.md +sed -i -e 's/\.md\(#[a-z\-]*\)*)/.html\1)/g' "$TMPFILE" +sed -i -e 's/\.md\(#[a-z\-]*\)*]/.html\1]/g' "$TMPFILE" # work around issue #2872 -TOC=$(grep -q "^x-toc-enable: true$" temp.md && printf '%s\n' "--toc --toc-depth=2") || TOC="" +TOC=$(grep -q "^x-toc-enable: true$" "$TMPFILE" && printf '%s\n' "--toc --toc-depth=2") || TOC="" # work around heterogenous pandoc versions SMART=$(pandoc -v | grep -q '2\.0' || printf '%s\n' "--smart") || SMART="" # chuck through pandoc -pandoc $TOC $SMART temp.md -s --css /global.css $OPTS \ +pandoc $TOC $SMART "$TMPFILE" -s --css /global.css $OPTS \ --template template.html --metadata return="$RETURN"> $FILE.html # additionally, produce bare file for RSS @@ -76,3 +78,6 @@ pandoc $1 > $FILE.bare.html # generate section title anchors as [link] sed -i -e 's_^\(.*\)__' $FILE.html + +# clean up temporary file +rm -f "$TMPFILE" -- cgit v1.2.3-70-g09d2