#!/sbin/openrc-run

description="Lenovo Yoga Book BCM4752 GNSS transport"

command="/usr/libexec/yogabook-gnss-run"
command_background=false

supervisor="supervise-daemon"
supervise_daemon_args="--respawn-delay 5 --respawn-max 3 --respawn-period 60"

depend() {
    need localmount
    use udev
    before gpsd-yogabook
}

start_pre() {
    if [ ! -x /var/lib/yogabook-gnss/root/system/vendor/bin/gpsd ]; then
        eerror "Import the proprietary GNSS runtime first."
        eerror "Run: yogabook-gnss-import"
        return 1
    fi

    if [ ! -c /dev/ttyS5 ]; then
        eerror "GNSS serial device /dev/ttyS5 is missing."
        return 1
    fi
}