Add deploy-remote-web.sh for musruser/remote web deployment
This commit is contained in:
1 parent
c2fe503777
commit
03250e35d1
2 files changed
+128
No files matched your search
@@ -78,6 +78,21 @@ make -C docs html
|
||||
sudo ./scripts/deploy-web.sh
|
||||
```
|
||||
|
||||
To deploy to a remote server (e.g. musruser.psi.ch) from this machine,
|
||||
`deploy-remote-web.sh` copies a tarball, extracts it on the remote host, and
|
||||
runs `deploy-web.sh` via sudo (remote user must have sudo rights):
|
||||
|
||||
```bash
|
||||
make -C docs html
|
||||
./scripts/deploy-remote-web.sh [path/to/muSRFlow.tar.gz]
|
||||
# or let it create a temporary archive from the current tree:
|
||||
./scripts/deploy-remote-web.sh
|
||||
```
|
||||
|
||||
Set `MUSRFLOW_REMOTE_HOST` / `MUSRFLOW_REMOTE_USER` / `MUSRFLOW_REMOTE_SSH` as
|
||||
needed. `MUSRFLOW_WEB_TARGET`, `MUSRFLOW_CGI_TARGET`,
|
||||
`MUSRFLOW_STARTUP_XML_TARGET`, and `MUSRFLOW_DATA_ROOT` are passed through.
|
||||
|
||||
The complete manual is installed under `/muSRFlow/docs/`, including its styles
|
||||
and search index. Rebuild it before each deployment to include documentation and
|
||||
version changes. If `docs/_build/html/index.html` is missing or empty, deployment
|
||||
|
||||
Executable
+113
@@ -0,0 +1,113 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright (C) 2026 Zaher Salman
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#
|
||||
# Deploy muSRFlow web assets to a remote host (e.g. musruser.psi.ch).
|
||||
# Copies the required files to a temporary directory on the remote host,
|
||||
# then runs deploy-web.sh there with sudo so Apache can read/execute them.
|
||||
#
|
||||
# Usage:
|
||||
# ./scripts/deploy-remote-web.sh [path/to/muSRFlow.tar.gz]
|
||||
#
|
||||
# If no tarball is given, a temporary tar.gz is created from the current
|
||||
# working tree (including docs/_build/html if present). Build docs first:
|
||||
# make -C docs html
|
||||
#
|
||||
# Environment:
|
||||
# MUSRFLOW_REMOTE_HOST Remote host (default: musruser.psi.ch)
|
||||
# MUSRFLOW_REMOTE_USER SSH user (default: current user)
|
||||
# MUSRFLOW_REMOTE_SSH Extra ssh/scp options (e.g. "-J jumphost")
|
||||
# MUSRFLOW_REMOTE_TMP Remote temp base dir (default: /tmp)
|
||||
# MUSRFLOW_WEB_TARGET Passed through to deploy-web.sh
|
||||
# MUSRFLOW_CGI_TARGET Passed through to deploy-web.sh
|
||||
# MUSRFLOW_STARTUP_XML_TARGET Passed through to deploy-web.sh
|
||||
# MUSRFLOW_DATA_ROOT Passed through to deploy-web.sh
|
||||
# MUSRFLOW_BUILD_REVISION Passed through to deploy-web.sh
|
||||
#
|
||||
# The remote user must be able to run: sudo ./scripts/deploy-web.sh
|
||||
# (passwordless sudo for that command, or you will be prompted if TTY allows).
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
remote_host="${MUSRFLOW_REMOTE_HOST:-musruser.psi.ch}"
|
||||
remote_user="${MUSRFLOW_REMOTE_USER:-}"
|
||||
remote_ssh_opts=(${MUSRFLOW_REMOTE_SSH:-})
|
||||
remote_tmp_base="${MUSRFLOW_REMOTE_TMP:-/tmp}"
|
||||
|
||||
if [ -n "$remote_user" ]; then
|
||||
remote="${remote_user}@${remote_host}"
|
||||
else
|
||||
remote="${remote_host}"
|
||||
fi
|
||||
|
||||
tarball="${1:-}"
|
||||
cleanup_tarball=""
|
||||
if [ -z "$tarball" ]; then
|
||||
if [ ! -s "$project_root/docs/_build/html/index.html" ]; then
|
||||
printf 'HTML manual missing. Run: make -C "%s/docs" html\n' "$project_root" >&2
|
||||
exit 1
|
||||
fi
|
||||
tarball="$(mktemp "${TMPDIR:-/tmp}/musrflow-deploy.XXXXXX.tar.gz")"
|
||||
cleanup_tarball="$tarball"
|
||||
printf 'Creating temporary deployment archive: %s\n' "$tarball"
|
||||
# Include only what deploy-web.sh needs, plus docs build and scripts.
|
||||
tar -C "$project_root" -czf "$tarball" \
|
||||
index.html quick-start.html ZGUI.css \
|
||||
muSRFitweb.js muSRFitRoot.js muSRFitParameterPlot.js muSRFitlib.js \
|
||||
assets package.json build-revision.txt \
|
||||
scripts/deploy-web.sh \
|
||||
cgi/single_musrfit.cgi cgi/musrfit_startup.xml \
|
||||
docs/_build/html
|
||||
fi
|
||||
|
||||
if [ ! -f "$tarball" ]; then
|
||||
printf 'Tarball not found: %s\n' "$tarball" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
remote_dir="${remote_tmp_base}/musrflow-deploy.$$.$(date +%s)"
|
||||
remote_tar="${remote_dir}/$(basename "$tarball")"
|
||||
|
||||
printf 'Copying %s to %s:%s\n' "$tarball" "$remote" "$remote_dir"
|
||||
ssh "${remote_ssh_opts[@]}" "$remote" "mkdir -p '$remote_dir'"
|
||||
scp "${remote_ssh_opts[@]}" "$tarball" "$remote:$remote_tar"
|
||||
|
||||
# Build env assignments for remote deploy-web.sh
|
||||
env_args=()
|
||||
for var in MUSRFLOW_WEB_TARGET MUSRFLOW_CGI_TARGET MUSRFLOW_STARTUP_XML_TARGET \
|
||||
MUSRFLOW_DATA_ROOT MUSRFLOW_BUILD_REVISION MUSRFLOW_WEB_OWNER MUSRFLOW_WEB_GROUP; do
|
||||
val="${!var-}"
|
||||
if [ -n "$val" ]; then
|
||||
# escape single quotes for remote shell
|
||||
esc="${val//\'/\'\\\'\'}"
|
||||
env_args+=("$var='$esc'")
|
||||
fi
|
||||
done
|
||||
|
||||
printf 'Extracting and deploying on %s (sudo)...\n' "$remote"
|
||||
ssh "${remote_ssh_opts[@]}" -t "$remote" bash -s -- "$remote_dir" "$remote_tar" "${env_args[*]-}" << 'REMOTE'
|
||||
set -euo pipefail
|
||||
remote_dir="$1"; remote_tar="$2"; env_assign="${3-}"
|
||||
cd "$remote_dir"
|
||||
tar -xzf "$remote_tar"
|
||||
# Find extracted root (tar may include top-level dir or files)
|
||||
if [ -f scripts/deploy-web.sh ]; then
|
||||
root=.
|
||||
elif [ -f */scripts/deploy-web.sh ]; then
|
||||
root="$(dirname "$(echo */scripts/deploy-web.sh | awk '{print $1}')")"
|
||||
else
|
||||
echo "deploy-web.sh not found after extraction" >&2; exit 1
|
||||
fi
|
||||
cd "$root"
|
||||
# shellcheck disable=SC2086
|
||||
sudo env $env_assign ./scripts/deploy-web.sh
|
||||
cd /
|
||||
rm -rf "$remote_dir"
|
||||
REMOTE
|
||||
|
||||
if [ -n "$cleanup_tarball" ]; then
|
||||
rm -f "$cleanup_tarball"
|
||||
fi
|
||||
|
||||
printf 'Remote deployment to %s complete.\n' "$remote"
|
||||
Reference in new issue
Block a user