|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +set -eu |
| 4 | + |
| 5 | +PROJECT_URL="https://github.com/ActivLayer/activlayer" |
| 6 | +DEFAULT_SOURCE="$PROJECT_URL/archive/refs/heads/community-edition.zip" |
| 7 | +SOURCE="${ACTIVLAYER_SOURCE:-$DEFAULT_SOURCE}" |
| 8 | +INSTALL_ROOT="${ACTIVLAYER_INSTALL_ROOT:-$HOME/.local/share/activlayer}" |
| 9 | +BIN_DIR="${ACTIVLAYER_BIN_DIR:-$HOME/.local/bin}" |
| 10 | +PYTHON="${ACTIVLAYER_PYTHON:-python3}" |
| 11 | + |
| 12 | +fail() { |
| 13 | + printf 'ActivLayer installation failed: %s\n' "$1" >&2 |
| 14 | + exit 1 |
| 15 | +} |
| 16 | + |
| 17 | +command -v "$PYTHON" >/dev/null 2>&1 || fail "Python 3.11 or newer is required." |
| 18 | + |
| 19 | +"$PYTHON" -c ' |
| 20 | +import sys |
| 21 | +if sys.version_info < (3, 11): |
| 22 | + raise SystemExit("ActivLayer requires Python 3.11 or newer.") |
| 23 | +' || fail "Python 3.11 or newer is required." |
| 24 | + |
| 25 | +case "$INSTALL_ROOT" in |
| 26 | + ""|/|"$HOME") fail "Refusing unsafe installation directory: $INSTALL_ROOT" ;; |
| 27 | +esac |
| 28 | + |
| 29 | +printf 'Installing ActivLayer Community Edition...\n' |
| 30 | +mkdir -p "$INSTALL_ROOT" "$BIN_DIR" |
| 31 | + |
| 32 | +if [ ! -x "$INSTALL_ROOT/venv/bin/python" ]; then |
| 33 | + "$PYTHON" -m venv "$INSTALL_ROOT/venv" || fail "Could not create the isolated environment." |
| 34 | +fi |
| 35 | + |
| 36 | +"$INSTALL_ROOT/venv/bin/python" -m pip install \ |
| 37 | + --disable-pip-version-check \ |
| 38 | + --quiet \ |
| 39 | + --upgrade \ |
| 40 | + "$SOURCE" || fail "Package installation failed." |
| 41 | + |
| 42 | +"$INSTALL_ROOT/venv/bin/activlayer" --version >/dev/null || fail "Installed command is not healthy." |
| 43 | +ln -sf "$INSTALL_ROOT/venv/bin/activlayer" "$BIN_DIR/activlayer" |
| 44 | + |
| 45 | +case ":$PATH:" in |
| 46 | + *":$BIN_DIR:"*) |
| 47 | + printf '\nActivLayer is ready. Run:\n activlayer --help\n' |
| 48 | + ;; |
| 49 | + *) |
| 50 | + case "${SHELL:-}" in |
| 51 | + */zsh) PROFILE="$HOME/.zprofile" ;; |
| 52 | + */bash) |
| 53 | + if [ -f "$HOME/.bash_profile" ]; then |
| 54 | + PROFILE="$HOME/.bash_profile" |
| 55 | + else |
| 56 | + PROFILE="$HOME/.profile" |
| 57 | + fi |
| 58 | + ;; |
| 59 | + *) PROFILE="$HOME/.profile" ;; |
| 60 | + esac |
| 61 | + PATH_LINE="export PATH=\"$BIN_DIR:\$PATH\"" |
| 62 | + if [ ! -f "$PROFILE" ] || ! grep -F "$PATH_LINE" "$PROFILE" >/dev/null 2>&1; then |
| 63 | + printf '\n%s\n' "$PATH_LINE" >> "$PROFILE" |
| 64 | + fi |
| 65 | + printf '\nActivLayer is installed. Open a new terminal, then run:\n activlayer --help\n' |
| 66 | + ;; |
| 67 | +esac |
0 commit comments