-
Notifications
You must be signed in to change notification settings - Fork 430
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·65 lines (55 loc) · 1.77 KB
/
run.sh
File metadata and controls
executable file
·65 lines (55 loc) · 1.77 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
#!/usr/bin/env bash
set -euo pipefail
log() { printf "[INFO] %s\n" "$*"; }
warn() { printf "[WARN] %s\n" "$*" >&2; }
error() { printf "[ERROR] %s\n" "$*" >&2; }
NDD_DATA_DIR="./data"
BINARY_FILE=""
NDD_AUTH_TOKEN=""
print_help() {
cat <<EOF
Usage: $(basename "$0") [OPTIONS]
Options:
ndd_data_dir=DIR Set the data directory (default: ./data)
binary_file=FILE Set the binary file to run (default: auto-detected in build/)
ndd_auth_token=TOKEN Set the auth token (default: empty)
--help, -h Show this help message and exit
Description:
Runs the ndd binary. It attempts to find a binary starting with 'ndd-*'
in the 'build' directory if not explicitly provided.
EOF
}
main() {
for ARG in "$@"; do
case "$ARG" in
ndd_data_dir=*)
NDD_DATA_DIR="${ARG#*=}"
;;
binary_file=*)
BINARY_FILE="${ARG#*=}"
;;
ndd_auth_token=*)
NDD_AUTH_TOKEN="${ARG#*=}"
;;
--help|-h)
print_help
exit 0
;;
esac
done
if [[ -z "$BINARY_FILE" ]]; then
# check if build folder exists and if any binary starting with ndd-* exists, if yes then save the filename in a variable
if [[ -d "build" && -n "$(find build -maxdepth 1 -name 'ndd-*' -type f)" ]]; then
BINARY_FILE=$(find build -maxdepth 1 -name 'ndd-*' -type f | head -n 1)
log "Found binary: $BINARY_FILE"
else
error "No binary found"
exit 1
fi
fi
# run the binary with the arguments passed to this script
if [[ -n "$BINARY_FILE" ]]; then
eval "NDD_DATA_DIR=$NDD_DATA_DIR NDD_AUTH_TOKEN=$NDD_AUTH_TOKEN $BINARY_FILE"
fi
}
main "$@"