#!/bin/sh
set -e

if command -v update-desktop-database >/dev/null 2>&1; then
    update-desktop-database -q /usr/share/applications || true
fi
if command -v udevadm >/dev/null 2>&1; then
    modprobe uinput 2>/dev/null || true
    modprobe uhid 2>/dev/null || true
    udevadm control --reload-rules || true
    udevadm trigger --name-match=uinput || true
    udevadm trigger --name-match=uhid || true
fi

if command -v ufw >/dev/null 2>&1 && ufw status | grep -q '^Status: active'; then
    ufw allow 48300/tcp comment 'SUN Stream Engine' || true
    ufw allow 48301/udp comment 'SUN Stream Host Discovery' || true
    ufw allow 48301/tcp comment 'SUN Stream Host Control' || true
    ufw allow 48302/tcp comment 'SUN Stream Desktop Input' || true
fi
