summaryrefslogtreecommitdiff
blob: 07e56402298b633cda10f2cd169b080653dffeeb (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id: bashcomp.eselect 367 2007-03-28 14:35:23Z pioto $

DESCRIPTION="Manage VDR plugins"
MAINTAINER="zzam@gentoo.org"
SVN_DATE='$Date$'
VERSION=$(svn_date_to_version "${SVN_DATE}")

find_plugins() {
	local plugins plugin f plugindir="${ROOT}/usr/lib/vdr/plugins"

	for f in ${plugindir}/libvdr-*.so* ; do
		[[ -e ${f} ]] || continue

		plugin="${f##*/libvdr-}"
		plugin="${plugin%.so.*}"
		plugins="${plugins}\n${plugin}"
	done

	echo -ne ${plugins} | sort -u
}

show_enabled_plugins() {
	local plugins line conffile="${ROOT}/etc/conf.d/vdr.plugins"

	exec 3<${conffile}
	while read plugin <&3; do
		[ "${plugin}" = "" ] && continue
		[ "${plugin#"#"}" != "${plugin}" ] && continue
		plugins="${plugins}\n${plugin}"
	done

	echo -ne ${plugins} | sort -u
}

is_enabled() {
	local conffile="${ROOT}/etc/conf.d/vdr.plugins"
	
	egrep -q "^${1}\$" "${conffile}" || return 1
	return 0
}

plugin_exists() {
	local f plugindir="${ROOT}/usr/lib/vdr/plugins"

	for f in ${plugindir}/libvdr-${1}.so.*; do
		[[ -e "${f}" ]] && return 0
	done
	return 1
}

### show action ###

describe_show() {
	echo "Show enabled VDR plugins"
}

do_show() {
	local plugins
	[[ -z "${@}" ]] || die -q "Too many parameters"

	plugins=( $(show_enabled_plugins) )

	write_list_start "Enabled VDR plugins:"
	if [[ -n "${plugins[@]}" ]] ; then
		set -- "${plugins[@]}"
		for plugin; do
			write_kv_list_entry "${plugin}" ""
		done
	else
		write_kv_list_entry "(none enabled)" ""
	fi
}

### list action ###

describe_list() {
	echo "List available VDR plugins"
}

do_list() {
	local opts
	plugins=( $(find_plugins) )
	write_list_start "Available VDR plugins:"

	if [[ -n "${plugins[@]}" ]] ; then
		for (( n = 0 ; n < ${#plugins[@]} ; ++n )) ; do
			is_enabled ${plugins[${n}]} && \
				plugins[${n}]="${plugins[${n}]} $(highlight '*')"
		done
		write_numbered_list "${plugins[@]}"
	else
		write_kv_list_entry "(none found)" ""
	fi

	return 0
}

### enable action ###

describe_enable() {
	echo "Enable specified Plugin(s)"
}

describe_enable_parameters() {
	echo "<plugin>"
}

describe_enable_options() {
	echo "<plugin> : Plugin name"
}

do_enable() {
	local conffile="${ROOT}/etc/conf.d/vdr.plugins" plugins plugin

	[[ -z ${1} ]] && die -q "You didn't specify any plugins to enable."

	# make sure we have proper permissions
	[[ -w ${conffile} ]] || \
		die -q "You don't have permission to write to ${conffile}"

	plugins=( $(find_plugins) )

	for plugin in $@ ; do
		local p=${plugin}
		
		is_number ${p} && \
			p=${plugins[$(( ${p} - 1 ))]}

		[[ -z "${p}" ]] && \
			die -q "Plugin \"${plugin}\" doesn't appear to be valid!"

		plugin=${p}

		# ignore any unrecognized options
		[[ ${plugin} == --* ]] && continue

		# does plugin exist
		if ! plugin_exists "${plugin}"; then
			write_error_msg "Plugin ${plugin} doesn't exist"
			continue
		fi

		# already enabled?
		if is_enabled "${plugin}"; then
			write_error_msg "Plugin ${plugin} is already enabled"
			continue
		fi

		# finally, add it to conffile
		echo "${plugin}" >> "${conffile}"
	done
}

### disable action ###

describe_disable() {
	echo "Disable specified plugin(s)"
}

describe_disable_parameters() {
	echo "<plugin>"
}

describe_disable_options() {
	echo "<plugin> : Plugin name"
}


do_disable() {
	local conffile="${ROOT}/etc/conf.d/vdr.plugins" plugins plugin

	[[ -z ${1} ]] && die -q "You didn't specify any plugins to disable"

	[[ -w ${conffile} ]] || \
		die -q "You don't have permission to write to ${conffile}"

	plugins=( $(find_plugins) )

	for plugin in $@ ; do
		local p=${plugin}
		
		is_number ${p} && \
			p=${plugins[$(( ${p} - 1 ))]}

		[[ -z "${p}" ]] && \
			die -q "Plugin \"${plugin}\" doesn't appear to be valid!"

		plugin=${p}

		# ignore any unrecognized options
		[[ ${plugin} == --* ]] && continue

		# is in installed?
		if ! is_enabled "${plugin}"; then
			write_error_msg "${plugin} is not enabled"
			continue
		fi

		sed -e "/^${plugin}\$/d" -i "${conffile}"
	done
}

# vim: set ft=eselect :