#!/usr/bin/env bash set -euo pipefail MODE="${1:-}" usage() { cat >&2 <<'EOF' Uso: server: bootstrap_docs_lan_share.sh server /percorso/day0 192.168.0.0/24 [share_dir] [modules_csv] client: bootstrap_docs_lan_share.sh client host:/export/path /mount/point /workspace/path EOF exit 1 } require_cmd() { if ! command -v "$1" >/dev/null 2>&1; then echo "Comando richiesto non trovato: $1" >&2 exit 1 fi } copy_tree() { local src="$1" local dst="$2" mkdir -p "$dst" if command -v rsync >/dev/null 2>&1; then rsync -a --delete "$src/" "$dst/" else rm -rf "$dst" mkdir -p "$dst" cp -a "$src/." "$dst/" fi } server_mode() { local day0_root="${2:-}" local network_cidr="${3:-}" local share_dir="${4:-/srv/netgescon/shared-docs}" local modules_csv="${5:-docs,scripts/ai}" local -a module_paths=() local module [[ -n "$day0_root" && -n "$network_cidr" ]] || usage [[ -d "$day0_root/docs" ]] || { echo "docs/ non trovata in $day0_root" >&2; exit 1; } [[ -d "$day0_root/scripts/ai" ]] || { echo "scripts/ai non trovata in $day0_root" >&2; exit 1; } mkdir -p "$share_dir/scripts" "$share_dir/exchange" "$share_dir/modules" copy_tree "$day0_root/docs" "$share_dir/docs" copy_tree "$day0_root/scripts/ai" "$share_dir/scripts/ai" IFS=',' read -r -a module_paths <<< "$modules_csv" for module in "${module_paths[@]}"; do module="${module#./}" module="${module%/}" [[ -n "$module" ]] || continue [[ "$module" == "docs" || "$module" == "scripts/ai" ]] && continue if [[ -d "$day0_root/$module" ]]; then mkdir -p "$share_dir/modules/$(dirname "$module")" copy_tree "$day0_root/$module" "$share_dir/modules/$module" fi done cat < $mount_point/docs $workspace_dir/scripts/ai -> $mount_point/scripts/ai $workspace_dir/exchange -> $mount_point/exchange $workspace_dir/modules/shared -> $mount_point/modules EOF } case "$MODE" in server) server_mode "$@" ;; client) client_mode "$@" ;; *) usage ;; esac