#!/usr/bin/env bash # Recursively chown /srv/projects inside Dev CT 5700 to the primary dev user. # Use when rsync --delete-remote fails with Permission denied (root-owned files on VM). # # Requires: SSH as root to the Proxmox node that hosts VMID 5700 (default r630-04). # # Usage: # ./scripts/deployment/fix-dev-vm-srv-projects-ownership.sh --dry-run # ./scripts/deployment/fix-dev-vm-srv-projects-ownership.sh # # Env: # DEV_VM_CTID — LXC ID (default 5700) # DEV_VM_USER — owning user inside CT (default dev1) # DEV_VM_PVE_HOST — override Proxmox node IP/hostname (default: get_host_for_vmid + R630_04 fallback) # Do not use generic PROXMOX_HOST here; it may point at the wrong node. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" export PROJECT_ROOT # shellcheck source=/dev/null source "${PROJECT_ROOT}/scripts/lib/load-project-env.sh" 2>/dev/null || true DRY_RUN=0 while [[ $# -gt 0 ]]; do case "$1" in --dry-run) DRY_RUN=1; shift ;; --help|-h) sed -n '1,22p' "$0" | tail -n +2 exit 0 ;; *) echo "ERROR: unknown argument: $1 (try --help)" >&2 exit 1 ;; esac done CTID="${DEV_VM_CTID:-5700}" OWNER="${DEV_VM_USER:-dev1}" if [[ -n "${DEV_VM_PVE_HOST:-}" ]]; then NODE="$DEV_VM_PVE_HOST" else NODE="$(get_host_for_vmid "$CTID" 2>/dev/null || true)" fi NODE="${NODE:-${PROXMOX_HOST_R630_04:-192.168.11.14}}" REMOTE_CMD="pct exec $CTID -- chown -R ${OWNER}:${OWNER} /srv/projects" echo "=== Fix Dev VM /srv/projects ownership ===" echo "Node: root@${NODE}" echo "CT: $CTID" echo "Owner: $OWNER" echo "" if [[ "$DRY_RUN" == "1" ]]; then echo "DRY-RUN: ssh root@${NODE} \"$REMOTE_CMD\"" exit 0 fi ssh -o BatchMode=yes -o ConnectTimeout=15 -o StrictHostKeyChecking=accept-new "root@${NODE}" "$REMOTE_CMD" echo "Done."