File: munin-node.preinst

package info (click to toggle)
munin 1.2.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,940 kB
  • ctags: 98
  • sloc: sh: 4,215; makefile: 452; perl: 135
file content (76 lines) | stat: -rw-r--r-- 1,964 bytes parent folder | download | duplicates (2)
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
75
76
#! /bin/bash

set -e

lrrd_sums="
11ba4c57f20b31166cbd3064430506ea:/etc/lrrd/client-conf.d/lrrd-client
8975c4124fdd1209d5732ce0e68578fa:/etc/lrrd/client.conf
"

migrate() {
	local from=$1; shift;
	local to=$1; shift;
	
	[ -r "$from" -a ! -e "$to" ] || return 0;

	for pair in $lrrd_sums; do
		local sum=${pair%:*}
		local file=${pair#*:}

		[ "$file" = "$from" ] || continue;
		
		if [ "$(md5sum $file | cut -f1 -d' ')" = "$sum" ]; then
			return 0;
		fi
	done

	[ -d ${to%/*} ] || mkdir -p ${to%/*}

	cp -dp $from $to

	for subst in $*; do
		perl -pi -e $subst $to
	done
}

convert_from_lrrd() {

	[ -e /etc/lrrd/client.conf ] || return 0;

	echo -n "Creating initial Munin-node configuration based on your LRRD installation.."

	migrate /etc/lrrd/client.conf /etc/munin/munin-node.conf \
		's,^(\s*log_file\s*)/var/log/lrrd/lrrd-client.log$,$1/var/log/munin/munin-node.log,' \
		's,^(\s*pid_file\s*)/var/run/lrrd/lrrd-client.pid$,$1/var/run/munin/munin-node.pid,'
	
	migrate /etc/lrrd/client-conf.d/lrrd-client /etc/munin/plugin-conf.d/munin-node \
		's,^(\s*user\s*)lrrd,$1munin,' \
		's,^(\s*group\s*)lrrd,$1munin,'
	
	GLOBIGNORE=/etc/lrrd/client-conf.d/lrrd-client
	for f in /etc/lrrd/client-conf.d/*; do
		migrate $f /etc/munin/plugin-conf.d${f#/etc/lrrd/client-conf.d} \
			's,^(\s*user\s*)lrrd,$1munin,' \
			's,^(\s*group\s*)lrrd,$1munin,'
	done

	if [ -d /etc/lrrd/client.d ]; then
		for f in $(find /etc/lrrd/client.d ! -lname '/usr/share/lrrd/plugins/*' -a ! -type d); do
			migrate $f /etc/munin/plugins${f#/etc/lrrd/client.d}
		done
		for f in $(find /etc/lrrd/client.d -lname '/usr/share/lrrd/plugins/*' -a ! -type d); do
			local link=$(readlink $f)
			mkdir -p /etc/munin/plugins
			ln -s /usr/share/munin/plugins${link#/usr/share/lrrd/plugins} \
				/etc/munin/plugins${f#/etc/lrrd/client.d}
		done
	fi

	echo $'done.\nYour old LRRD configuration is left untouched.'
}

if [ "$1" = "install" -a -z "$2" ]; then
	convert_from_lrrd
fi

#DEBHELPER#