From bc21859752984db6a35eb7f6cd95e41452d792a1 Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Fri, 21 Apr 2023 05:48:12 +0200 Subject: [PATCH] formalize cache busting script for easy usage when not using install.sh --- cachebust.list | 12 ++++++++++++ cachebust.sh | 30 ++++++++++++++++++++++++++++++ install.sh | 38 +++++--------------------------------- 3 files changed, 47 insertions(+), 33 deletions(-) create mode 100644 cachebust.list create mode 100755 cachebust.sh diff --git a/cachebust.list b/cachebust.list new file mode 100644 index 000000000..e8681aadc --- /dev/null +++ b/cachebust.list @@ -0,0 +1,12 @@ +images/sprites.png +dbloader.js +defaults.js +early.js +flags.js +formatter.js +layers.js +markers.js +planeObject.js +registrations.js +script.js +style.css diff --git a/cachebust.sh b/cachebust.sh new file mode 100755 index 000000000..79fddd534 --- /dev/null +++ b/cachebust.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -e +trap 'echo "[ERROR] Error in line $LINENO when executing: $BASH_COMMAND"' ERR + +if [[ -z "$1" ]] || [[ -z "$2" ]]; then + echo "ERROR: usage: ./cachebust.sh " + exit 1 +fi + +LISTPATH="$1" +HTMLFOLDER="$2" + +sedreplaceargs=() + +SCRIPT_JS="" +while read -r FILE; do + md5sum=$(md5sum "$FILE" | cut -d' ' -f1) + prefix=$(cut -d '.' -f1 <<< "$FILE") + postfix=$(cut -d '.' -f2 <<< "$FILE") + newname="${prefix}_${md5sum}.${postfix}" + mv "$FILE" "$newname" + sedreplaceargs+=("-e" "s#${FILE}#${newname}#") + if [[ "$FILE" == "script.js" ]]; then + SCRIPT_JS="$newname" + fi +done < "$LISTPATH" + +sed -i "${sedreplaceargs[@]}" "$HTMLFOLDER"/index.html +sed -i "${sedreplaceargs[@]}" "$HTMLFOLDER"/"$SCRIPT_JS" diff --git a/install.sh b/install.sh index 0ef8f4546..cdc93f772 100755 --- a/install.sh +++ b/install.sh @@ -117,10 +117,10 @@ cd "$dir" if [[ "$1" == "test" ]] then - rm -r /tmp/tar1090-test 2>/dev/null || true - mkdir -p /tmp/tar1090-test - cp -r ./* /tmp/tar1090-test - cd /tmp/tar1090-test + rm -rf "$ipath/git" || true + mkdir -p "$ipath/git" + cp -r ./* "$ipath/git" + cd "$ipath/git" TAR_VERSION=$(date +%s) else if ! getGIT "$repo" "master" "$ipath/git" || ! cd "$ipath/git" @@ -296,35 +296,7 @@ do sed -i -e "s/tar1090 on github/tar1090 on github ($(date +%y%m%d))/" index.html - # cache busting sprites.png - { - spritename="sprites_$(md5sum images/sprites.png | cut -d' ' -f1).png" - mv "images/sprites.png" "images/${spritename}" - sed -i -e "s#sprites.png#${spritename}#g" script.js - sed -i -e "s#sprites.png#${spritename}#g" index.html - } - - # cache busting js / css - { - sedargs=("sed" "-i" "index.html") - for file in dbloader.js defaults.js early.js flags.js formatter.js layers.js markers.js planeObject.js registrations.js script.js style.css; do - md5sum=$(md5sum $file | cut -d' ' -f1) - prefix=$(cut -d '.' -f1 <<< "$file") - postfix=$(cut -d '.' -f2 <<< "$file") - newname="${prefix}_${md5sum}.${postfix}" - mv "$file" "$newname" - if [[ $nginx == yes ]]; then - gzip -k -3 "$newname" - fi - sedargs+=("-e" "s#${file}#${newname}#") - done - - "${sedargs[@]}" - } - - if [[ $nginx == yes ]]; then - gzip -k -3 ./libs/*.js - fi + "$ipath/git/cachebust.sh" "$ipath/git/cachebust.list" "$TMP" rm -rf "$html_path" mv "$TMP" "$html_path"