Files
muSRFlow/scripts/deploy-web.sh
salman 5a91b1a043 Drop legacy musrfit-gui credit from MSRs and expose the version on the web
Generated MSRs no longer carry the old musrfit-gui repository URL; the
header names muSRFlow, the author, the licence, and the muSRFlow site,
and the reference fixtures follow. The Quick Start/help page gains an
About muSRFlow section with the version, author, and licence, mirroring
the Electron Help > About dialog: the Electron window is fed
app.getVersion() over the quickStartSection channel, while the web
deploy brands the installed page with the package.json version
(idempotent sed on a __MUSRFLOW_VERSION__ token that renders as
'development build' when unsubstituted).
2026-09-14 11:36:45 +02:00

120 lines
5.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Copyright (C) 2026 Zaher Salman
# SPDX-License-Identifier: GPL-3.0-or-later
set -euo pipefail
project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
web_target="${MUSRFLOW_WEB_TARGET:-/var/www/html/muSRFlow}"
cgi_target="${MUSRFLOW_CGI_TARGET:-/var/www/cgi-bin/single_musrfit.cgi}"
# Server-owned startup XML read by the CGI to build portable RUN names. It is
# part of this deployment (not a system config file) and lives beside the CGI,
# outside the web document root so it is never served to browsers.
startup_target="${MUSRFLOW_STARTUP_XML_TARGET:-/var/www/cgi-bin/musrfit_startup.xml}"
# Install only assets used by the browser build. Parameter plotting and ROOT
# rendering are loaded as separate browser modules.
install -d -m 0755 "$web_target" "$web_target/assets"
install -m 0644 \
"$project_root/index.html" \
"$project_root/quick-start.html" \
"$project_root/ZGUI.css" \
"$project_root/muSRFitweb.js" \
"$project_root/muSRFitRoot.js" \
"$project_root/muSRFitParameterPlot.js" \
"$project_root/muSRFitlib.js" \
"$web_target/"
install -m 0644 \
"$project_root/assets/musrflow-favicon.png" \
"$project_root/assets/musrflow-icon.png" \
"$web_target/assets/"
# Brand the installed help page with the current release version, matching the
# About dialog in the Electron edition. The source keeps a __MUSRFLOW_VERSION__
# token that renders as "development build" when left unsubstituted; the
# installed copy is rewritten with the version from package.json. Idempotent:
# an already-branded file contains no token, so re-running matches nothing.
if command -v node >/dev/null 2>&1; then
version="$(node -p 'require(process.argv[1]).version' "$project_root/package.json")"
tmp_qs="$(mktemp)"
sed "s#__MUSRFLOW_VERSION__#$version#g" "$web_target/quick-start.html" > "$tmp_qs"
install -m 0644 "$tmp_qs" "$web_target/quick-start.html"
rm -f "$tmp_qs"
printf 'Branded %s with muSRFlow version %s\n' "$web_target/quick-start.html" "$version"
else
printf 'node not found; quick-start.html keeps the source version token\n'
fi
# Apache executes the runner through the existing /cgi-bin ScriptAlias.
install -m 0755 "$project_root/cgi/single_musrfit.cgi" "$cgi_target"
# Install the server-owned startup XML beside the CGI. The CGI reads it to
# resolve portable RUN names; it must be readable by Apache but is not under
# the document root.
install -m 0644 "$project_root/cgi/musrfit_startup.xml" "$startup_target"
# The startup XML names each instrument's data root as an absolute <data_path>.
# The shipped file targets the PSI layout. On a machine whose data tree lives
# under a different root (e.g. /mnt/fake), the portable-RUN resolver would
# reject every local path as "not configured". When MUSRFLOW_DATA_ROOT is set,
# rewrite the <data_path> prefixes in the installed copy to that root so the
# resolver matches the local tree. The edit is applied to the installed file
# only, never the repository source, and is idempotent: re-running on an already
# rewritten file matches none of the old prefixes.
if [ -n "${MUSRFLOW_DATA_ROOT:-}" ]; then
data_root="$(printf '%s' "$MUSRFLOW_DATA_ROOT" | sed 's/[&/\\]/\\&/g')"
tmp_xml="$(mktemp)"
sed -e "s#/psi.ch/group/lmu/public/data/#$data_root/#g" \
-e "s#/mnt/data/nemu/his<#$data_root/nemu/his<#g" \
"$startup_target" > "$tmp_xml"
install -m 0644 "$tmp_xml" "$startup_target"
rm -f "$tmp_xml"
printf 'Rewrote <data_path> roots in %s to %s\n' "$startup_target" "$MUSRFLOW_DATA_ROOT"
fi
# The browser assets and the CGI must be readable (and, for the CGI, executable)
# by the web server. On the live server the web space is owned by the apache
# user; on a developer machine the files may instead be owned by the deploying
# user and served straight from a user-owned tree. Determine the owner to hand
# the files to, preferring an explicit override, then a real web-server account,
# and keeping the current owner when it is already the deploying user (the
# common developer-machine case, where the deploying user simply owns the web
# space and chowning to a nonexistent apache user would fail).
web_owner="${MUSRFLOW_WEB_OWNER:-}"
web_group="${MUSRFLOW_WEB_GROUP:-$web_owner}"
if [ -z "$web_owner" ]; then
# Detect from the target filesystem: if the deployed tree is already owned
# by the invoking user, leave ownership untouched.
if [ "$(stat -c %u "$web_target")" = "$(id -u)" ]; then
web_owner=""
web_group=""
else
# Prefer a real web-server account when one exists.
for cand in apache www-data httpd; do
if id "$cand" >/dev/null 2>&1; then
web_owner="$cand"
web_group="$cand"
break
fi
done
# With no matching account, fall back to the invoking user (the trees
# were written by this deploy, so they are already owned by them).
[ -z "$web_owner" ] && web_owner="$(id -un)" && web_group="$(id -gn)"
fi
fi
if [ -n "$web_owner" ]; then
chown -R "$web_owner:$web_group" "$web_target/"
chown "$web_owner:$web_group" "$cgi_target" "$startup_target"
chmod -R u+rX "$web_target/" 2>/dev/null || true
fi
printf 'Installed muSRFlow web assets in %s\n' "$web_target"
printf 'Installed muSRFlow CGI runner at %s\n' "$cgi_target"
printf 'Installed muSRFlow startup XML at %s\n' "$startup_target"
if [ -n "$web_owner" ]; then
printf 'Ownership set to %s:%s\n' "$web_owner" "$web_group"
else
printf 'Ownership left unchanged (deployed by the owning user)\n'
fi