aboutsummaryrefslogtreecommitdiff
path: root/opt.local
blob: 506967a726ad4c958e9f07c821004791df7da85f (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# Copyright(c) 2019 Bjørn Mork <bjorn@mork.no>

PATH=$PATH:/opt
export LD_LIBRARY_PATH=/opt:$LD_LIBRARY_PATH
VERSION=$(cat /opt/version)

die() {
	echo $@
	exit 1
}

showUsage() {
	die "$0 {start|stop|restart|status}"
}

action=$1

start() {
	echo "opt.local version $VERSION"

	echo "Make sure there is an admin account with the pincode as password"
	grep -Eq ^admin: /etc/passwd || echo admin:x:0:0::/:/bin/sh >>/etc/passwd
	grep -Eq ^admin:x: /etc/passwd && echo "admin:$(pibinfo Pincode)" | chpasswd

	echo "Starting telnetd"
	pidof telnetd || telnetd

	[ -n "$(tdb get HTTPAccount AdminPasswd_ss)" ] || tdb set HTTPAccount AdminPasswd_ss="$(pibinfo Pincode)"
	/etc/rc.d/init.d/extra_lighttpd.sh start

	[ "$(tdb get RTPServer RejectExtIP_byte)" -eq "0" ] || {
	    echo "Making RTSP accessible from the outside, with authentication enabled"
	    tdb set RTPServer RejectExtIP_byte=0
            [ "$(tdb get RTPServer Authenticate_byte)" -eq "1" ] || tdb set RTPServer Authenticate_byte=1
            /etc/rc.d/init.d/firewall.sh reload
	    /etc/rc.d/init.d/rtspd.sh restart
	}
}

stop() {
	killall -TERM telnetd
	/etc/rc.d/init.d/extra_lighttpd.sh stop
}

status() {
    echo -n "telnetd pid is " &&  pidof telnetd
    /etc/rc.d/init.d/extra_lighttpd.sh status
    /etc/rc.d/init.d/firewall.sh status
    /etc/rc.d/init.d/rtspd.sh status
}

case $action in
	start)
		start
	;;
	stop)
		stop
	;;
	restart)
		stop
		sleep 1
		start
	;;
	status)
		status
	;;
	*)
		showUsage
	;;
esac

exit 0