aboutsummaryrefslogtreecommitdiff
blob: 93dd872d9418c91a62ab679d775f37e245d08e83 (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
# Manages loading of plugins (i.e. creating command-line-options for vdr)

init_tmp_dirs() {
	PL_TMP=/var/vdr/tmp
	if [ ! -d "${PL_TMP}" ]; then
		mkdir "${PL_TMP}"
		chown vdr:vdr "${PL_TMP}"
	fi
}

print_skip_header() {
	if [ "${skip_header_printed}" != "1" ]; then
		ewarn "  Skipped these plugins:"
		vdr_log "Skipped these plugins:"
		skip_header_printed=1
	fi
}

load_plugin_list_start() {
	rm -f "${LOADED_PLUGINS_FILE}"
	prepare_plugin_checks

	local PLUGIN_CONF=/etc/conf.d/vdr.plugins PLUGIN= line=
	if [ -f "${PLUGIN_CONF}" ]; then
		exec 3<${PLUGIN_CONF}
		while read line <&3; do
			[ "${line}" = "" ] && continue
			[ "${line#"#"}" != "${line}" ] && continue
			PLUGIN="${line}"
			check_plugin "${PLUGIN}" || continue
			PLUGINS="${PLUGINS} ${PLUGIN}"
		done
		exec 3<&-
	
		# result of checks
		if [ -n "${skipped_plugins_patchlevel}" ]; then
			print_skip_header
			ewarn "    Wrong Patchlevel: ${skipped_plugins_patchlevel}"
			vdr_log "Wrong Patchlevel: ${skipped_plugins_patchlevel}"
		fi
		if [ -n "${skipped_plugins_not_found}" ]; then
			print_skip_header
			ewarn "    Not Existing:     ${skipped_plugins_not_found}"
			vdr_log "Not Existing: ${skipped_plugins_not_found}"
		fi
	fi
}

load_plugin_list_stop() {
	if [ -e "${LOADED_PLUGINS_FILE}" ]; then
		PLUGINS=$(cat "${LOADED_PLUGINS_FILE}" )
	fi
}

init_plugin_loader() {
	local phase="$1"
	init_tmp_dirs

	# Load list of plugins which were started to exec correct rcaddons
	LOADED_PLUGINS_FILE="${PL_TMP}"/loaded_plugins
	PLUGINS=""
	skipped_plugins_patchlevel=""
	skipped_plugins_not_found=""

	local skip_tmp_file="${PL_TMP}/plugins_skipped"
	rm -f "${skip_tmp_file}"*

	case "$phase" in
		start)	load_plugin_list_start ;;
		stop)	load_plugin_list_stop ;;
	esac
}

prepare_plugin_checks() {
	# find plugin lib dir, needed for multilib ...
	plugin_dir=$(pkg-config --variable=libdir vdr)

	# needed for plugin patchlevel check
	vdr_checksum_dir="${plugin_dir%/plugins}/checksums"
	vdr_checksum="${PL_TMP}"/header-md5-vdr

	_PLUGIN_CHECK_HEADER=false
	if yesno "${PLUGIN_CHECK_PATCHLEVEL:-yes}"; then
		vdr-get-header-checksum > "${vdr_checksum}" && _PLUGIN_CHECK_HEADER=true
	fi
}

check_plugin() {
	local PLUGIN="${1}"
	local plugin_file="${plugin_dir}/libvdr-${PLUGIN}.so.${APIVERSION}"

	if [ ! -f "${plugin_file}" ]; then
		skip_plugin "${PLUGIN}" "NOT_FOUND"
		return 1
	fi

	local plugin_checksum_file=${vdr_checksum_dir}/header-md5-vdr-${PLUGIN}
	if ${_PLUGIN_CHECK_HEADER} && [ -e "${plugin_checksum_file}" ]; then
		if ! cmp -s ${vdr_checksum} ${plugin_checksum_file}; then
			skip_plugin "${PLUGIN}" "PATCHLEVEL"
			return 1
		fi
	fi

	#if ldd ${plugin_file} 2>/dev/null | grep -q "not found"; then
	#	skip_plugin "${PLUGIN}" "unresolved deps - please use revdep-rebuild"
	#	return
	#fi
	return 0
}

run_plugin_addon()
{
	local PLUGIN="${1}"
	local call_func="${2}"

	unset _EXTRAOPTS
	if [ -f "/etc/conf.d/vdr.${PLUGIN}" ]; then
		. /etc/conf.d/vdr.${PLUGIN}
	fi

	load_addon plugin-${PLUGIN} ${call_func}
}

add_plugin_param()
{
	# append new parameter
	vdrplugin_opts="${vdrplugin_opts} $1"
}

skip_plugin() {
	# globally set this to signal skipping
	SKIP_PLUGIN=1

	local PLUGIN="$1"
	local ERROR="$2"

	local skip_tmp_file="${PL_TMP}/plugins_skipped"
	echo "${PLUGIN}" >> "${skip_tmp_file}_ALL" || return 1
	echo "${PLUGIN}" >> "${skip_tmp_file}_${ERROR}" || return 1

	case "${ERROR}" in
	PATCHLEVEL)
		skipped_plugins_patchlevel="${skipped_plugins_patchlevel} ${PLUGIN}"
		;;
	NOT_FOUND)
		skipped_plugins_not_found="${skipped_plugins_not_found} ${PLUGIN}"
		;;
	esac
	return 0
}

add_plugin_params_to_vdr_call() {
	# add the param to the vdr-call
	add_param "${vdrplugin_opts} ${_EXTRAOPTS}"
}

loop_all_plugins() {
	local PLUGIN func="$1" prepare_cmdline=0

	case "$func" in
	plugin_pre_vdr_start)
		for PLUGIN in ${PLUGINS}; do
			SKIP_PLUGIN=0
			vdrplugin_opts="--plugin=${PLUGIN}"
			run_plugin_addon "${PLUGIN}" "${func}" || return 1
			[ "${SKIP_PLUGIN}" = 1 ] && continue

        	        add_plugin_params_to_vdr_call
			echo "${PLUGIN}" >> "${LOADED_PLUGINS_FILE}"
		done
		;;
	*)
		for PLUGIN in ${PLUGINS}; do
			run_plugin_addon "${PLUGIN}" "${func}" || return 1
		done
		;;
	esac
	return 0
}