#!/usr/bin/env bash
set -euo pipefail

SRC_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Binaries
install -d /usr/bin
install -m 755 "$SRC_DIR/qrng-xdma" /usr/bin/gq-qrng-daemon
install -m 755 "$SRC_DIR/gq-tools" /usr/bin/gq-tools

# Library
install -d /usr/lib
install -m 755 "$SRC_DIR/libtcti-gq.so" /usr/lib/libtss2-tcti-gq.so

# Systemd service
install -d /etc/systemd/system
install -m 644 "$SRC_DIR/gq-accel-qrng.service" \
    /etc/systemd/system/gq-accel-qrng.service

# Refresh linker cache
ldconfig

# Reload systemd
systemctl daemon-reload

echo "Installation complete."
echo "Enable service with:"
echo "  systemctl enable gq-accel-qrng.service"
echo "Start service with:"
echo "  systemctl start gq-accel-qrng.service"
