-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathentrypoint.sh
More file actions
53 lines (42 loc) · 1.25 KB
/
entrypoint.sh
File metadata and controls
53 lines (42 loc) · 1.25 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
#!/bin/bash
set -e
SCRIPTS_DIR="/opt/scripts"
command="$1"
shift || true # shift so "$@" holds arguments for the subcommand
# --------------------------------------------------------
# Show dynamic help
# --------------------------------------------------------
show_help() {
echo "== Mapper Toolbox =="
echo ""
for script in "$SCRIPTS_DIR"/*.sh; do
# Extract metadata
NAME=$(grep -m1 "^# @name" "$script" | cut -d' ' -f3-)
DESC=$(grep -m1 "^# @desc" "$script" | cut -d' ' -f3-)
USAGE=$(grep -m1 "^# @usage" "$script" | cut -d' ' -f3-)
[ -z "$NAME" ] && continue
echo " $NAME"
echo " $DESC"
[ -n "$USAGE" ] && echo " Usage: $USAGE"
echo ""
done
}
# Default or help
if [ -z "$command" ] || [ "$command" = "help" ]; then
show_help
exit 0
fi
# --------------------------------------------------------
# Dispatch to scripts automatically
# --------------------------------------------------------
script="$SCRIPTS_DIR/$command.sh"
if [ ! -f "$script" ]; then
echo "[ERROR] Unknown command: $command"
echo "Try: nzp help"
exit 1
fi
if [ ! -x "$script" ]; then
echo "[ERROR] Script exists but is not executable: $script"
exit 1
fi
exec "$script" "$@"