|
1 | 1 | #!/bin/sh |
2 | 2 | # |
3 | 3 | # install_modules.sh — install specified modules, or all in config/enabled_modules.conf if none given |
4 | | -# Usage: ./install_modules.sh [--log[=FILE]] [-h] [module1 module2 ...] |
| 4 | +# Usage: ./install_modules.sh [--debug[=FILE]] [-h] [module1 module2 ...] |
5 | 5 |
|
6 | | -set -x |
7 | | - |
8 | | -# |
9 | | -# 1) Figure out where this script lives |
10 | | -# |
| 6 | +############################################################################## |
| 7 | +# 1) Locate this script’s path |
| 8 | +############################################################################## |
11 | 9 | case "$0" in |
12 | 10 | */*) SCRIPT_PATH="$0" ;; |
13 | 11 | *) SCRIPT_PATH="$(command -v -- "$0" 2>/dev/null || printf "%s" "$0")" ;; |
14 | 12 | esac |
15 | 13 | SCRIPT_DIR="$(cd -- "$(dirname -- "$SCRIPT_PATH")" && pwd)" |
16 | 14 |
|
17 | | -# |
| 15 | +############################################################################## |
18 | 16 | # 2) Determine PROJECT_ROOT, MODULE_DIR, and enabled‑modules file |
19 | | -# |
| 17 | +############################################################################## |
20 | 18 | if [ "$(basename "$SCRIPT_DIR")" = "scripts" ]; then |
21 | 19 | PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" |
22 | 20 | else |
23 | 21 | PROJECT_ROOT="$SCRIPT_DIR" |
24 | 22 | fi |
25 | 23 | MODULE_DIR="$PROJECT_ROOT/modules" |
26 | 24 | ENABLED_FILE="$PROJECT_ROOT/config/enabled_modules.conf" |
| 25 | +export PROJECT_ROOT |
27 | 26 |
|
28 | | -# |
29 | | -# 3) Logging defaults |
30 | | -# |
31 | | -FORCE_LOG=0 |
32 | | -LOG_FILE="" |
33 | | - |
34 | | -# |
35 | | -# 4) Help text |
36 | | -# |
| 27 | +############################################################################## |
| 28 | +# 3) Help text |
| 29 | +############################################################################## |
37 | 30 | usage() { |
38 | 31 | cat <<EOF |
39 | | -Usage: $0 [--log[=FILE]] [-h] [module1 module2 ...] |
| 32 | +Usage: $0 [--debug[=FILE]] [-h] [module1 module2 ...] |
40 | 33 |
|
41 | | - --log, -l Capture stdout, stderr & xtrace into: |
42 | | - ${PROJECT_ROOT}/logs/ |
43 | | - Or use --log=FILE for a custom path. |
| 34 | + --debug, -d Enable xtrace and capture all output (stdout/stderr/xtrace) |
| 35 | + into logs/ (or into FILE if you do --debug=FILE). |
44 | 36 |
|
45 | 37 | -h, --help Show this help and exit. |
46 | 38 |
|
|
50 | 42 | exit 0 |
51 | 43 | } |
52 | 44 |
|
53 | | -# |
54 | | -# 5) Parse flags |
55 | | -# |
| 45 | +# show help? |
| 46 | +case "$1" in |
| 47 | + -h|--help) usage ;; |
| 48 | +esac |
| 49 | + |
| 50 | +############################################################################## |
| 51 | +# 4) Parse just --debug |
| 52 | +############################################################################## |
| 53 | +DEBUG_MODE=0 |
| 54 | +DEBUG_LOGFILE="" |
56 | 55 | while [ $# -gt 0 ]; do |
57 | 56 | case "$1" in |
58 | | - -l|--log) FORCE_LOG=1 ;; |
59 | | - -l=*|--log=*) FORCE_LOG=1; LOG_FILE="${1#*=}" ;; |
60 | | - -h|--help) usage ;; |
61 | | - --) shift; break ;; |
| 57 | + -d|--debug) |
| 58 | + DEBUG_MODE=1 |
| 59 | + shift |
| 60 | + ;; |
| 61 | + -d=*|--debug=*) |
| 62 | + DEBUG_MODE=1 |
| 63 | + DEBUG_LOGFILE="${1#*=}" |
| 64 | + shift |
| 65 | + ;; |
| 66 | + --) shift; break ;; |
62 | 67 | -*) |
63 | 68 | echo "Unknown option: $1" >&2 |
64 | 69 | usage |
65 | 70 | ;; |
66 | 71 | *) break ;; |
67 | 72 | esac |
68 | | - shift |
69 | 73 | done |
70 | 74 |
|
71 | | -# |
72 | | -# 6) Locate and source logging helper |
73 | | -LOG_HELPER="$PROJECT_ROOT/logs/logging.sh" |
74 | | - |
75 | | -if [ ! -f "$LOG_HELPER" ]; then |
76 | | - echo "❌ $LOG_HELPER not found. Aborting." >&2 |
77 | | - exit 1 |
| 75 | +# build flag to pass to module scripts |
| 76 | +if [ "$DEBUG_MODE" -eq 1 ]; then |
| 77 | + if [ -n "$DEBUG_LOGFILE" ]; then |
| 78 | + DBG_FLAG="--debug=$DEBUG_LOGFILE" |
| 79 | + else |
| 80 | + DBG_FLAG="--debug" |
| 81 | + fi |
78 | 82 | fi |
79 | 83 |
|
80 | | -# shellcheck source=logs/logging.sh |
81 | | -. "$LOG_HELPER" |
82 | | -init_logging "$0" |
83 | | - |
| 84 | +############################################################################## |
| 85 | +# 5) Initialize logging+xtrace if requested |
| 86 | +############################################################################## |
| 87 | +# shellcheck source=../logs/logging.sh |
| 88 | +. "$PROJECT_ROOT/logs/logging.sh" |
| 89 | +if [ "$DEBUG_MODE" -eq 1 ]; then |
| 90 | + set -x |
| 91 | + init_logging "$(basename "$0" .sh)" |
| 92 | +fi |
84 | 93 |
|
85 | | -# |
86 | | -# 7) Determine module list |
87 | | -# |
| 94 | +############################################################################## |
| 95 | +# 6) Determine module list |
| 96 | +############################################################################## |
88 | 97 | if [ "$#" -gt 0 ]; then |
89 | 98 | MODULES="$*" |
90 | 99 | else |
91 | | - if [ ! -f "$ENABLED_FILE" ]; then |
| 100 | + [ -f "$ENABLED_FILE" ] || { |
92 | 101 | echo "❌ No modules specified and $ENABLED_FILE not found" >&2 |
93 | 102 | exit 1 |
94 | | - fi |
| 103 | + } |
95 | 104 | MODULES="$(grep -Ev '^\s*(#|$)' "$ENABLED_FILE")" |
96 | 105 | fi |
97 | 106 |
|
98 | | -# |
99 | | -# 8) Always install base-system first (if present) |
100 | | -# |
| 107 | +############################################################################## |
| 108 | +# 7) Install base‑system first (if present) |
| 109 | +############################################################################## |
101 | 110 | echo "🔧 Installing prerequisite module: base-system" |
102 | | -sh "$MODULE_DIR/base-system/setup.sh" |
| 111 | +sh "$MODULE_DIR/base-system/setup.sh" ${DBG_FLAG} |
103 | 112 |
|
104 | | -# |
105 | | -# 9) Install the rest of the modules |
106 | | -# |
| 113 | +############################################################################## |
| 114 | +# 8) Install the rest |
| 115 | +############################################################################## |
107 | 116 | for mod in $MODULES; do |
108 | 117 | [ "$mod" = "base-system" ] && continue |
109 | | - |
110 | | - DIR="$MODULE_DIR/$mod" |
111 | | - # pick the setup script (generic or fallback) |
112 | | - SETUP="$DIR/setup.sh" |
113 | | - |
114 | 118 | echo "👉 Installing module: $mod" |
115 | | - sh "$SETUP" |
| 119 | + sh "$MODULE_DIR/$mod/setup.sh" ${DBG_FLAG} |
116 | 120 | done |
117 | 121 |
|
118 | 122 | echo "" |
119 | 123 | echo "✅ All requested modules installed." |
120 | | - |
|
0 commit comments