]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/vdradmin/install-ipfire.sh
Never include rc.local or firewall.local in a core update.
[people/teissler/ipfire-2.x.git] / config / vdradmin / install-ipfire.sh
1 #!/bin/bash
2 # Copyright (c) 2005/6 Andreas Mair
3 #
4 #
5 # Download and patchscript for VDRAdmin-AM
6 # (based on install.sh Copyright (c) 2003 Frank (xpix) Herrmann)
7
8 PATH=$PATH:/sbin:/bin:/usr/sbin:/usr/bin
9 DESTDIR=${DESTDIR}
10 LIBDIR=${LIBDIR:-$DESTDIR/usr/share/vdradmin}
11 ETCDIR=${ETCDIR:-$DESTDIR/etc/vdradmin}
12 DOCDIR=${DOCDIR:-$DESTDIR/usr/share/doc/vdradmin}
13 BINDIR=${BINDIR:-$DESTDIR/usr/bin}
14 LOCDIR=${LOCDIR:-$DESTDIR/usr/share/locale}
15 MANDIR=${MANDIR:-$DESTDIR/usr/share/man/man1}
16 LOGDIR=${LOGDIR:-$DESTDIR/var/log}
17 CACHEDIR=${CACHEDIR:-$DESTDIR/var/cache/vdradmin}
18 PIDFILE=${PIDFILE:-$DESTDIR/var/run/vdradmind.pid}
19 VIDEODIR=${VIDEODIR:-/var/video}
20 EPGIMAGES=${EPGIMAGES:-$VIDEODIR/epgimages}
21 VDRCONF=${VDRCONF:-/etc/vdr}
22
23 function usage()
24 {
25 echo ""
26 echo "usage: $(basename $0) [-c | -u | -p | -h]"
27 echo ""
28 echo -e "\t-c : Run \"vdradmind -c\" after installation (=configure)."
29 echo -e "\t-u : Perform uninstall."
30 echo -e "\t-p : List and optionally install required Perl modules."
31 echo -e "\t-h : This message."
32 echo ""
33 exit 0
34 }
35
36 function killRunningVDRAdmin()
37 {
38 local KILLED=0
39 local PID=$(pidof vdradmind)
40 [ "$PID" ] || PID=$(ps a | grep vdradmind.pl | grep perl | grep -v grep | cut -d' ' -f1)
41 if [ "$PID" ]; then
42 KILLED=1
43 kill $PID
44 fi
45
46 return $KILLED
47 }
48
49 # $1 - the Perl module to check for.
50 function checkPerlModule()
51 {
52 [ -z "$1" ] && return 1
53
54 local MODULE=$1
55 local ALT_MODULE=$2
56 local ALT_MESSAGE=
57 [ "$ALT_MODULE" ] && ALT_MESSAGE=" or $ALT_MODULE"
58
59 echo -n "Checking for Perl module $MODULE$ALT_MESSAGE... "
60 perl -ce 'BEGIN{$0 =~ /(^.*\/)/; $BASENAME = $1; unshift(@INC, $BASENAME . "lib/");} use '$MODULE >/dev/null 2>&1
61 if [ $? -eq 2 ]; then
62 if [ "$ALT_MODULE" ]; then
63 perl -ce 'BEGIN{$0 =~ /(^.*\/)/; $BASENAME = $1; unshift(@INC, $BASENAME . "lib/");} use '$ALT_MODULE >/dev/null 2>&1
64 [ $? -eq 0 ] && echo " $ALT_MODULE found" && return 0
65 fi
66 echo " MISSING"
67 read -p "Do you want to install $MODULE? [y/N]"
68 [ "$REPLY" = "y" -o "$REPLY" = "Y" ] && su -c "perl -MCPAN -e 'CPAN::install \"$MODULE\"'"
69 else
70 echo " found"
71 fi
72
73 }
74
75 function perlModules()
76 {
77 echo ""
78 echo "*** Required ***"
79 checkPerlModule locale
80 checkPerlModule Env
81 checkPerlModule Template
82 checkPerlModule Template::Plugin::JavaScript
83 checkPerlModule CGI
84 checkPerlModule HTTP::Date
85 checkPerlModule IO::Socket
86 checkPerlModule Time::Local
87 checkPerlModule MIME::Base64
88 checkPerlModule File::Temp
89 checkPerlModule URI::Escape
90
91
92 echo ""
93 echo "You need Locale::gettext OR Locale::Messages"
94 checkPerlModule Locale::gettext Locale::Messages
95
96 echo ""
97 echo "*** Optional ***"
98 echo "* Required for AutoTimer email notification"
99 #checkPerlModule Net::SMTP
100 #checkPerlModule Authen::SASL
101 echo "* Required for AutoTimer email notification and CRAM-MD5 authentication"
102 checkPerlModule Digest::HMAC_MD5
103 echo "* Required if VDR and VDRAdmin-AM use different character encoding"
104 checkPerlModule Encode
105 echo "* Required for IPv6 support"
106 #checkPerlModule IO::Socket::INET6
107 echo "* Required for SSL support (https)"
108 #checkPerlModule IO::Socket::SSL
109 echo "* Required if you want to use gzip'ed HTTP responses"
110 checkPerlModule Compress::Zlib
111 echo "* Required if you want to log to syslog"
112 checkPerlModule Sys::Syslog
113 }
114
115 function makeDir()
116 {
117 [ -z "$1" ] && return 1
118 local DIR=$1
119 local MUST_CREATE=${2:-0}
120 if [ -e "$DIR" -a ! -d "$DIR" ]; then
121 echo "$DIR exists but is no directory!"
122 echo "Aborting..."
123 return 1
124 elif [ -d $DIR -a $MUST_CREATE = 1 ]; then
125 echo "$DIR exists. Please remove it before calling install.sh!"
126 echo "Aborting..."
127 return 1
128 fi
129 if [ ! -e "$DIR" ]; then
130 mkdir -p "$DIR"
131 if [ $? -ne 0 ]; then
132 echo "Failed to create directory $DIR!"
133 echo "Aborting..."
134 return 1
135 fi
136 fi
137
138 return 0
139 }
140
141 function doInstall()
142 {
143 echo ""
144 echo "********* Installing VDRAdmin-AM *************"
145 echo ""
146
147 perlModules
148
149 makeDir $LIBDIR 1 && cp -r template lib $LIBDIR || exit 1
150 makeDir $DOCDIR && cp -r contrib COPYING CREDITS HISTORY INSTALL LGPL.txt README* REQUIREMENTS FAQ $DOCDIR || exit 1
151 makeDir $MANDIR && cp vdradmind.pl.1 $MANDIR/vdradmind.1 || exit 1
152 makeDir $ETCDIR || exit 1
153
154 (
155 cd locale
156 for lang in *
157 do
158 makeDir $LOCDIR/$lang/LC_MESSAGES/ && install -m 644 $lang/LC_MESSAGES/vdradmin.mo $LOCDIR/$lang/LC_MESSAGES/vdradmin.mo || exit 1
159 done
160 )
161
162 local RESTART=
163 [ ! -e $BINDIR ] && mkdir -p $BINDIR
164 if [ -d $BINDIR ]; then
165 killRunningVDRAdmin
166 if [ $? -ne 0 ] ; then
167 RESTART=1
168 echo "Killed running VDRAdmin-AM..."
169 fi
170 sed <vdradmind.pl >$BINDIR/vdradmind \
171 -e "s/^\(my \$SEARCH_FILES_IN_SYSTEM *=\) 0;/\1 1;/" \
172 -e "s:/usr/share/vdradmin/lib:${LIBDIR}/lib:" \
173 -e "s:/usr/share/vdradmin/template:${LIBDIR}/template:" \
174 -e "s:/var/log:${LOGDIR}:" \
175 -e "s:/var/cache/vdradmin:${CACHEDIR}:" \
176 -e "s:/var/run/vdradmind.pid:${PIDFILE}:" \
177 -e "s:\(\$ETCDIR *= \)\"/etc/vdradmin\";:\1\"${ETCDIR}\";:" \
178 -e "s:/usr/share/locale:${LOCDIR}:" \
179 -e "s:\(\$CONFIG{VIDEODIR} *= \)\"/video\";:\1\"${VIDEODIR}\";:" \
180 -e "s:\(\$CONFIG{EPGIMAGES} *= \)\"\$CONFIG{VIDEODIR}/epgimages\";:\1\"${EPGIMAGES}\";:" \
181 -e "s:\(\$CONFIG{VDRCONFDIR} *= \)\"\$CONFIG{VIDEODIR}\";:\1\"${VDRCONF}\";:"
182
183 chmod a+x $BINDIR/vdradmind
184
185 if [ "$CONFIG" ]; then
186 echo "Configuring VDRAdmin-AM..."
187 $BINDIR/vdradmind -c
188 fi
189
190 if [ "$RESTART" ]; then
191 echo "Restarting VDRAdmin-AM..."
192 $BINDIR/vdradmind
193 fi
194
195 echo ""
196 if [ -e $BINDIR/vdradmind.pl ]; then
197 echo "Removing ancient $BINDIR/vdradmind.pl"
198 rm -f $BINDIR/vdradmind.pl
199 fi
200 if [ -e $MANDIR/vdradmind.pl.1 ]; then
201 echo "Removing ancient $MANDIR/vdradmind.pl.1"
202 rm -f $MANDIR/vdradmind.pl.1
203 fi
204 else
205 echo "$BINDIR exists but is no directory!"
206 echo "Aborting..."
207 exit 1
208 fi
209
210 echo ""
211 echo ""
212 echo "VDRAdmin-AM has been installed!"
213 echo ""
214 if [ -z "$RESTART" ]; then
215 echo "Run \"$BINDIR/vdradmind\" to start VDRAdmin-AM."
216 echo ""
217 fi
218 echo "NOTE:"
219 echo "If you want to run VDRAdmin-AM in a different language you must set the LANG environment variable (see README)."
220 echo ""
221 echo "NOTE2:"
222 echo "If you would like VDRAdmin-AM to start at system's boot, please modify your system's init scripts."
223 exit 0
224 }
225
226 function doUninstall()
227 {
228 echo ""
229 echo "********* Uninstalling VDRAdmin-AM *************"
230 echo ""
231
232 killRunningVDRAdmin
233 if [ -d $DOCDIR ]; then
234 rm -rf $DOCDIR
235 fi
236 if [ -d $LIBDIR ]; then
237 rm -rf $LIBDIR
238 fi
239 if [ -d $CACHEDIR ]; then
240 rm -rf $CACHEDIR
241 fi
242 if [ -e $MANDIR/vdradmind.pl.1 ]; then
243 rm -f $MANDIR/vdradmind.pl.1
244 fi
245 if [ -e $MANDIR/vdradmind.1 ]; then
246 rm -f $MANDIR/vdradmind.1
247 fi
248 if [ -e $BINDIR/vdradmind.pl ]; then
249 rm -f $BINDIR/vdradmind.pl
250 fi
251 if [ -e $BINDIR/vdradmind ]; then
252 rm -f $BINDIR/vdradmind
253 fi
254 rm -f $LOCDIR/*/LC_MESSAGES/vdradmin.mo
255
256 echo ""
257 echo "VDRAdmin-AM has been uninstalled!"
258 echo ""
259 if [ -d $ETCDIR ]; then
260 echo "Your configuration files located in $ETCDIR have NOT been deleted!"
261 echo "If you want to get rid of them, please delete them manually!"
262 echo ""
263 fi
264 }
265
266 UNINSTALL=
267 CONFIG=
268 PERL=
269 while [ "$1" ]
270 do
271 case $1 in
272 -u) UNINSTALL=1;;
273 -c) CONFIG=1;;
274 -p) PERL=1;;
275 -h) usage;;
276 *) echo "Ignoring param \"$1\$.";;
277 esac
278 shift
279 done
280
281 if [ $(basename $0) = "uninstall.sh" -o "$UNINSTALL" ]; then
282 doUninstall
283 elif [ "$PERL" ]; then
284 echo ""
285 echo "Testing required Perl modules..."
286 perlModules
287 echo "...done."
288 else
289 doInstall
290 fi