#!/bin/sh

export SLINT_BACKEND=linuxkms-software





case "$1" in
    start)
        mode=$(
            SLINT_DRM_MODE=list /usr/bin/winf-photobooth-app 2>&1 |
                awk '$1 == "Index:" && $4 == 1280 && $6 == 1024 {
                    print $2
                    exit
                }'
        )

        if [ -z "$mode" ]; then
            echo "No 1280x1024 display mode available" >&2
            exit 1
        fi

        export SLINT_DRM_MODE="$mode"
        start-stop-daemon -S -b -m \
            -p /run/winf-photobooth-app.pid \
            -x /usr/bin/winf-photobooth-app \
            -O /var/log/winf-photobooth-app.log
        ;;

    stop)
        start-stop-daemon -K -p /run/winf-photobooth-app.pid
        ;;
    restart)
        "$0" stop
        "$0" start
        ;;
esac
