applications/luci-statistics: prepare lucid configuration on firstboot
[project/luci.git] / applications / luci-statistics / root / etc / init.d / luci_statistics
1 #!/bin/sh /etc/rc.common
2 START=79
3
4 boot() {
5         ### prepare publisher
6         if ! uci get lucid.rrdimg >/dev/null 2>/dev/null; then
7                 uci batch <<-EOF
8 set lucid.rrdimg=DirectoryPublisher
9 set lucid.rrdimg.name='Statistics Images'
10 set lucid.rrdimg.physical=/tmp/rrdimg
11 set lucid.rrdimg.virtual=/rrdimg
12 set lucid.rrdimg.domain=''
13
14 add_list lucid.http.publisher=rrdimg
15 add_list lucid.https.publisher=rrdimg   
16
17 commit lucid
18 EOF
19                 /etc/init.d/lucid restart
20         fi
21
22         start
23 }
24
25 start() {
26         ### replace shipped config with symlink
27         if [ ! -L /etc/collectd.conf ]; then
28                 test -f /etc/collectd.conf && mv /etc/collectd.conf /etc/collectd.conf.bak
29                 ln -s /var/etc/collectd.conf /etc/collectd.conf
30         fi
31
32         ### create config
33         mkdir -p /var/etc
34         /usr/bin/stat-genconfig > /var/etc/collectd.conf
35
36         ### prepare rrdimg directory
37         if [ "$(uci get luci_statistics.rrdtool.image_path 2>/dev/null)" != "$(uci get lucid.rrdimg.physical 2>/dev/null)" ]; then
38                 uci set lucid.rrdimg.physical=$(uci get luci_statistics.rrdtool.image_path)
39                 uci commit lucid
40                 /etc/init.d/lucid restart
41         fi
42
43         ### flush LuCI index cache
44         test -f /var/luci-indexcache && rm /var/luci-indexcache
45
46         ### workaround broken permissions on /tmp
47         chmod 1777 /tmp
48 }
49
50 restart() {
51         ### regenerate config / prepare environment
52         start
53
54         ### restart collectd
55         /etc/init.d/collectd restart
56 }