#!/usr/bin/env bash
set -euo pipefail
RESPALDO="${1:-}"
DESTINO="${2:-/home/iotcuboc/pyme}"
if [ -z "$RESPALDO" ] || [ ! -f "$RESPALDO/ARCHIVOS.txt" ]; then
  echo "Uso: bash RESTAURAR.sh /ruta/del/respaldo [/home/iotcuboc/pyme]"
  exit 1
fi
while IFS= read -r archivo; do
  if [ -f "$RESPALDO/$archivo" ]; then
    mkdir -p "$DESTINO/$(dirname "$archivo")"
    cp -p "$RESPALDO/$archivo" "$DESTINO/$archivo"
    php -l "$DESTINO/$archivo" >/dev/null || { echo "ERROR de sintaxis al restaurar $archivo"; exit 1; }
  fi
done < "$RESPALDO/ARCHIVOS.txt"
echo "Restauración completada desde $RESPALDO"
