mirror of
https://git.sr.ht/~seirdy/seirdy.one
synced 2024-11-10 00:12:09 +00:00
avoid supressing compressor errors
This commit is contained in:
parent
f4d43d1e35
commit
7bd1a14ef5
3 changed files with 24 additions and 6 deletions
8
scripts/brotli-wrapper.sh
Normal file
8
scripts/brotli-wrapper.sh
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# compress a file with brotli if it isn't already compressed.
|
||||||
|
set -e -u
|
||||||
|
|
||||||
|
if [ ! -f "$1.br" ]; then
|
||||||
|
brotli -Z -- "$1"
|
||||||
|
fi
|
||||||
|
|
|
@ -5,18 +5,19 @@
|
||||||
# 2. "gzip" or "brotli"
|
# 2. "gzip" or "brotli"
|
||||||
# 3. ECT zopfli compression level
|
# 3. ECT zopfli compression level
|
||||||
|
|
||||||
# no pipefail here since there are no pipes.
|
#shellcheck disable=SC3040 # This only sets pipefail if it's available and otherwise does nothing
|
||||||
|
set -o pipefail 2>/dev/null || true
|
||||||
set -e -u
|
set -e -u
|
||||||
|
|
||||||
|
dirname="$(dirname "$0")"
|
||||||
output_dir="$1"
|
output_dir="$1"
|
||||||
format="$2"
|
format="$2"
|
||||||
|
|
||||||
alias find_compressible='find "$output_dir" -type f \( -name "*.html" -o -name "*.txt" -o -name "*.xml" -o -name "*.webmanifest" -o -name "*.*.svg" -o -name "*.json" \)'
|
alias find_compressible='find "$output_dir" -type f \( -name "*.html" -o -name "*.txt" -o -name "*.xml" -o -name "*.webmanifest" -o -name "*.*.svg" -o -name "*.json" \)'
|
||||||
|
|
||||||
if [ "$format" = "gzip" ]; then
|
if [ "$format" = "gzip" ]; then
|
||||||
compress_level="$3"
|
# compression level should be the third argument
|
||||||
find_compressible -exec ect -quiet -"$compress_level" -gzip {} \;
|
find_compressible | xargs -n1 sh "$dirname/ect-wrapper.sh" "${3-6}"
|
||||||
find_compressible -exec touch -r {} {}.gz \;
|
elif [ "$format" = "brotli" ]; then
|
||||||
elif [ "$2" = "brotli" ]; then
|
find_compressible | xargs -n1 sh "$dirname/brotli-wrapper.sh"
|
||||||
find_compressible -exec brotli -Z -- {} \;
|
|
||||||
fi
|
fi
|
||||||
|
|
9
scripts/ect-wrapper.sh
Normal file
9
scripts/ect-wrapper.sh
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# compress a file with ect and preserve the mtime
|
||||||
|
# args: compression level and filename.
|
||||||
|
set -e -u
|
||||||
|
|
||||||
|
if [ ! -f "$2.gz" ]; then
|
||||||
|
ect -quiet -"$1" -gzip "$2"
|
||||||
|
touch -r "$2" "$2.gz"
|
||||||
|
fi
|
Loading…
Reference in a new issue