mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-10-07 14:06:40 +00:00
Fetched with wget and piped to bash, $0 is "bash" and the script resolves its own directory to wherever the shell happens to be. It then reports "shasum: /root/requirements.txt: No such file or directory", which names a path the reader never chose and says nothing about the real problem. It now checks for the files it needs and names both places it runs from: the installed engine directory on a Proxmox host, or oci/ in a clone. PACKAGE-CONTENTS.md called it the "installer entry point", which is what invites fetching it over the network in the first place. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
59 lines
2.0 KiB
Bash
Executable File
59 lines
2.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
|
|
ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
VENV_DIR="$ROOT_DIR/.venv"
|
|
REQUIREMENTS="$ROOT_DIR/requirements.txt"
|
|
STAMP="$VENV_DIR/.requirements.sha256"
|
|
|
|
# The orchestrator lives beside this script, so it has to run from where it
|
|
# was installed. Piped from a URL there is no directory to read: $0 is "bash",
|
|
# ROOT_DIR becomes the working directory, and the first missing file reports a
|
|
# path nobody asked for.
|
|
if [ ! -r "$REQUIREMENTS" ] || [ ! -d "$ROOT_DIR/src/proxmenux_oci" ]; then
|
|
cat >&2 <<EOF
|
|
ERROR: this script runs from the directory it was installed in, next to
|
|
requirements.txt and src/. It cannot be piped from a URL.
|
|
|
|
On a Proxmox host with ProxMenux installed:
|
|
/usr/local/share/proxmenux/oci/engine/proxmenux-oci.sh "\$@"
|
|
|
|
From a clone of the repository:
|
|
cd oci && ./proxmenux-oci.sh "\$@"
|
|
EOF
|
|
exit 1
|
|
fi
|
|
|
|
command -v python3 >/dev/null 2>&1 || {
|
|
echo "ERROR: Python 3 is required." >&2
|
|
exit 1
|
|
}
|
|
|
|
if python3 -c 'import yaml, jsonschema' >/dev/null 2>&1; then
|
|
PYTHON=python3
|
|
else
|
|
if [[ ! -x "$VENV_DIR/bin/python" ]] || ! "$VENV_DIR/bin/python" -m pip --version >/dev/null 2>&1; then
|
|
echo "Preparing the local Python environment..."
|
|
rm -rf "$VENV_DIR"
|
|
python3 -m venv "$VENV_DIR" || {
|
|
echo "ERROR: could not create the virtual environment. On Debian, install python3-venv, python3-yaml and python3-jsonschema." >&2
|
|
exit 1
|
|
}
|
|
fi
|
|
if command -v shasum >/dev/null 2>&1; then
|
|
CURRENT_HASH=$(shasum -a 256 "$REQUIREMENTS" | awk '{print $1}')
|
|
else
|
|
CURRENT_HASH=$(sha256sum "$REQUIREMENTS" | awk '{print $1}')
|
|
fi
|
|
INSTALLED_HASH=$(cat "$STAMP" 2>/dev/null || true)
|
|
if [[ "$CURRENT_HASH" != "$INSTALLED_HASH" ]]; then
|
|
echo "Installing the converter dependencies..."
|
|
"$VENV_DIR/bin/python" -m pip install --disable-pip-version-check -r "$REQUIREMENTS"
|
|
printf '%s\n' "$CURRENT_HASH" >"$STAMP"
|
|
fi
|
|
PYTHON="$VENV_DIR/bin/python"
|
|
fi
|
|
|
|
export PYTHONPATH="$ROOT_DIR/src${PYTHONPATH:+:$PYTHONPATH}"
|
|
exec "$PYTHON" -m proxmenux_oci "$@"
|