[patch-team] - This adds support for channels in znc configuration - Signed-off-by...
[openwrt/svn-archive/archive.git] / net / znc / files / znc.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2010 Openwrt.org
3
4 START=60
5
6 PID_FILE=/tmp/etc/znc/znc.pid
7 ZNC_CONFIG=/tmp/etc/znc/configs/znc.conf
8
9 add_param() {
10 echo "$1 = $2" >> $ZNC_CONFIG
11 }
12
13 add_chan() {
14 chan=${2% *}
15 pass=${1#* }
16 echo " <Chan $chan>" >> $ZNC_CONFIG
17 [ "$chan" != "$pass" ] && echo " Key = $pass" >> $ZNC_CONFIG
18 echo " </Chan>" >> $ZNC_CONFIG
19 }
20
21 znc_global() {
22 local znc="$1"
23 local anoniplimit
24 local maxbuffersize
25 local connectdelay
26 local serverthrottle
27
28
29 config_get anoniplimit "$znc" anoniplimit
30 config_get maxbuffersize "$znc" maxbuffersize
31 config_get connectdelay "$znc" connectdelay
32 config_get serverthrottle "$znc" serverthrottle
33
34 [ -z $anoniplimit ] || echo "AnonIPLimit = $anoniplimit" >> $ZNC_CONFIG
35 [ -z $maxbuffersize ] || echo "MaxBufferSize = $maxbuffersize" >> $ZNC_CONFIG
36 [ -z $connectdelay ] || echo "ConnectDelay = $connectdelay" >> $ZNC_CONFIG
37 [ -z $serverthrottle ] || echo "ServerThrottle = $anoniplimit" >> $ZNC_CONFIG
38
39 echo "PidFile = $PID_FILE" >> $ZNC_CONFIG
40
41 config_list_foreach "$znc" listener "add_param Listener"
42 config_list_foreach "$znc" module "add_param LoadModule"
43
44 add_param LoadModule "droproot nobody nogroup"
45 }
46
47 add_user() {
48 local user="$1"
49 local password
50 local nick
51 local altnick
52 local ident
53 local realname
54 local buffer
55 local quitmsg
56 local chanmodes
57 local vhost
58
59 config_get password "$user" password
60 config_get nick "$user" nick
61 config_get altnick "$user" altnick
62 config_get ident "$user" ident
63 config_get realname "$user" realname
64 config_get buffer "$user" buffer
65 config_get quitmsg "$user" quitmsg
66 config_get chanmodes "$user" chanmodes
67 config_get vhost "$user" vhost
68
69 echo "<User $user>" >> $ZNC_CONFIG
70 echo " Pass = plain#$password" >> $ZNC_CONFIG
71 echo " Nick = $nick" >> $ZNC_CONFIG
72 echo " AltNick = ${altnick:-$nick"_"}" >> $ZNC_CONFIG
73 echo " Ident = ${ident:-$nick}" >> $ZNC_CONFIG
74 echo " RealName = ${realname:-$nick}" >> $ZNC_CONFIG
75 [ -z "$vhost" ] || echo " VHost = $vhost" >> $ZNC_CONFIG
76 echo " Buffer = ${buffer:-50}" >> $ZNC_CONFIG
77 echo " KeepBuffer = false" >> $ZNC_CONFIG
78 echo " ChanModes = ${chanmodes:-"+stn"}" >> $ZNC_CONFIG
79 [ -z "$quitmsg" ] || echo " QuitMsg = $quitmsg" >> $ZNC_CONFIG
80
81 config_list_foreach "$user" server "add_param \" Server\""
82 config_list_foreach "$user" module "add_param \" LoadModule\""
83 config_list_foreach "$user" channel "add_chan"
84 echo "</User>" >> $ZNC_CONFIG
85 }
86
87
88 start() {
89 mkdir -p /tmp/etc/znc/configs/
90 [ -f "$ZNC_CONFIG" ] && rm "$ZNC_CONFIG"
91 config_load znc
92 config_foreach znc_global znc
93 config_foreach add_listener listener
94 config_foreach add_user user
95
96 chown -R nobody:nogroup /tmp/etc/znc
97 /usr/bin/znc -d/tmp/etc/znc -r >/dev/null &
98 }
99
100 stop() {
101 [ -f "$PID_FILE" ] && kill $(cat "$PID_FILE")
102 }
103