Skip to content

Commit

Permalink
formalize cache busting script for easy usage when not using install.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedehopf committed Apr 21, 2023
1 parent c51bbe1 commit bc21859
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 33 deletions.
12 changes: 12 additions & 0 deletions cachebust.list
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions cachebust.sh
Original file line number Diff line number Diff line change
@@ -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 <path_to_cachebust.list> <tar1090_html_folder>"
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"
38 changes: 5 additions & 33 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit bc21859

Please sign in to comment.