From 1a0073eae06326c466bd38732a317179aa0af47f Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Mon, 26 May 2025 15:20:48 +0800 Subject: [PATCH] few tweaks to readme and install script --- README.md | 6 +- scripts/docker-install.sh | 114 ++++++++++++++++++++++++-------------- 2 files changed, 75 insertions(+), 45 deletions(-) mode change 100644 => 100755 scripts/docker-install.sh diff --git a/README.md b/README.md index 5c73c151..50464ff0 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,7 @@ Fleetbase is a modular logistics and supply chain operating system designed to s ```bash git clone git@github.com:fleetbase/fleetbase.git -cd fleetbase -sh scripts/docker-install.sh +cd fleetbase && ./scripts/docker-install.sh ``` ## πŸ“– Table of contents @@ -73,8 +72,7 @@ Make sure you have both the latest versions of docker and docker-compose install ```bash git clone git@github.com:fleetbase/fleetbase.git -cd fleetbase -sh scripts/docker-install.sh +cd fleetbase && ./scripts/docker-install.sh ``` ### Accessing Fleetbase diff --git a/scripts/docker-install.sh b/scripts/docker-install.sh old mode 100644 new mode 100755 index caa8ece5..58a02e65 --- a/scripts/docker-install.sh +++ b/scripts/docker-install.sh @@ -1,57 +1,84 @@ #!/usr/bin/env bash # scripts/docker-install.sh -# Fleetbase β€œone‑liner” Docker installer -# -------------------------------------- +# Fleetbase Docker installer (dev / prod aware) +# -------------------------------------------- set -euo pipefail -# ──────────────────────────────────────────────────────────── -# 1. Get host value (CLI arg β†’ prompt β†’ default) -# ──────────────────────────────────────────────────────────── -if [[ $# -ge 1 && -n "$1" ]]; then - HOST="$1" -else - read -rp "Enter host or IP address to bind to [localhost]: " HOST_INPUT - HOST="${HOST_INPUT:-localhost}" -fi +############################################################################### +# 1. Ask for host (default: localhost) +############################################################################### +read -rp "Enter host or IP address to bind to [localhost]: " HOST_INPUT +HOST=${HOST_INPUT:-localhost} echo "➜ Using host: $HOST" -# Resolve project root no matter where the script is called from +############################################################################### +# 2. Ask for environment (development | production) +############################################################################### +while true; do + read -rp "Choose environment (development / production) [development]: " ENV_INPUT + ENV_INPUT=$(echo "$ENV_INPUT" | tr '[:upper:]' '[:lower:]') + case "$ENV_INPUT" in + ""|d|dev|development) ENVIRONMENT=development; break ;; + p|prod|production) ENVIRONMENT=production; break ;; + *) echo "Please type either 'development' or 'production'." ;; + esac +done +echo "➜ Environment: $ENVIRONMENT" + +USE_HTTPS=false +APP_DEBUG=true +SC_SECURE=false +if [[ "$ENVIRONMENT" == "production" ]]; then + USE_HTTPS=true + APP_DEBUG=false + SC_SECURE=true +fi + +############################################################################### +# 3. Determine project root no matter where script is called from +############################################################################### SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" PROJECT_ROOT="$( cd "$SCRIPT_DIR/.." && pwd )" cd "$PROJECT_ROOT" -# ──────────────────────────────────────────────────────────── -# 2. Generate a fresh Laravel APP_KEY -# ──────────────────────────────────────────────────────────── +############################################################################### +# 4. Generate a fresh Laravel APP_KEY +############################################################################### if ! command -v openssl >/dev/null 2>&1; then - echo "βœ– openssl is required but not found. Install it and retry." >&2 - exit 1 + echo "βœ– openssl is required but not found. Install it and retry." >&2 + exit 1 fi APP_KEY="base64:$(openssl rand -base64 32 | tr -d '\n')" echo "βœ” Generated APP_KEY" -# ──────────────────────────────────────────────────────────── -# 3. Ensure docker‑compose.override.yml has the right values -# ──────────────────────────────────────────────────────────── +############################################################################### +# 5. Ensure docker‑compose.override.yml is present & updated +############################################################################### OVERRIDE_FILE="docker-compose.override.yml" -# We’ll use yq if available (best for YAML‑safe edits) +# url helpers +SCHEME_API=$([[ "$USE_HTTPS" == true ]] && echo "https" || echo "http") +SCHEME_CONSOLE=$([[ "$USE_HTTPS" == true ]] && echo "https" || echo "http") + update_override_with_yq() { yq -i " - .services.application.environment.APP_KEY = \"$APP_KEY\" | - .services.application.environment.CONSOLE_HOST = \"http://$HOST:4200\" + .services.application.environment.APP_KEY = \"$APP_KEY\" | + .services.application.environment.CONSOLE_HOST = \"$SCHEME_CONSOLE://$HOST:4200\" | + .services.application.environment.ENVIRONMENT = \"$ENVIRONMENT\" | + .services.application.environment.APP_DEBUG = \"$APP_DEBUG\" " "$OVERRIDE_FILE" echo "βœ” $OVERRIDE_FILE updated (yq)" } -# Fallback: createβ€―or append the section with plain Bash if yq isn’t installed -create_or_append_override() { +create_override() { cat > "$OVERRIDE_FILE" </dev/null 2>&1; then update_override_with_yq else - # simple backup, then naive append‑or‑overwrite section cp "$OVERRIDE_FILE" "${OVERRIDE_FILE}.bak.$(date +%Y%m%d%H%M%S)" echo "β„ΉοΈŽ Existing $OVERRIDE_FILE backed up (no yq found β€” recreating)" - create_or_append_override + create_override fi else - create_or_append_override + create_override fi -# ──────────────────────────────────────────────────────────── -# 4. Update ./console/fleetbase.config.json -# ──────────────────────────────────────────────────────────── -CONFIG_PATH="console/fleetbase.config.json" -mkdir -p "$(dirname "$CONFIG_PATH")" +############################################################################### +# 6. Write console/fleetbase.config.json atomically +############################################################################### +CONFIG_DIR="console" +CONFIG_PATH="$CONFIG_DIR/fleetbase.config.json" +mkdir -p "$CONFIG_DIR" -cat > "$CONFIG_PATH" < "${CONFIG_PATH}.tmp" <