#!/bin/bash set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" USER_NAME="$(whoami)" VM_DIR="/opt/victoriametrics" echo "🔧 Setting up Weather Station..." # ── VictoriaMetrics ─────────────────────────────────────────────────────────── if ! systemctl is-enabled --quiet victoriametrics 2>/dev/null; then echo "📦 Installing VictoriaMetrics..." sudo mkdir -p $VM_DIR/data cd $VM_DIR wget -qO vm.tar.gz "https://github.com/VictoriaMetrics/VictoriaMetrics/releases/download/v1.146.0/victoria-metrics-linux-arm64-v1.146.0.tar.gz" sudo tar -xzf vm.tar.gz sudo chmod +x $VM_DIR/victoria-metrics-prod rm /tmp/vm.tar.gz sudo tee /etc/systemd/system/victoriametrics.service > /dev/null < /dev/null; then echo "📦 Installing Node.js..." curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - sudo apt install -y nodejs else echo "✅ Node.js already installed, skipping..." fi if [ ! -d "$SCRIPT_DIR/server/public/index.html" ]; then echo "🌐 Building Client..." cd "$SCRIPT_DIR/client" npm ci npx vite build else echo "✅ Client installed, skipping..." fi if [ ! -d "$SCRIPT_DIR/server/node_modules" ]; then echo "🌐 Installing Server..." cd "$SCRIPT_DIR/server" npm ci else echo "✅ Server installed, skipping..." fi if ! systemctl is-enabled --quiet weather-station 2>/dev/null; then echo "⚙️ Installing server service..." sudo tee /etc/systemd/system/weather-station.service > /dev/null </dev/null; then echo "⚙️ Installing sensor service..." sudo tee /etc/systemd/system/weather-sensors.service > /dev/null <