summaryrefslogtreecommitdiff
blob: ed5c4b11835f5e33c98bce4b2946d904ad4f72cb (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
75
76
77
78
#!/sbin/openrc-run
# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

DICTD_PID="/var/run/dictd.pid"

prepconfig() {
	local TMPCONF INDEXFILES CNT DNAME DICT SAVEDIR
	if [ ! -e "${DICTDCONF}" ]; then
		eerror "Config file ${DICTDCONF} not found."
		return 1
	fi

	# if no dictionaries, skip startup.
	# The new way of doing this is to scan /usr/lib/dict and tweek the conf
	einfo "Scanning for dictionaries..."
	if [ ! -d "${DLIBDIR}" ]; then
		eerror "${DLIBDIR} doesn't exist, no dictionaries found."
		return 1
	fi

	SAVEDIR=${PWD}
	cd "${DLIBDIR}"
	INDEXFILES=$(ls *.index)
	if [ -z "${INDEXFILES}" ]; then
		eerror "No dictionaries found at ${DLIBDIR}."
		eerror "Please, emerge at least one of app-dicts/dictd-* dictionaries."
		return 1
	fi

	TMPCONF=$(mktemp -t dictd.conf.XXXXXXXXXX)
	cat ${DICTDCONF} | sed -e '/^#LASTLINE/,$d' > ${TMPCONF}
	echo "#LASTLINE" >> ${TMPCONF}

	CNT=0
	for i in ${INDEXFILES}; do
		DNAME=$(echo $i | sed -e 's/[.]index$//')
		#two possible names for a matching dictionary, check which is there.
		if [ -f ${DNAME}.dict.dz ]; then
			DICT=${DNAME}.dict.dz
		elif [ -f ${DNAME}.dict ];then
			DICT=${DNAME}.dict
		else
			ewarn "Index $i has no matching dictionaray..."
		fi

		#ok, go an index, and a dixtionary, append.
		echo "database ${DNAME} { data \"${DLIBDIR}/${DICT}\"" >> ${TMPCONF}
		echo "         index \"${DLIBDIR}/$i\" }" >> ${TMPCONF}

		CNT=$(expr ${CNT} + 1)
	done

	cd "${SAVEDIR}"
	mv "${TMPCONF}" "${DICTDCONF}"
	chown 0:dictd "${DICTDCONF}"
	chmod g+r "${DICTDCONF}"
	einfo "Done, ${CNT} dictionaries found."
}

depend() {
	need localmount
}

start() {
	prepconfig || return 1
	ebegin "Starting dictd"
	start-stop-daemon --start --quiet --pidfile ${DICTD_PID} --exec \
			/usr/sbin/dictd -- --pid-file ${DICTD_PID} ${DICTD_OPTS}
	eend $?
}

stop() {
	ebegin "Stopping dictd"
	start-stop-daemon --stop --quiet --pidfile ${DICTD_PID} --exec /usr/sbin/dictd
	eend $?
}