From 073c779f9383a3fce33a03b460b664e4a916f6f3 Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Thu, 18 Nov 2021 00:07:09 +0100 Subject: [PATCH] removed the use of sed -i which is not portable --- rivet.sh | 63 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/rivet.sh b/rivet.sh index 4625c38..26b1c51 100644 --- a/rivet.sh +++ b/rivet.sh @@ -110,6 +110,7 @@ footerfile=$srcdir/_footer.html metafile=$srcdir/_metadata.html objlist="$(mktemp)" objdate="$(mktemp)" +tmpsed="$(mktemp)" # Check if index.md is present if ! [ -e "$srcdir"/index.md ]; then @@ -133,10 +134,14 @@ if ! [ -e "$metafile" ]; then fi # Remove junk from {header,footer} files -sed -i 's///' "$headerfile" -sed -i 's/<\/header>//' "$headerfile" -sed -i 's///' "$footerfile" -sed -i 's/<\/footer>//' "$footerfile" +sed 's///' "$headerfile" > "$tmpsed" +mv "$tmpsed" "$headerfile" +sed 's/<\/header>//' "$headerfile" > "$tmpsed" +mv "$tmpsed" "$headerfile" +sed 's///' "$footerfile" > "$tmpsed" +mv "$tmpsed" "$headerfile" +sed 's/<\/footer>//' "$footerfile" > "$tmpsed" +mv "$tmpsed" "$headerfile" # Remove any junk from the domain eg. [https://]domain.com[/] domain="$(echo "$2" | sed -e 's/^https*:\/\///' -e 's/\/$//')" @@ -170,7 +175,8 @@ rm -f "$objdate" while IFS="" read -r file; do stat -c '%y' "$file" >> "$objdate" done < "$objlist" -sed -i -e "s,^\/*[^\/]*\/,$destdir/," "$objlist" +sed -e "s,^\/*[^\/]*\/,$destdir/," "$objlist" > "$tmpsed" +mv "$tmpsed" "$objlist" # Convert convertible files while IFS="" read -r file; do @@ -178,18 +184,21 @@ while IFS="" read -r file; do done < "$objlist" # Convert the file list to a list that contains the path of all the html files -sed -i -e 's/\.md$/\.html/' "$objlist" +sed -e 's/\.md$/\.html/' "$objlist" > "$tmpsed" +mv "$tmpsed" "$objlist" # Create a list that contains the links to all html files linklist="$(mktemp)" cp -f "$objlist" "$linklist" -sed -i -e "s/^$destdir//" "$linklist" +sed -e "s/^$destdir//" "$linklist" > "$tmpsed" +mv "$tmpsed" "$linklist" # Insert metadata into if ! [ "$SKIP_META" ]; then find "$destdir" -name "*.html" | while IFS="" read -r file; do - sed -i "//r $metafile" "$file" + sed "//r $metafile" "$file" > "$tmpsed" + mv "$tmpsed" "$file" done fi @@ -216,27 +225,33 @@ EOF printf "

%s - %s

\n" "$line" "$ldate" "$title" >> "$tmpfile" done < "$linklist" echo '' >> "$tmpfile" - sed -i '/<\/body>/i REPLACE' "$destdir"/index.html - sed -i "/^REPLACE/r $tmpfile" "$destdir"/index.html - sed -i 's/^REPLACE//' "$destdir"/index.html + sed '/<\/body>/i REPLACE' "$destdir"/index.html > "$tmpsed" + mv "$tmpsed" "$destdir"/index.html + sed "/^REPLACE/r $tmpfile" "$destdir"/index.html > "$tmpsed" + mv "$tmpsed" "$destdir"/index.html + sed 's/^REPLACE//' "$destdir"/index.html > "$tmpsed" + mv "$tmpsed" "$destdir"/index.html rm -f "$tmpfile" fi # enclose article inside
find "$destdir" -name "*.html" | while IFS="" read -r file; do - sed -i -e '//a
' -e '/<\/body>/i
' "$file" + sed -e '//a
' -e '/<\/body>/i
' "$file" > "$tmpsed" + mv "$tmpsed" "$file" done # Prepate the header if ! [ "$SKIP_HEADER" ]; then tmphead="$(mktemp)" cp "$headerfile" "$tmphead" - sed -i '1s/^/
/' "$tmphead" + sed '1s/^/
/' "$tmphead" > "$tmpsed" + mv "$tmpsed" "$tmphead" echo '
' >> "$tmphead" find "$destdir" -name "*.html" | while IFS="" read -r file; do - sed -i "//r $tmphead" "$file" + sed "//r $tmphead" "$file" > "$tmpsed" + mv "$tmpsed" "$file" done rm -f "$tmphead" fi @@ -245,13 +260,17 @@ fi if ! [ "$SKIP_FOOTER" ]; then tmpfoot="$(mktemp)" cp "$footerfile" "$tmpfoot" - sed -i '1s/^/