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

if [[ ${EUID:-$(id -u)} -ne 0 ]]; then
    echo "Run with sudo: sudo otcred-setup" >&2
    exit 1
fi

client=/opt/otcred/otcred_linux_xrdp_qr
hook=/opt/otcred/libotcred_xrdp_hook.so
if [[ ! -x "$client" || ! -r "$hook" ]]; then
    echo "OT Cred client files are missing; reinstall the otcred-linux RPM." >&2
    exit 1
fi

if ! command -v xrdp >/dev/null 2>&1; then
    echo "XRDP is required. Install XRDP first, then run sudo otcred-setup." >&2
    exit 1
fi

cd /
exec "$client" --install
