Blueforce-Linux/scripts/install/installer/modules/01-precheck.sh
emirhanmamak-blueforce 8cb0c72065 Enhance installation scripts with root privilege checks and user guidance
- Added a check in `blueforce-install.sh` to ensure the script is run with root privileges, providing user-friendly error messages and guidance for launching with sudo or using check mode.
- Updated `01-precheck.sh` to conditionally require root privileges based on the check mode, allowing for non-root execution in read-only mode.
- Modified test scripts to reflect changes in the installation process, ensuring accurate reporting of the Python console's presence and adjusting expectations accordingly.
2026-09-17 14:35:34 +03:00

78 lines
3.2 KiB
Bash
Executable file
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# Pre-flight checks: root, Ubuntu release, RAM and disk.
#
# Network is informational here and never a gate: an offline install takes its
# packages from the local bundle, so it needs neither the Internet nor the
# central endpoint. Three things are reported separately for the operator:
# 1. local network link — no intent, not used by the install,
# 2. Internet — NOT required for an offline install (no warning),
# 3. central connection — not needed during install; that is the enrollment
# stage's job.
# This module therefore never fails because a network probe failed.
#
# Idempotent: safe to re-run. Supports --check for read-only verification.
# Exit codes: 0 = OK, 3 = SKIP (optional step, nothing to do), 1 = real failure.
set -euo pipefail
MODULE="01-precheck"
LOG_FILE="${LOG_FILE:-/var/log/blueforce-install.log}"
DEALER_ID="${DEALER_ID:-}"
BF_HOSTNAME="${BF_HOSTNAME:-}"
BF_DEVICE="${BF_DEVICE:-}"
STATE_DIR="${STATE_DIR:-/var/lib/blueforce}"
log() {
local msg="$1"
mkdir -p "$(dirname "$LOG_FILE")" 2>/dev/null || true
echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) [01-precheck] $msg" | tee -a "$LOG_FILE"
}
CHECK_MODE=0
if [[ "${1:-}" == "--check" ]]; then CHECK_MODE=1; fi
MIN_RAM_MB=2048
MIN_DISK_MB=20480
fail() { log "FAIL: $1"; echo "FAIL: $1" >&2; exit 1; }
info() { log "BİLGİ: $1"; }
# Read-only network report. Nothing here can fail the install.
report_network() {
if ip -o link show up 2>/dev/null | grep -qv ' lo:'; then
info "yerel ağ: bağlantı var (kurulum için gerekmiyor, kullanılmıyor)"
else
info "yerel ağ: bağlantı görünmüyor (kurulum için gerekmiyor, kullanılmıyor)"
fi
if [[ "${BF_OFFLINE:-0}" == 1 ]]; then
# Offline install: no probe at all, and no warning either.
info "internet: kurulum yerel paket deposundan yapılır; internet GEREKMEZ"
elif getent hosts archive.ubuntu.com >/dev/null 2>&1; then
info "internet: erişilebilir (geliştirme/test kipi)"
else
info "internet: erişilemiyor (bu kurulum için gerekmez)"
fi
info "merkez bağlantısı: kurulum sırasında gerekmez; enrollment aşamasında doğrulanır"
}
run_checks() {
if [[ "$CHECK_MODE" -eq 0 ]]; then
[[ "$(id -u)" -eq 0 ]] || fail "must run as root"
else
info "yönetici yetkisi: salt-okunur denetim; root gerekmiyor"
fi
if [[ -f /etc/os-release ]]; then
# shellcheck disable=SC1091
. /etc/os-release
[[ "${VERSION_ID:-}" == 26.04* ]] || fail "unsupported OS: ${NAME:-unknown} ${VERSION_ID:-unknown} (need Ubuntu 26.04)"
else
fail "/etc/os-release not found"
fi
local ram_mb disk_mb
ram_mb=$(awk '/MemTotal/ {printf "%d", $2/1024}' /proc/meminfo)
[[ "$ram_mb" -ge "$MIN_RAM_MB" ]] || fail "RAM too low: ${ram_mb}MB (need >= ${MIN_RAM_MB}MB)"
disk_mb=$(df -m / --output=avail | tail -1 | tr -d ' ')
[[ "$disk_mb" -ge "$MIN_DISK_MB" ]] || fail "disk too low: ${disk_mb}MB free on / (need >= ${MIN_DISK_MB}MB)"
report_network
log "OK: ön denetim geçti (Ubuntu ${VERSION_ID}, RAM ${ram_mb}MB, disk ${disk_mb}MB boş; yerel kurulum=$([[ "${BF_OFFLINE:-0}" == 1 ]] && echo evet || echo hayır))"
}
run_checks