#!/bin/sh
### BEGIN INIT INFO
# Provides:          retrodebian-xorg-autoconfig
# Required-Start:    $local_fs
# Required-Stop:
# Default-Start:     S
# Default-Stop:
# Short-Description: Generate xorg.conf for RetroDebian at boot
# Description:       Detect video hardware and generate /etc/X11/xorg.conf
### END INIT INFO

FLAG_FILE="/var/lib/retrodebian/xorg-autoconfig.done"
XORG_CONF="/etc/X11/xorg.conf"
AUTOCONFIG_BIN="/opt/retrodebian/xorg/autoconfig.sh"

case "$1" in
    start)
        [ -f "$FLAG_FILE" ] && exit 0
        [ -x "$AUTOCONFIG_BIN" ] || exit 0

        mkdir -p /var/lib/retrodebian || exit 0

        "$AUTOCONFIG_BIN" "$XORG_CONF" || exit 0
        touch "$FLAG_FILE" || exit 0
        ;;
    stop|restart|force-reload)
        ;;
    *)
        echo "Usage: $0 start" >&2
        exit 1
        ;;
esac

exit 0