This commit is contained in:
2026-04-27 04:31:32 +03:30
commit 8feb949d7d
8 changed files with 773 additions and 0 deletions
+122
View File
@@ -0,0 +1,122 @@
#!/usr/bin/env bash
set -euo pipefail
BUILD_FLAG=0
FORCE_FLAG=0
DOCKER_MODULES=()
MAX_STEP=3
usage() {
cat <<'EOF'
Usage:
./bootstrap_modules.sh [--build] [--force] [--step N] [module ...]
Steps:
1. Run `add_submodules.sh`
2. Run `add_schemas_submodule.sh`
3. Run `run_docker_modules.sh`
Options:
--build Pass `--build` to `run_docker_modules.sh`
--force Pass `--force` to submodule add scripts
--step N Run only up to step N (1, 2, or 3)
-h, --help Show this help message
Examples:
./bootstrap_modules.sh
./bootstrap_modules.sh --step 2
./bootstrap_modules.sh --force
./bootstrap_modules.sh --build
./bootstrap_modules.sh Ai Backend
./bootstrap_modules.sh --build Ai SensorHub
./bootstrap_modules.sh --force --step 2
EOF
}
while [[ "$#" -gt 0 ]]; do
case "$1" in
--build)
BUILD_FLAG=1
shift
;;
--force)
FORCE_FLAG=1
shift
;;
--step)
if [[ "$#" -lt 2 ]]; then
echo "Missing value for --step" >&2
usage
exit 1
fi
MAX_STEP="$2"
shift 2
;;
-h|--help)
usage
exit 0
;;
--)
shift
while [[ "$#" -gt 0 ]]; do
DOCKER_MODULES+=("$1")
shift
done
;;
-*)
echo "Unknown option: $1" >&2
usage
exit 1
;;
*)
DOCKER_MODULES+=("$1")
shift
;;
esac
done
if [[ ! "$MAX_STEP" =~ ^[1-3]$ ]]; then
echo "Invalid value for --step: ${MAX_STEP}. Use 1, 2, or 3." >&2
exit 1
fi
run_script() {
local script_path="$1"
shift || true
if [[ ! -x "$script_path" ]]; then
echo "Script is not executable: ${script_path}" >&2
exit 1
fi
echo "Running ${script_path} $*"
"$script_path" "$@"
}
submodule_args=()
if [[ "$FORCE_FLAG" -eq 1 ]]; then
submodule_args+=("--force")
fi
if [[ "$MAX_STEP" -ge 1 ]]; then
run_script "./add_submodules.sh" "${submodule_args[@]}"
fi
if [[ "$MAX_STEP" -ge 2 ]]; then
run_script "./add_schemas_submodule.sh" "${submodule_args[@]}"
fi
docker_args=()
if [[ "$BUILD_FLAG" -eq 1 ]]; then
docker_args+=("--build")
fi
if [[ "${#DOCKER_MODULES[@]}" -gt 0 ]]; then
docker_args+=("${DOCKER_MODULES[@]}")
fi
if [[ "$MAX_STEP" -ge 3 ]]; then
run_script "./run_docker_modules.sh" "${docker_args[@]}"
fi
echo "Bootstrap completed."