diff --git a/install.sh b/install.sh index a035a6e..4875246 100755 --- a/install.sh +++ b/install.sh @@ -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 <&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,28 +129,28 @@ 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 +$BUILT Run ./build.sh first." @@ -156,15 +159,17 @@ Run ./build.sh first." # ------------------------------------------------------------ if [[ -e "$INSTALL_DIR" ]]; then + if [[ "$FORCE" -ne 1 ]]; then die "Installation already exists: - $INSTALL_DIR +$INSTALL_DIR 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" < "$HDC_WRAPPER" < "$HD_JOE_WRAPPER" </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 <