-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell-script.template.sh
More file actions
78 lines (59 loc) · 1.96 KB
/
shell-script.template.sh
File metadata and controls
78 lines (59 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
# WARNING: Please DO NOT edit this file! It is maintained in the [repository name] (https://github.com/org/repo). Raise a PR instead.
set -euo pipefail
# Short description of what this script does. This is a <tool> command wrapper.
# It will run <tool> natively if it is installed, otherwise it will run it in
# a Docker container.
#
# Usage:
# $ [options] ./script-name.sh
#
# Options:
# file=path/to/file # Description, default is 'default-value'
# FORCE_USE_DOCKER=true # If set to true the command is run in a Docker container, default is 'false'
# VERBOSE=true # Show all the executed commands, default is 'false'
#
# Exit codes:
# 0 - Success
# 1 - Failure
# ==============================================================================
function main() {
cd "$(git rev-parse --show-toplevel)"
local file=${file:-default-value}
if command -v toolname > /dev/null 2>&1 && ! is-arg-true "${FORCE_USE_DOCKER:-false}"; then
file="$file" run-tool-natively
else
file="$file" run-tool-in-docker
fi
}
# Run tool natively.
# Arguments (provided as environment variables):
# file=[path to the file]
function run-tool-natively() {
toolname "$file"
}
# Run tool in a Docker container.
# Arguments (provided as environment variables):
# file=[path to the file]
function run-tool-in-docker() {
# shellcheck disable=SC1091
source ./scripts/docker/docker.lib.sh
# shellcheck disable=SC2155
local image=$(name=org/toolname docker-get-image-version-and-pull)
docker run --rm --platform linux/amd64 \
--volume "$PWD":/workdir \
"$image" \
toolname "/workdir/$file"
}
# ==============================================================================
function is-arg-true() {
if [[ "$1" =~ ^(true|yes|y|on|1|TRUE|YES|Y|ON)$ ]]; then
return 0
else
return 1
fi
}
# ==============================================================================
is-arg-true "${VERBOSE:-false}" && set -x
main "$@"
exit 0