#!/bin/bash
# Install systemd service files

set -e

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DEPLOYMENT_DIR="$( cd "$SCRIPT_DIR/.." && pwd )"

echo "Installing systemd service files..."

# Copy service files
cp "$DEPLOYMENT_DIR/systemd/explorer-indexer.service" /etc/systemd/system/
cp "$DEPLOYMENT_DIR/systemd/explorer-api.service" /etc/systemd/system/
cp "$DEPLOYMENT_DIR/systemd/solacescanscout-frontend.service" /etc/systemd/system/
cp "$DEPLOYMENT_DIR/systemd/cloudflared.service" /etc/systemd/system/

# Set permissions
chmod 644 /etc/systemd/system/explorer-*.service
chmod 644 /etc/systemd/system/solacescanscout-frontend.service
chmod 644 /etc/systemd/system/cloudflared.service

# Reload systemd
systemctl daemon-reload

echo "Service files installed. Enable with:"
echo "  systemctl enable explorer-indexer explorer-api solacescanscout-frontend"
echo "  systemctl start explorer-indexer explorer-api solacescanscout-frontend"
