summaryrefslogtreecommitdiff
path: root/net/remarkable-devd/files/remarkable.in
blob: b7c4aaa6d082ac6e073021381327017356067e5d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/sh
#
# PROVIDE: remarkable
# REQUIRE: FILESYSTEMS netif
# BEFORE: devd
# KEYWORD: shutdown

. /etc/rc.subr

name=remarkable
rcvar=remarkable_enable
load_rc_config $name

devd_device=${2}
start_cmd="${name}_start"

remarkable_start_devd()
{
    # Find the USB Ethernet for the device
    # We first grab the total number of interfaces in
    # the case when all the interfaces are USB Ethernet
    local total_ifs=`sysctl -n net.link.generic.system.ifcount`
    local i=0
    for i in $(seq 0 $total_ifs)
    do
	ueparent=`sysctl -n net.ue.$i.%parent`
	if [ $? -eq 0 ] && [ $ueparent = $devd_device ]; then
	    /sbin/dhclient ue$i
	    return
	fi
    done
    echo "Couldn't find a remarkable tablet."
}

remarkable_start()
{
    if [ "$devd_device" ]; then
	remarkable_start_devd
    else
	echo "Plug in your Remarkable to connect to it" 
    fi
}

run_rc_command "$1"