This commit is contained in:
Joakim
2026-10-17 18:38:13 +02:00
parent 653c17b982
commit e223ca0cdd

View File

@@ -4,62 +4,57 @@ set -euo pipefail
# ============================================================
# HedgeDoc JOE - user local installer
#
# Installs everything below ~/.local and does not modify
# the system installation of joe.
# No sudo.
# No modification of /usr/bin/joe.
# Everything required at runtime is copied below ~/.local.
#
# After installation the source tree may be removed.
# After a successful installation the source tree can be
# removed.
# ============================================================
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# ------------------------------------------------------------
# Installation locations
# Defaults
# ------------------------------------------------------------
BIN_DIR="${BIN_DIR:-$HOME/.local/bin}"
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/lib/hedgedoc-joe}"
INSTALLED_JOE="$INSTALL_DIR/joe"
INSTALLED_COMMON="$INSTALL_DIR/hd_common"
INSTALLED_HDC="$INSTALL_DIR/hd-cli"
INSTALLED_HD_JOE="$INSTALL_DIR/hd-joe"
VENV_DIR="$INSTALL_DIR/venv"
JOE_WRAPPER="$BIN_DIR/joe"
HDC_WRAPPER="$BIN_DIR/hdc"
HD_JOE_WRAPPER="$BIN_DIR/hd-joe"
# Built JOE binary
BUILT="$SCRIPT_DIR/joe-patch/build/joe-4.8/joe/joe"
# ------------------------------------------------------------
# Options
# ------------------------------------------------------------
BIN_DIR="$HOME/.local/bin"
INSTALL_DIR="$HOME/.local/lib/hedgedoc-joe"
FORCE=0
# ------------------------------------------------------------
# Help
# ------------------------------------------------------------
usage() {
cat <<EOF
Usage: $0 [options]
Usage:
$0 [options]
Options:
--force Replace existing installation
--install-dir DIR Installation directory
--bin-dir DIR User executable directory
--install-dir DIR Runtime installation directory
--bin-dir DIR Command directory
-h, --help Show this help
Default installation:
Binaries:
$HOME/.local/bin/
Defaults:
Runtime:
$HOME/.local/lib/hedgedoc-joe/
$HOME/.local/lib/hedgedoc-joe
Commands:
$HOME/.local/bin
EOF
}
# ------------------------------------------------------------
# Arguments
# ------------------------------------------------------------
while [[ $# -gt 0 ]]; do
case "$1" in
--force)
FORCE=1
shift
@@ -67,18 +62,20 @@ while [[ $# -gt 0 ]]; do
--install-dir)
[[ $# -ge 2 ]] || {
echo "ERROR: --install-dir requires an argument" >&2
echo "ERROR: --install-dir requires a directory"
exit 1
}
INSTALL_DIR="$2"
shift 2
;;
--bin-dir)
[[ $# -ge 2 ]] || {
echo "ERROR: --bin-dir requires an argument" >&2
echo "ERROR: --bin-dir requires a directory"
exit 1
}
BIN_DIR="$2"
shift 2
;;
@@ -89,14 +86,17 @@ while [[ $# -gt 0 ]]; do
;;
*)
echo "ERROR: Unknown option: $1" >&2
usage >&2
echo "ERROR: Unknown option: $1"
usage
exit 1
;;
esac
done
# Recalculate paths if --install-dir / --bin-dir changed.
# ------------------------------------------------------------
# Installed paths
# ------------------------------------------------------------
INSTALLED_JOE="$INSTALL_DIR/joe"
INSTALLED_COMMON="$INSTALL_DIR/hd_common"
INSTALLED_HDC="$INSTALL_DIR/hd-cli"
@@ -107,12 +107,15 @@ JOE_WRAPPER="$BIN_DIR/joe"
HDC_WRAPPER="$BIN_DIR/hdc"
HD_JOE_WRAPPER="$BIN_DIR/hd-joe"
BUILT="$SCRIPT_DIR/joe-patch/build/joe-4.8/joe/joe"
# ------------------------------------------------------------
# Helpers
# Functions
# ------------------------------------------------------------
die() {
echo "ERROR: $*" >&2
echo
echo "ERROR: $*"
exit 1
}
@@ -126,25 +129,25 @@ info() {
info "Checking source tree"
[[ -d "$SCRIPT_DIR/hd_common" ]] ||
die "Missing $SCRIPT_DIR/hd_common"
[[ -d "$SCRIPT_DIR/hd-cli" ]] ||
die "Missing source directory: $SCRIPT_DIR/hd-cli"
die "Missing $SCRIPT_DIR/hd-cli"
[[ -d "$SCRIPT_DIR/hd-joe" ]] ||
die "Missing source directory: $SCRIPT_DIR/hd-joe"
[[ -d "$SCRIPT_DIR/hd_common" ]] ||
die "Missing source directory: $SCRIPT_DIR/hd_common"
die "Missing $SCRIPT_DIR/hd-joe"
[[ -f "$SCRIPT_DIR/hd_common/requirements.txt" ]] ||
die "Missing: $SCRIPT_DIR/hd_common/requirements.txt"
die "Missing hd_common/requirements.txt"
[[ -f "$SCRIPT_DIR/hd-cli/requirements.txt" ]] ||
die "Missing: $SCRIPT_DIR/hd-cli/requirements.txt"
die "Missing hd-cli/requirements.txt"
[[ -f "$SCRIPT_DIR/hd-joe/requirements.txt" ]] ||
die "Missing: $SCRIPT_DIR/hd-joe/requirements.txt"
die "Missing hd-joe/requirements.txt"
[[ -x "$BUILT" ]] ||
[[ -f "$BUILT" ]] ||
die "Built JOE binary not found:
$BUILT
@@ -156,6 +159,7 @@ Run ./build.sh first."
# ------------------------------------------------------------
if [[ -e "$INSTALL_DIR" ]]; then
if [[ "$FORCE" -ne 1 ]]; then
die "Installation already exists:
@@ -165,6 +169,7 @@ Use --force to replace it."
fi
info "Removing existing installation"
rm -rf "$INSTALL_DIR"
fi
@@ -178,12 +183,13 @@ mkdir -p "$INSTALL_DIR"
mkdir -p "$BIN_DIR"
# ------------------------------------------------------------
# Install JOE
# Install patched JOE
# ------------------------------------------------------------
info "Installing patched JOE"
install -m 0755 "$BUILT" "$INSTALLED_JOE"
cp "$BUILT" "$INSTALLED_JOE"
chmod 0755 "$INSTALLED_JOE"
# ------------------------------------------------------------
# Install Python applications
@@ -196,7 +202,7 @@ cp -a "$SCRIPT_DIR/hd-cli" "$INSTALLED_HDC"
cp -a "$SCRIPT_DIR/hd-joe" "$INSTALLED_HD_JOE"
# ------------------------------------------------------------
# Python virtual environment
# Create Python virtual environment
# ------------------------------------------------------------
info "Creating Python virtual environment"
@@ -204,38 +210,49 @@ info "Creating Python virtual environment"
python3 -m venv "$VENV_DIR"
PYTHON="$VENV_DIR/bin/python3"
PIP="$PYTHON -m pip"
[[ -x "$PYTHON" ]] ||
die "Python virtual environment could not be created"
# ------------------------------------------------------------
# Install Python dependencies
# ------------------------------------------------------------
info "Upgrading pip"
"$PYTHON" -m pip install --upgrade pip
# ------------------------------------------------------------
# Python dependencies
# ------------------------------------------------------------
info "Installing Python dependencies"
"$PYTHON" -m pip install \
-r "$INSTALLED_COMMON/requirements.txt" \
-r "$INSTALLED_HDC/requirements.txt" \
-r "$INSTALLED_COMMON/requirements.txt"
"$PYTHON" -m pip install \
-r "$INSTALLED_HDC/requirements.txt"
"$PYTHON" -m pip install \
-r "$INSTALLED_HD_JOE/requirements.txt"
# ------------------------------------------------------------
# Verify Python installation
# Python import path
#
# Both of these paths are included so the installed programs
# work whether they import modules as:
# Include both:
#
# hd_common.hd_core
# ~/.local/lib/hedgedoc-joe
#
# or directly as:
# and:
#
# hd_core
# ~/.local/lib/hedgedoc-joe/hd_common
#
# This supports both package-style and direct imports.
# ------------------------------------------------------------
PYTHONPATH_VALUE="$INSTALL_DIR:$INSTALLED_COMMON"
# ------------------------------------------------------------
# Verify Python installation
# ------------------------------------------------------------
info "Testing Python installation"
PYTHONPATH="$PYTHONPATH_VALUE" \
@@ -245,17 +262,16 @@ print(" hd_common: OK")
'
# ------------------------------------------------------------
# Install wrappers
# Create joe wrapper
# ------------------------------------------------------------
info "Installing command wrappers"
info "Creating joe wrapper"
cat > "$JOE_WRAPPER" <<EOF
#!/usr/bin/env bash
set -e
INSTALL_DIR="$INSTALL_DIR"
VENV_DIR="$VENV_DIR"
export PYTHONPATH="\$INSTALL_DIR:\$INSTALL_DIR/hd_common\${PYTHONPATH:+:\$PYTHONPATH}"
@@ -264,6 +280,11 @@ EOF
chmod 0755 "$JOE_WRAPPER"
# ------------------------------------------------------------
# Create hdc wrapper
# ------------------------------------------------------------
info "Creating hdc wrapper"
cat > "$HDC_WRAPPER" <<EOF
#!/usr/bin/env bash
@@ -280,6 +301,11 @@ EOF
chmod 0755 "$HDC_WRAPPER"
# ------------------------------------------------------------
# Create hd-joe wrapper
# ------------------------------------------------------------
info "Creating hd-joe wrapper"
cat > "$HD_JOE_WRAPPER" <<EOF
#!/usr/bin/env bash
@@ -297,22 +323,22 @@ EOF
chmod 0755 "$HD_JOE_WRAPPER"
# ------------------------------------------------------------
# Final verification
# Verify files
# ------------------------------------------------------------
info "Verifying installation"
[[ -x "$INSTALLED_JOE" ]] ||
die "Installed JOE is not executable"
[[ -x "$JOE_WRAPPER" ]] ||
die "joe wrapper was not installed"
die "joe wrapper is not executable"
[[ -x "$HDC_WRAPPER" ]] ||
die "hdc wrapper was not installed"
die "hdc wrapper is not executable"
[[ -x "$HD_JOE_WRAPPER" ]] ||
die "hd-joe wrapper was not installed"
[[ -x "$INSTALLED_JOE" ]] ||
die "JOE binary was not installed"
die "hd-joe wrapper is not executable"
[[ -d "$INSTALLED_COMMON" ]] ||
die "hd_common was not installed"
@@ -324,67 +350,67 @@ info "Verifying installation"
die "hd-joe was not installed"
[[ -x "$VENV_DIR/bin/python3" ]] ||
die "Python virtual environment was not installed"
die "Python environment is missing"
# ------------------------------------------------------------
# Test installed Python environment
# ------------------------------------------------------------
info "Testing installed runtime"
# Test that Python can actually see the installed tree.
PYTHONPATH="$PYTHONPATH_VALUE" \
"$PYTHON" -c '
import hd_common.hd_core
print(" Python runtime: OK")
'
# Test JOE itself.
"$INSTALLED_JOE" --version >/dev/null 2>&1 || {
echo "WARNING: JOE --version test failed"
}
# ------------------------------------------------------------
# Test JOE binary
# ------------------------------------------------------------
info "Testing installed JOE"
if "$INSTALLED_JOE" --version >/dev/null 2>&1; then
echo " JOE: OK"
else
echo " WARNING: JOE --version failed"
fi
# ------------------------------------------------------------
# Done
# ------------------------------------------------------------
cat <<EOF
============================================================
Installation complete
============================================================
Runtime:
$INSTALL_DIR
Commands:
$JOE_WRAPPER
$HDC_WRAPPER
$HD_JOE_WRAPPER
Installed components:
JOE:
$INSTALLED_JOE
Common:
$INSTALLED_COMMON
HedgeDoc CLI:
$INSTALLED_HDC
HedgeDoc JOE:
$INSTALLED_HD_JOE
Python environment:
$VENV_DIR
No system files were modified.
No sudo was required.
The installation is independent of:
$SCRIPT_DIR
You can therefore remove the source tree after verifying
the installation.
If ~/.local/bin is not already in PATH, add:
export PATH="$HOME/.local/bin:\$PATH"
============================================================
EOF
echo
echo "============================================================"
echo "Installation complete"
echo "============================================================"
echo
echo "Runtime:"
echo " $INSTALL_DIR"
echo
echo "Commands:"
echo " $JOE_WRAPPER"
echo " $HDC_WRAPPER"
echo " $HD_JOE_WRAPPER"
echo
echo "Installed:"
echo " $INSTALLED_JOE"
echo " $INSTALLED_COMMON"
echo " $INSTALLED_HDC"
echo " $INSTALLED_HD_JOE"
echo " $VENV_DIR"
echo
echo "No sudo was used."
echo "System JOE was not modified."
echo
echo "The installation is independent of:"
echo " $SCRIPT_DIR"
echo
echo "You can remove the source tree after verifying the"
echo "installed commands."
echo
echo "If ~/.local/bin is not in PATH:"
echo
echo ' export PATH="$HOME/.local/bin:$PATH"'
echo
echo "============================================================"