Fix web dashboard config path and install script robustness

- Fix GNIZA_CONFIG_DIR in systemd service: /usr/local/gniza/etc -> /etc/gniza
- Add LOG_DIR and PYTHONPATH to systemd environment
- Fix default CONFIG_DIR in web/app.py and web/__main__.py
- Refactor install.sh web setup into function for robustness
- Replace Unicode box-drawing chars with ASCII in install.sh
- Read from /dev/tty to prevent stdin issues

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
shuki
2026-03-06 05:55:33 +02:00
parent a868143eca
commit 3464a0d19f
4 changed files with 37 additions and 27 deletions

View File

@@ -7,7 +7,9 @@ Type=simple
ExecStart=/usr/bin/python3 -m web
WorkingDirectory=/usr/local/gniza
Environment=GNIZA_DIR=/usr/local/gniza
Environment=GNIZA_CONFIG_DIR=/usr/local/gniza/etc
Environment=GNIZA_CONFIG_DIR=/etc/gniza
Environment=LOG_DIR=/var/log/gniza
Environment=PYTHONPATH=/usr/local/gniza
Restart=on-failure
RestartSec=5

View File

@@ -3,7 +3,7 @@ set -eo pipefail
REPO_URL="https://git.linux-hosting.co.il/shukivaknin/gniza4linux.git"
# Colors force enable when piped (curl | bash), since output still goes to terminal
# Colors - force enable when piped (curl | bash), since output still goes to terminal
C_GREEN=$'\033[0;32m'
C_RED=$'\033[0;31m'
C_YELLOW=$'\033[0;33m'
@@ -15,7 +15,7 @@ warn() { echo "${C_YELLOW}[WARN]${C_RESET} $*" >&2; }
error() { echo "${C_RED}[ERROR]${C_RESET} $*" >&2; }
die() { error "$1"; exit 1; }
# ── Determine install mode ───────────────────────────────────
# -- Determine install mode -----------------------------------
if [[ $EUID -eq 0 ]]; then
MODE="root"
INSTALL_DIR="/usr/local/gniza"
@@ -38,7 +38,7 @@ info "Config dir: $CONFIG_DIR"
info "Log dir: $LOG_DIR"
echo ""
# ── Determine source ────────────────────────────────────────
# -- Determine source ----------------------------------------
SOURCE_DIR=""
# Check if running from a local clone (won't work when piped via curl)
@@ -62,7 +62,7 @@ if [[ -z "$SOURCE_DIR" ]]; then
SOURCE_DIR="$TMPDIR/gniza4linux"
fi
# ── Check dependencies ──────────────────────────────────────
# -- Check dependencies --------------------------------------
info "Checking dependencies..."
for cmd in bash rsync; do
if ! command -v "$cmd" &>/dev/null; then
@@ -76,7 +76,7 @@ for cmd in ssh curl; do
fi
done
# ── Install files ────────────────────────────────────────────
# -- Install files --------------------------------------------
info "Installing to $INSTALL_DIR..."
mkdir -p "$INSTALL_DIR"
@@ -104,7 +104,7 @@ fi
# Make entrypoint executable
chmod +x "$INSTALL_DIR/bin/gniza"
# ── Install Python TUI dependencies ─────────────────────────
# -- Install Python TUI dependencies -------------------------
if command -v python3 &>/dev/null; then
info "Installing Python TUI dependencies (textual, textual-serve, flask)..."
if python3 -m pip install --break-system-packages textual textual-serve flask 2>/dev/null; then
@@ -119,12 +119,12 @@ else
warn "python3 not found. TUI mode will not be available."
fi
# ── Create symlink ───────────────────────────────────────────
# -- Create symlink -------------------------------------------
info "Creating symlink: $BIN_LINK -> $INSTALL_DIR/bin/gniza"
mkdir -p "$(dirname "$BIN_LINK")"
ln -sf "$INSTALL_DIR/bin/gniza" "$BIN_LINK"
# ── Create config directories ───────────────────────────────
# -- Create config directories -------------------------------
info "Setting up config directory: $CONFIG_DIR"
mkdir -p "$CONFIG_DIR/targets.d"
mkdir -p "$CONFIG_DIR/remotes.d"
@@ -137,15 +137,15 @@ if [[ "$MODE" == "root" ]]; then
chmod 700 "$CONFIG_DIR/schedules.d"
fi
# ── Create log directory ─────────────────────────────────────
# -- Create log directory -------------------------------------
info "Setting up log directory: $LOG_DIR"
mkdir -p "$LOG_DIR"
# ── Create work directory ───────────────────────────────────
# -- Create work directory -----------------------------------
info "Setting up work directory: $WORK_DIR"
mkdir -p "$WORK_DIR"
# ── Copy example configs (if not already present) ────────────
# -- Copy example configs (if not already present) ------------
if [[ ! -f "$CONFIG_DIR/gniza.conf" ]]; then
cp "$INSTALL_DIR/etc/gniza.conf.example" "$CONFIG_DIR/gniza.conf"
info "Created default config: $CONFIG_DIR/gniza.conf"
@@ -159,24 +159,24 @@ for example in target.conf.example remote.conf.example schedule.conf.example; do
fi
done
# ── Web dashboard setup ─────────────────────────────────────
enable_web="n"
read -rp "Enable web dashboard? (y/n) [n]: " enable_web || true
if [ "$enable_web" = "y" ] || [ "$enable_web" = "Y" ]; then
# Update config
if grep -q "^WEB_ENABLED=" "$CONFIG_DIR/gniza.conf" 2>/dev/null; then
sed -i 's|^WEB_ENABLED=.*|WEB_ENABLED="yes"|' "$CONFIG_DIR/gniza.conf"
# -- Web dashboard setup --
setup_web_dashboard() {
local conf="$CONFIG_DIR/gniza.conf"
# Update config: WEB_ENABLED
if grep -q "^WEB_ENABLED=" "$conf" 2>/dev/null; then
sed -i 's|^WEB_ENABLED=.*|WEB_ENABLED="yes"|' "$conf"
else
echo 'WEB_ENABLED="yes"' >> "$CONFIG_DIR/gniza.conf"
echo 'WEB_ENABLED="yes"' >> "$conf"
fi
# Generate random API key
local api_key
api_key="$(python3 -c 'import secrets; print(secrets.token_urlsafe(32))')"
if grep -q "^WEB_API_KEY=" "$CONFIG_DIR/gniza.conf" 2>/dev/null; then
sed -i "s|^WEB_API_KEY=.*|WEB_API_KEY=\"${api_key}\"|" "$CONFIG_DIR/gniza.conf"
if grep -q "^WEB_API_KEY=" "$conf" 2>/dev/null; then
sed -i "s|^WEB_API_KEY=.*|WEB_API_KEY=\"${api_key}\"|" "$conf"
else
echo "WEB_API_KEY=\"${api_key}\"" >> "$CONFIG_DIR/gniza.conf"
echo "WEB_API_KEY=\"${api_key}\"" >> "$conf"
fi
echo "Web API key: $api_key"
info "Web API key: $api_key"
echo "Save this key -- you will need it to log into the dashboard."
# Install systemd service (root only)
if [ "$MODE" = "root" ]; then
@@ -184,9 +184,17 @@ if [ "$enable_web" = "y" ] || [ "$enable_web" = "Y" ]; then
else
warn "Systemd service installation requires root. Start manually: gniza web start"
fi
}
enable_web="n"
if [ -t 0 ]; then
read -rp "Enable web dashboard? (y/n) [n]: " enable_web </dev/tty || true
fi
if [ "$enable_web" = "y" ] || [ "$enable_web" = "Y" ]; then
setup_web_dashboard
fi
# ── Done ─────────────────────────────────────────────────────
# -- Done -----------------------------------------------------
echo ""
echo "${C_GREEN}${C_BOLD}Installation complete!${C_RESET}"
echo ""

View File

@@ -4,7 +4,7 @@ from pathlib import Path
from web.app import create_app, parse_conf
CONFIG_DIR = Path(os.environ.get("GNIZA_CONFIG_DIR", "/usr/local/gniza/etc"))
CONFIG_DIR = Path(os.environ.get("GNIZA_CONFIG_DIR", "/etc/gniza"))
def main():

View File

@@ -10,7 +10,7 @@ from flask import (
session, jsonify, flash,
)
CONFIG_DIR = Path(os.environ.get("GNIZA_CONFIG_DIR", "/usr/local/gniza/etc"))
CONFIG_DIR = Path(os.environ.get("GNIZA_CONFIG_DIR", "/etc/gniza"))
LOG_DIR = Path(os.environ.get("LOG_DIR", "/var/log/gniza"))