2024-01-31 18:06:23 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# This tool generates code in shell which is meant to be inline'd into
|
|
|
|
# a larger script; called with a variable name and a path, it produces
|
|
|
|
# a script which will result in that variable being set to the path to
|
|
|
|
# the contents of that path.
|
|
|
|
#
|
|
|
|
# This is used in bootstrap-aws-installer to bundle local files into
|
|
|
|
# the EC2 user data, so that those canonical versions can be used to
|
|
|
|
# bootstrap the host.
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
var="$1"
|
|
|
|
file="$2"
|
|
|
|
|
2024-02-07 18:28:01 +01:00
|
|
|
mode="$(stat -c "%a" "$file")"
|
|
|
|
|
2024-01-31 18:06:23 +01:00
|
|
|
encoded="$(gzip --stdout "$file" | base64)"
|
|
|
|
cat <<embedded-shell-output
|
|
|
|
$var="\$(mktemp)"
|
2024-02-07 18:28:01 +01:00
|
|
|
chmod "$mode" "\$$var"
|
2024-01-31 18:06:23 +01:00
|
|
|
base64 -d <<"encoded-shell-script" | gzip -d > "\$$var"
|
|
|
|
$encoded
|
|
|
|
encoded-shell-script
|
|
|
|
embedded-shell-output
|