87 lines
3.5 KiB
Bash
Executable File
87 lines
3.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Supported invocation:
|
|
# curl -fsSL https://git.ssh.surf/snxraven/gnome-jarvis/raw/branch/main/packaging/web-installer.sh | bash -s -- --enable
|
|
# Override JARVIS_SERVER and JARVIS_REPO for a mirror or private deployment.
|
|
|
|
SERVER="${JARVIS_SERVER:-https://git.ssh.surf}"
|
|
REPO="${JARVIS_REPO:-snxraven/gnome-jarvis}"
|
|
REF="${JARVIS_REF:-rolling}"
|
|
USER_AGENT="${JARVIS_USER_AGENT:-JARVIS-QVAC-web-installer/0.1}"
|
|
TMP_DIR=""
|
|
|
|
usage() {
|
|
cat <<'EOF'
|
|
JARVIS-QVAC web installer
|
|
|
|
Usage:
|
|
curl -fsSL https://git.ssh.surf/snxraven/gnome-jarvis/raw/branch/main/packaging/web-installer.sh | bash -s -- [--enable]
|
|
|
|
Options:
|
|
--enable Enable and start the per-user jarvisd.service after install.
|
|
--help Show this help.
|
|
|
|
Environment:
|
|
JARVIS_SERVER Gitea server base URL.
|
|
JARVIS_REPO Gitea owner/repository, default snxraven/gnome-jarvis.
|
|
JARVIS_REF Gitea ref to install, default rolling.
|
|
JARVIS_USER_AGENT HTTP User-Agent value for the archive request.
|
|
EOF
|
|
}
|
|
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--enable) ;;
|
|
--help|-h) usage; exit 0 ;;
|
|
*) echo "Unknown option: $arg" >&2; usage >&2; exit 2 ;;
|
|
esac
|
|
done
|
|
|
|
command -v curl >/dev/null || { echo "curl is required" >&2; exit 1; }
|
|
command -v tar >/dev/null || { echo "tar is required" >&2; exit 1; }
|
|
TMP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/jarvis-web-install.XXXXXX")"
|
|
cleanup() { rm -rf "$TMP_DIR"; }
|
|
trap cleanup EXIT
|
|
|
|
ARCHIVE_URL="${SERVER%/}/${REPO}/archive/${REF}.tar.gz"
|
|
ARCHIVE="${TMP_DIR}/jarvis.tar.gz"
|
|
case "$(uname -m)" in
|
|
x86_64|amd64) BUNDLE_NAME="jarvis-qvac-bare-linux-x64.tar.gz" ;;
|
|
aarch64|arm64) BUNDLE_NAME="jarvis-qvac-bare-linux-arm64.tar.gz" ;;
|
|
*) BUNDLE_NAME="" ;;
|
|
esac
|
|
BUNDLE_URL="${JARVIS_BUNDLE_URL:-${SERVER%/}/${REPO}/releases/download/rolling/${BUNDLE_NAME}}"
|
|
BUNDLE="${TMP_DIR}/${BUNDLE_NAME}"
|
|
if [[ -n "${BUNDLE_NAME}" ]]; then
|
|
echo "Trying the self-contained Bare bundle ${BUNDLE_NAME}"
|
|
if curl --fail --location --silent --show-error --retry 3 --proto '=https' --tlsv1.2 \
|
|
--user-agent "${USER_AGENT}" "${BUNDLE_URL}" -o "${BUNDLE}" && test -s "${BUNDLE}"; then
|
|
mkdir -p "${TMP_DIR}/bundle"
|
|
tar -xzf "${BUNDLE}" -C "${TMP_DIR}/bundle"
|
|
SOURCE_DIR="$(find "${TMP_DIR}/bundle" -mindepth 1 -maxdepth 1 -type d -print -quit)"
|
|
test -n "${SOURCE_DIR}" || { echo "Bare bundle contained no application directory" >&2; exit 1; }
|
|
test -x "${SOURCE_DIR}/packaging/install.sh" || { echo "Bare bundle contained no installer" >&2; exit 1; }
|
|
echo "Installing the bundled Bare runtime; Node.js is not required"
|
|
bash "${SOURCE_DIR}/packaging/install.sh" "$@"
|
|
exit $?
|
|
fi
|
|
fi
|
|
if ! command -v npm >/dev/null || ! command -v node >/dev/null; then
|
|
echo "No published Bare bundle was found. Use JARVIS_REF=rolling or set JARVIS_BUNDLE_URL; Node.js is only needed for a source fallback." >&2
|
|
exit 1
|
|
fi
|
|
echo "Downloading JARVIS-QVAC source ref '${REF}' from ${SERVER}"
|
|
curl --fail --location --silent --show-error --retry 3 --proto '=https' --tlsv1.2 \
|
|
--user-agent "${USER_AGENT}" \
|
|
"$ARCHIVE_URL" -o "$ARCHIVE"
|
|
test -s "$ARCHIVE"
|
|
mkdir -p "$TMP_DIR/src"
|
|
tar -xzf "$ARCHIVE" -C "$TMP_DIR/src"
|
|
SOURCE_DIR="$(find "$TMP_DIR/src" -mindepth 1 -maxdepth 1 -type d -print -quit)"
|
|
test -n "$SOURCE_DIR" || { echo "Downloaded archive contained no source directory" >&2; exit 1; }
|
|
test -x "$SOURCE_DIR/packaging/install.sh" || { echo "Downloaded ref has no installer" >&2; exit 1; }
|
|
|
|
echo "Installing into the current user account"
|
|
bash "$SOURCE_DIR/packaging/install.sh" "$@"
|