diff --git a/lib/common.sh b/lib/common.sh index a80ad63..ea68faa 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -96,6 +96,41 @@ save_site_config() { # Load immediately so all service modules inherit the values when sourced load_site_config +# ── OS detection ───────────────────────────────────────────────────────────── +OS_DISTRO="unknown" +OS_VERSION="unknown" +OS_CODENAME="unknown" + +detect_os() { + [ -f /etc/os-release ] || return 0 + local key val + while IFS='=' read -r key val; do + val="${val//\"/}" + case "$key" in + ID) OS_DISTRO="$val" ;; + VERSION_ID) OS_VERSION="$val" ;; + VERSION_CODENAME|UBUNTU_CODENAME) + [ "$OS_CODENAME" = "unknown" ] && OS_CODENAME="$val" ;; + esac + done < /etc/os-release + export OS_DISTRO OS_VERSION OS_CODENAME +} + +# Return 0 (true) if the detected Ubuntu version is >= the argument (e.g., "24.04"). +ubuntu_version_ge() { + [ "$OS_DISTRO" = "ubuntu" ] || return 1 + local a="${OS_VERSION//./}" b="${1//./}" + [ "${a:-0}" -ge "${b:-0}" ] 2>/dev/null +} + +# pip install --user as actual user. +# Centralised so any future version-specific pip flags land in one place. +pip_user_install() { + sudo -u "$ACTUAL_USER" pip3 install --user --quiet "$@" +} + +detect_os + # ── Pre-flight ─────────────────────────────────────────────────────────────── require_root() { if [ "${EUID:-$(id -u)}" -ne 0 ]; then diff --git a/services/sky-cam.sh b/services/sky-cam.sh index 985c0cd..fa27fba 100644 --- a/services/sky-cam.sh +++ b/services/sky-cam.sh @@ -43,8 +43,7 @@ install_sky-cam() { # ── Python packages ────────────────────────────────────────────────────── log_info "Installing Python packages..." - local PIP="pip3 install --user --quiet" - sudo -u "$ACTUAL_USER" $PIP suntime pytz requests skyfield Pillow numpy scipy \ + pip_user_install suntime pytz requests skyfield Pillow numpy scipy \ || log_warning "Some pip packages may have failed — check output above" log_success "Python packages installed" diff --git a/services/sync-cc.sh b/services/sync-cc.sh index 7117be7..4b3592c 100644 --- a/services/sync-cc.sh +++ b/services/sync-cc.sh @@ -48,10 +48,8 @@ install_sync-cc() { log_success "System packages installed" # ── pip packages ───────────────────────────────────────────────────────── - # Install as the actual (non-root) user so packages land in ~/.local log_info "Installing Python packages (openai-whisper, ffsubsync)..." - local PIP_CMD="pip3 install --user --quiet openai-whisper ffsubsync" - if sudo -u "$ACTUAL_USER" $PIP_CMD; then + if pip_user_install openai-whisper ffsubsync; then log_success "Python packages installed" else log_warning "pip install reported errors — the tool may still work if packages were partially installed" diff --git a/setup.sh b/setup.sh index a4e83c1..dc082e7 100755 --- a/setup.sh +++ b/setup.sh @@ -153,12 +153,13 @@ fi require_root _VER="$(cat "$HERE/VERSION" 2>/dev/null || echo '?')" +_OS_LINE="${OS_DISTRO^} ${OS_VERSION} (${OS_CODENAME})" if is_installed base; then # ── Re-run: base already present — skip required step ──────────────────── echo "" echo "╔══════════════════════════════════════════════════════════════╗" - echo "║ Ubuntu Post-Install · v${_VER}" + echo "║ Ubuntu Post-Install · v${_VER} · ${_OS_LINE}" echo "╚══════════════════════════════════════════════════════════════╝" echo "" echo " Base packages already installed — skipping required setup." @@ -168,9 +169,16 @@ else # ── First run: show required banner, confirm, install ──────────────────── echo "" echo "╔══════════════════════════════════════════════════════════════╗" - echo "║ Ubuntu Post-Install · v${_VER}" + echo "║ Ubuntu Post-Install · v${_VER} · ${_OS_LINE}" echo "╚══════════════════════════════════════════════════════════════╝" echo "" + if [ "$OS_DISTRO" != "ubuntu" ]; then + log_warning "Detected OS: ${_OS_LINE} — this script targets Ubuntu. Proceed with caution." + echo "" + elif ! ubuntu_version_ge "24.04"; then + log_warning "Ubuntu ${OS_VERSION} detected — tested on 24.04+. Some packages may differ." + echo "" + fi echo "REQUIRED (installed/verified first):" echo " • Essential CLI packages: net-tools, git, curl, wget, htop, tree," echo " ncdu, zip/unzip, jq, rsync, and glow (markdown reader)"