-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild
More file actions
executable file
·82 lines (68 loc) · 1.49 KB
/
build
File metadata and controls
executable file
·82 lines (68 loc) · 1.49 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
79
80
81
82
#!/usr/bin/env bash
set -o errexit
set -o nounset
# compatibility check
# shellcheck disable=SC2128
if [ "$BASH_VERSINFO" -lt 4 ]; then
# shellcheck disable=SC2128
echo "ERROR: Incompatible Bash detected: $BASH $BASH_VERSINFO $BASH_VERSION"
exit 2
fi
declare -g basename=$(basename "$0")
declare -g basedir=$(cd "$(dirname "$0")" && pwd)
declare -g command_default=""
# show message and exit
function die {
echo "$1"
exit 1
}
# show usage and exit
function usage {
set +o nounset
local syntax="$1"
set -o nounset
if [[ -z "$syntax" ]]; then
echo "usage: $basename <command> [options]"
else
echo "usage: $basename $syntax"
fi
exit 2
}
# run self
function self {
$0 "$@"
}
function main {
build_config="$basedir/build-config.bash"
# shellcheck source=build-config.bash
source "$build_config"
build_local_config="$basedir/build-local.bash"
if [[ -f "$build_local_config" ]]; then
# shellcheck source=build-local.bash
source "$build_local_config"
fi
set +o nounset
command="$1"
set -o nounset
set +o errexit
shift
set -o errexit
if [[ -z "$command" ]]; then
if [[ -n "$command_default" ]]; then
self "$command_default"
else
# complain if no command is given
usage
fi
fi
# attempt to lookup command function
local fn="command_$command"
if [[ "$(type -t $fn)" = 'function' ]]; then
$fn "$@"
else
# complain about missing command function
echo "Unknown command: $command"
usage
fi
}
main "$@"