Add OS detection; surface version in header; centralise pip installs

lib/common.sh:
  - detect_os(): reads /etc/os-release into OS_DISTRO, OS_VERSION,
    OS_CODENAME globals (exported, auto-called on source)
  - ubuntu_version_ge(): numeric version comparison helper
  - pip_user_install(): central wrapper for pip3 install --user so any
    future version-specific flags are in one place

setup.sh:
  - Both header banners now show detected OS line (e.g., "Ubuntu 24.04 (noble)")
  - First-run path warns if not Ubuntu or < 24.04

services/sky-cam.sh, services/sync-cc.sh:
  - Replace inline pip3 invocations with pip_user_install helper

https://claude.ai/code/session_01Y4dMKtkqkpvmgDKoRdzhTG
This commit is contained in:
Claude
2026-06-03 23:49:51 +00:00
parent 370c513606
commit ef08fef540
4 changed files with 47 additions and 7 deletions
+35
View File
@@ -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
+1 -2
View File
@@ -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"
+1 -3
View File
@@ -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"
+10 -2
View File
@@ -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)"