#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" SKILL_DIR="$(cd -- "$SCRIPT_DIR/.." && pwd)" HOME_DIR="${HOME:?HOME is required}" WORKSPACE_DEFAULT="$HOME_DIR/.openclaw/workspace" WORKSPACE="${WATCHDOG_B_WORKSPACE:-$WORKSPACE_DEFAULT}" SYSTEMD_USER_DIR="${WATCHDOG_B_SYSTEMD_USER_DIR:-$HOME_DIR/.config/systemd/user}" CONFIG_DIR="${WATCHDOG_B_CONFIG_DIR:-$HOME_DIR/.config/openclaw}" LIVE_SCRIPT_DIR="${WATCHDOG_B_LIVE_SCRIPT_DIR:-$WORKSPACE/scripts/watchdog-b}" INSTALL_ENV_EXAMPLE=0 FORCE=0 usage() { cat </scripts/watchdog-b) --install-env-example Also install watchdog-b.env.example to /watchdog-b.env.example --force Overwrite existing files in live paths -h, --help Show this help EOF } while [[ $# -gt 0 ]]; do case "$1" in --workspace) WORKSPACE="$2"; shift 2 ;; --systemd-user-dir) SYSTEMD_USER_DIR="$2"; shift 2 ;; --config-dir) CONFIG_DIR="$2"; shift 2 ;; --live-script-dir) LIVE_SCRIPT_DIR="$2"; shift 2 ;; --install-env-example) INSTALL_ENV_EXAMPLE=1; shift ;; --force) FORCE=1; shift ;; -h|--help) usage; exit 0 ;; *) echo "unknown argument: $1" >&2 usage >&2 exit 2 ;; esac done mkdir -p "$LIVE_SCRIPT_DIR" "$SYSTEMD_USER_DIR" "$CONFIG_DIR" copy_file() { local src="$1" local dest="$2" if [[ -e "$dest" && "$FORCE" != "1" ]]; then echo "skip existing: $dest" return 0 fi install -m 0644 "$src" "$dest" echo "installed: $dest" } copy_exec() { local src="$1" local dest="$2" if [[ -e "$dest" && "$FORCE" != "1" ]]; then echo "skip existing: $dest" return 0 fi install -m 0755 "$src" "$dest" echo "installed: $dest" } render_service() { local src="$SCRIPT_DIR/openclaw-watchdog-b.service" local dest="$SYSTEMD_USER_DIR/openclaw-watchdog-b.service" if [[ -e "$dest" && "$FORCE" != "1" ]]; then echo "skip existing: $dest" return 0 fi sed \ -e "s#%h/.openclaw/workspace#${WORKSPACE//\#/\\#}#g" \ -e "s#%h/.config/openclaw#${CONFIG_DIR//\#/\\#}#g" \ -e "s#%h/.openclaw/workspace/scripts/watchdog-b#${LIVE_SCRIPT_DIR//\#/\\#}#g" \ "$src" > "$dest" chmod 0644 "$dest" echo "installed: $dest" } copy_exec "$SCRIPT_DIR/check_openclaw_state.sh" "$LIVE_SCRIPT_DIR/check_openclaw_state.sh" copy_exec "$SCRIPT_DIR/run_watchdog_b.sh" "$LIVE_SCRIPT_DIR/run_watchdog_b.sh" copy_exec "$SCRIPT_DIR/verify_watchdog_b_e2e.sh" "$LIVE_SCRIPT_DIR/verify_watchdog_b_e2e.sh" copy_exec "$SCRIPT_DIR/notify_watchdog_b.py" "$LIVE_SCRIPT_DIR/notify_watchdog_b.py" copy_exec "$SCRIPT_DIR/openclaw_runtime_probe.py" "$LIVE_SCRIPT_DIR/openclaw_runtime_probe.py" copy_file "$SCRIPT_DIR/owner_report_consumer.py" "$LIVE_SCRIPT_DIR/owner_report_consumer.py" copy_file "$SCRIPT_DIR/owner_report_driver.py" "$LIVE_SCRIPT_DIR/owner_report_driver.py" copy_file "$SCRIPT_DIR/owner_report_producer.py" "$LIVE_SCRIPT_DIR/owner_report_producer.py" copy_file "$SCRIPT_DIR/openclaw-watchdog-b.timer" "$SYSTEMD_USER_DIR/openclaw-watchdog-b.timer" render_service if [[ "$INSTALL_ENV_EXAMPLE" == "1" ]]; then copy_file "$SCRIPT_DIR/watchdog-b.env.example" "$CONFIG_DIR/watchdog-b.env.example" fi cat <