106 lines
2.7 KiB
Bash
106 lines
2.7 KiB
Bash
#!/bin/bash
|
|
#
|
|
# Veridian Edge Agent Installer
|
|
# For Raspberry Pi / Ubuntu
|
|
#
|
|
|
|
set -e
|
|
|
|
INSTALL_DIR="/opt/veridian-edge"
|
|
SERVICE_NAME="veridian-edge"
|
|
CURRENT_USER="${SUDO_USER:-$USER}"
|
|
|
|
echo "🌱 Veridian Edge Agent Installer"
|
|
echo "================================"
|
|
echo ""
|
|
|
|
# Check if running as root
|
|
if [ "$EUID" -ne 0 ]; then
|
|
echo "⚠️ Please run with sudo: sudo ./install.sh"
|
|
exit 1
|
|
fi
|
|
|
|
# Check for Bun
|
|
if ! command -v bun &> /dev/null; then
|
|
echo "📦 Installing Bun..."
|
|
curl -fsSL https://bun.sh/install | bash
|
|
export BUN_INSTALL="/home/$CURRENT_USER/.bun"
|
|
export PATH="$BUN_INSTALL/bin:$PATH"
|
|
fi
|
|
|
|
echo "✅ Bun installed: $(bun --version)"
|
|
|
|
# Create install directory
|
|
echo "📁 Creating $INSTALL_DIR..."
|
|
mkdir -p "$INSTALL_DIR"
|
|
chown "$CURRENT_USER:$CURRENT_USER" "$INSTALL_DIR"
|
|
|
|
# Copy files (assume running from repo root)
|
|
echo "📋 Copying files..."
|
|
if [ -f "package.json" ]; then
|
|
cp -r ./* "$INSTALL_DIR/"
|
|
else
|
|
echo "❌ Error: Run this script from the veridian-edge repository root"
|
|
exit 1
|
|
fi
|
|
|
|
# Install dependencies
|
|
echo "📦 Installing dependencies..."
|
|
cd "$INSTALL_DIR"
|
|
sudo -u "$CURRENT_USER" bun install
|
|
|
|
# Create config if not exists
|
|
if [ ! -f "$INSTALL_DIR/config.json" ]; then
|
|
echo "📝 Creating config.json from template..."
|
|
cp "$INSTALL_DIR/config.example.json" "$INSTALL_DIR/config.json"
|
|
echo ""
|
|
echo "⚠️ IMPORTANT: Edit $INSTALL_DIR/config.json with your credentials!"
|
|
echo ""
|
|
fi
|
|
|
|
# Create data directory
|
|
mkdir -p "/home/$CURRENT_USER/.local/share/veridian-edge"
|
|
chown "$CURRENT_USER:$CURRENT_USER" "/home/$CURRENT_USER/.local/share/veridian-edge"
|
|
|
|
# Create systemd service
|
|
echo "🔧 Creating systemd service..."
|
|
BUN_PATH="/home/$CURRENT_USER/.bun/bin/bun"
|
|
cat > "/etc/systemd/system/$SERVICE_NAME.service" <<EOF
|
|
[Unit]
|
|
Description=Veridian SensorPush Edge Agent
|
|
After=network-online.target
|
|
Wants=network-online.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=$CURRENT_USER
|
|
WorkingDirectory=$INSTALL_DIR
|
|
ExecStart=$BUN_PATH run src/index.ts
|
|
Restart=always
|
|
RestartSec=10
|
|
WatchdogSec=120
|
|
StandardOutput=journal
|
|
StandardError=journal
|
|
Environment=HOME=/home/$CURRENT_USER
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
# Enable and start service
|
|
echo "🚀 Enabling and starting service..."
|
|
systemctl daemon-reload
|
|
systemctl enable "$SERVICE_NAME"
|
|
|
|
echo ""
|
|
echo "================================"
|
|
echo "✅ Installation complete!"
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo " 1. Edit config: sudo nano $INSTALL_DIR/config.json"
|
|
echo " 2. Start service: sudo systemctl start $SERVICE_NAME"
|
|
echo " 3. Check status: sudo systemctl status $SERVICE_NAME"
|
|
echo " 4. View logs: journalctl -u $SERVICE_NAME -f"
|
|
echo ""
|
|
echo "Health check: curl http://localhost:3030/health"
|
|
echo "================================"
|