#!/usr/bin/env bash set -euo pipefail INSTALL_DIR="/opt/logar-server" CONFIG_DIR="/etc/logar" # Parse command line options while [[ $# -gt 0 ]]; do case "$1" in --config-dir|--data-dir) CONFIG_DIR="$2" shift 2 ;; *) shift ;; esac done echo "============================================================" echo " LOGAR Server Enterprise Linux Installer" echo "============================================================" # 1. Mutual Exclusion Check: Deny installation if LOGAR Client is present if [ -f "/opt/logar-client/Linux_Client" ] || [ -f "/etc/systemd/system/logar-client.service" ]; then echo "[-] Error: LOGAR Client is already installed on this machine." >&2 echo "[-] LOGAR Server cannot be installed on a host where LOGAR Client is present (LOGAR Server includes built-in log collection)." >&2 echo "[-] Please uninstall LOGAR Client first before installing LOGAR Server." >&2 exit 1 fi # 2. Existing LOGAR Server Detection for In-Place Update Mode IS_UPDATE=0 if [ -f "${INSTALL_DIR}/Server" ] || [ -f "/etc/systemd/system/logar-server.service" ]; then IS_UPDATE=1 echo "[*] Existing LOGAR Server installation detected. Performing in-place upgrade..." fi # Interactive configuration if running in a terminal without CLI arguments (only for fresh install) if [ "${IS_UPDATE}" -eq 0 ] && [ -t 0 ]; then read -r -p "Enter Data and Configuration Directory [${CONFIG_DIR}]: " USER_CFG if [ -n "${USER_CFG}" ]; then CONFIG_DIR="${USER_CFG}" fi fi if [ "${IS_UPDATE}" -eq 1 ] && command -v systemctl >/dev/null 2>&1; then echo "[*] Stopping LOGAR Server service for upgrade..." systemctl stop logar-server.service || true fi mkdir -p "${INSTALL_DIR}" "${CONFIG_DIR}" "/var/log/logar" if [ -f "dist/Server.bin" ]; then cp dist/Server.bin "${INSTALL_DIR}/Server" elif [ -f "dist/Server" ]; then cp dist/Server "${INSTALL_DIR}/Server" elif [ -f "dist/LOGAR_Server" ]; then cp dist/LOGAR_Server "${INSTALL_DIR}/Server" else echo "[!] Warning: dist/Server.bin binary not found in current directory. Continuing with existing binary if present." fi if [ -f "${INSTALL_DIR}/Server" ]; then chmod +x "${INSTALL_DIR}/Server" fi cat < /etc/systemd/system/logar-server.service [Unit] Description=LOGAR Hub and Aggregator Engine After=network.target [Service] Type=simple WorkingDirectory=${INSTALL_DIR} ExecStart=${INSTALL_DIR}/Server --config ${CONFIG_DIR}/server_config.json Restart=always RestartSec=5s User=root LimitNOFILE=65536 [Install] WantedBy=multi-user.target EOF if command -v systemctl >/dev/null 2>&1; then systemctl daemon-reload systemctl enable --now logar-server.service || true echo "[+] LOGAR Server service installed and activated." else echo "[+] Systemd service installed at /etc/systemd/system/logar-server.service" fi