#!/usr/bin/env bash
set -eu

if [ "$#" -lt 1 ]; then
    echo "Uso: ./RESTAURAR.sh /ruta/del/respaldo [/ruta/del/proyecto]" >&2
    exit 1
fi

DIR_RESPALDO="$1"
BASE_PROYECTO="${2:-/home/iotcuboc/pyme}"
ORIGEN="$DIR_RESPALDO/public/recetas_v3.php"
DESTINO="$BASE_PROYECTO/public/recetas_v3.php"

if [ ! -f "$ORIGEN" ]; then
    echo "ERROR: el respaldo no contiene public/recetas_v3.php" >&2
    exit 1
fi

cp -p "$ORIGEN" "$DESTINO"

if command -v php >/dev/null 2>&1; then
    php -l "$DESTINO"
fi

echo "Respaldo restaurado correctamente en: $DESTINO"

