#!/usr/bin/env /lib/runit/invoke-run
set -e

NAME="gpm"
DAEMON=/usr/sbin/gpm
CFG=/etc/gpm.conf

# Exit service if DAEMON is not installed
if [ ! -x $DAEMON ]; then
	exit 161
fi

# Create options based on config file
if [ -r $CFG ]; then
    . $CFG
    if [ -n "$device" ]; then DAEMON_OPTS="$DAEMON_OPTS -m $device"; fi
    if [ -n "$type" ]; then DAEMON_OPTS="$DAEMON_OPTS -t $type"; fi
    if [ -n "$responsiveness" ]; then DAEMON_OPTS="$DAEMON_OPTS -r $responsiveness"; fi
    if [ -n "$sample_rate" ]; then DAEMON_OPTS="$DAEMON_OPTS -s $sample_rate"; fi
    # Yes, this /IS/ correct! There is no space after -R!!!!!!
    # I reserve the right to throw manpages at anyone who disagrees.
    if [ -n "$repeat_type" ] && [ "$repeat_type" != "none" ]; then
        DAEMON_OPTS="$DAEMON_OPTS -R$repeat_type"
    fi
    if [ -n "$append" ]; then DAEMON_OPTS="$DAEMON_OPTS $append"; fi
    # If both the second device and type are specified, use it.
    if [ -n "$device2" ] && [ -n "$type2" ] ; then
        DAEMON_OPTS="$DAEMON_OPTS -M -m $device2 -t $type2"
    fi
fi

#~ exec 2>&1
exec 1>&2

exec $DAEMON -D ${DAEMON_OPTS} > /dev/null

#~ exec $DAEMON -D -m /dev/input/mouse0 -t imps2 
