Files
TRIMSP/scripts/deploy-web.sh
T

76 lines
2.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Copyright (C) 2026 Zaher Salman
# SPDX-License-Identifier: GPL-2.0-only
set -euo pipefail
project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
web_target="${TRIMSP_WEB_TARGET:-/var/www/html/TRIMSP-NL}"
cgi_target="${TRIMSP_CGI_TARGET:-/var/www/cgi-bin/singleTrimSP.cgi}"
trimsp_binary="${TRIMSP_BIN_PATH:-/usr/local/bin/trimspNL}"
web_owner="${TRIMSP_WEB_OWNER:-apache}"
web_group="${TRIMSP_WEB_GROUP:-apache}"
plotly_source="$project_root/node_modules/plotly.js-dist/plotly.js"
if [[ ! -x "$trimsp_binary" ]]; then
printf 'Installed TRIM.SP-NL binary is not executable: %s\n' "$trimsp_binary" >&2
printf 'Install it first or set TRIMSP_BIN_PATH.\n' >&2
exit 1
fi
if [[ ! -f "$plotly_source" ]]; then
printf 'Plotly browser bundle not found: %s\n' "$plotly_source" >&2
printf 'Run npm install before deploying.\n' >&2
exit 1
fi
perl -c "$project_root/singleTrimSP.cgi" >/dev/null
# Install only files used by the browser application. Electron-specific code,
# package metadata, tests, and Fortran sources stay outside the document root.
install -d -m 0755 "$web_target" "$(dirname "$cgi_target")"
install -m 0644 \
"$project_root/TrimSP.html" \
"$project_root/quick-start.html" \
"$project_root/TrimSPlib.js" \
"$project_root/TrimSPweb.js" \
"$project_root/myplots.js" \
"$project_root/ZGUI.css" \
"$project_root/plotly.css" \
"$project_root/icon.png" \
"$web_target/"
install -m 0644 "$plotly_source" "$web_target/plotly.js"
ln -sfn TrimSP.html "$web_target/index.html"
# Keep the repository CGI generic while embedding the selected installed
# binary path in the deployed copy.
cgi_stage="$(mktemp)"
trap 'rm -f "$cgi_stage"' EXIT
escaped_trimsp_binary="${trimsp_binary//\\/\\\\}"
escaped_trimsp_binary="${escaped_trimsp_binary//&/\\&}"
escaped_trimsp_binary="${escaped_trimsp_binary//|/\\|}"
escaped_trimsp_binary="${escaped_trimsp_binary//\"/\\\"}"
sed 's|^my \$trimsp_bin = .*|my $trimsp_bin = "'"$escaped_trimsp_binary"'";|' \
"$project_root/singleTrimSP.cgi" > "$cgi_stage"
install -m 0755 "$cgi_stage" "$cgi_target"
if getent passwd "$web_owner" >/dev/null 2>&1 && getent group "$web_group" >/dev/null 2>&1; then
chown -R "$web_owner:$web_group" "$web_target"
chown "$web_owner:$web_group" "$cgi_target"
else
printf 'Warning: owner/group %s:%s does not exist; ownership was not changed.\n' \
"$web_owner" "$web_group" >&2
fi
if command -v restorecon >/dev/null 2>&1; then
restorecon -RF "$web_target" "$cgi_target" || true
fi
printf 'Installed TRIMSP-NL web assets in %s\n' "$web_target"
printf 'Installed TRIMSP-NL CGI runner at %s\n' "$cgi_target"
printf 'Using installed TRIM.SP-NL engine at %s\n' "$trimsp_binary"
printf '\nThe web server must provide:\n'
printf ' /cgi-bin/singleTrimSP.cgi -> %s\n' "$cgi_target"
printf 'For SELinux deployments, verify CGI execution and write access with:\n'
printf ' ausearch -m avc -ts recent\n'