summaryrefslogtreecommitdiffstats
path: root/net/baresip/files/baresip.init
blob: 17efa67d061e0b3b7b9581b7962038679a167920 (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
#!/bin/sh /etc/rc.common
# Copyright (C) 2017 OpenWrt.org

START=92
USE_PROCD=1
PROG=/usr/bin/baresip
ACCOUNTS=

add_account()
{
	local user password server transport append ignore mediaenc
	local acc

	uci_validate_section baresip account "${1}" \
		'ignore:bool:0' \
		'user:string' \
		'password:string' \
		'server:string' \
		'transport:string:udp' \
		'mediaenc:string' \
		'append:string'

	[ "$ignore" = "0" ] || return

	acc="<sip:${user}@${server};transport=${transport}>"
	[ -n "$mediaenc" ] && acc="${acc};mediaenc=${mediaenc}"
	[ -n "$password" ] && acc="${acc};auth_pass=${password}"
	[ -n "$append" ] && acc="${acc};${append}"

	ACCOUNTS="${ACCOUNTS}${acc}\n"
}

start_service()
{
	local enable options

	uci_validate_section baresip baresip main \
		'enable:bool:0' \
		'options:string'

	[ "$enable" = "0" ] && return

	config_load baresip
	config_foreach add_account account
	printf "$ACCOUNTS" > /etc/baresip/accounts

	procd_open_instance
	procd_set_param command $PROG -f /etc/baresip $options
	procd_set_param user baresip
	procd_set_param respawn
	procd_close_instance
}

service_triggers()
{
	procd_add_reload_trigger baresip
}

reload_service()
{
	/etc/init.d/baresip restart
}