Skip to content

Commit 9a90efa

Browse files
committed
bundle-script.sh: Implement optional gzip compression
1 parent b4b4a43 commit 9a90efa

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

bundle-script.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ USAGE="bundle-script.sh [OPTIONS] input output [dependency [dependency [...]]]
1010
1111
Options:
1212
--check, -c If provided, the bundled script will be called with the given arguments to
13-
check if it works (i.e. returns with exit code 0)."
13+
check if it works (i.e. returns with exit code 0).
14+
--gzip, -z Use additional gzip compression for bundled scripts"
1415

1516
. "$(dirname "$BASH_SOURCE")/lib/parse_args.sh"
1617
REQUIRED=("input" "output")
17-
KEYWORDS=("--check" "-c")
18+
KEYWORDS=("--check" "-c" "--gzip;bool" "-z;bool")
1819
set_trap 1
1920
parse_args __USAGE "$USAGE" __DESCRIPTION "$DESCRIPTION" "$@"
2021

@@ -53,8 +54,15 @@ do
5354
source_file="$(basename "${source_path}")"
5455
echo "##### ${source_file} #####"
5556
echo -n "source <(echo '"
56-
cat "${source_path}" | base64 -w 0
57-
echo "' | base64 -d)"
57+
if [[ -z "${KW_ARGS['--gzip']-"${KW_ARGS['-z']}"}" ]]
58+
then
59+
base64 -w 0 "$source_path"
60+
else
61+
gzip -cq "$source_path" | base64 -w 0
62+
fi
63+
echo -n "' | base64 -d"
64+
[[ -z "${KW_ARGS['--gzip']-"${KW_ARGS['-z']}"}" ]] || echo -n " | gunzip -cq"
65+
echo ")"
5866
echo -n "######"
5967
for n in $(seq ${#source_file}); do echo -n "#"; done
6068
echo "######"
@@ -74,6 +82,7 @@ done < "$input_script"
7482
check_args="${KW_ARGS['--check']-${KW_ARGS['-c']}}"
7583
if [[ -n "$check_args" ]]
7684
then
85+
bash "$output_script" $check_args || true
7786
bash "$output_script" $check_args > /dev/null 2>&1 || {
7887
echo "ERROR: The bundled script doesn't seem to work ('bash \"$output_script\" $check_args' terminated with exit code $?)!" >&2
7988
exit 2

0 commit comments

Comments
 (0)