phase: 02-operations-maintenance
plan: 03
type: execute
wave: 1
depends_on: []
files_modified: [deploy_rkl.sh]
autonomous: true
requirements: [OPS-04]

must_haves:
truths:
- "deploy_rkl.sh runs without errors on macOS (no GNU-only flags)"
- "deploy_rkl.sh runs without errors on Linux (no macOS-only tools)"
- "Script detects the platform and adapts commands accordingly"
artifacts:
- path: "deploy_rkl.sh"
provides: "Cross-platform deployment script"
contains: "uname"
key_links:
- from: "deploy_rkl.sh"
to: "platform detection"
via: "uname -s check"
pattern: "uname"



Make deploy_rkl.sh portable across macOS and Linux by replacing platform-specific commands with cross-platform alternatives and adding OS detection.

Purpose: OPS-04 requires the deployment script to work on both macOS and Linux without manual edits.
Output: Updated deploy_rkl.sh that detects the OS and uses appropriate commands.


@$HOME/.claude/get-shit-done/workflows/execute-plan.md
@$HOME/.claude/get-shit-done/templates/summary.md


@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/STATE.md



Task 1: Add OS detection and platform-adaptive commands
deploy_rkl.sh
deploy_rkl.sh

Rewrite deploy_rkl.sh to be cross-platform. The current script is entirely Linux/systemd-centric. Add these changes:

  1. OS detection block right after set -euo pipefail and the color definitions:
OS="$(uname -s)"
case "$OS" in
  Darwin) PLATFORM="macos" ;;
  Linux)  PLATFORM="linux" ;;
  *)      fail "Unsupported OS: $OS" ;;
esac
echo -e "  Platform: ${BOLD}${PLATFORM}${NC} ($(uname -m))"
  1. Platform-adaptive helper functions after the detection block:
pg_cmd() {
  if [ "$PLATFORM" = "linux" ]; then
    sudo -u postgres psql "$@"
  else
    psql "$@"
  fi
}

svc_restart() {
  local svc="$1"
  if [ "$PLATFORM" = "linux" ]; then
    systemctl restart "$svc"
  else
    # macOS: use launchctl or just print manual instruction
    warn "Bitte Service '$svc' manuell neustarten (kein systemd auf macOS)"
  fi
}

svc_active() {
  local svc="$1"
  if [ "$PLATFORM" = "linux" ]; then
    systemctl is-active --quiet "$svc"
  else
    # macOS: check via process or return true (manual restart assumed)
    pgrep -f "$svc" >/dev/null 2>&1
  fi
}

nginx_reload() {
  if [ "$PLATFORM" = "linux" ]; then
    nginx -t 2>&1 && ok "nginx config OK" || fail "nginx config fehlerhaft"
    systemctl reload nginx
  else
    nginx -t 2>&1 && ok "nginx config OK" || fail "nginx config fehlerhaft"
    sudo nginx -s reload 2>/dev/null || warn "nginx reload fehlgeschlagen — ggf. manuell"
  fi
}
  1. Replace hardcoded commands throughout the script:
  2. Line 31: Replace sudo -u postgres psql -d crumbforest_db -f ... with pg_cmd -d crumbforest_db -f /tmp/migrate_rkl.sql ...
  3. Line 34-37: Replace sudo -u postgres psql -d crumbforest_db -c ... with pg_cmd -d crumbforest_db -c ...
  4. Line 66-67: Replace nginx block with call to nginx_reload
  5. Line 76: Replace systemctl restart forest-api with svc_restart forest-api
  6. Line 79: Replace systemctl is-active --quiet forest-api with svc_active forest-api
  7. Line 83: Replace journalctl -u forest-api --no-pager -n 15 with:
    bash if [ "$PLATFORM" = "linux" ]; then journalctl -u forest-api --no-pager -n 15 else warn "Logs: Check console output or log file manually" fi

  8. macOS nginx config path: On macOS, nginx config is typically in /usr/local/etc/nginx/ or /opt/homebrew/etc/nginx/. Add:

if [ "$PLATFORM" = "linux" ]; then
  NGINX_SITES="/etc/nginx/sites-available"
else
  NGINX_SITES="/opt/homebrew/etc/nginx/servers"
fi

Then replace /etc/nginx/sites-available/ and /etc/nginx/sites-enabled/ references with the variable. On macOS, skip the symlink step (Homebrew nginx uses servers/ directly).

  1. pip path: The hardcoded /opt/crumbforest/venv/bin/pip may not exist on macOS dev setups. Make it configurable:
VENV_PIP="${VENV_PIP:-/opt/crumbforest/venv/bin/pip}"
if [ ! -f "$VENV_PIP" ]; then
  warn "pip nicht gefunden: $VENV_PIP — bitte VENV_PIP setzen"
  warn "Beispiel: VENV_PIP=./venv/bin/pip ./deploy_rkl.sh"
fi



cd /Users/bmt/Documents/RKL-OZM-Chat-Hook-v.0.0 && bash -n deploy_rkl.sh && grep -q 'uname' deploy_rkl.sh && grep -q 'PLATFORM' deploy_rkl.sh && grep -q 'Darwin' deploy_rkl.sh && grep -q 'Linux' deploy_rkl.sh && echo 'all checks passed'


- bash -n deploy_rkl.sh succeeds (valid bash syntax)
- grep "uname" deploy_rkl.sh returns a match (OS detection present)
- grep "PLATFORM" deploy_rkl.sh returns a match (platform variable used)
- grep "Darwin" deploy_rkl.sh returns a match (macOS case handled)
- grep "Linux" deploy_rkl.sh returns a match (Linux case handled)
- grep "pg_cmd" deploy_rkl.sh returns a match (PostgreSQL abstracted)

deploy_rkl.sh detects the OS via uname and uses platform-appropriate commands for PostgreSQL, nginx, and service management. No manual edits needed to switch between macOS and Linux.


- bash -n deploy_rkl.sh passes (valid syntax)
- Script contains OS detection via uname -s
- Platform-specific commands (systemctl, sudo -u postgres) are wrapped in conditionals


deploy_rkl.sh runs without syntax errors on both macOS and Linux. Platform-specific commands are abstracted behind helper functions with OS detection.

After completion, create `.planning/phases/02-operations-maintenance/02-03-SUMMARY.md`