aboutsummaryrefslogtreecommitdiff
blob: f240c35e808f6f6882c75ad7a455227e15edee47 (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
#!/bin/sh

# VDR helper script for using a systemd unit together
# with media-tv/gentoo-vdr-scripts
#
# inspired by the old OpenRC script /etc/init.d/vdr by Mathias Schwarzott
# Lucian Muresan < lucianm AT users DOT sourceforge DOT net >
# Joerg Bornkessel <hd_brummy@gentoo.org>

# Distributed under the terms of the GNU General Public License v2

# read our main options
. /etc/conf.d/vdr
. /etc/conf.d/vdr.watchdogd

# inspired by the old OpenRC script /etc/init.d/vdr:
cd /var/vdr
unset MAIL
. /usr/share/vdr/inc/functions.sh

include rc-functions
include plugin-functions
init_tmp_dirs

VDR_LOG_FILE="${PL_TMP}/vdr-start-log"

# this is the environment file to pass user and parameters to the systemd unit file
SYSTEMD_ENV_FILE="${PL_TMP}/systemd_env"

#common_init

# dummy functions to make the rest of gentoo-vdr-scripts happy,
# as we do not want to rely on openrc's implementations of these
# commands:
ebegin() {
	vdr_log "ACTION: $@"
}

eend() {
	vdr_log "RESULT: $@"
}

ewarn() {
	vdr_log "WARN:   $@"
}

einfo() {
	vdr_log "INFO:   $@"
}


# some additional logging functions
eerror() {
	vdr_log "ERROR:  $@"
}

eexitfail() {
	eerror "$@"
	exit 1
}


clear_logfile() {
	rm -f "${VDR_LOG_FILE}"
	printf "" > "${VDR_LOG_FILE}"
}

#
# Used to log error-messages in startscript to show them on
# OSD later when choosing apropriate point in commands.
#

vdr_log()
{
	echo "$@" >> "${VDR_LOG_FILE}"
}

#
#
# Depending on $1, we execute the scripts needed
# before/after starting, or before/after stopping VDR,
# and exit with non-zero error code on failure, in such
# way that the systemd unit will fail and the problems
# have to be investigated in logs, journal, or even
# by executing these parts of the script manually in
# the console as user 'vdr'
if [ "$1" = "--start-pre" ]; then
	ebegin "--start-pre"
	clear_logfile
	init_params
	init_plugin_loader start || eexitfail "init_plugin_loader start"
	load_addons_prefixed pre-start || eexitfail "load_addons_prefixed pre-start"

	# these options are what we need to start VDR from the systemd unit file
	echo "VDR_OPTS=\"${vdr_opts}\"" > ${SYSTEMD_ENV_FILE}

	# X11 DISPLAY 
	# (needed for media-plugins/vdr-softhddevice supporting OpenGL OSD)
	echo "DISPLAY=$DISPLAY" >> ${SYSTEMD_ENV_FILE}

	# LANG LC_COLLATE from /etc/conf.d/vdr will be ignored, wrt bug 530690
	echo "LANG=$LANG" >> ${SYSTEMD_ENV_FILE}
	echo "LC_COLLATE=${VDR_SORT_ORDER}" >> ${SYSTEMD_ENV_FILE}
	# Using LC_ALL is strongly discouraged as it can't be overridden later on.
	# Please use it only when testing and never set it in a startup file.
#	echo "LC_ALL=$LANG" >> ${SYSTEMD_ENV_FILE}

	# remove the command line --user argument if set by the scripts so far,
	# as the user under which vdr will run is controlled by systemd
	sed -e "s:'-u' 'vdr' ::" -i ${SYSTEMD_ENV_FILE}

	sync
	eend "--start-pre"
elif [ "$1" = "--start-post" ]; then
	ebegin "--start-post"
	load_addons_prefixed post-start || eexitfail "load_addons_prefixed post-start"
	eend "--start-post"
elif [ "$1" = "--stop-pre" ]; then
	ebegin "--stop-pre"
	init_plugin_loader stop || eexitfail "init_plugin_loader stop"
	load_addons_prefixed pre-stop || eexitfail "load_addons_prefixed pre-stop"
	eend "--stop-pre"
elif [ "$1" = "--stop-post" ]; then
	ebegin "--stop-post"
	load_addons_prefixed post-stop || eexitfail "load_addons_prefixed post-stop"
	eend "--stop-post"
fi