Skip to content

Commit 4c1a3ca

Browse files
committed
Use sed instead of envsubst for more portability
1 parent 208990b commit 4c1a3ca

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

webapp/src/main/resources/templates/cli/install.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@
1919
mkdir -p {{installDirectory}}
2020

2121
# Create the bash wrapper for the CLI
22-
cat << 'EOF' | envsubst '$PWD' > {{installDirectory}}/mojito
22+
cat > {{installDirectory}}/mojito-tmp << 'EOF'
2323
#!/usr/bin/env bash
2424
{{#hasHeaders}}
2525
{{#headers}}
2626
if [ -z "{{{envVarPresenceCheck}}}" ]; then
2727
echo "Environment variable {{envVar}} must be set before running this command."
28-
exit 1
2928
fi
3029
{{/headers}}
3130
{{#authenticationMode}}
@@ -39,6 +38,10 @@ java -Dl10n.resttemplate.host={{host}} \
3938
-jar {{installDirectory}}/mojito-cli.jar "$@" ;
4039
EOF
4140

41+
_ESC="$(printf '%s' "${PWD}" | sed 's/[\/&]/\\&/g')"
42+
sed "s|\${PWD}|$_ESC|g" {{installDirectory}}/mojito-tmp > {{installDirectory}}/mojito
43+
rm {{installDirectory}}/mojito-tmp
44+
4245
# Make the wrapper executable
4346
chmod +x {{installDirectory}}/mojito
4447

webapp/src/test/resources/com/box/l10n/mojito/service/cli/install.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,19 @@
1919
mkdir -p ${PWD}/.mojito
2020

2121
# Create the bash wrapper for the CLI
22-
cat > ${PWD}/.mojito/mojito << 'EOF'
22+
cat > ${PWD}/.mojito/mojito-tmp << 'EOF'
2323
#!/usr/bin/env bash
24-
java -Dl10n.resttemplate.host=localhost \\
25-
-Dl10n.resttemplate.scheme=http \\
26-
-Dl10n.resttemplate.port=8080 \\
27-
-Dlogging.file.path=${PWD}/.mojito \\
28-
-jar ${PWD}/.mojito/mojito-cli.jar "\$@" ;
24+
java -Dl10n.resttemplate.host=localhost \
25+
-Dl10n.resttemplate.scheme=http \
26+
-Dl10n.resttemplate.port=8080 \
27+
-Dlogging.file.path=${PWD}/.mojito \
28+
-jar ${PWD}/.mojito/mojito-cli.jar "$@" ;
2929
EOF
3030

31+
_ESC="$(printf '%s' "${PWD}" | sed 's/[\/&]/\\&/g')"
32+
sed "s|\${PWD}|$_ESC|g" ${PWD}/.mojito/mojito-tmp > ${PWD}/.mojito/mojito
33+
rm ${PWD}/.mojito/mojito-tmp
34+
3135
# Make the wrapper executable
3236
chmod +x ${PWD}/.mojito/mojito
3337

webapp/src/test/resources/com/box/l10n/mojito/service/cli/install_with_cf_headers.sh

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,26 @@
1919
mkdir -p ${PWD}/.mojito
2020

2121
# Create the bash wrapper for the CLI
22-
cat > ${PWD}/.mojito/mojito << 'EOF'
22+
cat > ${PWD}/.mojito/mojito-tmp << 'EOF'
2323
#!/usr/bin/env bash
2424
if [ -z "${L10N_RESTTEMPLATE_HEADER_HEADERS_CF_ACCESS_CLIENT_ID:-}" ]; then
2525
echo "Environment variable L10N_RESTTEMPLATE_HEADER_HEADERS_CF_ACCESS_CLIENT_ID must be set before running this command."
26-
exit 1
2726
fi
2827
if [ -z "${L10N_RESTTEMPLATE_HEADER_HEADERS_CF_ACCESS_CLIENT_SECRET:-}" ]; then
2928
echo "Environment variable L10N_RESTTEMPLATE_HEADER_HEADERS_CF_ACCESS_CLIENT_SECRET must be set before running this command."
30-
exit 1
3129
fi
3230
export L10N_RESTTEMPLATE_AUTHENTICATION_MODE=HEADER
33-
java -Dl10n.resttemplate.host=localhost \\
34-
-Dl10n.resttemplate.scheme=http \\
35-
-Dl10n.resttemplate.port=8080 \\
36-
-Dlogging.file.path=${PWD}/.mojito \\
37-
-jar ${PWD}/.mojito/mojito-cli.jar "\$@" ;
31+
java -Dl10n.resttemplate.host=localhost \
32+
-Dl10n.resttemplate.scheme=http \
33+
-Dl10n.resttemplate.port=8080 \
34+
-Dlogging.file.path=${PWD}/.mojito \
35+
-jar ${PWD}/.mojito/mojito-cli.jar "$@" ;
3836
EOF
3937

38+
_ESC="$(printf '%s' "${PWD}" | sed 's/[\/&]/\\&/g')"
39+
sed "s|\${PWD}|$_ESC|g" ${PWD}/.mojito/mojito-tmp > ${PWD}/.mojito/mojito
40+
rm ${PWD}/.mojito/mojito-tmp
41+
4042
# Make the wrapper executable
4143
chmod +x ${PWD}/.mojito/mojito
4244

0 commit comments

Comments
 (0)