#!/bin/sh

PID_FILE="/var/run/io-mapping.pid"

start() {
    HW_TYPE=$(jq -re .hw_type /tmp/device_features)

    if [ $HW_TYPE == "82" ]; then
        CONF_FILE=/etc/bm44.json
    fi
    barix-wd --pid-file="${PID_FILE}" --start --background -- io-mapping server $CONF_FILE
}

stop() {
    barix-wd --stop --wait --pid-file="${PID_FILE}"
}

case "$1" in
    start)
        start
        ;;

    stop)
        stop
        ;;

    *)
        echo "Usage: $0 {start|stop}"
        exit 1
esac

exit $?
