-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinstall.sh
executable file
·301 lines (272 loc) · 7.98 KB
/
install.sh
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#!/bin/bash
# vim:noet:sw=4:ts=4:
# Copyright (c) 2005-2014 Andreas Mair
#
#
# Download and patchscript for VDRAdmin-AM
# (based on install.sh Copyright (c) 2003 Frank (xpix) Herrmann)
PATH=$PATH:/sbin:/bin:/usr/sbin:/usr/bin
PREFIX=${PREFIX}
LIBDIR=${LIBDIR:-$PREFIX/usr/share/vdradmin}
ETCDIR=${ETCDIR:-$PREFIX/etc/vdradmin}
DOCDIR=${DOCDIR:-$PREFIX/usr/share/doc/vdradmin}
BINDIR=${BINDIR:-$PREFIX/usr/bin}
LOCDIR=${LOCDIR:-$PREFIX/usr/share/locale}
MANDIR=${MANDIR:-$PREFIX/usr/share/man}
LOGDIR=${LOGDIR:-$PREFIX/var/log/vdradmin}
CACHEDIR=${CACHEDIR:-$PREFIX/var/cache/vdradmin}
PIDFILE=${PIDFILE:-$PREFIX/var/run/vdradmin/vdradmind.pid}
VIDEODIR=${VIDEODIR:-/video}
EPGIMAGES=${EPGIMAGES:-$VIDEODIR/epgimages}
VDRCONF=${VDRCONF:-$VIDEODIR}
function usage()
{
echo ""
echo "usage: $(basename $0) [-c | -u | -p | -h]"
echo ""
echo -e "\t-c : Run \"vdradmind -c\" after installation (=configure)."
echo -e "\t-u : Perform uninstall."
echo -e "\t-p : List and optionally install required Perl modules."
echo -e "\t-h : This message."
echo ""
exit 0
}
function killRunningVDRAdmin()
{
local KILLED=0
local PID=$(pidof vdradmind)
[ "$PID" ] || PID=$(ps a | grep vdradmind.pl | grep perl | grep -v grep | cut -d' ' -f1)
if [ "$PID" ]; then
KILLED=1
kill $PID
fi
return $KILLED
}
# $1 - the Perl module to check for.
function checkPerlModule()
{
[ -z "$1" ] && return 1
local MODULE=$1
local ALT_MODULE=$2
local ALT_MESSAGE=
[ "$ALT_MODULE" ] && ALT_MESSAGE=" or $ALT_MODULE"
echo -n "Checking for Perl module $MODULE$ALT_MESSAGE... "
perl -ce 'BEGIN{$0 =~ /(^.*\/)/; $BASENAME = $1; unshift(@INC, $BASENAME . "lib/");} use '$MODULE >/dev/null 2>&1
if [ $? -eq 2 ]; then
if [ "$ALT_MODULE" ]; then
perl -ce 'BEGIN{$0 =~ /(^.*\/)/; $BASENAME = $1; unshift(@INC, $BASENAME . "lib/");} use '$ALT_MODULE >/dev/null 2>&1
[ $? -eq 0 ] && echo " $ALT_MODULE found" && return 0
fi
echo " MISSING"
read -p "Do you want to install $MODULE? [y/N]"
[ "$REPLY" = "y" -o "$REPLY" = "Y" ] && su -c "perl -MCPAN -e 'CPAN::install \"$MODULE\"'"
else
echo " found"
fi
}
function perlModules()
{
echo ""
echo "*** Required ***"
checkPerlModule locale
checkPerlModule Template
checkPerlModule Template::Plugin::JavaScript
checkPerlModule CGI
checkPerlModule HTTP::Date
checkPerlModule IO::Socket
checkPerlModule Time::Local
checkPerlModule MIME::Base64
checkPerlModule File::Temp
checkPerlModule File::Find
checkPerlModule URI
checkPerlModule URI::Escape
checkPerlModule HTTP::Tiny
checkPerlModule HTTP::Daemon
echo ""
echo "You need Locale::gettext OR Locale::Messages"
checkPerlModule Locale::gettext Locale::Messages
echo ""
echo "*** Optional ***"
echo "* Required for AutoTimer email notification"
checkPerlModule Net::SMTP
checkPerlModule Authen::SASL
echo "* Required for AutoTimer email notification and CRAM-MD5 authentication"
checkPerlModule Digest::HMAC_MD5
echo "* Required if VDR and VDRAdmin-AM use different character encoding"
checkPerlModule Encode
echo "* Required for IPv6 support"
checkPerlModule IO::Socket::INET6
echo "* Required for SSL support (https)"
checkPerlModule HTTP::Daemon::SSL
echo "* Required if you want to use gzip'ed HTTP responses"
checkPerlModule Compress::Zlib
echo "* Required if you want to log to syslog"
checkPerlModule Sys::Syslog
}
function makeDir()
{
[ -z "$1" ] && return 1
local DIR=$1
local MUST_CREATE=${2:-0}
if [ -e "$DIR" -a ! -d "$DIR" ]; then
echo "$DIR exists but is no directory!"
echo "Aborting..."
return 1
elif [ -d $DIR -a $MUST_CREATE = 1 ]; then
echo "$DIR exists. Please remove it before calling install.sh!"
echo "Aborting..."
return 1
fi
if [ ! -e "$DIR" ]; then
mkdir -p "$DIR"
if [ $? -ne 0 ]; then
echo "Failed to create directory $DIR!"
echo "Aborting..."
return 1
fi
fi
return 0
}
function doInstall()
{
echo ""
echo "********* Installing VDRAdmin-AM *************"
echo ""
perlModules
makeDir $DESTDIR/$LIBDIR 1 && cp -r template lib $DESTDIR/$LIBDIR || exit 1
makeDir $DESTDIR/$BINDIR || exit 1
makeDir $DESTDIR/$DOCDIR && cp -r contrib COPYING CREDITS HISTORY INSTALL LGPL.txt README* REQUIREMENTS FAQ $DESTDIR/$DOCDIR || exit 1
makeDir $DESTDIR/$MANDIR/man8 && cp vdradmind.pl.1 $DESTDIR/$MANDIR/man8/vdradmind.8 || exit 1
(
cd locale
for lang in *
do
makeDir $DESTDIR/$LOCDIR/$lang/LC_MESSAGES/ && install -m 644 $lang/LC_MESSAGES/vdradmin.mo $DESTDIR/$LOCDIR/$lang/LC_MESSAGES/vdradmin.mo || exit 1
done
)
local RESTART=
if [ -d $DESTDIR/$BINDIR ]; then
killRunningVDRAdmin
if [ $? -ne 0 ] ; then
RESTART=1
echo "Killed running VDRAdmin-AM..."
fi
sed <vdradmind.pl >$DESTDIR/$BINDIR/vdradmind \
-e "s/^\(my \$SEARCH_FILES_IN_SYSTEM *=\) 0;/\1 1;/" \
-e "s:/usr/share/vdradmin/lib:${LIBDIR}/lib:" \
-e "s:/usr/share/vdradmin/template:${LIBDIR}/template:" \
-e "s:/var/log/vdradmin:${LOGDIR}:" \
-e "s:/var/cache/vdradmin:${CACHEDIR}:" \
-e "s:/var/run/vdradmin/vdradmind.pid:${PIDFILE}:" \
-e "s:\(\$ETCDIR *= \)\"/etc/vdradmin\";:\1\"${ETCDIR}\";:" \
-e "s:/usr/share/locale:${LOCDIR}:" \
-e "s:\(\$CONFIG{VIDEODIR} *= \)\"/video\";:\1\"${VIDEODIR}\";:" \
-e "s:\(\$CONFIG{EPGIMAGES} *= \)\"\$CONFIG{VIDEODIR}/epgimages\";:\1\"${EPGIMAGES}\";:" \
-e "s:\(\$CONFIG{VDRCONFDIR} *= \)\"\$CONFIG{VIDEODIR}\";:\1\"${VDRCONF}\";:"
chmod a+x $DESTDIR/$BINDIR/vdradmind
if [ "$CONFIG" ]; then
echo "Configuring VDRAdmin-AM..."
$DESTDIR/$BINDIR/vdradmind -c
fi
if [ "$RESTART" ]; then
echo "Restarting VDRAdmin-AM..."
$DESTDIR/$BINDIR/vdradmind
fi
echo ""
if [ -e $DESTDIR/$BINDIR/vdradmind.pl ]; then
echo "Removing ancient $DESTDIR/$BINDIR/vdradmind.pl"
rm -f $DESTDIR/$BINDIR/vdradmind.pl
fi
for man in man1/vdradmind.pl.1 man1/vdradmind.1; do
if [ -e $DESTDIR/$MANDIR/$man ]; then
echo "Removing ancient $DESTDIR/$MANDIR/$man"
rm -f $DESTDIR/$MANDIR/$man
fi
done
else
echo "$DESTDIR/$BINDIR exists but is no directory!"
echo "Aborting..."
exit 1
fi
echo ""
echo ""
echo "VDRAdmin-AM has been installed!"
echo ""
if [ -z "$RESTART" ]; then
echo "Run \"$DESTDIR/$BINDIR/vdradmind\" to start VDRAdmin-AM."
echo ""
fi
echo "NOTE:"
echo "If you want to run VDRAdmin-AM in a different language you must set the LANG environment variable (see README)."
echo ""
echo "NOTE2:"
echo "If you would like VDRAdmin-AM to start at system's boot, please modify your system's init scripts."
local USED_DIRS="$(echo -e "$ETCDIR\n$LOGDIR\n$CACHEDIR\n$(dirname "$PIDFILE")" | sort -u)"
echo
echo "NOTE3:"
echo "VDRAdmin-AM needs to access some directories:"
echo "$USED_DIRS"
echo
echo "Please check that the user VDRAdmin-AM runs has enough permissions to access them!"
exit 0
}
function doUninstall()
{
echo ""
echo "********* Uninstalling VDRAdmin-AM *************"
echo ""
killRunningVDRAdmin
if [ -d $DESTDIR/$DOCDIR ]; then
rm -rf $DESTDIR/$DOCDIR
fi
if [ -d $DESTDIR/$LIBDIR ]; then
rm -rf $DESTDIR/$LIBDIR
fi
if [ -d $DESTDIR/$CACHEDIR ]; then
rm -rf $DESTDIR/$CACHEDIR
fi
for man in man1/vdradmind.pl.1 man1/vdradmind.1 man8/vdradmind.8; do
if [ -e $DESTDIR/$MANDIR/$man ]; then
rm -f $DESTDIR/$MANDIR/$man
fi
done
if [ -e $DESTDIR/$BINDIR/vdradmind.pl ]; then
rm -f $DESTDIR/$BINDIR/vdradmind.pl
fi
if [ -e $DESTDIR/$BINDIR/vdradmind ]; then
rm -f $DESTDIR/$BINDIR/vdradmind
fi
rm -f $DESTDIR/$LOCDIR/*/LC_MESSAGES/vdradmin.mo
echo ""
echo "VDRAdmin-AM has been uninstalled!"
echo ""
if [ -d $DESTDIR/$ETCDIR ]; then
echo "Your configuration files located in $DESTDIR/$ETCDIR have NOT been deleted!"
echo "If you want to get rid of them, please delete them manually!"
echo ""
fi
}
UNINSTALL=
CONFIG=
PERL=
while [ "$1" ]
do
case $1 in
-u) UNINSTALL=1;;
-c) CONFIG=1;;
-p) PERL=1;;
-h) usage;;
*) echo "Ignoring param \"$1\$.";;
esac
shift
done
if [ $(basename $0) = "uninstall.sh" -o "$UNINSTALL" ]; then
doUninstall
elif [ "$PERL" ]; then
echo ""
echo "Testing required Perl modules..."
perlModules
echo "...done."
else
doInstall
fi