#!/bin/bash
# chmod +x debian/postinst

set -e

case "$1" in
    configure)
        # Создаем директории
        mkdir -p /var/log/gpio-monitoring
        mkdir -p /var/lib/gpio-monitoring
        mkdir -p /opt/gpio-monitoring/web

        # Устанавливаем права
        chown -R gpio-monitor:gpio-monitor /var/log/gpio-monitoring
        chown -R gpio-monitor:gpio-monitor /var/lib/gpio-monitoring
        chown -R gpio-monitor:gpio-monitor /opt/gpio-monitoring

        # Перезагружаем systemd
        systemctl daemon-reload 2>/dev/null || true

        # Включаем сервис, но не запускаем автоматически
        systemctl enable gpio-monitor-server.service 2>/dev/null || true
        systemctl start gpio-monitor-server.service

        # Создаем symlink для логов
        ln -sf /var/log/gpio-monitoring /opt/gpio-monitoring/logs 2>/dev/null || true

        echo "GPIO Monitor Server установлен"
        echo "Для запуска: sudo systemctl start gpio-monitor-server"
        ;;
esac

exit 0
