#!/usr/bin/env bash set -euo pipefail if [[ ${EUID} -ne 0 ]]; then echo "Ejecute este script con sudo." >&2 exit 1 fi PROJECT_SOURCE="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" PROJECT_TARGET="/opt/photobioreactor" CONFIG_TARGET="/etc/photobioreactor" SERVICE_USER="photobioreactor" apt-get update apt-get install -y nodejs npm nginx i2c-tools build-essential if ! id "${SERVICE_USER}" >/dev/null 2>&1; then useradd --system --create-home --groups i2c "${SERVICE_USER}" fi install -d -o "${SERVICE_USER}" -g "${SERVICE_USER}" "${PROJECT_TARGET}" install -d -o "${SERVICE_USER}" -g "${SERVICE_USER}" "${CONFIG_TARGET}" cp -a "${PROJECT_SOURCE}/." "${PROJECT_TARGET}/" rm -rf "${PROJECT_TARGET}/node_modules" cd "${PROJECT_TARGET}" npm ci --omit=dev make -C sensors/EZOCommand chown -R "${SERVICE_USER}:${SERVICE_USER}" "${PROJECT_TARGET}" install -m 0644 deployment/photobioreactor.env /etc/default/photobioreactor install -o "${SERVICE_USER}" -g "${SERVICE_USER}" -m 0600 \ config/notifications.json "${CONFIG_TARGET}/notifications.json" install -m 0644 deployment/photobioreactor-api.service /etc/systemd/system/ install -m 0644 deployment/photobioreactor-acquisition.service /etc/systemd/system/ install -m 0644 deployment/nginx-photobioreactor.conf \ /etc/nginx/sites-available/photobioreactor ln -sfn /etc/nginx/sites-available/photobioreactor \ /etc/nginx/sites-enabled/photobioreactor rm -f /etc/nginx/sites-enabled/default systemctl daemon-reload nginx -t systemctl enable --now photobioreactor-api systemctl enable --now photobioreactor-acquisition systemctl reload nginx echo "Instalación terminada. Revise: systemctl status photobioreactor-*"