· 10 years ago · Aug 18, 2016, 06:20 PM
1#!/bin/sh
2# ***** BEGIN LICENSE BLOCK *****
3# Version: MPL 1.1
4#
5# The contents of this file are subject to the Mozilla Public License Version
6# 1.1 (the "License"); you may not use this file except in compliance with
7# the License. You may obtain a copy of the License at
8# http://www.mozilla.org/MPL/
9#
10# Software distributed under the License is distributed on an "AS IS" basis,
11# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12# for the specific language governing rights and limitations under the
13# License.
14#
15# The Original Code is IRC Auto Downloader
16#
17# The Initial Developer of the Original Code is
18# David Nilsson.
19# Portions created by the Initial Developer are Copyright (C) 2010, 2011
20# the Initial Developer. All Rights Reserved.
21#
22# Contributor(s):
23#
24#This version of the Brocks Autodl-setup script is provided and maintained by Smoke @ http://weedpornandbeer.com
25#Version - 1.41a last updated 09/14/2013 by Smoke
26# ***** END LICENSE BLOCK *****
27
28AUTODL_IRSSI_ZIP_URL="http://sourceforge.net/projects/autodl-irssi/files/autodl-irssi-v1.31.zip/download"
29SVN_PATH_RUTORRENT_PLUGIN="https://svn.code.sf.net/p/autodl-irssi/code/trunk/rutorrent/autodl-irssi"
30
31WEBMIN_URL="http://www.webmin.com/download/webmin-current.tar.gz"
32
33RUTORRENT_TRUNK_DIR="https://rutorrent.googlecode.com/svn/trunk"
34
35# The official tarballs are tried if subversion fails.
36RUTORRENT_VERSION="3.4"
37RUTORRENT_CORE_NAME="rutorrent-$RUTORRENT_VERSION.tar.gz"
38RUTORRENT_CORE_URL="http://rutorrent.googlecode.com/files/$RUTORRENT_CORE_NAME"
39RUTORRENT_PLUGINS_NAME="plugins-$RUTORRENT_VERSION.tar.gz"
40RUTORRENT_PLUGINS_URL="http://rutorrent.googlecode.com/files/$RUTORRENT_PLUGINS_NAME"
41RUTORRENT_CORE_URL2="http://sourceforge.net/projects/autodl-irssi/files/inst-files/$RUTORRENT_CORE_NAME/download"
42RUTORRENT_PLUGINS_URL2="http://sourceforge.net/projects/autodl-irssi/files/inst-files/$RUTORRENT_PLUGINS_NAME/download"
43
44RUTORRENT_PLUGINS=
45
46# These are the ruTorrent plugins that will get installed. To remove one, either
47# remove the whole line or comment it (prepend a '#' to the start of the line).
48# If the line starts with '#', the plugin is not installed.
49RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS _getdir"
50RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS _task"
51RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS autotools"
52RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS chunks"
53RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS cookies"
54RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS cpuload"
55RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS create"
56RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS data"
57RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS datadir"
58RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS diskspace"
59RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS edit"
60RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS erasedata"
61RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS extsearch"
62RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS feeds"
63RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS geoip"
64RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS httprpc"
65RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS ipad"
66RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS loginmgr"
67#RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS mediainfo"
68RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS ratio"
69RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS retrackers"
70#RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS rpc"
71RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS rss"
72RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS rssurlrewrite"
73RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS scheduler"
74RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS seedingtime"
75#RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS show_peers_like_wtorrent"
76RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS source"
77RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS theme"
78RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS throttle"
79RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS tracklabels"
80RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS trafic"
81RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS unpack"
82
83
84# For building rtorrent
85LIBCURL_NAME="curl-7.28.1"
86LIBCURL_URL="http://curl.haxx.se/download/$LIBCURL_NAME.tar.gz"
87SIGCPP20_NAME="libsigc++-2.3.1"
88SIGCPP20_URL="http://ftp.gnome.org/pub/GNOME/sources/libsigc++/2.3/$SIGCPP20_NAME.tar.gz"
89XMLRPC_SVN_DIR="https://svn.code.sf.net/p/xmlrpc-c/code/stable"
90LIBTORRENT_VERSION="0.13.3"
91LIBTORRENT_NAME="libtorrent-$LIBTORRENT_VERSION"
92LIBTORRENT_URL="http://libtorrent.rakshasa.no/downloads/$LIBTORRENT_NAME.tar.gz"
93LIBTORRENT_URL2="http://sourceforge.net/projects/autodl-irssi/files/inst-files/$LIBTORRENT_NAME.tar.gz/download"
94RTORRENT_VERSION="0.9.3"
95RTORRENT_NAME="rtorrent-$RTORRENT_VERSION"
96RTORRENT_URL="http://libtorrent.rakshasa.no/downloads/$RTORRENT_NAME.tar.gz"
97RTORRENT_URL2="http://sourceforge.net/projects/autodl-irssi/files/inst-files/$RTORRENT_NAME.tar.gz/download"
98
99HTPASSWD_PY_SCRIPT_URL="http://trac.edgewall.org/export/10433/trunk/contrib/htpasswd.py"
100HTPASSWD_PY_SCRIPT_URL2="http://sourceforge.net/projects/autodl-irssi/files/inst-files/htpasswd.py/download"
101
102NGINX_NAME="nginx-1.3.9"
103NGINX_URL="http://nginx.org/download/$NGINX_NAME.tar.gz"
104
105LIGHTTPD_NAME="lighttpd-1.4.32"
106LIGHTTPD_URL="http://download.lighttpd.net/lighttpd/releases-1.4.x/$LIGHTTPD_NAME.tar.gz"
107
108MOD_SCGI_VERSION="1.14"
109MOD_SCGI_URL="http://python.ca/scgi/releases/scgi-$MOD_SCGI_VERSION.tar.gz"
110
111UNRAR_VERSION="4.0.7"
112UNRAR_URL="http://www.rarlab.com/rar/unrarsrc-$UNRAR_VERSION.tar.gz"
113
114# Dirs relative to user's home directory
115RTORRENT_REL_DOWNLOAD_DIR="downloads"
116RTORRENT_REL_WATCH_DIR="rtorrent/watch"
117RTORRENT_REL_SESSION_DIR="rtorrent/session"
118
119REQUIRED_PERL_MODULES="Time::HiRes XML::LibXML Archive::Zip Net::SSLeay HTML::Parser Digest::SHA1 JSON"
120REQUIRED_PHP_MODULES="json xml sockets"
121
122# If set to y, add 'load perl' to .irssi/startup
123IRSSI_LOAD_PERL=n
124IGNORE_IRSSI=n
125
126# Start port. When we need a new port number, this port is incremented by one.
127CURRENT_PORT=23875
128DEFAULT_PORT_FTP=21
129DEFAULT_PORT_FTPES=990
130DEFAULT_UMASK=022
131RPC_PREFIX=RPC
132
133LSB_DEFAULT_START="2 3 4 5"
134LSB_DEFAULT_STOP="0 1 6"
135
136# Setting these to anything other than 80 and 443 may not work with Apache (since the
137# code assumed it would always be 80 and 443).
138HTTP_PORT=80
139HTTPS_PORT=443
140
141SCGI_HOST="127.0.0.1"
142
143INTERACTIVE=n
144USE_RUTORRENT_PLUGIN=n
145REINSTALL_RUTORRENT_PLUGIN=n
146INSTALL_AUTODL_IRSSI=n
147RUTORRENT_PASSWORD_PROTECTED=n
148USERS=
149RUTORRENT_BASE_PATH=
150INSTALL_STARTUP_SCRIPT=n
151BUILD_RTORRENT=n
152INSTALL_WEB_SERVER=
153INSTALL_RUTORRENT=n
154INSTALL_VSFTPD=n
155FTP_PORT=
156USE_ENCRYPTED_FTP=n
157INSTALL_WEBMIN=n
158USER_TIMEZONE=
159
160RUTORRENT_SITE_REALM="My ruTorrent web site"
161AUTODL_STARTUP_DESC="Start autodl-irssi and rtorrent"
162PHPCGI_STARTUP_DESC="Start php-cgi"
163NGINX_STARTUP_DESC="Start nginx"
164LIGHTTPD_STARTUP_DESC="Start lighttpd"
165
166PATH="$PATH:/usr/local/bin"
167
168# Find an echo that supports -e
169echo=echo
170for cmd in echo /bin/echo; do
171 $cmd >/dev/null 2>&1 || continue
172 if ! $cmd -e "" | grep -qE '^-e'; then
173 echo=$cmd
174 break
175 fi
176done
177
178CSI=$($echo -e "\033[")
179CEND="${CSI}0m"
180CDGREEN="${CSI}32m"
181CRED="${CSI}1;31m"
182CGREEN="${CSI}1;32m"
183CYELLOW="${CSI}1;33m"
184CBLUE="${CSI}1;34m"
185CMAGENTA="${CSI}1;35m"
186CCYAN="${CSI}1;36m"
187CQUESTION="$CMAGENTA"
188CWARNING="$CRED"
189CMSG="$CCYAN"
190
191errorExit() {
192 cat << EOF
193$CWARNING
194***ERROR***
195$*
196***ERROR***
197$CEND
198Help forum: ${CGREEN}http://sourceforge.net/apps/phpbb/autodl-irssi/$CEND
199EOF
200 exit 1
201}
202
203exitHelp() {
204 cat << EOF
205
206autodl-irssi and ruTorrent plugin installer
207
208 sh $0 [options]
209
210Options:
211
212--rtorrent
213 Will build and install rtorrent, libtorrent and xmlrpc-c from source code.
214
215--rtorrent-noexec-patch
216 Patch rtorrent to disallow remote users from executing code.
217
218--apache
219 Install Apache web server.
220
221--nginx
222 Install nginx web server.
223
224--lighttpd
225 Install lighttpd web server.
226
227--rutorrent
228 Install ruTorrent. Requires a web server, eg. --apache.
229
230--vsftpd
231 Install vsftpd.
232
233--ftpes
234 Use encrypted FTP (FTPES).
235
236--ftp-port <port>
237 FTP server port.
238
239--webmin
240 Install Webmin.
241
242-p
243--rutorrent-plugin
244 Use or install the autodl-irssi ruTorrent plugin. If it's already installed,
245 it will be updated (svn up), unless --reinstall-plugin option is used in
246 which case it will be re-installed.
247
248-i
249--reinstall-plugin
250 Re-install the autodl-irssi ruTorrent plugin if it's already installed.
251
252-a
253--install-autodl
254 Install autodl-irssi.
255
256-u user:autodlPass:webUser:webPass
257--user user:autodlPass:webUser:webPass
258 The $(uname -s) user, autodl-irssi password, ruTorrent user, ruTorrent password.
259 You can use more than one -u option. If autodlPassword is not set, a random
260 password will be used.
261
262-w
263--password-protected
264 Use this option if ruTorrent is password protected. It's required if you
265 want to use more than one ruTorrent user. Not needed if you install
266 ruTorrent.
267
268-r PATH
269--rutorrent-base-path PATH
270 Path to ruTorrent, eg. /var/www/rutorrent. Not needed if you install
271 ruTorrent.
272
273-s
274--install-startup-script
275 Install a startup script (service) which will start Irssi and rtorrent when
276 the computer boots.
277
278-h
279--help
280 Show this help text
281
282Examples (as root user):
283
284 sh $0 --rtorrent --apache --rutorrent --vsftpd --ftpes --webmin -p -a -s -u user1::user1:pass1 -u user2::user2:pass2
285
286Installs rtorrent, Apache, ruTorrent, vsftpd (encrypted), Webmin the
287autodl-irssi plugin, autodl-irssi, installs a service (starting Irssi and
288rtorrent) for both users.
289
290 sh $0 -p -a -u user::user:pass -r /var/www/rutorrent -s
291
292Installs autodl-irssi + ruTorrent plugin for user 'user'. ruTorrent has not been
293password protected. Also installs the startup script.
294
295 sh $0 -p -a -u user1::user1:pass1 -u user2::user2:pass2 -w -r /var/www/rutorrent -s
296
297Installs autodl-irssi + ruTorrent plugin for users 'user1' and 'user2'.
298ruTorrent has been password protected. Also installs the startup script.
299
300 sh $0 --rtorrent -a -u user1 -u user2 -u user3 -u user4 -s
301
302Installs rtorrent, autodl-irssi and the startup script.
303
304Help forum: http://sourceforge.net/apps/phpbb/autodl-irssi/
305EOF
306 exit 1
307}
308
309parseCommandLine() {
310 while [ $# -gt 0 ]; do
311 local arg="$1"
312 shift
313
314 if [ "$arg" = "-p" ] || [ "$arg" = "--rutorrent-plugin" ]; then
315 USE_RUTORRENT_PLUGIN=y
316 elif [ "$arg" = "-i" ] || [ "$arg" = "--reinstall-plugin" ]; then
317 REINSTALL_RUTORRENT_PLUGIN=y
318 elif [ "$arg" = "-a" ] || [ "$arg" = "--install-autodl" ]; then
319 INSTALL_AUTODL_IRSSI=y
320 elif [ "$arg" = "-u" ] || [ "$arg" = "--user" ]; then
321 USERS="$USERS $1"
322 shift
323 elif [ "$arg" = "-w" ] || [ "$arg" = "--password-protected" ]; then
324 RUTORRENT_PASSWORD_PROTECTED=y
325 elif [ "$arg" = "-r" ] || [ "$arg" = "--rutorrent-base-path" ]; then
326 RUTORRENT_BASE_PATH="$1"
327 shift
328 elif [ "$arg" = "-s" ] || [ "$arg" = "--install-startup-script" ]; then
329 INSTALL_STARTUP_SCRIPT=y
330 elif [ "$arg" = "--rtorrent" ]; then
331 BUILD_RTORRENT=y
332 elif [ "$arg" = "--apache" ]; then
333 INSTALL_WEB_SERVER=apache
334 elif [ "$arg" = "--nginx" ]; then
335 INSTALL_WEB_SERVER=nginx
336 elif [ "$arg" = "--lighttpd" ]; then
337 INSTALL_WEB_SERVER=lighttpd
338 elif [ "$arg" = "--rutorrent" ]; then
339 INSTALL_RUTORRENT=y
340 elif [ "$arg" = "--vsftpd" ]; then
341 INSTALL_VSFTPD=y
342 elif [ "$arg" = "--ftpes" ]; then
343 USE_ENCRYPTED_FTP=y
344 elif [ "$arg" = "--ftp-port" ]; then
345 FTP_PORT="$1"
346 shift
347 elif [ "$arg" = "--webmin" ]; then
348 INSTALL_WEBMIN=y
349 else
350 exitHelp
351 fi
352 done
353}
354
355# Sets os and os_long to the OS type and OS name respectively
356detectOs() {
357 local DISTRIB_ID=
358 local DISTRIB_DESCRIPTION=
359 if [ -f /etc/lsb-release ]; then
360 . /etc/lsb-release
361 fi
362
363 if [ -f /etc/fedora-release ]; then
364 os=fedora
365 os_long="$(cat /etc/fedora-release)"
366 # Must be before PCLinuxOS, Mandriva, and a whole bunch of other OS tests
367 elif [ -f /etc/unity-release ]; then
368 os=unity
369 os_long="$(cat /etc/unity-release)"
370 elif [ -f /etc/pclinuxos-release ]; then
371 os=pclinuxos
372 os_long="$(cat /etc/pclinuxos-release)"
373 elif [ "$DISTRIB_ID" = "Ubuntu" ]; then
374 os=debian
375 os_long="$DISTRIB_DESCRIPTION"
376 elif [ "$DISTRIB_ID" = "LinuxMint" ]; then
377 os=debian
378 os_long="$DISTRIB_DESCRIPTION"
379 # Must be before Debian
380 elif [ "$DISTRIB_ID" = "Peppermint" ]; then
381 os=debian
382 os_long="$DISTRIB_DESCRIPTION"
383 elif [ "$DISTRIB_ID" = "MEPIS" ]; then
384 os=debian
385 os_long="$DISTRIB_DESCRIPTION"
386 elif [ -f /etc/clearos-release ]; then
387 os=fedora
388 os_long="$(cat /etc/clearos-release)"
389 elif [ -f /etc/pardus-release ]; then
390 os=pardus
391 os_long="$(cat /etc/pardus-release)"
392 elif [ -f /etc/chakra-release ]; then
393 os=arch
394 os_long="Chakra $(cat /etc/chakra-release)"
395 elif [ -f /etc/frugalware-release ]; then
396 os=frugalware
397 os_long="$(cat /etc/frugalware-release)"
398 # Must test this before Gentoo
399 elif [ -f /etc/sabayon-release ]; then
400 os=sabayon
401 os_long="$(cat /etc/sabayon-release)"
402 elif [ -f /etc/arch-release ]; then
403 os=arch
404 os_long="Arch Linux"
405 elif [ -f /etc/gentoo-release ]; then
406 os=gentoo
407 os_long="$(cat /etc/gentoo-release)"
408 elif [ -f /etc/SuSE-release ]; then
409 os=opensuse
410 os_long="$(grep SUSE /etc/SuSE-release | head -n1)"
411 elif [ -f /etc/debian_version ]; then
412 os=debian
413 local prefix=
414 if ! uname -s | grep -q GNU; then
415 prefix="GNU/"
416 fi
417 os_long="Debian $prefix$(uname -s) $(cat /etc/debian_version)"
418 # Must test for mandriva before centos since it also has /etc/redhad-release
419 elif [ -f /etc/mandriva-release ]; then
420 os=mandriva
421 os_long="$(cat /etc/mandriva-release)"
422 elif [ -f /etc/redhat-release ]; then
423 os=fedora
424 os_long="$(cat /etc/redhat-release)"
425 elif [ -f /etc/vector-version ]; then
426 os=slaptget
427 os_long="VectorLinux $(cat /etc/vector-version)"
428 elif [ -f /etc/slackware-version ]; then
429 if isProgramInstalled slapt-get; then
430 os=slaptget
431 os_long="$(cat /etc/slackware-version)"
432 else
433 os=other
434 os_long="$(cat /etc/slackware-version)"
435 fi
436 elif [ $(uname -s) = "FreeBSD" ]; then
437 os=freebsd
438 os_long=FreeBSD
439 elif [ $(uname -s) = "DragonFly" ]; then
440 os=dragonfly
441 os_long="DragonFly BSD"
442 elif [ $(uname -s) = "OpenBSD" ]; then
443 os=openbsd
444 os_long=OpenBSD
445 elif [ $(uname -s) = "NetBSD" ]; then
446 os=netbsd
447 os_long=NetBSD
448 else
449 os=other
450 os_long="$(uname -s)"
451 fi
452
453 os_long="${os_long:-$(uname -s)}"
454}
455
456# In-place editing like sed -i but more portable...
457sed_i() {
458 local cmd="$1"
459 local file="$2"
460 isProgramInstalled ed || errorExit "ed is not installed!"
461 local addr=","
462 echo "$cmd" | grep -qE '^/' && addr=
463 ed -s "$file" > /dev/null 2>&1 << EOF
464$addr$cmd
465w
466q
467EOF
468}
469
470getFirst() {
471 echo $1
472}
473
474# Returns true if $1 is one of $2..$n
475arrayIsPresent() {
476 local val="$1"
477 shift
478 for v in "$@"; do
479 [ "$v" = "$val" ] && return 0
480 done
481 return 1
482}
483
484canGeneratePasswords() {
485 [ -c /dev/urandom ]
486}
487
488generatePassword() {
489 newPassword=$(cat /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c17)
490}
491
492isProgramInstalled() {
493 which "$1" > /dev/null 2>&1 && return 0
494 return 1
495}
496
497isPerlModuleInstalled() {
498 perl -M$1 -e '' > /dev/null 2>&1 && return 0
499 return 1
500}
501
502# Add $1 or $2 if it exists, to PACKAGES if program $1 isn't present
503addProgram() {
504 isProgramInstalled $1 || PACKAGES="$PACKAGES ${2:-$1}"
505}
506
507# Add $2 to PACKAGES if perl module $1 isn't present
508addPerlModule() {
509 isPerlModuleInstalled $1 || PACKAGES="$PACKAGES $2"
510}
511
512installPackages() {
513 [ -z "$INSTALL" ] && return
514 [ -z "$PACKAGES" ] && return
515 $INSTALL $PACKAGES
516 PACKAGES=
517}
518
519installPerlModule() {
520 isPerlModuleInstalled $1 || $INSTALL $2
521}
522
523installProgram() {
524 isProgramInstalled $1 || $INSTALL ${2:-$1}
525}
526
527installBuildTools() {
528 [ "$BUILD_TOOLS_INSTALLED" = y ] && return
529 PACKAGES="$BUILD_TOOLS"
530 installPackages
531 BUILD_TOOLS_INSTALLED=y
532}
533
534# Detects missing Perl modules and stores them in MISSING_PERL_MODULES
535detectMissingPerlModules() {
536 OLD_PERL_MODULES=
537 MISSING_PERL_MODULES=
538 for module in $REQUIRED_PERL_MODULES; do
539 isPerlModuleInstalled $module || MISSING_PERL_MODULES="$MISSING_PERL_MODULES $module"
540 done
541
542 # Make sure the JSON module is new
543 if isPerlModuleInstalled JSON && ! perl -MJSON -e '&decode_json("{}")' > /dev/null 2>&1; then
544 echo "${CWARNING}Old JSON module is installed. Need to install from CPAN.$CEND"
545 MISSING_PERL_MODULES="$MISSING_PERL_MODULES JSON"
546 OLD_PERL_MODULES="$OLD_PERL_MODULES JSON"
547 fi
548
549 if echo "$MISSING_PERL_MODULES" | grep -wq JSON; then
550 MISSING_PERL_MODULES="JSON::XS $MISSING_PERL_MODULES"
551 fi
552 if echo "$MISSING_PERL_MODULES" | grep -q 'XML::LibXML'; then
553 # Sometimes the cpan script doesn't install the required dependencies
554 MISSING_PERL_MODULES="XML::NamespaceSupport XML::SAX $MISSING_PERL_MODULES"
555 fi
556}
557
558# Detect where cpan is installed and place the path in the CPAN variable.
559# PCLinuxOS/Mandriva append the version number...
560detectCpanBin() {
561 for file in $(which cpan 2> /dev/null) $(ls /usr/bin/cpan-* 2> /dev/null); do
562 if [ -x "$file" ]; then
563 CPAN="$file"
564 return
565 fi
566 done
567 isPerlModuleInstalled CPAN && return
568 errorExit "Could not find the cpan script or the CPAN Perl module. Can't install missing Perl modules."
569}
570
571isValidTzName() {
572 echo "$1" | LC_ALL=C grep -qE '^[A-Z][^/ ]*(/[A-Z][^/ ]*)?$' && return 0
573 return 1
574}
575
576detectTimeZone() {
577 [ -n "$USER_TIMEZONE" ] && return
578
579 local hash=
580 local hasher=
581 local files=
582 local zoneinfoPath=/usr/share/zoneinfo
583 [ -d "$zoneinfoPath" ] || return
584 if hasher=md5sum; isProgramInstalled $hasher || hasher=sha1sum; isProgramInstalled $hasher; then
585 hash=$($hasher /etc/localtime | awk '{print $1}')
586 files="$(find $zoneinfoPath -type f -print | xargs $hasher | grep -E "^$hash\\>" | awk '{print $2}')"
587 elif hasher=md5; isProgramInstalled $hasher || hasher=sha1; isProgramInstalled $hasher; then
588 hash=$($hasher /etc/localtime | sed -e 's/^.* = \([a-zA-Z0-9]*\)$/\1/')
589 files="$(find $zoneinfoPath -type f -print | xargs $hasher | grep -E "$hash\$" | sed -e 's/^[^ ]* (\([^)]*\)).*/\1/')"
590 else
591 return
592 fi
593
594 # Detect all possible timezone names
595 local timezones=
596 for path in $files; do
597 local tz="${path#$zoneinfoPath/}"
598 while true; do
599 isValidTzName "$tz" && break
600 local newTz="${tz#*/}"
601 [ "$newTz" = "$tz" ] && tz= && break
602 tz="$newTz"
603 done
604 isValidTzName "$tz" && timezones="$timezones $tz"
605 done
606
607 # Now find the ones PHP likes...
608 local okRegions="(Africa|America|Antarctica|Arctic|Asia|Atlantic|Australia|Europe|Indian|Pacific)"
609 for tz in $timezones; do
610 echo "$tz" | grep -qE "^$okRegions/" && USER_TIMEZONE="$tz" && return
611 done
612
613 # Return the first one we found
614 for tz in $timezones; do
615 USER_TIMEZONE="$tz"
616 return
617 done
618}
619
620getNumCpus() {
621 [ -n "$NUMCPUS" ] && return
622 [ -f /proc/cpuinfo ] && NUMCPUS=$(cat /proc/cpuinfo | grep '^processor' | wc -l) && return
623 isProgramInstalled sysctl && sysctl -n hw.ncpu | grep -qE '^[1-9][0-9]*$' && NUMCPUS=$(sysctl -n hw.ncpu) && return
624 NUMCPUS=1
625}
626
627# Appends $value to $varName in $file, creating the var if it doesn't exist. The
628# value is not appended if it already exists.
629appendFileStringVar() {
630 local file="$1"
631 local varName="$2"
632 local value="$3"
633
634 [ -f "$file" ] || errorExit "File '$file' does not exist"
635
636 local varLine=$(grep -E "^$varName=" "$file" | tail -n1)
637 if [ -z "$varLine" ]; then
638 echo "$varName=\"$value\"" >> "$file"
639 else
640 echo "$varLine" | grep -qE "[='\" ]$value(\"|'| |$)" && return
641
642 local q=
643 echo "$varLine" | grep -qE "^$varName='" && q="'"
644 echo "$varLine" | grep -qE "^$varName=\"" && q='"'
645 sed_i "s#^\\($varName=\\)$q\\(.*\\)$q#\\1\"\\2 $value\"#" "$file"
646 fi
647}
648
649# Set a variable in a script file to a new value. The variable is created if it does not exist
650setScriptVariable() {
651 local file="$1"
652 local name=$2
653 local value="$3"
654
655 [ -f "$file" ] || errorExit "File does not exist: $file"
656
657 local newLine="$name=\"$value\""
658 if grep -qE "^$name=" $file; then
659 sed_i "s!^$name=.*\$!$newLine!" "$file"
660 else
661 echo "$newLine" >> "$file"
662 fi
663}
664
665userExists() {
666 id -rg "$1" > /dev/null 2>&1 && return 0
667 return 1
668}
669
670setSvnOpts() {
671 SVN_OPTS=
672 isProgramInstalled svn || return
673 # svn sometimes gives an error message 'broken pipe'. Ignore it.
674 if svn help co 2>/dev/null | grep -q 'non-interactive' && svn help co 2>/dev/null | grep -q 'trust-server-cert'; then
675 SVN_OPTS="--non-interactive --trust-server-cert"
676 fi
677}
678
679downloadFile() {
680 local filename="$1"
681 shift
682 for url in "$@"; do
683 for i in 1 2 3 4 5; do
684 wget --no-check-certificate -O "$filename" "$url" && return 0
685 done
686 done
687 return 1
688}
689
690buildMakeProgram() {
691 local url="$1"
692 local name="$2"
693 local builddir="$3"
694 local srcdir="$4"
695 local makefile="${5:-Makefile}"
696
697 buildStart
698 echo "${CMSG}Downloading $name source code...$CEND"
699 cd "$BUILD_DIR"
700 local filename="${url##*/}"
701 downloadFile "$filename" "$url" || errorExit "Could not download $name source code."
702 tar xzf "$filename"
703 srcdir="${srcdir:-${filename%.tar.gz}}"
704 cd "$srcdir/$builddir"
705 local make=${MAKE:-make}
706 echo "${CMSG}Building $name...$CEND"
707 $make -f $makefile all || errorExit "Could not build $name."
708 $make -f $makefile install || errorExit "Could not install $name."
709 echo "${CMSG}$name is now installed$CEND"
710 buildEnd
711}
712
713buildProgram() {
714 local prog="$1"
715
716 echo "${CMSG}Building $prog...$CEND"
717
718 ./configure --prefix=$PREFIX $2 || errorExit "Could not configure $prog. Try again, or try logging out and in and try again."
719
720 getNumCpus
721 local make=${MAKE:-make}
722 local makeopts="-j$NUMCPUS"
723 $make $makeopts || $make || errorExit "Could not build $prog"
724 $make install || errorExit "Could not install $prog"
725
726 local ldsoconf=/etc/ld.so.conf
727 touch "$ldsoconf"
728 grep -qE "^$PREFIX/lib$" $ldsoconf || echo "$PREFIX/lib" >> $ldsoconf
729 ldconfig || errorExit "ldconfig failed"
730
731 echo "${CMSG}$prog is now installed.$CEND"
732}
733
734downloadAndBuild() {
735 local prog="$1"
736 local urls="$2"
737 local name="$3"
738 local configOptions="$4"
739 local patchUrl="$5"
740
741 cd "$BUILD_DIR"
742 echo "${CMSG}Downloading $prog source code...$CEND"
743 downloadFile "$name.tar.gz" $urls || errorExit "Could not download $prog source code."
744 tar xzf $name.tar.gz
745
746 if echo "$patchUrl" | grep '^[a-z]*://'; then
747 echo "${CMSG}Patching $prog...$CEND"
748 PACKAGES="patch"
749 installPackages
750 isProgramInstalled patch || errorExit "patch is not installed!"
751 downloadFile the.patch "$patchUrl" || errorExit "Could not download the patch file."
752 patch -p1 -d $name < the.patch || errorExit "Could not patch $prog."
753 elif [ -n "$patchUrl" ]; then
754 echo "${CMSG}Patching $prog...$CEND"
755 cd $name
756 eval $patchUrl
757 cd ..
758 fi
759
760 cd $name
761 buildProgram "$prog" "$configOptions"
762}
763
764checkoutAndBuild() {
765 local prog="$1"
766 local url="$2"
767 local configOptions="$3"
768 cd "$BUILD_DIR"
769 echo "${CMSG}Downloading $prog source code...$CEND"
770 svn export $SVN_OPTS "$url" "$prog" || errorExit "Could not download $prog source code."
771 cd "$prog"
772 buildProgram "$prog" "$configOptions"
773}
774
775buildStart() {
776 PREFIX=/usr/local
777 OLD_PATH="$PATH"
778 PATH="$PATH:$PREFIX/bin"
779 PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig
780 export PKG_CONFIG_PATH
781 BUILD_DIR="$(echo ~)/build-tmp"
782
783 rm -rf "$BUILD_DIR"
784 mkdir "$BUILD_DIR" || errorExit "Could not create build directory."
785}
786
787buildEnd() {
788 cd
789 rm -rf "$BUILD_DIR"
790
791 [ -n "$OLD_PATH" ] && PATH="$OLD_PATH"
792 unset OLD_PATH
793 unset PKG_CONFIG_PATH
794}
795
796buildRtorrent() {
797 installBuildTools
798 osHandler_$os installRtorrentBuildTools
799 isProgramInstalled pkg-config || errorExit "pkg-config is not installed."
800
801 # Minimum version is 7.15.4 but I had problems with 7.15.5 on CentOS. Set
802 # it to 7.18.0 (the version Ubuntu Server 8.04 is using).
803 if ! pkg-config --atleast-version=7.18.0 libcurl; then
804 downloadAndBuild "libcurl" "$LIBCURL_URL" "$LIBCURL_NAME" ""
805 # Prevent 'Unknown keyword 'URL' in ....' error
806 sed_i 's/^URL:/#URL:/' $PREFIX/lib/pkgconfig/libcurl.pc
807 fi
808 if ! pkg-config --exists sigc++-2.0; then
809 downloadAndBuild "sigc++-2.0" "$SIGCPP20_URL" "$SIGCPP20_NAME" ""
810 fi
811 checkoutAndBuild "xmlrpc-c" "$XMLRPC_SVN_DIR" "--disable-cplusplus"
812 downloadAndBuild "libtorrent" "$LIBTORRENT_URL $LIBTORRENT_URL2" "$LIBTORRENT_NAME" "" patchLibtorrent
813 downloadAndBuild "rtorrent" "$RTORRENT_URL $RTORRENT_URL2" "$RTORRENT_NAME" "--with-xmlrpc-c" ""
814}
815
816patchLibtorrent() {
817 # For gcc 4.6.0
818 ed -s "src/torrent/data/block_transfer.h" > /dev/null 2>&1 << EOF
819/#define LIBTORRENT_BLOCK_TRANSFER_H
820a
821#include <stddef.h>
822.
823w
824q
825EOF
826 ed -s "src/data/memory_chunk.cc" > /dev/null 2>&1 << EOF
827/#include "config.h"
828a
829#include <stddef.h>
830.
831w
832q
833EOF
834}
835
836installRtorrent() {
837 buildStart
838 buildRtorrent
839 buildEnd
840}
841
842installUnrar() {
843 isProgramInstalled unrar && return
844 installBuildTools
845 buildMakeProgram "$UNRAR_URL" "unrar" "" "unrar" "makefile.unix"
846}
847
848installModScgi() {
849 local modScgiFile="$1"
850 local modulesPath="$2"
851 [ -f "$modScgiFile" ] && errorExit "mod_scgi file already exists."
852 [ -d "$modulesPath" ] || errorExit "Apache modules path '$modulesPath' does not exist."
853
854 buildMakeProgram "$MOD_SCGI_URL" "mod_scgi" "apache2"
855 echo "LoadModule scgi_module $modulesPath/mod_scgi.so" > $modScgiFile
856}
857
858isPortUsed() {
859 local port="$1"
860 netstat -an | grep tcp | grep -w LISTEN | grep -qE "[.:]$port[ ]" && return 0
861 return 1
862}
863
864isValidIpAddress() {
865 # It's not 100% accurate ... ;)
866 echo $1 | grep -qE '^[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?$'
867}
868
869getIpAddress() {
870 isValidIpAddress "$OUR_IP_ADDRESS" && return
871 echo "${CMSG}Detecting your IP address...$CEND"
872 isValidIpAddress "$OUR_IP_ADDRESS" || OUR_IP_ADDRESS=$(wget --no-check-certificate http://www.whatismyip.com/automation/n09230945.asp -O - -o /dev/null)
873 isValidIpAddress "$OUR_IP_ADDRESS" || OUR_IP_ADDRESS=$(ifconfig -a | grep "inet addr" | head -n1 | awk -F: '{print $2}' | awk '{print $1}')
874 isValidIpAddress "$OUR_IP_ADDRESS" || OUR_IP_ADDRESS="1.2.3.4"
875}
876
877getNewPortNumber() {
878 while true; do
879 newPortNumber=$CURRENT_PORT
880 CURRENT_PORT=$(expr $CURRENT_PORT + 1)
881 isValidPortNumber $newPortNumber || errorExit "Invalid port number. Change CURRENT_PORT."
882 isPortUsed $newPortNumber || break
883 echo "${CWARNING}Port $newPortNumber is in use, trying next port...$CEND"
884 done
885}
886
887# Returns true if it's a valid ruTorrent base path
888isValidRutorrentBasePath() {
889 [ -n "$1" ] && [ -d "$1/conf" ]
890}
891
892isValidPassword() {
893 echo "$1" | grep -qE "^ " && return 1
894 echo "$1" | grep -qE " \$" && return 1
895 echo "$1" | grep -qE '^$' && return 1
896 echo "$1" | grep -q ':' && return 1
897 echo "'$1'" | grep -q ' ' && return 1
898 return 0
899}
900
901isValidPortNumber() {
902 echo "$1" | grep -qiE '^[0-9]+$' || return 1
903 echo "$1" | grep -qiE '[0-9][0-9][0-9][0-9][0-9][0-9]' && return 1
904 [ $1 -ge 1024 ] && [ $1 -le 65535 ]
905}
906
907isValidWebUser() {
908 [ -z "$1" ] && return 1
909 echo "$1" | LC_ALL=C grep -qE '[A-Z:]' && return 1
910 return 0
911}
912
913initUsers() {
914 local users=
915 for packedUser in $USERS; do
916 extractPackedUser $packedUser
917
918 if [ -z "$autodlPort" ]; then
919 getNewPortNumber
920 autodlPort=$newPortNumber
921 fi
922 if [ -z "$scgiPort" ]; then
923 getNewPortNumber
924 scgiPort=$newPortNumber
925 fi
926 if [ -z "$rtorrentPort" ]; then
927 getNewPortNumber
928 rtorrentPort=$newPortNumber
929 fi
930 if canGeneratePasswords; then
931 if [ -z "$autodlPassword" ]; then
932 generatePassword
933 autodlPassword="$newPassword"
934 fi
935 fi
936
937 users="$users $osUser:$autodlPassword:$webUser:$webPass:$autodlPort:$scgiPort:$rtorrentPort"
938 done
939 USERS="$users"
940}
941
942extractPackedUser() {
943 local packedUser="$1"
944
945 osUser="$(echo $packedUser | cut -d: -f1)"
946 autodlPassword="$(echo $packedUser | cut -d: -f2)"
947 webUser="$(echo $packedUser | cut -d: -f3)"
948 webPass="$(echo $packedUser | cut -d: -f4)"
949 autodlPort="$(echo $packedUser | cut -d: -f5)"
950 scgiPort="$(echo $packedUser | cut -d: -f6)"
951 rtorrentPort="$(echo $packedUser | cut -d: -f7)"
952}
953
954getUserGroup() {
955 local user="$1"
956
957 userExists "$user" || errorExit "The user '$user' does not exist."
958 group=$(grep -w $(id -rg $user) /etc/group | cut -d: -f1)
959 [ -z "$group" ] && group="$user"
960}
961
962getUserDir() {
963 local user="$1"
964
965 [ -z "$user" ] && errorExit "Invalid user (blank)."
966 userDir="$(eval echo ~$user)"
967 [ -d "$userDir" ] || errorExit "User $user's home directory does not exist."
968}
969
970resetOwner() {
971 local user="$1"
972 shift
973
974 if [ "$ISROOT" = y ]; then
975 getUserGroup "$user"
976 chown -R $user:$group "$@"
977 fi
978}
979
980# Updates MISSING_PHP_MODULES with all missing required PHP modules
981detectMissingPhpModules() {
982 MISSING_PHP_MODULES=
983 local php=${WWW_PHP_CGI:-php}
984 for module in $REQUIRED_PHP_MODULES; do
985 $php -m 2> /dev/null | grep -wq $module || MISSING_PHP_MODULES="$MISSING_PHP_MODULES $module"
986 done
987}
988
989installMissingPhpPackages() {
990 PACKAGES=
991 for module in $MISSING_PHP_MODULES; do
992 PACKAGES="$PACKAGES php-$module"
993 done
994 installPackages
995}
996
997installMissingPhp5Packages() {
998 PACKAGES=
999 for module in $MISSING_PHP_MODULES; do
1000 PACKAGES="$PACKAGES php5-$module"
1001 done
1002 installPackages
1003}
1004
1005enablePhpIniModules() {
1006 local phpIni="$1"
1007 shift
1008 for module in "$@"; do
1009 grep -qE "^extension=$module.so" "$phpIni" && continue
1010 sed_i "s/^; *\\(extension=$module.so.*\\)/\\1/" "$phpIni"
1011 grep -qE "^extension=$module.so" "$phpIni" && continue
1012 echo "extension=$module.so" >> "$phpIni"
1013 done
1014}
1015
1016installMissingPhpModules() {
1017 detectMissingPhpModules
1018 [ -z "$MISSING_PHP_MODULES" ] && return
1019
1020 osHandler_$os installPhpModules
1021
1022 detectMissingPhpModules
1023 [ -z "$MISSING_PHP_MODULES" ] && return
1024 cat << EOF
1025$CWARNING
1026The following PHP modules appear to be missing:
1027 $MISSING_PHP_MODULES
1028If the autodl-irssi ruTorrent plugin isn't working, you now know why. Install
1029them using your package manager or enable them in your php.ini file, and
1030restart your web server.$CEND
1031EOF
1032}
1033
1034addLogrotateConfig() {
1035 local serviceName="$1"
1036 local logFiles="$2"
1037 local postrotateScript="$3"
1038
1039 local logrotate_d=/etc/logrotate.d
1040 [ -d "$logrotate_d" ] || errorExit "Missing logrotate dir: $logrotate_d"
1041
1042 cat > "$logrotate_d/$serviceName" << EOF
1043$logFiles {
1044 missingok
1045 daily
1046 rotate 14
1047 notifempty
1048 compress
1049 delaycompress
1050 sharedscripts
1051 postrotate
1052 $postrotateScript
1053 endscript
1054}
1055EOF
1056 [ $? -eq 0 ] || errorExit "Could not write logrotate file $logrotate_d/$serviceName"
1057}
1058
1059detectPhpCgi() {
1060 WWW_PHP_CGI=${WWW_PHP_CGI:-$(which php-cgi | head -n1)}
1061 [ -x "$WWW_PHP_CGI" ] || errorExit "Could not find php-cgi"
1062 "$WWW_PHP_CGI" -v | grep -q 'cgi-fcgi' || errorExit "$WWW_PHP_CGI does not support FastCGI"
1063}
1064
1065# $i is the i'th user number
1066getUserRpcMount() {
1067 local i=$1
1068 verifyWebServerVars
1069 # Make sure /RPC10 accesses aren't going to /RPC1 by padding with zeros. This is
1070 # easier than making sure every web server handles it correctly. Eg., lighttpd's
1071 # scgi.server table is read in order, so if you add /RPC1 before /RPC10, then
1072 # /RPC10 accesses will go to /RPC1. A fix would of course be to place /RPC10
1073 # before /RPC1 but it's easy to forget. Now we use /RPC00001 .. /RPC99999
1074 echo "/$RPC_PREFIX$(printf '%05d' $i)"
1075}
1076
1077createSelfSignedCertFile() {
1078 local pemfile="$1"
1079
1080 if [ ! -f "$OTHER_PEM_FILE" ]; then
1081 echo "${CMSG}Creating the self-signed certificate.$CEND"
1082 rm -f "$pemfile"
1083 openssl req -new -newkey rsa:1024 -days 1000 -nodes -x509 -keyout "$pemfile" -out "$pemfile" -batch \
1084 || errorExit "Failed to create self-signed certificate."
1085 OTHER_PEM_FILE="$pemfile"
1086 CREATED_CERT_FILE=y
1087 else
1088 rm -f "$pemfile"
1089 cp "$OTHER_PEM_FILE" "$pemfile" || errorExit "Failed to copy self-signed certificate."
1090 fi
1091
1092 chmod 0600 "$pemfile"
1093}
1094
1095detectHtpasswd() {
1096 [ -z "$htpasswd" ] && isProgramInstalled htpasswd && htpasswd=htpasswd
1097 [ -z "$htpasswd" ] && isProgramInstalled htpasswd2 && htpasswd=htpasswd2
1098 if [ -z "$htpasswd" ]; then
1099 installProgram python
1100 if isProgramInstalled python; then
1101 cd
1102 downloadFile "htpasswd.py" "$HTPASSWD_PY_SCRIPT_URL" "$HTPASSWD_PY_SCRIPT_URL2" \
1103 && htpasswd="python $(pwd)/htpasswd.py"
1104 fi
1105 fi
1106 [ -z "$htpasswd" ] && errorExit "Could not find htpasswd"
1107}
1108
1109verifyWebServerVars() {
1110 [ -z "$WWW_PEMFILE" ] && errorExit "You have not initialized WWW_PEMFILE"
1111 [ -z "$WWW_PASSWORD_FILE" ] && errorExit "You have not initialized WWW_PASSWORD_FILE"
1112 [ -z "$WWW_ROOT" ] && errorExit "You have not initialized WWW_ROOT"
1113 [ -z "$WWW_USER" ] && errorExit "You have not initialized WWW_USER"
1114 [ -z "$WWW_GROUP" ] && errorExit "You have not initialized WWW_GROUP"
1115}
1116
1117initializeWwwRootVar() {
1118 WWW_ROOT=${WWW_ROOT:-/var/rutorrent}
1119}
1120
1121createWebServerUserGroup() {
1122 verifyWebServerVars
1123 if ! grep -qE "^$WWW_GROUP:" /etc/group; then
1124 groupadd -r $WWW_GROUP 2>/dev/null || groupadd $WWW_GROUP || errorExit "Could not create web server group."
1125 fi
1126 if ! grep -qE "^$WWW_USER:" /etc/passwd; then
1127 local useradd="useradd -d $WWW_ROOT -g $WWW_GROUP -s /bin/sh"
1128 $useradd -M -r $WWW_USER 2>/dev/null || $useradd $WWW_USER || errorExit "Could not create web server user."
1129 fi
1130}
1131
1132resetAuthPasswordFilePermissions() {
1133 [ -n "$WWW_USER" ] || errorExit "WWW_USER not initialized"
1134 [ -n "$WWW_GROUP" ] || errorExit "WWW_GROUP not initialized"
1135 chmod 0400 "$WWW_PASSWORD_FILE"*
1136 chown $WWW_USER:$WWW_GROUP "$WWW_PASSWORD_FILE"*
1137}
1138
1139createAuthPasswordFile() {
1140 verifyWebServerVars
1141 : > "$WWW_PASSWORD_FILE"
1142 resetAuthPasswordFilePermissions
1143}
1144
1145# Some web servers (eg. nginx) can't allow just ONE user access to a certain
1146# location. To fix that, create one password file per user.
1147createOnePasswordFilePerUser() {
1148 for packedUser in $USERS; do
1149 extractPackedUser $packedUser
1150 grep "^$webUser:" "$WWW_PASSWORD_FILE" > "${WWW_PASSWORD_FILE}_$webUser"
1151 done
1152 resetAuthPasswordFilePermissions
1153}
1154
1155updatePhpTimezone() {
1156 if [ ! -f "$WWW_PHP_INI" ]; then
1157 echo "${CWARNING}Could not find php.ini file: $WWW_PHP_INI$CEND"
1158 return
1159 fi
1160 [ -z "$USER_TIMEZONE" ] && return
1161
1162 local zws="[ ]*"
1163 local newLine="date.timezone = $USER_TIMEZONE"
1164 if grep -qE "^${zws}date\\.timezone[ =]" "$WWW_PHP_INI"; then
1165 return
1166 elif grep -qE "^${zws}[;#]${zws}date\\.timezone[ =]" "$WWW_PHP_INI"; then
1167 sed_i "s!^${zws}[;#]${zws}date\\.timezone[ =].*\$!$newLine!" "$WWW_PHP_INI"
1168 else
1169 cat >> "$WWW_PHP_INI" << EOF
1170[Date]
1171$newLine
1172EOF
1173 fi
1174}
1175
1176doDetectTimeZone() {
1177 echo "${CMSG}Detecting timezone...$CEND"
1178 detectTimeZone
1179 if [ -n "$USER_TIMEZONE" ]; then
1180 echo "${CMSG}Timezone: $USER_TIMEZONE$CEND"
1181
1182 updatePhpTimezone
1183 else
1184 echo "${CWARNING}Could not detect timezone!$CEND"
1185 fi
1186}
1187
1188webServerCommonInitialization() {
1189 mkdir -p $WWW_ROOT
1190 doDetectTimeZone
1191 createSelfSignedCertFile "$WWW_PEMFILE"
1192 createAuthPasswordFile
1193}
1194
1195resetWebServerPermissions() {
1196 verifyWebServerVars
1197 chown -R $WWW_USER:$WWW_GROUP $WWW_ROOT || errorExit "Could not set web server as owner of $WWW_ROOT"
1198}
1199
1200createPhpcgiSocket() {
1201 PHPCGI_SOCKET_DIR=/etc/phpcgi
1202 PHPCGI_SOCKET_FILE="$PHPCGI_SOCKET_DIR/php-cgi.socket"
1203 mkdir -p "$PHPCGI_SOCKET_DIR"
1204 chown $WWW_USER:$WWW_GROUP "$PHPCGI_SOCKET_DIR"
1205 chmod 0770 "$PHPCGI_SOCKET_DIR"
1206}
1207
1208verifyApacheServerVars() {
1209 verifyWebServerVars
1210 [ -z "$APACHE_SITE_FILE" ] && errorExit "You have not initialized APACHE_SITE_FILE"
1211}
1212
1213apacheCreateApxs2Symlink() {
1214 # The makefile uses apxs2, so make a symlink
1215 if ! isProgramInstalled apxs2; then
1216 local apxs=$(which apxs 2>/dev/null) && ln -s "$apxs" "${apxs}2"
1217 fi
1218}
1219
1220initializeApacheVars() {
1221 local apacheUser="$1"
1222 local apacheGroup="$2"
1223 local apacheSitesDir="$3"
1224
1225 [ -n "$apacheUser" ] || errorExit "Invalid apache user: $apacheUser"
1226 [ -n "$apacheGroup" ] || errorExit "Invalid apache group: $apacheGroup"
1227 [ -d "$apacheSitesDir" ] || errorExit "Invalid apache sites dir: $apacheSitesDir"
1228 [ -d "$APACHE_DIR" ] || errorExit "Invalid apache dir: $APACHE_DIR"
1229
1230 APACHE_SITE_NAME=${APACHE_SITE_NAME:-rutorrent.conf}
1231 APACHE_SITE_FILE=$apacheSitesDir/$APACHE_SITE_NAME
1232 initializeWwwRootVar
1233 WWW_PASSWORD_FILE=$APACHE_DIR/rutorrent_passwd
1234 WWW_PEMFILE=$APACHE_DIR/rutorrent.pem
1235 WWW_USER="$apacheUser"
1236 WWW_GROUP="$apacheGroup"
1237}
1238
1239apacheGetRpcLocationDirectives() {
1240 if [ "$INSTALL_RUTORRENT" = y ]; then
1241 local i=1
1242 for packedUser in $USERS; do
1243 extractPackedUser $packedUser
1244 local rpcMount="$(getUserRpcMount $i)"
1245 cat << EOF
1246 <Location "$rpcMount">
1247 AuthType Basic
1248 AuthName "$RUTORRENT_SITE_REALM"
1249 AuthUserFile "$WWW_PASSWORD_FILE"
1250 Require user $webUser
1251 </Location>
1252EOF
1253 i=$(expr $i + 1)
1254 done
1255 fi
1256}
1257
1258apacheGetVirtualHost() {
1259 local port=$1
1260 local ssl=$2
1261 cat << EOF
1262<VirtualHost *:$port>
1263$(if [ "$ssl" = y ]; then
1264 echo " SSLEngine On"
1265 echo " SSLCertificateFile $WWW_PEMFILE"
1266fi)
1267 ServerAdmin admin@rutorrent
1268 ServerName localhost
1269 DocumentRoot $WWW_ROOT
1270
1271 <Directory />
1272 AllowOverride None
1273 Order deny,allow
1274 Deny from all
1275 </Directory>
1276 <Location />
1277 AuthType Basic
1278 AuthName "$RUTORRENT_SITE_REALM"
1279 AuthUserFile "$WWW_PASSWORD_FILE"
1280 Require valid-user
1281 Order allow,deny
1282 Allow from all
1283 </Location>
1284 <Location ~ "^/rutorrent/(conf|share)">
1285 Order deny,allow
1286 Deny from all
1287 </Location>
1288 <Location ~ "/\\\\.svn">
1289 Order deny,allow
1290 Deny from all
1291 </Location>
1292$(apacheGetRpcLocationDirectives)
1293</VirtualHost>
1294EOF
1295}
1296
1297apacheWriteSiteFile() {
1298 verifyApacheServerVars
1299 cat > "$APACHE_SITE_FILE" << EOF
1300ServerName localhost
1301
1302$(apacheGetVirtualHost $HTTP_PORT n)
1303$(apacheGetVirtualHost $HTTPS_PORT y)
1304EOF
1305
1306 if [ "$INSTALL_RUTORRENT" = y ]; then
1307 local i=1
1308 local lp=; isWebServerRpcModule || lp='#'
1309 for packedUser in $USERS; do
1310 extractPackedUser $packedUser
1311 local rpcMount="$(getUserRpcMount $i)"
1312 echo "${lp}SCGIMount $rpcMount $SCGI_HOST:$scgiPort" >> "$APACHE_SITE_FILE"
1313
1314 i=$(expr $i + 1)
1315 done
1316 fi
1317}
1318
1319apacheCommonInitialization() {
1320 local buildTools="$1"
1321 local modulesDir="$2"
1322
1323 webServerCommonInitialization
1324 apacheWriteSiteFile
1325
1326 if [ -n "$APACHE_SCGI_FILE" ] && [ ! -f "$APACHE_SCGI_FILE" ]; then
1327 installBuildTools
1328 PACKAGES="$buildTools"
1329 installPackages
1330 apacheCreateApxs2Symlink
1331
1332 # Compiling mod_scgi will fail unless we remove this warning-as-error flag
1333 local configVarsFile="$APACHE_DIR/modules/build/config_vars.mk"
1334 [ -f "$configVarsFile" ] && sed_i 's/-Werror=format-security//g' "$configVarsFile"
1335
1336 installModScgi "$APACHE_SCGI_FILE" "$modulesDir"
1337 fi
1338}
1339
1340installCommonWebServerStuff_mandriva() {
1341 # Also add some extra tools for ruTorrent and some of its plugins
1342 PACKAGES="php-cli gzip curl openssl logrotate"
1343 installPackages
1344 PACKAGE="unrar"
1345 installPackages
1346 PACKAGES="php-geoip"
1347 installPackages
1348}
1349
1350# Used by Mandriva, Unity Linux, and PCLinuxOS
1351installApache_mandriva() {
1352 installCommonWebServerStuff_mandriva
1353 PACKAGES="apache-mpm-prefork apache-mod_ssl apache-mod_php"
1354 installPackages
1355
1356 WWW_PHP_INI=/etc/php.ini
1357 APACHE_DIR=/etc/httpd
1358 local APACHE_CONF_D=$APACHE_DIR/conf.d
1359 local APACHE_SITES_DIR=$APACHE_DIR/conf/vhosts.d
1360 APACHE_SCGI_FILE=$APACHE_CONF_D/scgi.conf
1361 initializeApacheVars apache apache "$APACHE_SITES_DIR"
1362 apacheCommonInitialization "libopenssl-devel apache-devel" $APACHE_DIR/modules
1363
1364 for file in 00_default_vhosts.conf 01_default_ssl_vhost.conf; do
1365 [ -f "$APACHE_SITES_DIR/$file" ] && mv -f "$APACHE_SITES_DIR/$file" "$APACHE_SITES_DIR/$file-bak"
1366 done
1367
1368 resetWebServerPermissions
1369 chkconfig httpd on
1370 service httpd restart || errorExit "Could not start $INSTALL_WEB_SERVER"
1371}
1372
1373installCommonWebServerStuff_gentoo() {
1374 # Also add some extra tools for ruTorrent and some of its plugins
1375 PACKAGES="dev-lang/php logrotate"
1376 addProgram gzip app-arch/gzip
1377 addProgram curl net-misc/curl
1378 addProgram openssl dev-libs/openssl
1379 addProgram unrar app-arch/unrar
1380 installPackages
1381
1382 ACCEPT_LICENSE=MaxMind
1383 export ACCEPT_LICENSE
1384 PACKAGES="dev-php5/pecl-geoip"
1385 installPackages
1386 unset ACCEPT_LICENSE
1387}
1388
1389installApache_gentoo() {
1390 installCommonWebServerStuff_gentoo
1391 PACKAGES="www-servers/apache app-admin/apache-tools"
1392 installPackages
1393 PACKAGES="www-apache/mod_scgi"
1394 installPackages
1395
1396 WWW_PHP_INI=$(ls /etc/php/apache2-php5*/php.ini | tail -n1)
1397 [ -f "$WWW_PHP_INI" ] || errorExit "Could not find Apache php.ini file"
1398 APACHE_DIR=/etc/apache2
1399 local APACHE_CONF=$APACHE_DIR/httpd.conf
1400 local APACHE_SITES_DIR=$APACHE_DIR/vhosts.d
1401 local SERVER_ROOT=$(grep -E ^ServerRoot $APACHE_CONF | head -n1 | sed -e 's!^.*[ ][^/]*\(/[^"]*\).*!\1!')
1402 APACHE_SCGI_FILE="$APACHE_DIR/modules.d/scgi.conf"
1403 [ -d "$SERVER_ROOT" ] || errorExit "Apache server root dir does not exist: $SERVER_ROOT"
1404 initializeApacheVars apache apache "$APACHE_SITES_DIR"
1405 apacheCommonInitialization "" $SERVER_ROOT/modules
1406
1407 for file in 00_default_ssl_vhost.conf 00_default_vhost.conf; do
1408 [ -f "$APACHE_SITES_DIR/$file" ] && mv -f "$APACHE_SITES_DIR/$file" "$APACHE_SITES_DIR/$file-bak"
1409 done
1410
1411 appendFileStringVar /etc/conf.d/apache2 APACHE2_OPTS "-D SCGI"
1412 appendFileStringVar /etc/conf.d/apache2 APACHE2_OPTS "-D PHP5"
1413 appendFileStringVar /etc/conf.d/apache2 APACHE2_OPTS "-D SSL"
1414 cat >> $APACHE_SITE_FILE << EOF
1415Listen $HTTP_PORT
1416Listen $HTTPS_PORT
1417EOF
1418
1419 resetWebServerPermissions
1420 rc-update add apache2 default
1421 osHandler_$os restart_$INSTALL_WEB_SERVER
1422}
1423
1424nginxGetRpcMounts() {
1425 if [ "$INSTALL_RUTORRENT" = y ]; then
1426 local i=1
1427 local lp=; isWebServerRpcModule || lp='#'
1428 for packedUser in $USERS; do
1429 extractPackedUser $packedUser
1430 getUserScgiSocketPath "$osUser"
1431 local rpcMount="$(getUserRpcMount $i)"
1432
1433 cat << EOF
1434$lp location ~ ^$rpcMount\$ {
1435$lp include scgi_params;
1436$lp scgi_pass unix:$scgiSocketPath;
1437$lp auth_basic "$RUTORRENT_SITE_REALM";
1438$lp auth_basic_user_file "${WWW_PASSWORD_FILE}_$webUser";
1439$lp }
1440EOF
1441
1442 i=$(expr $i + 1)
1443 done
1444 fi
1445}
1446
1447nginxGetServerSection() {
1448 local port=$1
1449 local ssl=$2
1450
1451 cat << EOF
1452 server {
1453 listen $port;
1454 server_name localhost;
1455 auth_basic "$RUTORRENT_SITE_REALM";
1456 auth_basic_user_file "$WWW_PASSWORD_FILE";
1457
1458$(if [ "$ssl" = y ]; then
1459 cat << EOF2
1460 ssl on;
1461 ssl_certificate $WWW_PEMFILE;
1462 ssl_certificate_key $WWW_PEMFILE;
1463EOF2
1464fi)
1465
1466 location ~ ^/rutorrent/(?:share|conf) {
1467 deny all;
1468 }
1469
1470 location ~ /\.ht {
1471 deny all;
1472 }
1473
1474 location ~ /\.svn {
1475 deny all;
1476 }
1477
1478 location / {
1479 root $WWW_ROOT;
1480 index index.php index.html index.htm;
1481 }
1482
1483 location ~ \.php$ {
1484 root "$WWW_ROOT";
1485 fastcgi_pass unix:$PHPCGI_SOCKET_FILE;
1486 fastcgi_index index.php;
1487 fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
1488 include fastcgi_params;
1489 }
1490
1491$(nginxGetRpcMounts)
1492 }
1493EOF
1494}
1495
1496nginxWriteConfFile() {
1497 getNumCpus
1498 cat > $NGINX_CONF << EOF
1499worker_processes $NUMCPUS;
1500user $WWW_USER $WWW_GROUP;
1501events {
1502 worker_connections 1024;
1503}
1504
1505http {
1506 include mime.types;
1507 default_type application/octet-stream;
1508 sendfile on;
1509 keepalive_timeout 65;
1510
1511 # I have to set min length to 0 and http version to 1.0 or it won't compress
1512 # the XML-RPC (SCGI) responses. Those responses can be quite large if you're
1513 # using many torrent files.
1514 gzip on;
1515 gzip_min_length 0;
1516 gzip_http_version 1.0;
1517 gzip_types text/plain text/xml application/xml application/json text/css application/x-javascript text/javascript application/javascript;
1518
1519$(nginxGetServerSection $HTTP_PORT n)
1520$(nginxGetServerSection $HTTPS_PORT y)
1521}
1522EOF
1523 [ $? -eq 0 ] || errorExit "Could not write to file $NGINX_CONF"
1524}
1525
1526buildNginx() {
1527 buildStart
1528 PREFIX=$NGINX_DIR
1529 NGINX_BIN=$PREFIX/sbin/nginx
1530 NGINX_CONF=$PREFIX/conf/nginx.conf
1531 NGINX_PID_FILE=$PREFIX/nginx.pid
1532 NGINX_ACCESS_LOG=$PREFIX/logs/access.log
1533 NGINX_ERROR_LOG=$PREFIX/logs/error.log
1534 local configureFlags="\
1535 --prefix=$PREFIX \
1536 --sbin-path=$NGINX_BIN \
1537 --conf-path=$NGINX_CONF \
1538 --pid-path=$NGINX_PID_FILE \
1539 --lock-path=$PREFIX/logs/nginx.lock \
1540 --error-log-path=$NGINX_ERROR_LOG \
1541 --http-log-path=$NGINX_ACCESS_LOG \
1542 --user=$WWW_USER \
1543 --group=$WWW_GROUP \
1544 --with-http_ssl_module"
1545 export CFLAGS="$NGINX_CFLAGS"
1546 downloadAndBuild "nginx" "$NGINX_URL" "$NGINX_NAME" "$configureFlags" patchNginx
1547 unset CFLAGS
1548 buildEnd
1549}
1550
1551patchNginx() {
1552 # Get rid of the -Werror flag for gcc 4.6.0
1553 sed_i "s!-Werror[a-zA-Z0-9=-]*!!" "auto/cc/gcc"
1554}
1555
1556installNginx() {
1557 SCGI_USE_UNIX_DOMAIN_SOCKET=y
1558 CREATE_ONE_PASSWORD_FILE_PER_USER=y
1559 installBuildTools
1560 osHandler_$os preNginxInstall
1561 installUnrar
1562
1563 NGINX_DIR=/usr/local/nginx
1564 initializeWwwRootVar
1565 WWW_PASSWORD_FILE=$NGINX_DIR/rutorrent_passwd
1566 WWW_PEMFILE=$NGINX_DIR/rutorrent.pem
1567 WWW_USER=${WWW_USER:-nginx}
1568 WWW_GROUP=${WWW_GROUP:-nginx}
1569
1570 detectPhpCgi
1571 createWebServerUserGroup
1572 createPhpcgiSocket
1573
1574 buildNginx
1575 webServerCommonInitialization
1576 nginxWriteConfFile
1577
1578 addLogrotateConfig nginx \
1579 "$NGINX_ACCESS_LOG $NGINX_ERROR_LOG" \
1580 "[ -f \"$NGINX_PID_FILE\" ] && kill -USR1 \$(cat \"$NGINX_PID_FILE\") >/dev/null 2>&1; true"
1581
1582 resetWebServerPermissions
1583 osHandler_$os installPhpCgiService
1584 osHandler_$os installNginxService
1585}
1586
1587preNginxInstall_gentoo() {
1588 installCommonWebServerStuff_gentoo
1589 PACKAGES="libpcre openssl zlib php"
1590 installPackages
1591 WWW_PHP_INI=$(ls /etc/php/cgi-php5*/php.ini | tail -n1)
1592 [ -f "$WWW_PHP_INI" ] || errorExit "Could not find php-cgi php.ini file"
1593}
1594
1595preLighttpdInstall_gentoo() {
1596 preNginxInstall_gentoo
1597}
1598
1599lighttpdGetRpcRequire() {
1600 if [ "$INSTALL_RUTORRENT" = y ]; then
1601 local i=1
1602 for packedUser in $USERS; do
1603 extractPackedUser $packedUser
1604 local rpcMount="$(getUserRpcMount $i)"
1605
1606 cat << EOF
1607 "$rpcMount" => (
1608 "method" => "basic",
1609 "realm" => "$RUTORRENT_SITE_REALM",
1610 "require" => "user=$webUser",
1611 ),
1612EOF
1613 i=$(expr $i + 1)
1614 done
1615 fi
1616}
1617
1618lighttpdGetScgiServerTable() {
1619 echo 'scgi.server = ('
1620
1621 if [ "$INSTALL_RUTORRENT" = y ]; then
1622 local i=1
1623 local lp=; isWebServerRpcModule || lp='#'
1624 for packedUser in $USERS; do
1625 extractPackedUser $packedUser
1626 getUserScgiSocketPath "$osUser"
1627 local rpcMount="$(getUserRpcMount $i)"
1628
1629 cat << EOF
1630$lp "$rpcMount" => (
1631$lp (
1632$lp "socket" => "$scgiSocketPath",
1633$lp "check-local" => "disable",
1634$lp "disable-time" => 0,
1635$lp ),
1636$lp ),
1637EOF
1638 i=$(expr $i + 1)
1639 done
1640 fi
1641
1642 echo ')'
1643}
1644
1645lighttpdWriteConfFile() {
1646 cat > $LIGHTTPD_CONF << EOF
1647server.follow-symlink = "disable"
1648server.max-connections = 512
1649server.max-fds = 1024
1650server.max-keep-alive-idle = 15
1651dir-listing.activate = "disable"
1652server.pid-file = "$LIGHTTPD_PID_FILE"
1653server.errorlog = "$LIGHTTPD_ERROR_LOG"
1654accesslog.filename = "$LIGHTTPD_ACCESS_LOG"
1655
1656$(if [ $(uname -s) = Linux ]; then
1657 echo 'server.event-handler = "linux-sysepoll"'
1658 echo 'server.network-backend = "linux-sendfile"'
1659fi)
1660
1661server.username = "$WWW_USER"
1662server.groupname = "$WWW_GROUP"
1663
1664server.modules = (
1665# "mod_rewrite",
1666# "mod_redirect",
1667# "mod_alias",
1668 "mod_access",
1669 "mod_auth",
1670# "mod_status",
1671# "mod_simple_vhost",
1672# "mod_evhost",
1673# "mod_userdir",
1674# "mod_secdownload",
1675 "mod_fastcgi",
1676# "mod_proxy",
1677# "mod_cgi",
1678 "mod_scgi",
1679# "mod_ssi",
1680# "mod_compress",
1681# "mod_usertrack",
1682# "mod_expire",
1683# "mod_rrdtool",
1684 "mod_accesslog",
1685)
1686
1687fastcgi.server = (
1688 ".php" => (
1689 (
1690 "socket" => "$PHPCGI_SOCKET_FILE",
1691 ),
1692 ),
1693)
1694
1695index-file.names = ( "index.php", "index.html", "index.htm" )
1696static-file.exclude-extensions = ( ".fcgi", ".php", ".rb", "~", ".inc" )
1697
1698mimetype.assign = (
1699 ".html" => "text/html",
1700 ".htm" => "text/html",
1701 ".txt" => "text/plain",
1702 ".csv" => "text/plain",
1703 ".ini" => "text/plain",
1704 ".jpg" => "image/jpeg",
1705 ".jpeg" => "image/jpeg",
1706 ".gif" => "image/gif",
1707 ".png" => "image/png",
1708 ".bmp" => "image/bmp",
1709 ".css" => "text/css",
1710 ".js" => "application/javascript",
1711 ".ico" => "image/x-icon",
1712 ".json" => "application/json",
1713 ".torrent" => "application/x-bittorrent",
1714 ".pdf" => "application/pdf",
1715 ".bz2" => "application/x-bzip2",
1716 ".gz" => "application/x-gzip",
1717 ".tar.gz" => "application/x-tgz",
1718 ".tar" => "application/x-tar",
1719 ".tar.bz2" => "application/x-bzip-compressed-tar",
1720 ".tbz" => "application/x-bzip-compressed-tar",
1721 ".tgz" => "application/x-tgz",
1722 ".zip" => "application/zip",
1723 ".mp3" => "audio/mpeg",
1724 ".flac" => "audio/x-flac",
1725 ".m3u" => "audio/x-mpegurl",
1726 ".wma" => "audio/x-ms-wma",
1727 ".wax" => "audio/x-ms-wax",
1728 ".ogg" => "audio/ogg",
1729 ".wav" => "audio/x-wav",
1730 ".dtd" => "text/xml",
1731 ".xml" => "text/xml",
1732 ".mpeg" => "video/mpeg",
1733 ".mpg" => "video/mpeg",
1734 ".mp4" => "video/mp4",
1735 ".wmv" => "video/x-ms-wmv",
1736 ".avi" => "video/x-msvideo",
1737)
1738
1739server.document-root = "$WWW_ROOT"
1740server.port = $HTTP_PORT
1741
1742\$SERVER["socket"] == ":$HTTPS_PORT" {
1743 ssl.engine = "enable"
1744 ssl.pemfile = "$WWW_PEMFILE"
1745}
1746
1747url.access-deny = (".htaccess")
1748\$HTTP["url"] =~ "^/rutorrent/(?:share|conf)" {
1749 url.access-deny = ("")
1750}
1751\$HTTP["url"] =~ "/\\.svn" {
1752 url.access-deny = ("")
1753}
1754
1755auth.backend = "htpasswd"
1756auth.backend.htpasswd.userfile = "$WWW_PASSWORD_FILE"
1757auth.require = (
1758$(lighttpdGetRpcRequire)
1759 "/" => (
1760 "method" => "basic",
1761 "realm" => "$RUTORRENT_SITE_REALM",
1762 "require" => "valid-user",
1763 ),
1764)
1765
1766$(lighttpdGetScgiServerTable)
1767EOF
1768 [ $? -eq 0 ] || errorExit "Could not write to file $LIGHTTPD_CONF"
1769}
1770
1771buildLighttpd() {
1772 buildStart
1773 PREFIX=$LIGHTTPD_DIR
1774 LIGHTTPD_BIN=$PREFIX/sbin/lighttpd
1775 LIGHTTPD_CONF=$PREFIX/lighttpd.conf
1776
1777 # The log dir will be set to owner lighttpd since it's started as non-root.
1778 # Put the pid file there so it can write to it.
1779 LIGHTTPD_LOG_DIR=$PREFIX/logs
1780 LIGHTTPD_PID_FILE=$LIGHTTPD_LOG_DIR/lighttpd.pid
1781 LIGHTTPD_ERROR_LOG=$LIGHTTPD_LOG_DIR/error.log
1782 LIGHTTPD_ACCESS_LOG=$LIGHTTPD_LOG_DIR/access.log
1783
1784 local configureFlags="\
1785 --prefix=$PREFIX \
1786 --with-openssl \
1787 --with-pcre \
1788 --with-zlib \
1789 --without-bzip2"
1790 downloadAndBuild "lighttpd" "$LIGHTTPD_URL" "$LIGHTTPD_NAME" "$configureFlags"
1791 buildEnd
1792}
1793
1794installLighttpd() {
1795 SCGI_USE_UNIX_DOMAIN_SOCKET=y
1796 installBuildTools
1797 osHandler_$os preLighttpdInstall
1798 installUnrar
1799
1800 LIGHTTPD_DIR=/usr/local/lighttpd
1801 initializeWwwRootVar
1802 WWW_PASSWORD_FILE=$LIGHTTPD_DIR/rutorrent_passwd
1803 WWW_PEMFILE=$LIGHTTPD_DIR/rutorrent.pem
1804 WWW_USER=${WWW_USER:-lighttpd}
1805 WWW_GROUP=${WWW_GROUP:-lighttpd}
1806
1807 detectPhpCgi
1808 createWebServerUserGroup
1809 createPhpcgiSocket
1810
1811 buildLighttpd
1812 webServerCommonInitialization
1813 lighttpdWriteConfFile
1814
1815 addLogrotateConfig lighttpd \
1816 "$LIGHTTPD_ACCESS_LOG $LIGHTTPD_ERROR_LOG" \
1817 "[ -f \"$LIGHTTPD_PID_FILE\" ] && kill -HUP \$(cat \"$LIGHTTPD_PID_FILE\") >/dev/null 2>&1; true"
1818
1819 mkdir -p "$LIGHTTPD_LOG_DIR"
1820 chown -R $WWW_USER:$WWW_GROUP "$LIGHTTPD_LOG_DIR"
1821
1822 resetWebServerPermissions
1823 osHandler_$os installPhpCgiService
1824 osHandler_$os installLighttpdService
1825}
1826
1827# Add $name=$value to the file, or modify an existing line if present in the file
1828setVsftpdValue() {
1829 local confFile="$1"
1830 local name="$2"
1831 local value="$3"
1832 local newLine="$name=$value"
1833
1834 sed_i "s!^[ ]*$name[ =:].*\$!$newLine!" "$confFile"
1835 grep -qE "^$newLine$" "$confFile" || echo "$newLine" >> "$confFile"
1836}
1837
1838# Same as setVsftpdValue but makes sure the option exists
1839setVsftpdValue2() {
1840 local confFile="$1"
1841 local name="$2"
1842 local value="$3"
1843
1844 [ -z "$VSFTPD_PATH" ] && return
1845 grep -q "$name" "$VSFTPD_PATH" && setVsftpdValue "$confFile" "$name" "$value"
1846}
1847
1848updateVsftpdConf() {
1849 local confFile="$1"
1850 touch "$confFile"
1851
1852 VSFTPD_PATH=$(which vsftpd 2>/dev/null)
1853
1854 setVsftpdValue "$confFile" anonymous_enable NO
1855 setVsftpdValue "$confFile" dirlist_enable YES
1856 setVsftpdValue "$confFile" download_enable YES
1857 setVsftpdValue "$confFile" guest_enable NO
1858 setVsftpdValue "$confFile" listen YES
1859 setVsftpdValue "$confFile" listen_ipv6 NO
1860 setVsftpdValue "$confFile" local_enable YES
1861 setVsftpdValue "$confFile" local_umask $DEFAULT_UMASK
1862 setVsftpdValue "$confFile" max_per_ip 0
1863 setVsftpdValue "$confFile" pasv_enable YES
1864 setVsftpdValue "$confFile" port_enable YES
1865 setVsftpdValue "$confFile" pasv_promiscuous NO
1866 setVsftpdValue "$confFile" port_promiscuous NO
1867 setVsftpdValue "$confFile" pasv_min_port 0
1868 setVsftpdValue "$confFile" pasv_max_port 0
1869 setVsftpdValue "$confFile" write_enable YES
1870
1871 if [ "$USE_ENCRYPTED_FTP" = y ]; then
1872 local pemfile=/etc/vsftpd.pem
1873 createSelfSignedCertFile "$pemfile"
1874
1875 FTP_SERVER_TYPE="FTPES - Encrypted (FTP over explicit TLS/SSL)"
1876 FTP_PORT=${FTP_PORT:-$DEFAULT_PORT_FTPES}
1877 setVsftpdValue "$confFile" listen_port $FTP_PORT
1878 setVsftpdValue "$confFile" ssl_enable YES
1879
1880 setVsftpdValue "$confFile" allow_anon_ssl NO
1881 setVsftpdValue "$confFile" force_local_data_ssl YES
1882 setVsftpdValue "$confFile" force_local_logins_ssl YES
1883 setVsftpdValue "$confFile" ssl_sslv2 NO
1884 setVsftpdValue "$confFile" ssl_sslv3 NO
1885 setVsftpdValue "$confFile" ssl_tlsv1 YES
1886 setVsftpdValue "$confFile" rsa_cert_file "$pemfile"
1887
1888 setVsftpdValue2 "$confFile" implicit_ssl NO
1889 setVsftpdValue2 "$confFile" require_cert NO
1890 setVsftpdValue2 "$confFile" require_ssl_reuse NO
1891 setVsftpdValue2 "$confFile" ssl_request_cert YES
1892 setVsftpdValue2 "$confFile" strict_ssl_read_eof NO
1893 setVsftpdValue2 "$confFile" strict_ssl_write_shutdown NO
1894 setVsftpdValue2 "$confFile" validate_cert NO
1895 else
1896 FTP_SERVER_TYPE="FTP - Non-encrypted"
1897 FTP_PORT=${FTP_PORT:-$DEFAULT_PORT_FTP}
1898 setVsftpdValue "$confFile" listen_port $FTP_PORT
1899 setVsftpdValue "$confFile" ssl_enable NO
1900 fi
1901
1902 # The private key is in rsa_cert_file
1903 sed_i 'g/rsa_private_key_file/d' "$confFile"
1904}
1905
1906installVsftpd_chkconfig() {
1907 local vsftpdConf="$1"
1908 installProgram vsftpd
1909 [ -f "$vsftpdConf" ] || errorExit "Invalid vsftpd.conf file: $vsftpdConf"
1910 updateVsftpdConf "$vsftpdConf"
1911 chkconfig vsftpd on
1912 if ! service vsftpd restart; then
1913 if [ "$SELINUX_ENABLED" = y ]; then
1914 errorExit "Could not restart vsftpd. SELinux could be the reason."
1915 else
1916 errorExit "Could not restart vsftpd"
1917 fi
1918 fi
1919}
1920
1921installVsftpd_gentoo() {
1922 installProgram net-ftp/vsftpd
1923 local vsftpdConf=/etc/vsftpd/vsftpd.conf
1924 if ! [ -f $vsftpdConf ]; then
1925 touch $vsftpdConf
1926 [ -f $vsftpdConf.example ] && cp $vsftpdConf.example $vsftpdConf
1927 fi
1928 updateVsftpdConf $vsftpdConf
1929 rc-update add vsftpd default
1930 /etc/init.d/vsftpd restart
1931}
1932
1933installService_chkconfig1() {
1934 CHKCONFIG_SERVICE_NAME=$1
1935 CHKCONFIG_SERVICE_FILE=/etc/init.d/$CHKCONFIG_SERVICE_NAME
1936 CHKCONFIG_LOCK_FILE=/var/lock/subsys/$CHKCONFIG_SERVICE_NAME
1937}
1938
1939installService_chkconfig2() {
1940 chmod +x "$CHKCONFIG_SERVICE_FILE" || errorExit "Could not set +x bit, file $CHKCONFIG_SERVICE_FILE."
1941 chkconfig --add $CHKCONFIG_SERVICE_NAME || errorExit "Could not install service $CHKCONFIG_SERVICE_FILE. Run this script as root."
1942 service $CHKCONFIG_SERVICE_NAME restart
1943}
1944
1945getChkconfigScriptContents() {
1946 local desc="$1"
1947 cat << EOF
1948# chkconfig: 2345 85 15
1949# description: $desc
1950EOF
1951}
1952
1953getLsbStartupScriptContents() {
1954 local startupName="$1"
1955 local desc="$2"
1956 cat << EOF
1957### BEGIN INIT INFO
1958# Provides: $startupName
1959# Required-Start: \$local_fs \$network \$syslog
1960# Required-Stop: \$local_fs \$syslog
1961# Default-Start: $LSB_DEFAULT_START
1962# Default-Stop: $LSB_DEFAULT_STOP
1963# Short-Description: $desc
1964# Description: $desc
1965### END INIT INFO
1966EOF
1967}
1968
1969# You must define v_{startIt,stopIt,restartIt,showStatus} and isStarted funcs
1970getLsbStartupFooter() {
1971 cat << EOF
1972resetPath # Some include files may have reset it
1973LOCKFILE=$1
1974updateLock() {
1975 [ -z "\$LOCKFILE" ] && return
1976 if isStarted; then
1977 touch \$LOCKFILE
1978 else
1979 rm -f \$LOCKFILE
1980 fi
1981}
1982
1983RETVAL=0
1984case \$1 in
1985 start)
1986 v_startIt
1987 ;;
1988 stop)
1989 v_stopIt
1990 ;;
1991 force-reload|restart)
1992 v_restartIt
1993 ;;
1994 try-restart)
1995 isStarted && v_restartIt
1996 ;;
1997 status)
1998 v_showStatus
1999 ;;
2000 *)
2001 echo "Usage: \$0 {start|stop|restart|try-restart|force-reload|status}"
2002 RETVAL=1
2003 ;;
2004esac
2005
2006updateLock
2007exit \$RETVAL
2008EOF
2009}
2010
2011getCommonStartupScriptContents_autodl() {
2012 local USER="$1"
2013 local STARTUPNAME="$2"
2014 cat << EOF
2015NAME=$STARTUPNAME
2016USER=$USER
2017SESSIONNAME=autodl
2018
2019resetPath() {
2020 PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:\$PATH"
2021}
2022resetPath
2023
2024# Make sure the path is correct, and make sure we're in the home dir.
2025USER_INIT="umask $DEFAULT_UMASK; cd; PATH=\\\$PATH:\$PATH"
2026
2027# Run user command, ignoring any messages sent to stdout (eg. 'No mail.')
2028runUserCmd() {
2029 su - \$USER -c "\$USER_INIT; \$1" >/dev/null && return 0
2030 return 1
2031}
2032
2033isStarted() {
2034 su - \$USER -c "\$USER_INIT; screen -ls | grep -qE \\"[ ][0-9]+\\\\.\$SESSIONNAME[ ]\\"" >/dev/null && return 0
2035 return 1
2036}
2037
2038startIt() {
2039 isStarted && return 0
2040
2041 local START_IRSSI=n
2042 local START_RTORRENT=n
2043 which irssi > /dev/null 2>&1 && START_IRSSI=y
2044 which rtorrent > /dev/null 2>&1 && START_RTORRENT=y
2045
2046 case \$START_IRSSI\$START_RTORRENT in
2047 yy)
2048 runUserCmd "screen -S \$SESSIONNAME -d -t rtorrent -m rtorrent"
2049 runUserCmd "screen -d -r \$SESSIONNAME -X screen -t irssi irssi"
2050 ;;
2051 yn)
2052 runUserCmd "screen -S \$SESSIONNAME -d -t irssi -m irssi"
2053 ;;
2054 ny)
2055 runUserCmd "screen -S \$SESSIONNAME -d -t rtorrent -m rtorrent"
2056 ;;
2057 nn)
2058 ;;
2059 esac
2060 return 0
2061}
2062
2063stopIt() {
2064 isStarted || return 0
2065
2066 runUserCmd "screen -d -r \$SESSIONNAME -p irssi -X stuff \\"/quit
2067/quit
2068\\""
2069 runUserCmd "screen -d -r \$SESSIONNAME -p rtorrent -X xon"
2070
2071 for i in 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4; do
2072 isStarted || break
2073 sleep 1
2074 done
2075
2076 # If it's still not stopped, kill the whole screen session
2077 if isStarted; then
2078 echo -n "Couldn't stop it. Killing screen session..."
2079 runUserCmd "screen -d -r \$SESSIONNAME -p rtorrent -X xon"
2080 sleep 2
2081 runUserCmd "screen -d -r \$SESSIONNAME -X quit"
2082 echo "Done."
2083 fi
2084
2085 return 0
2086}
2087
2088v_restartIt() {
2089 v_stopIt
2090 v_startIt
2091}
2092
2093v_showStatus() {
2094 if isStarted; then
2095 echo "\$NAME is running."
2096 else
2097 echo "\$NAME is stopped."
2098 fi
2099}
2100EOF
2101}
2102
2103getChkconfigScriptContents_autodl() {
2104 getChkconfigScriptContents "$AUTODL_STARTUP_DESC"
2105}
2106
2107# LSB style script, also supports chkconfig
2108# $1 = user name
2109# $2 = service name
2110getLsbStartupHeader_autodl() {
2111 local USER="$1"
2112 local STARTUPNAME="$2"
2113 cat << EOF
2114$(getChkconfigScriptContents_autodl)
2115$(getLsbStartupScriptContents "$STARTUPNAME" "$AUTODL_STARTUP_DESC")
2116
2117$(getCommonStartupScriptContents_autodl "$USER" "$STARTUPNAME")
2118EOF
2119}
2120
2121installService_mandriva() {
2122 local serviceName="$1"
2123 local headerCommand="$2"
2124 installService_chkconfig1 $serviceName
2125 cat > "$CHKCONFIG_SERVICE_FILE" << EOF
2126#!/bin/bash
2127$(eval $headerCommand)
2128
2129. /etc/rc.d/init.d/functions
2130
2131v_startIt() {
2132 gprintf "Starting %s:" "\$NAME"
2133 startIt && success "startup" || failure "startup"
2134 echo
2135}
2136
2137v_stopIt() {
2138 gprintf "Stopping %s:" "\$NAME"
2139 stopIt && success "stop" || failure "stop"
2140 echo
2141}
2142
2143$(getLsbStartupFooter "$CHKCONFIG_LOCK_FILE")
2144EOF
2145 [ $? -eq 0 ] || errorExit "Could not write to file $CHKCONFIG_SERVICE_FILE. Run this script as root."
2146 installService_chkconfig2
2147}
2148
2149installService_mandriva_autodl() {
2150 local user=$1
2151 installService_mandriva autodl_$user "getLsbStartupHeader_autodl \"$user\" \"\$CHKCONFIG_SERVICE_NAME\""
2152}
2153
2154installService_mandriva_phpcgi() {
2155 installService_mandriva phpcgi getLsbStartupHeader_phpcgi
2156}
2157
2158installService_mandriva_nginx() {
2159 installService_mandriva nginx getLsbStartupHeader_nginx
2160}
2161
2162installService_mandriva_lighttpd() {
2163 installService_mandriva lighttpd getLsbStartupHeader_lighttpd
2164}
2165
2166installService_gentoo() {
2167 local scriptName="$1"
2168 local desc="$2"
2169 local headerCommand="$3"
2170 local serviceFile="/etc/init.d/$scriptName"
2171
2172 cat > "$serviceFile" << EOF
2173#!/sbin/runscript
2174
2175name=$scriptName
2176description="$desc"
2177
2178depend() {
2179 need localmount
2180 need net
2181}
2182
2183$(eval $headerCommand)
2184
2185start() {
2186 ebegin "Starting \$name"
2187 startIt
2188 eend \$?
2189}
2190
2191stop() {
2192 ebegin "Stopping \$name"
2193 stopIt
2194 eend \$?
2195}
2196
2197status() {
2198 if isStarted; then
2199 einfo "status: started"
2200 return 0
2201 else
2202 einfo "status: stopped"
2203 return 1
2204 fi
2205}
2206EOF
2207 [ $? -eq 0 ] || errorExit "Could not write to file $serviceFile. Run this script as root."
2208 chmod +x "$serviceFile"
2209 rc-update add $scriptName default || errorExit "Could not add service $scriptName"
2210 $serviceFile restart
2211}
2212
2213installService_gentoo_autodl() {
2214 local user="$1"
2215 installService_gentoo autodl_$user "$AUTODL_STARTUP_DESC" "getCommonStartupScriptContents_autodl \"$user\" \"\$scriptName\""
2216}
2217
2218installService_gentoo_phpcgi() {
2219 installService_gentoo phpcgi "$PHPCGI_STARTUP_DESC" "getCommonStartupScriptContents_phpcgi \"$WWW_USER\" \"$WWW_PHP_CGI\""
2220}
2221
2222installService_gentoo_nginx() {
2223 installService_gentoo nginx "$NGINX_STARTUP_DESC" "getCommonStartupScriptContents_nginx \"$NGINX_BIN\""
2224}
2225
2226installService_gentoo_lighttpd() {
2227 installService_gentoo lighttpd "$LIGHTTPD_STARTUP_DESC" "getCommonStartupScriptContents_lighttpd \"$LIGHTTPD_BIN\""
2228}
2229
2230installService_bsd_autodl() {
2231 local user="$1"
2232 local scriptName="$2"
2233 local file="$3"
2234
2235 cat > "$file" << EOF
2236#!/bin/sh
2237# PROVIDE: autodl_$user
2238# REQUIRE: FILESYSTEMS NETWORKING
2239# KEYWORD: shutdown
2240
2241. /etc/rc.subr
2242
2243name=$scriptName
2244desc="$AUTODL_STARTUP_DESC"
2245start_cmd=v_startIt
2246stop_cmd=v_stopIt
2247restart_cmd=v_restartIt
2248reload_cmd=v_restartIt
2249status_cmd=v_showStatus
2250extra_commands="status"
2251
2252v_startIt() {
2253 echo -n "Starting \$NAME"
2254 startIt && echo "." || echo ". ERROR."
2255}
2256
2257v_stopIt() {
2258 echo -n "Stopping \$NAME..."
2259 stopIt && echo "done." || echo "ERROR."
2260}
2261
2262$(getCommonStartupScriptContents_autodl "$user" "$scriptName")
2263
2264load_rc_config \$name
2265run_rc_command "\$1"
2266EOF
2267 [ $? -eq 0 ] || errorExit "Could not write to file $file. Run this script as root."
2268 chmod +x "$file"
2269}
2270
2271getCommonStartupScriptContents_simpleService() {
2272 local USER="$1"
2273 local BINPATH="$2"
2274 local START_CMD="$3"
2275 local PID_FILE="$4"
2276 cat << EOF
2277USER=$USER
2278BINPATH="$BINPATH"
2279NAME=\${BINPATH##*/}
2280PID_FILE="$PID_FILE"
2281
2282resetPath() {
2283 PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:\$PATH"
2284}
2285resetPath
2286
2287getPids() {
2288 if [ -n "\$PID_FILE" ]; then
2289 pids=
2290 [ -f "\$PID_FILE" ] || return
2291 local the_pids="\$(cat "\$PID_FILE" 2>/dev/null)"
2292 for pid in \$the_pids; do
2293 PS_FORMAT= LINES= COLUMNS= ps ax | grep -qE "^[ ]*\$pid[ ]" && pids="\$pids \$pid"
2294 done
2295 [ -z "\$pids" ] && rm -f "\$PID_FILE"
2296 else
2297 # ps uses the COLUMNS variable... Make sure it's off so we get the full path.
2298 pids=\$(PS_FORMAT= LINES= COLUMNS= ps aux | grep -v grep | grep \$BINPATH | awk '{print \$2}')
2299 fi
2300}
2301
2302isStarted() {
2303 getPids
2304 [ -n "\$pids" ] && return 0
2305 return 1
2306}
2307
2308startIt() {
2309 isStarted && return 0
2310
2311 if [ \$USER = root ]; then
2312 $START_CMD
2313 else
2314 su - \$USER "-c $START_CMD"
2315 fi
2316 [ -n "\$PID_FILE" ] && sleep 2 # Allow it some time to create the pid file
2317 if ! isStarted; then
2318 for i in 1 2 3 4 5; do
2319 sleep 1
2320 isStarted && break
2321 done
2322 isStarted || return 1
2323 fi
2324
2325 return 0
2326}
2327
2328stopIt() {
2329 isStarted || return 0
2330
2331 kill \$pids 2>/dev/null
2332
2333 for i in 0 1 2 3 4 5 6 7 8 9; do
2334 isStarted || break
2335 sleep 1
2336 done
2337
2338 isStarted && kill -KILL \$pids 2>/dev/null
2339
2340 return 0
2341}
2342
2343v_startIt() {
2344 startIt
2345}
2346
2347v_stopIt() {
2348 stopIt
2349}
2350
2351v_restartIt() {
2352 v_stopIt
2353 v_startIt
2354}
2355
2356v_showStatus() {
2357 if isStarted; then
2358 echo "\$NAME is running."
2359 else
2360 echo "\$NAME is stopped."
2361 fi
2362}
2363EOF
2364}
2365
2366getCommonStartupScriptContents_phpcgi() {
2367 [ -n "$PHPCGI_SOCKET_FILE" ] || errorExit "PHPCGI_SOCKET_FILE is not initialized"
2368 getCommonStartupScriptContents_simpleService "$1" "$2" \
2369 "PHP_FCGI_CHILDREN=5 PHP_FCGI_MAX_REQUESTS=125 \$BINPATH -q -b \"$PHPCGI_SOCKET_FILE\" &"
2370}
2371
2372getLsbStartupHeader_phpcgi() {
2373 getChkconfigScriptContents "$PHPCGI_STARTUP_DESC"
2374 getLsbStartupScriptContents phpcgi "$PHPCGI_STARTUP_DESC"
2375
2376 getCommonStartupScriptContents_phpcgi "$WWW_USER" "$WWW_PHP_CGI"
2377}
2378
2379getCommonStartupScriptContents_nginx() {
2380 getCommonStartupScriptContents_simpleService "root" "$1" "\$BINPATH" "$NGINX_PID_FILE"
2381}
2382
2383getLsbStartupHeader_nginx() {
2384 getChkconfigScriptContents "$NGINX_STARTUP_DESC"
2385 getLsbStartupScriptContents nginx "$NGINX_STARTUP_DESC"
2386
2387 getCommonStartupScriptContents_nginx "$NGINX_BIN"
2388}
2389
2390getCommonStartupScriptContents_lighttpd() {
2391 getCommonStartupScriptContents_simpleService "root" "$1" "\$BINPATH -f $LIGHTTPD_CONF 2>/dev/null" "$LIGHTTPD_PID_FILE"
2392}
2393
2394getLsbStartupHeader_lighttpd() {
2395 getChkconfigScriptContents "$LIGHTTPD_STARTUP_DESC"
2396 getLsbStartupScriptContents lighttpd "$LIGHTTPD_STARTUP_DESC"
2397
2398 getCommonStartupScriptContents_lighttpd "$LIGHTTPD_BIN"
2399}
2400
2401addLsbHeaderToStartupScript() {
2402 local scriptPath="$1"
2403 local provides="${2:-$scriptPath}"
2404 local desc="${3:-$provides}"
2405 [ -x "$scriptPath" ] || return
2406 grep -qE '^### BEGIN INIT INFO' "$scriptPath" && return
2407 ed -s "$scriptPath" > /dev/null 2>&1 << EOF
24081a
2409$(getLsbStartupScriptContents "$provides" "$desc")
2410.
2411w
2412q
2413EOF
2414}
2415
2416installMissingPerlModules() {
2417 detectMissingPerlModules
2418 [ -z "$MISSING_PERL_MODULES" ] && return
2419 cat << EOF
2420$CWARNING
2421The following Perl modules are still missing:
2422 $MISSING_PERL_MODULES
2423I'll try to use the cpan script to install them.$CEND
2424EOF
2425
2426 # Some Perl modules will fail to build unless Test::More is installed
2427 MISSING_PERL_MODULES="Test::More $MISSING_PERL_MODULES"
2428
2429 echo "${CMSG}Installing cpan and required build tools...$CEND"
2430 installBuildTools
2431 osHandler_$os installCpanTools
2432 detectCpanBin
2433 if [ -n "$CPAN" ]; then
2434 $CPAN $MISSING_PERL_MODULES
2435 else
2436 local mods=
2437 for mod in $MISSING_PERL_MODULES; do
2438 [ -n "$mods" ] && mods="$mods,"
2439 mods="$mods \"$mod\""
2440 done
2441 perl -MCPAN -e "CPAN::Shell->install($mods)"
2442 fi
2443
2444 detectMissingPerlModules
2445 [ -z "$MISSING_PERL_MODULES" ] && return
2446 errorExit "CPAN somehow failed to install the missing Perl modules. Missing: $MISSING_PERL_MODULES"
2447}
2448
2449osHandler_debian() {
2450 case $1 in
2451 init)
2452 INSTALL="apt-get -y install"
2453 FEATURES="service rtorrent apache nginx lighttpd vsftpd webmin"
2454 BUILD_TOOLS="build-essential make file pkg-config libtool m4"
2455 ;;
2456 init2)
2457 apt-get update
2458 installProgram ed
2459
2460 # Make sure Debian 6 doesn't fail when adding new services. We need ed for this
2461 # so run it after installing ed...
2462 addLsbHeaderToStartupScript /etc/init.d/webmin "webmin" "webmin"
2463 ;;
2464 installTools)
2465 PACKAGES=
2466 addProgram svn subversion
2467 addProgram wget
2468 addProgram unzip
2469 addProgram screen
2470 installPackages
2471 # Make sure subversion won't complain about invalid certs
2472 $INSTALL ca-certificates
2473 ;;
2474 installAutodlTools)
2475 PACKAGES=
2476 addProgram perl
2477 addProgram irssi
2478 addPerlModule Archive::Zip libarchive-zip-perl
2479 addPerlModule HTML::Parser libhtml-parser-perl
2480 addPerlModule Digest::SHA1 libdigest-sha1-perl
2481 installPackages
2482
2483 installPerlModule Net::SSLeay libnet-ssleay-perl
2484 installPerlModule XML::LibXML libxml-libxml-perl
2485 installPerlModule JSON::XS libjson-xs-perl
2486 installPerlModule JSON libjson-perl
2487 ;;
2488 installCpanTools)
2489 # Need to remove the old JSON or cpan may fail to build the modules
2490 if echo "$OLD_PERL_MODULES" | grep -qE '(^| )JSON( |$)'; then
2491 apt-get -y remove libjson-perl
2492 fi
2493
2494 PACKAGES=
2495 if echo "$MISSING_PERL_MODULES" | grep -q 'XML::LibXML'; then
2496 PACKAGES="$PACKAGES libxml2 libxml2-dev zlib1g zlib1g-dev"
2497 fi
2498 if echo "$MISSING_PERL_MODULES" | grep -q 'Net::SSLeay'; then
2499 # There's no libssl package
2500 PACKAGES="$PACKAGES openssl libssl-dev zlib1g zlib1g-dev"
2501 fi
2502 installPackages
2503 ;;
2504 installRtorrentBuildTools)
2505 PACKAGES="libsigc++-2.0-dev libssl-dev libncurses-dev"
2506 if apt-cache search libcurl4-openssl-dev 2> /dev/null | grep -q 'libcurl4-openssl-dev'; then
2507 PACKAGES="$PACKAGES libcurl4-openssl-dev"
2508 else
2509 PACKAGES="$PACKAGES libcurl3-openssl-dev"
2510 fi
2511 installPackages
2512 ;;
2513 installPhpModules)
2514 installMissingPhp5Packages
2515 ;;
2516 _installService)
2517 local serviceName="$2"
2518 local headerCommand="$3"
2519 local serviceFile=/etc/init.d/$serviceName
2520 local lockFile=
2521 cat > "$serviceFile" << EOF
2522#!/bin/sh
2523$(eval $headerCommand)
2524
2525. /lib/lsb/init-functions
2526
2527v_startIt() {
2528 log_begin_msg "Starting \$NAME..."
2529 startIt
2530 log_end_msg \$?
2531}
2532
2533v_stopIt() {
2534 log_begin_msg "Stopping \$NAME..."
2535 stopIt
2536 log_end_msg \$?
2537}
2538
2539$(getLsbStartupFooter "$lockFile")
2540EOF
2541 [ $? -eq 0 ] || errorExit "Could not write to file $serviceFile. Run this script as root."
2542 chmod +x "$serviceFile" || errorExit "Could not set +x bit, file $serviceFile."
2543 update-rc.d $serviceName defaults || errorExit "Could not install service $serviceFile. Run this script as root."
2544 invoke-rc.d $serviceName restart
2545 ;;
2546 installAutodlService)
2547 local user=$2
2548 osHandler_$os _installService autodl_$user "getLsbStartupHeader_autodl \"$user\" \"\$serviceName\""
2549 ;;
2550 _installCommonWebServerStuff)
2551 # Also add some extra tools for ruTorrent and some of its plugins
2552 PACKAGES="php5-cli gzip curl openssl logrotate"
2553 installPackages
2554 # Ubuntu 8 doesn't have php5-geoip
2555 PACKAGES="php5-geoip"
2556 installPackages
2557 PACKAGES="unrar"
2558 installPackages
2559 ;;
2560 installApache)
2561 osHandler_$os _installCommonWebServerStuff
2562 PACKAGES="apache2-mpm-prefork libapache2-mod-php5 php5 "
2563 installPackages
2564 PACKAGES="libapache2-mod-scgi"; installPackages
2565
2566 WWW_PHP_INI=/etc/php5/apache2/php.ini
2567 APACHE_DIR=/etc/apache2
2568 APACHE_SITE_NAME=rutorrent
2569 APACHE_SCGI_FILE=$APACHE_DIR/mods-available/scgi.load
2570 initializeApacheVars www-data www-data "$APACHE_DIR/sites-available"
2571 apacheCommonInitialization "apache2-prefork-dev" /usr/lib/apache2/modules
2572
2573 a2enmod ssl || errorExit "Could not enable mod_ssl"
2574 a2enmod scgi || errorExit "Could not enable mod_scgi"
2575 # Ubuntu Server 6 doesn't come with this module
2576 a2enmod auth_basic
2577 a2dissite default
2578 a2dissite default-ssl
2579 a2ensite $APACHE_SITE_NAME || errorExit "Could not enable site"
2580 if ! grep -qE "^[ ]*Listen.*[: ]$HTTPS_PORT\\>" "$APACHE_DIR/ports.conf"; then
2581 echo "Listen $HTTPS_PORT" >> "$APACHE_DIR/ports.conf"
2582 fi
2583 resetWebServerPermissions
2584 invoke-rc.d apache2 restart || errorExit "Could not start $INSTALL_WEB_SERVER"
2585 ;;
2586 restart_apache)
2587 invoke-rc.d apache2 restart || errorExit "Could not start $INSTALL_WEB_SERVER"
2588 ;;
2589 installVsftpd)
2590 installProgram vsftpd
2591 updateVsftpdConf /etc/vsftpd.conf
2592 invoke-rc.d vsftpd restart || errorExit "Could not restart vsftpd"
2593 ;;
2594 preNginxInstall)
2595 WWW_PHP_INI=/etc/php5/cgi/php.ini
2596 osHandler_$os _installCommonWebServerStuff
2597 PACKAGES="libpcre3-dev libssl-dev zlib1g-dev php5-cgi"
2598 installPackages
2599
2600 # Make sure it builds on Debian GNU/kFreeBSD 6.0.
2601 if [ "$(uname -s)" != Linux ]; then
2602 NGINX_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64"
2603 fi
2604 ;;
2605 installPhpCgiService)
2606 osHandler_$os _installService phpcgi getLsbStartupHeader_phpcgi
2607 ;;
2608 installNginxService)
2609 osHandler_$os _installService nginx getLsbStartupHeader_nginx
2610 ;;
2611 restart_nginx)
2612 invoke-rc.d phpcgi restart || errorExit "Could not start php-cgi"
2613 invoke-rc.d nginx restart || errorExit "Could not start $INSTALL_WEB_SERVER"
2614 ;;
2615 preLighttpdInstall)
2616 WWW_PHP_INI=/etc/php5/cgi/php.ini
2617 osHandler_$os _installCommonWebServerStuff
2618 PACKAGES="libpcre3-dev libssl-dev zlib1g-dev php5-cgi"
2619 installPackages
2620 ;;
2621 installLighttpdService)
2622 osHandler_$os _installService lighttpd getLsbStartupHeader_lighttpd
2623 ;;
2624 restart_lighttpd)
2625 invoke-rc.d phpcgi restart || errorExit "Could not start php-cgi"
2626 invoke-rc.d lighttpd restart || errorExit "Could not start $INSTALL_WEB_SERVER"
2627 ;;
2628 postWebminInstall)
2629 addLsbHeaderToStartupScript /etc/init.d/webmin "webmin" "webmin"
2630 ;;
2631 *)
2632 ;;
2633 esac
2634}
2635
2636osHandler_fedora() {
2637 case $1 in
2638 init)
2639 INSTALL="yum -y install"
2640 FEATURES="service rtorrent apache nginx lighttpd vsftpd webmin"
2641 BUILD_TOOLS="gcc gcc-c++ make kernel-headers pkgconfig file libtool m4"
2642 ;;
2643 init2)
2644 installProgram which
2645 installProgram ed
2646 ;;
2647 installTools)
2648 PACKAGES=
2649 addProgram svn subversion
2650 addProgram wget
2651 addProgram unzip
2652 addProgram screen
2653 installPackages
2654 ;;
2655 installAutodlTools)
2656 if grep -q "release 4[. ]" /etc/redhat-release; then
2657 IRSSI_LOAD_PERL=y
2658 fi
2659 PACKAGES=
2660 addProgram perl
2661 addProgram irssi
2662 addPerlModule Time::HiRes perl-Time-HiRes
2663 addPerlModule Archive::Zip perl-Archive-Zip
2664 addPerlModule Net::SSLeay perl-Net-SSLeay
2665 addPerlModule HTML::Parser perl-HTML-Parser
2666 addPerlModule XML::LibXML perl-XML-LibXML
2667 addPerlModule Digest::SHA1 perl-Digest-SHA1
2668 addPerlModule JSON::XS perl-JSON-XS
2669 addPerlModule JSON perl-JSON
2670 installPackages
2671 ;;
2672 installCpanTools)
2673 # Need to remove the old JSON or cpan may fail to build the modules
2674 if echo "$OLD_PERL_MODULES" | grep -qE '(^| )JSON( |$)'; then
2675 yum -y remove perl-JSON
2676 fi
2677
2678 # CentOS doesn't have 'perl-CPAN'. It's in the 'perl' package though.
2679 PACKAGES="perl-CPAN"
2680 if echo "$MISSING_PERL_MODULES" | grep -q 'XML::LibXML'; then
2681 PACKAGES="$PACKAGES libxml2 libxml2-devel zlib zlib-devel"
2682 fi
2683 if echo "$MISSING_PERL_MODULES" | grep -q 'Net::SSLeay'; then
2684 PACKAGES="$PACKAGES openssl openssl-devel zlib zlib-devel"
2685 fi
2686 installPackages
2687 ;;
2688 installRtorrentBuildTools)
2689 # CentOS 5: curl-devel, no libsigc++20
2690 # Fedora 14: libcurl-devel
2691 PACKAGES="libsigc++20-devel ncurses-devel openssl-devel libcurl-devel curl-devel"
2692 installPackages
2693 ;;
2694 installPhpModules)
2695 ;;
2696 _installService)
2697 local serviceName="$2"
2698 local headerCommand="$3"
2699 installService_chkconfig1 $serviceName
2700 cat > "$CHKCONFIG_SERVICE_FILE" << EOF
2701#!/bin/bash
2702$(eval $headerCommand)
2703
2704. /etc/rc.d/init.d/functions
2705
2706v_startIt() {
2707 echo -n "Starting \$NAME: "
2708 startIt && success || failure
2709 echo
2710}
2711
2712v_stopIt() {
2713 echo -n "Stopping \$NAME: "
2714 stopIt && success || failure
2715 echo
2716}
2717
2718$(getLsbStartupFooter "$CHKCONFIG_LOCK_FILE")
2719EOF
2720 [ $? -eq 0 ] || errorExit "Could not write to file $CHKCONFIG_SERVICE_FILE. Run this script as root."
2721 installService_chkconfig2
2722 ;;
2723 installAutodlService)
2724 local user=$2
2725 osHandler_$os _installService autodl_$user "getLsbStartupHeader_autodl \"$user\" \"\$CHKCONFIG_SERVICE_NAME\""
2726 ;;
2727 _installCommonWebServerStuff)
2728 PACKAGE="php-cli gzip curl openssl unrar logrotate"
2729 installPackages
2730 # CentOS 4: will get an error about a php v4 dependency, so can't put it in above PACKAGE var
2731 PACKAGES="php-pecl-geoip"
2732 installPackages
2733 ;;
2734 installApache)
2735 osHandler_$os _installCommonWebServerStuff
2736 # Also add some extra tools for ruTorrent and some of its plugins
2737 PACKAGES="httpd httpd-tools mod_ssl mod_scgi php"
2738 installPackages
2739
2740 WWW_PHP_INI=/etc/php.ini
2741 APACHE_DIR=/etc/httpd
2742 local APACHE_CONF_D=$APACHE_DIR/conf.d
2743 APACHE_SCGI_FILE=$APACHE_CONF_D/scgi.conf
2744 initializeApacheVars apache apache "$APACHE_CONF_D"
2745 apacheCommonInitialization "httpd-devel" $APACHE_DIR/modules
2746
2747 [ -f "$APACHE_CONF_D/welcome.conf" ] && mv -f "$APACHE_CONF_D/welcome.conf" "$APACHE_CONF_D/welcome.conf-bak"
2748 # Remove an Apache warning by commenting out the default SSL VirtualHost
2749 sed_i '/^<VirtualHost _default_:443>/,/^<\/VirtualHost>/s/^/#/' $APACHE_CONF_D/ssl.conf
2750
2751 resetWebServerPermissions
2752 chkconfig httpd on
2753 service httpd restart || errorExit "Could not start $INSTALL_WEB_SERVER"
2754 ;;
2755 restart_apache)
2756 service httpd restart || errorExit "Could not start $INSTALL_WEB_SERVER"
2757 ;;
2758 installVsftpd)
2759 installVsftpd_chkconfig /etc/vsftpd/vsftpd.conf
2760 ;;
2761 preNginxInstall)
2762 WWW_PHP_INI=/etc/php.ini
2763 osHandler_$os _installCommonWebServerStuff
2764 PACKAGES="pcre-devel openssl-devel zlib-devel php-cgi"
2765 installPackages
2766 ;;
2767 installPhpCgiService)
2768 osHandler_$os _installService phpcgi getLsbStartupHeader_phpcgi
2769 ;;
2770 installNginxService)
2771 osHandler_$os _installService nginx getLsbStartupHeader_nginx
2772 ;;
2773 restart_nginx)
2774 service phpcgi restart || errorExit "Could not start php-cgi"
2775 service nginx restart || errorExit "Could not start $INSTALL_WEB_SERVER"
2776 ;;
2777 preLighttpdInstall)
2778 WWW_PHP_INI=/etc/php.ini
2779 osHandler_$os _installCommonWebServerStuff
2780 PACKAGES="pcre-devel openssl-devel zlib-devel php-cgi"
2781 installPackages
2782 ;;
2783 installLighttpdService)
2784 osHandler_$os _installService lighttpd getLsbStartupHeader_lighttpd
2785 ;;
2786 restart_lighttpd)
2787 service phpcgi restart || errorExit "Could not start php-cgi"
2788 service lighttpd restart || errorExit "Could not start $INSTALL_WEB_SERVER"
2789 ;;
2790 *)
2791 ;;
2792 esac
2793}
2794
2795osHandler_pclinuxos() {
2796 case $1 in
2797 init)
2798 INSTALL="apt-get -y install"
2799 FEATURES="service rtorrent apache nginx lighttpd vsftpd webmin"
2800 BUILD_TOOLS="gcc gcc-c++ make pkgconfig file libtool m4"
2801 ;;
2802 init2)
2803 apt-get update
2804 installProgram ed
2805 ;;
2806 installTools)
2807 PACKAGES=
2808 addProgram svn subversion
2809 addProgram wget
2810 addProgram unzip
2811 addProgram screen
2812 installPackages
2813 ;;
2814 installAutodlTools)
2815 IRSSI_LOAD_PERL=y
2816 PACKAGES=
2817 addProgram perl
2818 addProgram irssi
2819 rpm -q --quiet irssi-perl || PACKAGES="$PACKAGES irssi-perl"
2820 addPerlModule Archive::Zip perl-Archive-Zip
2821 addPerlModule HTML::Parser perl-HTML-Parser
2822 addPerlModule Digest::SHA1 perl-Digest-SHA1
2823 installPackages
2824
2825 installPerlModule Net::SSLeay perl-Net-SSLeay
2826 installPerlModule XML::LibXML perl-XML-LibXML
2827 installPerlModule JSON::XS perl-JSON-XS
2828 installPerlModule JSON perl-JSON
2829 ;;
2830 installCpanTools)
2831 # Need to remove the old JSON or cpan may fail to build the modules
2832 if echo "$OLD_PERL_MODULES" | grep -qE '(^| )JSON( |$)'; then
2833 apt-get -y remove perl-JSON
2834 fi
2835
2836 PACKAGES="perl-CPAN perl-devel"
2837 if echo "$MISSING_PERL_MODULES" | grep -q 'XML::LibXML'; then
2838 PACKAGES="$PACKAGES libxml2 libxml2-devel zlib1 zlib1-devel"
2839 fi
2840 if echo "$MISSING_PERL_MODULES" | grep -q 'Net::SSLeay'; then
2841 PACKAGES="$PACKAGES openssl libopenssl-devel zlib1 zlib1-devel"
2842 fi
2843 installPackages
2844 ;;
2845 installRtorrentBuildTools)
2846 PACKAGES="libsigc++2.0-devel libopenssl-devel libncurses-devel libcurl-devel"
2847 installPackages
2848 ;;
2849 installPhpModules)
2850 installMissingPhpPackages
2851 ;;
2852 installAutodlService)
2853 installService_mandriva_autodl $2
2854 ;;
2855 installApache)
2856 installApache_mandriva
2857 ;;
2858 restart_apache)
2859 service httpd restart || errorExit "Could not start $INSTALL_WEB_SERVER"
2860 ;;
2861 installVsftpd)
2862 installVsftpd_chkconfig /etc/vsftpd/vsftpd.conf
2863 ;;
2864 preNginxInstall)
2865 WWW_PHP_INI=/etc/php-cgi-fcgi.ini
2866 installCommonWebServerStuff_mandriva
2867 PACKAGES="pcre-devel libopenssl-devel zlib1-devel php-cgi"
2868 installPackages
2869 ;;
2870 installPhpCgiService)
2871 installService_mandriva_phpcgi
2872 ;;
2873 installNginxService)
2874 installService_mandriva_nginx
2875 ;;
2876 restart_nginx)
2877 service phpcgi restart || errorExit "Could not start php-cgi"
2878 service nginx restart || errorExit "Could not start $INSTALL_WEB_SERVER"
2879 ;;
2880 preLighttpdInstall)
2881 WWW_PHP_INI=/etc/php-cgi-fcgi.ini
2882 installCommonWebServerStuff_mandriva
2883 PACKAGES="pcre-devel libopenssl-devel zlib1-devel php-cgi"
2884 installPackages
2885 ;;
2886 installLighttpdService)
2887 installService_mandriva_lighttpd
2888 ;;
2889 restart_lighttpd)
2890 service phpcgi restart || errorExit "Could not start php-cgi"
2891 service lighttpd restart || errorExit "Could not start $INSTALL_WEB_SERVER"
2892 ;;
2893 *)
2894 ;;
2895 esac
2896}
2897
2898archAddService() {
2899 local serviceName="$1"
2900 local rcFile=/etc/rc.conf
2901 if ! grep -qE '^DAEMONS=' $rcFile; then
2902 echo "DAEMONS=($serviceName)" >> $rcFile
2903 elif ! grep -E '^DAEMONS=' $rcFile | grep -qE "[ (]$serviceName[ )]"; then
2904 sed_i "s/^\\(DAEMONS=(.*\\))/\\1 $serviceName)/" $rcFile
2905 fi
2906}
2907
2908osHandler_arch() {
2909 case $1 in
2910 init)
2911 INSTALL="pacman -Sq --noconfirm --needed"
2912 FEATURES="service rtorrent apache nginx lighttpd vsftpd webmin"
2913 BUILD_TOOLS="gcc make pkg-config file libtool m4"
2914 WWW_PHP_INI=/etc/php/php.ini
2915 ;;
2916 init2)
2917 pacman -Sy
2918 # If you don't do this, eg. svn may fail because of old libraries.
2919 # Do it twice in case pacman is updated.
2920 pacman -Su --noconfirm
2921 pacman -Su --noconfirm
2922 installProgram ed
2923 ;;
2924 installTools)
2925 PACKAGES=
2926 addProgram svn subversion
2927 addProgram wget
2928 addProgram unzip
2929 addProgram screen
2930 installPackages
2931 ;;
2932 installAutodlTools)
2933 PACKAGES=
2934 addProgram perl
2935 addProgram irssi
2936 addPerlModule HTML::Parser perl-html-parser
2937 addPerlModule Digest::SHA1 perl-digest-sha1
2938 installPackages
2939
2940 installPerlModule Archive::Zip perl-archive-zip
2941 installPerlModule Net::SSLeay perl-net-ssleay
2942 installPerlModule XML::LibXML perl-xml-libxml
2943 installPerlModule JSON::XS perl-json-xs
2944 installPerlModule JSON perl-json
2945 ;;
2946 installCpanTools)
2947 PACKAGES=
2948 if echo "$MISSING_PERL_MODULES" | grep -q 'XML::LibXML'; then
2949 PACKAGES="$PACKAGES libxml2 zlib"
2950 fi
2951 if echo "$MISSING_PERL_MODULES" | grep -q 'Net::SSLeay'; then
2952 PACKAGES="$PACKAGES openssl zlib"
2953 fi
2954 installPackages
2955 ;;
2956 installRtorrentBuildTools)
2957 PACKAGES="libsigc++ openssl ncurses curl"
2958 installPackages
2959 ;;
2960 installPhpModules)
2961 enablePhpIniModules "$WWW_PHP_INI" $MISSING_PHP_MODULES
2962 ;;
2963 _installService)
2964 local serviceName="$2"
2965 local headerCommand="$3"
2966 local serviceFile=/etc/rc.d/$serviceName
2967 local lockFile=/var/run/daemons/$serviceName
2968 cat > "$serviceFile" << EOF
2969#!/bin/sh
2970$(eval $headerCommand)
2971
2972. /etc/rc.conf
2973. /etc/rc.d/functions
2974
2975v_startIt() {
2976 stat_busy "Starting \$NAME: "
2977 startIt && stat_done || stat_fail
2978}
2979
2980v_stopIt() {
2981 stat_busy "Stopping \$NAME: "
2982 stopIt && stat_done || stat_fail
2983}
2984
2985$(getLsbStartupFooter "$lockFile")
2986EOF
2987 [ $? -eq 0 ] || errorExit "Could not write to file $serviceFile. Run this script as root."
2988 chmod +x "$serviceFile" || errorExit "Could not set +x bit, file $serviceFile."
2989 archAddService "$serviceName"
2990 $serviceFile restart
2991 ;;
2992 installAutodlService)
2993 local user="$2"
2994 osHandler_$os _installService autodl_$user "getLsbStartupHeader_autodl \"$user\" \"\$serviceName\""
2995 ;;
2996 _installCommonWebServerStuff)
2997 # Also add some extra tools for ruTorrent and some of its plugins
2998 PACKAGES="php gzip curl openssl logrotate"
2999 installPackages
3000 PACKAGE="unrar"
3001 installPackages
3002 PACKAGES="php-geoip"
3003 installPackages
3004 ;;
3005 _initializePhpIni)
3006 local geoipFile=/etc/php/conf.d/geoip.ini
3007 [ -f "$geoipFile" ] && enablePhpIniModules "$geoipFile" geoip
3008 sed_i "s/^\\(open_basedir.*\\)/;\\1/" "$WWW_PHP_INI"
3009 ;;
3010 installApache)
3011 osHandler_$os _installCommonWebServerStuff
3012 PACKAGES="apache php-apache"
3013 installPackages
3014
3015 APACHE_DIR=/etc/httpd
3016 local APACHE_CONF=$APACHE_DIR/conf/httpd.conf
3017 local APACHE_CONF_D=$APACHE_DIR/conf/extra
3018
3019 APACHE_SCGI_FILE=$APACHE_CONF_D/scgi.conf
3020 initializeApacheVars http http "$APACHE_CONF_D"
3021 apacheCommonInitialization "" $APACHE_DIR/modules
3022
3023 # Remove an Apache warning by commenting out the default SSL VirtualHost
3024 sed_i '/^<VirtualHost _default_:443>/,/^<\/VirtualHost>/s/^/#/' $APACHE_CONF_D/httpd-ssl.conf
3025 sed_i 's!^\(Include conf/extra/httpd-vhosts.conf.*\)!#\1!' $APACHE_CONF
3026
3027 cat > $APACHE_CONF_D/php5_module.conf << EOF
3028LoadModule php5_module modules/libphp5.so
3029DirectoryIndex index.php index.html
3030AddHandler application/x-httpd-php .php
3031AddHandler application/x-httpd-php-source .phps
3032EOF
3033 local loadFiles="php5_module.conf scgi.conf httpd-ssl.conf $APACHE_SITE_NAME"
3034 for file in $loadFiles; do
3035 sed_i "g!^Include conf/extra/$file!d" "$APACHE_CONF"
3036 done
3037 for file in $loadFiles; do
3038 echo "Include conf/extra/$file" >> "$APACHE_CONF"
3039 done
3040 osHandler_$os _initializePhpIni
3041
3042 resetWebServerPermissions
3043 archAddService httpd
3044 /etc/rc.d/httpd restart || errorExit "Could not start $INSTALL_WEB_SERVER"
3045 ;;
3046 restart_apache)
3047 /etc/rc.d/httpd restart || errorExit "Could not start $INSTALL_WEB_SERVER"
3048 ;;
3049 installVsftpd)
3050 installProgram vsftpd
3051 updateVsftpdConf /etc/vsftpd.conf
3052 archAddService vsftpd
3053 /etc/rc.d/vsftpd restart || errorExit "Could not start vsftpd"
3054 ;;
3055 preWebminInstall)
3056 sed_i 's!^init_dir=.*!init_dir=/etc/rc.d!' init/config-generic-linux
3057 ;;
3058 postWebminInstall)
3059 [ -x /etc/rc.d/webmin ] && archAddService webmin
3060 ;;
3061 preNginxInstall)
3062 osHandler_$os _installCommonWebServerStuff
3063 PACKAGES="pcre openssl zlib php-cgi"
3064 installPackages
3065 osHandler_$os _initializePhpIni
3066 ;;
3067 installPhpCgiService)
3068 osHandler_$os _installService phpcgi getLsbStartupHeader_phpcgi
3069 ;;
3070 installNginxService)
3071 osHandler_$os _installService nginx getLsbStartupHeader_nginx
3072 ;;
3073 restart_nginx)
3074 /etc/rc.d/phpcgi restart || errorExit "Could not start php-cgi"
3075 /etc/rc.d/nginx restart || errorExit "Could not start $INSTALL_WEB_SERVER"
3076 ;;
3077 preLighttpdInstall)
3078 osHandler_$os _installCommonWebServerStuff
3079 PACKAGES="pcre openssl zlib php-cgi"
3080 installPackages
3081 osHandler_$os _initializePhpIni
3082 ;;
3083 installLighttpdService)
3084 osHandler_$os _installService lighttpd getLsbStartupHeader_lighttpd
3085 ;;
3086 restart_lighttpd)
3087 /etc/rc.d/phpcgi restart || errorExit "Could not start php-cgi"
3088 /etc/rc.d/lighttpd restart || errorExit "Could not start $INSTALL_WEB_SERVER"
3089 ;;
3090 *)
3091 ;;
3092 esac
3093}
3094
3095osHandler_freebsd() {
3096 case $1 in
3097 init)
3098 INSTALL="pkg_add -r"
3099 FEATURES="service rtorrent webmin"
3100 MAKE=gmake
3101 # gcc, g++, make are always installed
3102 BUILD_TOOLS="pkg-config gmake file libtool"
3103 ;;
3104 init2)
3105 ;;
3106 installTools)
3107 PACKAGES=
3108 addProgram svn subversion
3109 addProgram wget
3110 addProgram unzip
3111 addProgram screen
3112 installPackages
3113 ;;
3114 installAutodlTools)
3115 PACKAGES=
3116 addProgram perl
3117 addProgram irssi
3118 addPerlModule Archive::Zip p5-Archive-Zip
3119 addPerlModule Net::SSLeay p5-Net-SSLeay
3120 addPerlModule HTML::Parser p5-HTML-Parser
3121 addPerlModule XML::LibXML p5-XML-LibXML
3122 addPerlModule Digest::SHA1 p5-Digest-SHA1
3123 addPerlModule JSON::XS p5-JSON-XS
3124 addPerlModule JSON p5-JSON
3125 installPackages
3126 ;;
3127 installCpanTools)
3128 PACKAGES=
3129 if echo "$MISSING_PERL_MODULES" | grep -q 'XML::LibXML'; then
3130 # zlib is already installed, seems like there's no zlib package.
3131 PACKAGES="$PACKAGES libxml2"
3132 fi
3133 if echo "$MISSING_PERL_MODULES" | grep -q 'Net::SSLeay'; then
3134 # zlib is already installed, seems like there's no zlib package.
3135 PACKAGES="$PACKAGES openssl"
3136 fi
3137 installPackages
3138 ;;
3139 installRtorrentBuildTools)
3140 PACKAGES="libsigc++20 openssl ncurses curl"
3141 installPackages
3142 ;;
3143 installPhpModules)
3144 installMissingPhp5Packages
3145 ;;
3146 installAutodlService)
3147 local user=$2
3148 local scriptName=autodl_$user
3149 local file=/etc/rc.d/$scriptName
3150 installService_bsd_autodl "$user" "$scriptName" "$file"
3151 setScriptVariable /etc/rc.conf ${scriptName}_enable YES
3152 $file restart
3153 ;;
3154 *)
3155 ;;
3156 esac
3157}
3158
3159osHandler_openbsd() {
3160 case $1 in
3161 init)
3162 INSTALL="pkg_add -r"
3163 FEATURES="webmin"
3164 BUILD_TOOLS="libtool"
3165 ;;
3166 init2)
3167 ;;
3168 installTools)
3169 PACKAGES=
3170 addProgram svn subversion--
3171 addProgram wget
3172 addProgram unzip
3173 addProgram screen screen--
3174 installPackages
3175 ;;
3176 installAutodlTools)
3177 PACKAGES=
3178 addProgram perl
3179 addProgram irssi irssi--
3180 addPerlModule Archive::Zip p5-Archive-Zip
3181 addPerlModule Net::SSLeay p5-Net-SSLeay
3182 addPerlModule HTML::Parser p5-HTML-Parser
3183 addPerlModule XML::LibXML p5-XML-LibXML
3184 addPerlModule Digest::SHA1 p5-Digest-SHA1
3185 addPerlModule JSON::XS p5-JSON-XS
3186 addPerlModule JSON p5-JSON
3187 installPackages
3188 ;;
3189 installCpanTools)
3190 PACKAGES=
3191 if echo "$MISSING_PERL_MODULES" | grep -q 'XML::LibXML'; then
3192 # zlib is already installed, seems like there's no zlib package.
3193 # libxml is v2
3194 PACKAGES="$PACKAGES libxml"
3195 fi
3196 if echo "$MISSING_PERL_MODULES" | grep -q 'Net::SSLeay'; then
3197 # zlib is already installed, seems like there's no zlib package.
3198 PACKAGES="$PACKAGES openssl"
3199 fi
3200 installPackages
3201 ;;
3202 installRtorrentBuildTools)
3203 ;;
3204 installPhpModules)
3205 installMissingPhp5Packages
3206 ;;
3207 installAutodlService)
3208 ;;
3209 *)
3210 ;;
3211 esac
3212}
3213
3214osHandler_netbsd() {
3215 case $1 in
3216 init)
3217 INSTALL="pkg_add"
3218 FEATURES="service webmin"
3219 MAKE=gmake
3220 BUILD_TOOLS="gmake pkg-config file libtool"
3221 ;;
3222 init2)
3223 ;;
3224 installTools)
3225 PACKAGES=
3226 # Need expat for subversion! It's not auto installed.
3227 addProgram svn expat
3228 addProgram svn subversion-base
3229 addProgram wget
3230 addProgram unzip
3231 addProgram screen
3232 installPackages
3233 ;;
3234 installAutodlTools)
3235 echo "The pre-built Irssi binary does not have Perl support so you must build it yourself!"
3236 IGNORE_IRSSI=y
3237 PACKAGES=
3238 addProgram perl
3239 addPerlModule Archive::Zip p5-Archive-Zip
3240 addPerlModule Net::SSLeay p5-Net-SSLeay
3241 addPerlModule HTML::Parser p5-HTML-Parser
3242 addPerlModule XML::LibXML p5-XML-LibXML
3243 addPerlModule Digest::SHA1 p5-Digest-SHA1
3244 addPerlModule JSON::XS p5-JSON-XS
3245 addPerlModule JSON p5-JSON
3246 installPackages
3247 ;;
3248 installCpanTools)
3249 PACKAGES=
3250 if echo "$MISSING_PERL_MODULES" | grep -q 'XML::LibXML'; then
3251 PACKAGES="$PACKAGES libxml2 zlib"
3252 fi
3253 if echo "$MISSING_PERL_MODULES" | grep -q 'Net::SSLeay'; then
3254 PACKAGES="$PACKAGES openssl zlib"
3255 fi
3256 installPackages
3257 ;;
3258 installRtorrentBuildTools)
3259 PACKAGES="libsigc++ openssl ncurses curl"
3260 installPackages
3261 ;;
3262 installPhpModules)
3263 installMissingPhp5Packages
3264 ;;
3265 installAutodlService)
3266 local user=$2
3267 local scriptName=autodl_$user
3268 local file=/etc/rc.d/$scriptName
3269 installService_bsd_autodl "$user" "$scriptName" "$file"
3270 setScriptVariable /etc/rc.conf ${scriptName} YES
3271 $file restart
3272 ;;
3273 *)
3274 ;;
3275 esac
3276}
3277
3278osHandler_dragonfly() {
3279 osHandler_netbsd "$@"
3280}
3281
3282osHandler_opensuse() {
3283 case $1 in
3284 init)
3285 INSTALL="zypper -n install"
3286 FEATURES="service rtorrent apache nginx lighttpd vsftpd webmin"
3287 BUILD_TOOLS="gcc gcc-c++ make pkg-config file libtool m4"
3288
3289 # Fix for 11.4 (and possibly future versions)
3290 if ! echo "$os_long" | grep -qE ' 11\.[0-3]'; then
3291 LSB_DEFAULT_START="3 5"
3292 LSB_DEFAULT_STOP="0 1 2 4 6"
3293 fi
3294 ;;
3295 init2)
3296 zypper refresh
3297 installProgram ed
3298 ;;
3299 installTools)
3300 PACKAGES=
3301 addProgram svn subversion
3302 addProgram wget
3303 addProgram unzip
3304 addProgram screen
3305 installPackages
3306 ;;
3307 installAutodlTools)
3308 PACKAGES=
3309 addProgram perl perl-base
3310 addProgram irssi
3311 addPerlModule Archive::Zip perl-Archive-Zip
3312 addPerlModule HTML::Parser perl-HTML-Parser
3313 addPerlModule Digest::SHA1 perl-Digest-SHA1
3314 installPackages
3315
3316 installPerlModule Net::SSLeay perl-Net-SSLeay
3317 installPerlModule XML::LibXML perl-XML-LibXML
3318 installPerlModule JSON::XS perl-JSON-XS
3319 installPerlModule JSON perl-JSON
3320 ;;
3321 installCpanTools)
3322 PACKAGES=
3323 if echo "$MISSING_PERL_MODULES" | grep -q 'XML::LibXML'; then
3324 PACKAGES="$PACKAGES libxml2 libxml2-devel zlib zlib-devel"
3325 fi
3326 if echo "$MISSING_PERL_MODULES" | grep -q 'Net::SSLeay'; then
3327 PACKAGES="$PACKAGES openssl libopenssl-devel zlib zlib-devel"
3328 fi
3329 installPackages
3330 ;;
3331 installRtorrentBuildTools)
3332 PACKAGES="libsigc++2-devel ncurses-devel libopenssl-devel libcurl-devel"
3333 installPackages
3334 ;;
3335 installPhpModules)
3336 installMissingPhp5Packages
3337 ;;
3338 _installService)
3339 local serviceName="$2"
3340 local headerCommand="$3"
3341 installService_chkconfig1 $serviceName
3342 cat > "$CHKCONFIG_SERVICE_FILE" << EOF
3343#!/bin/bash
3344$(eval $headerCommand)
3345
3346. /etc/rc.status
3347rc_reset
3348
3349v_startIt() {
3350 echo -n "Starting \$NAME"
3351 startIt
3352 rc_status -v
3353}
3354
3355v_stopIt() {
3356 echo -n "Stopping \$NAME"
3357 stopIt
3358 rc_status -v
3359}
3360
3361$(getLsbStartupFooter "$CHKCONFIG_LOCK_FILE")
3362EOF
3363 [ $? -eq 0 ] || errorExit "Could not write to file $CHKCONFIG_SERVICE_FILE. Run this script as root."
3364 installService_chkconfig2
3365 ;;
3366 installAutodlService)
3367 local user=$2
3368 osHandler_$os _installService autodl_$user "getLsbStartupHeader_autodl \"$user\" \"\$CHKCONFIG_SERVICE_NAME\""
3369 ;;
3370 _installCommonWebServerStuff)
3371 # Also add some extra tools for ruTorrent and some of its plugins
3372 PACKAGES="php5 gzip curl openssl logrotate"
3373 installPackages
3374 PACKAGES="unrar"
3375 installPackages
3376 ;;
3377 installApache)
3378 osHandler_$os _installCommonWebServerStuff
3379 PACKAGES="apache2-prefork apache2-mod_scgi apache2-mod_php5"
3380 installPackages
3381
3382 WWW_PHP_INI=/etc/php5/apache2/php.ini
3383 APACHE_DIR=/etc/apache2
3384 local APACHE_CONF_D=$APACHE_DIR/conf.d
3385 initializeApacheVars wwwrun www "$APACHE_CONF_D"
3386 apacheCommonInitialization "apache2-devel" $APACHE_DIR/modules
3387 appendFileStringVar /etc/sysconfig/apache2 APACHE_SERVER_FLAGS SSL
3388 a2enmod php5 || errorExit "Could not enable mod_php5"
3389 a2enmod scgi || errorExit "Could not enable mod_scgi"
3390
3391 resetWebServerPermissions
3392 chkconfig apache2 on
3393 service apache2 restart || errorExit "Could not start $INSTALL_WEB_SERVER"
3394 ;;
3395 restart_apache)
3396 service apache2 restart || errorExit "Could not start $INSTALL_WEB_SERVER"
3397 ;;
3398 installVsftpd)
3399 installVsftpd_chkconfig /etc/vsftpd.conf
3400 ;;
3401 preNginxInstall)
3402 WWW_PHP_INI=/etc/php5/fastcgi/php.ini
3403 osHandler_$os _installCommonWebServerStuff
3404 PACKAGES="pcre-devel libopenssl-devel zlib-devel php5-fastcgi"
3405 installPackages
3406 ;;
3407 installPhpCgiService)
3408 osHandler_$os _installService phpcgi getLsbStartupHeader_phpcgi
3409 ;;
3410 installNginxService)
3411 osHandler_$os _installService nginx getLsbStartupHeader_nginx
3412 ;;
3413 restart_nginx)
3414 service phpcgi restart || errorExit "Could not start php-cgi"
3415 service nginx restart || errorExit "Could not start $INSTALL_WEB_SERVER"
3416 ;;
3417 preLighttpdInstall)
3418 WWW_PHP_INI=/etc/php5/fastcgi/php.ini
3419 osHandler_$os _installCommonWebServerStuff
3420 PACKAGES="pcre-devel libopenssl-devel zlib-devel php5-fastcgi"
3421 installPackages
3422 ;;
3423 installLighttpdService)
3424 osHandler_$os _installService lighttpd getLsbStartupHeader_lighttpd
3425 ;;
3426 restart_lighttpd)
3427 service phpcgi restart || errorExit "Could not start php-cgi"
3428 service lighttpd restart || errorExit "Could not start $INSTALL_WEB_SERVER"
3429 ;;
3430 *)
3431 ;;
3432 esac
3433}
3434
3435osHandler_mandriva() {
3436 case $1 in
3437 init)
3438 INSTALL="urpmi --force"
3439 FEATURES="service rtorrent apache nginx lighttpd vsftpd webmin"
3440 BUILD_TOOLS="gcc gcc-c++ make pkgconfig file libtool m4"
3441 ;;
3442 init2)
3443 urpmi.update -a
3444 installProgram ed
3445 ;;
3446 installTools)
3447 PACKAGES=
3448 addProgram svn subversion
3449 addProgram wget
3450 addProgram unzip
3451 addProgram screen
3452 installPackages
3453 ;;
3454 installAutodlTools)
3455 IRSSI_LOAD_PERL=y
3456 PACKAGES=
3457 addProgram perl
3458 addProgram irssi
3459 rpm -q --quiet irssi-perl || PACKAGES="$PACKAGES irssi-perl"
3460 addPerlModule Archive::Zip perl-Archive-Zip
3461 addPerlModule HTML::Parser perl-HTML-Parser
3462 addPerlModule Digest::SHA1 perl-Digest-SHA1
3463 installPackages
3464
3465 installPerlModule Net::SSLeay perl-Net-SSLeay
3466 installPerlModule XML::LibXML perl-XML-LibXML
3467 installPerlModule JSON::XS perl-JSON-XS
3468 installPerlModule JSON perl-JSON
3469 ;;
3470 installCpanTools)
3471 # Need to remove the old JSON or cpan may fail to build the modules
3472 if echo "$OLD_PERL_MODULES" | grep -qE '(^| )JSON( |$)'; then
3473 urpme perl-JSON
3474 fi
3475
3476 PACKAGES="perl-CPAN perl-devel"
3477 if echo "$MISSING_PERL_MODULES" | grep -q 'XML::LibXML'; then
3478 PACKAGES="$PACKAGES libxml2 libxml2-devel zlib1 zlib1-devel"
3479 fi
3480 if echo "$MISSING_PERL_MODULES" | grep -q 'Net::SSLeay'; then
3481 PACKAGES="$PACKAGES openssl libopenssl-devel zlib1 zlib1-devel"
3482 fi
3483 installPackages
3484 ;;
3485 installRtorrentBuildTools)
3486 PACKAGES="zlib1-devel libstdc++-devel libsigc++2.0-devel libncurses-devel libopenssl-devel libcurl-devel"
3487 installPackages
3488 ;;
3489 installPhpModules)
3490 installMissingPhpPackages
3491 ;;
3492 installAutodlService)
3493 installService_mandriva_autodl $2
3494 ;;
3495 installApache)
3496 installApache_mandriva
3497 ;;
3498 restart_apache)
3499 service httpd restart || errorExit "Could not start $INSTALL_WEB_SERVER"
3500 ;;
3501 installVsftpd)
3502 installVsftpd_chkconfig /etc/vsftpd/vsftpd.conf
3503 ;;
3504 preNginxInstall)
3505 WWW_PHP_INI=/etc/php-cgi-fcgi.ini
3506 installCommonWebServerStuff_mandriva
3507 PACKAGES="pcre-devel libopenssl-devel zlib1-devel php-cgi"
3508 installPackages
3509 ;;
3510 installPhpCgiService)
3511 installService_mandriva_phpcgi
3512 ;;
3513 installNginxService)
3514 installService_mandriva_nginx
3515 ;;
3516 restart_nginx)
3517 service phpcgi restart || errorExit "Could not start php-cgi"
3518 service nginx restart || errorExit "Could not start $INSTALL_WEB_SERVER"
3519 ;;
3520 preLighttpdInstall)
3521 WWW_PHP_INI=/etc/php-cgi-fcgi.ini
3522 installCommonWebServerStuff_mandriva
3523 PACKAGES="pcre-devel libopenssl-devel zlib1-devel php-cgi"
3524 installPackages
3525 ;;
3526 installLighttpdService)
3527 installService_mandriva_lighttpd
3528 ;;
3529 restart_lighttpd)
3530 service phpcgi restart || errorExit "Could not start php-cgi"
3531 service lighttpd restart || errorExit "Could not start $INSTALL_WEB_SERVER"
3532 ;;
3533 *)
3534 ;;
3535 esac
3536}
3537
3538osHandler_pardus() {
3539 case $1 in
3540 init)
3541 INSTALL="pisi -y it"
3542 FEATURES="service rtorrent apache vsftpd"
3543 IS_OLD=n; echo $os_long | grep -qE '200[0-9]' && IS_OLD=y
3544 BUILD_TOOLS="kernel-headers gcc make pkgconfig file libtool m4"
3545 [ "$IS_OLD" = n ] && BUILD_TOOLS="$BUILD_TOOLS glibc-devel"
3546 ;;
3547 init2)
3548 pisi -y ur
3549 installProgram ed
3550 ;;
3551 installTools)
3552 PACKAGES=
3553 addProgram svn subversion
3554 addProgram wget
3555 addProgram unzip
3556 addProgram screen
3557 installPackages
3558 ;;
3559 installAutodlTools)
3560 PACKAGES=
3561 addProgram perl
3562 addProgram irssi
3563 addPerlModule Archive::Zip perl-Archive-Zip
3564 addPerlModule HTML::Parser perl-HTML-Parser
3565 addPerlModule Digest::SHA1 perl-Digest-SHA1
3566 installPackages
3567
3568 installPerlModule Net::SSLeay perl-Net-SSLeay
3569 installPerlModule XML::LibXML perl-XML-LibXML
3570 installPerlModule JSON::XS perl-JSON-XS
3571 installPerlModule JSON perl-JSON
3572 ;;
3573 installCpanTools)
3574 PACKAGES=
3575 if echo "$MISSING_PERL_MODULES" | grep -q 'XML::LibXML'; then
3576 PACKAGES="$PACKAGES libxml2 zlib"
3577 [ "$IS_OLD" = n ] && PACKAGES="$PACKAGES libxml2-devel zlib-devel"
3578 fi
3579 if echo "$MISSING_PERL_MODULES" | grep -q 'Net::SSLeay'; then
3580 PACKAGES="$PACKAGES openssl zlib"
3581 [ "$IS_OLD" = n ] && PACKAGES="$PACKAGES openssl-devel zlib-devel"
3582 fi
3583 installPackages
3584 ;;
3585 installRtorrentBuildTools)
3586 PACKAGES="libsigc++ ncurses openssl curl"
3587 installPackages
3588 if [ "$IS_OLD" = n ]; then
3589 $INSTALL ncurses-devel
3590
3591 # Pardus Corp 2 doesn't have these packages
3592 $INSTALL openssl-devel
3593 $INSTALL libsigc++-devel
3594 $INSTALL curl-devel
3595 fi
3596 ;;
3597 installPhpModules)
3598 ;;
3599 installAutodlService)
3600 local user="$2"
3601 local scriptName="autodl_$user"
3602 local serviceFile=$scriptName.py
3603 cd
3604 cat > $serviceFile << EOF
3605import os, time
3606from comar.service import *
3607
3608serviceType = 'server'
3609serviceDesc = _({'en': '$AUTODL_STARTUP_DESC'})
3610
3611sessionName = 'autodl'
3612user = '$user'
3613path = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
3614
3615# Make sure the path is correct, and make sure we're in the home dir.
3616userInit='umask $DEFAULT_UMASK; cd; PATH=\\\$PATH:' + path
3617
3618os.environ['PATH'] = path
3619
3620def runUserCmd(cmd):
3621 cmd = 'su - ' + user + ' -c "' + userInit + '; ' + cmd + '"'
3622 return os.system(cmd)
3623
3624def isStarted():
3625 if runUserCmd('screen -ls | grep -qE \\\\"[ ][0-9]+\\\\.' + sessionName + '[ ]\\\\"') == 0:
3626 return True
3627 return False
3628
3629@synchronized
3630def start():
3631 if isStarted() == True:
3632 return
3633
3634 startIrssi = 'n'
3635 startRtorrent = 'n'
3636 if os.system('which irssi') == 0:
3637 startIrssi = 'y'
3638 if os.system('which rtorrent') == 0:
3639 startRtorrent = 'y'
3640
3641 if (startIrssi == 'y' and startRtorrent == 'y'):
3642 runUserCmd("screen -S " + sessionName + " -d -t rtorrent -m rtorrent")
3643 runUserCmd("screen -d -r " + sessionName + " -X screen -t irssi irssi")
3644 elif (startIrssi == 'y' and startRtorrent == 'n'):
3645 runUserCmd("screen -S " + sessionName + " -d -t irssi -m irssi")
3646 elif (startIrssi == 'n' and startRtorrent == 'y'):
3647 runUserCmd("screen -S " + sessionName + " -d -t rtorrent -m rtorrent")
3648 else:
3649 pass
3650
3651@synchronized
3652def stop():
3653 if isStarted() == False:
3654 return
3655
3656 runUserCmd("screen -d -r " + sessionName + " -p irssi -X stuff \\\\\\"/quit\\n/quit\\n\\\\\\"")
3657 runUserCmd("screen -d -r " + sessionName + " -p rtorrent -X xon")
3658
3659 for i in range(15):
3660 if not isStarted():
3661 break
3662 time.sleep(1)
3663
3664 # If it's still not stopped, kill the whole screen session
3665 if isStarted():
3666 runUserCmd("screen -d -r " + sessionName + " -p rtorrent -X xon")
3667 time.sleep(2)
3668 runUserCmd("screen -d -r " + sessionName + " -X quit")
3669
3670def status():
3671 return isStarted()
3672EOF
3673 python << EOF
3674import sys
3675import comar
3676import dbus
3677
3678try:
3679 link = comar.Link(socket='/var/run/dbus/system_bus_socket')
3680 link.register('$scriptName', 'System.Service', '$(pwd)/$serviceFile')
3681except Exception, e:
3682 print "Exception:\n", sys.exc_info()
3683 sys.exit(1)
3684
3685sys.exit(0)
3686EOF
3687 [ $? -eq 0 ] || errorExit "Could not install startup file"
3688 rm -f $serviceFile
3689 service $scriptName on
3690 service $scriptName restart
3691 ;;
3692 installApache)
3693 # Also add some extra tools for ruTorrent and some of its plugins
3694 PACKAGES="apache mod_php php-cli gzip curl openssl"
3695 installPackages
3696 PACKAGES="unrar"
3697 installPackages
3698
3699 WWW_PHP_INI=
3700 for ini in /etc/php/apache2/php.ini /etc/php/php.ini; do
3701 if [ -f "$ini" ]; then
3702 WWW_PHP_INI="$ini"
3703 break
3704 fi
3705 done
3706 [ -f "$WWW_PHP_INI" ] || errorExit "Could not find Apache php.ini"
3707
3708 APACHE_DIR=/etc/apache2
3709 local APACHE_CONF=$APACHE_DIR/httpd.conf
3710 local APACHE_SITES_DIR=$APACHE_DIR/vhosts.d
3711 APACHE_SCGI_FILE="$APACHE_DIR/modules.d/scgi.conf"
3712 initializeApacheVars apache apache "$APACHE_SITES_DIR"
3713 apacheCommonInitialization "" /usr/lib/apache2/modules
3714
3715 for file in 00_default_vhost.conf; do
3716 [ -f "$APACHE_SITES_DIR/$file" ] && mv -f "$APACHE_SITES_DIR/$file" "$APACHE_SITES_DIR/$file-bak"
3717 done
3718
3719 if ! grep -qE '^[ ]*LoadModule.*mod_ssl\.' $APACHE_CONF; then
3720 echo "LoadModule ssl_module modules/mod_ssl.so" >> $APACHE_CONF
3721 echo "Listen $HTTPS_PORT" >> $APACHE_CONF
3722 fi
3723
3724 resetWebServerPermissions
3725 service apache on
3726 osHandler_$os restart_$INSTALL_WEB_SERVER
3727 ;;
3728 restart_apache)
3729 service apache stop
3730 sleep 5
3731 service apache start
3732 ;;
3733 installVsftpd)
3734 installProgram vsftpd
3735 updateVsftpdConf /etc/vsftpd/vsftpd.conf
3736 service vsftpd on
3737 service vsftpd stop
3738 sleep 5
3739 service vsftpd start
3740 ;;
3741 *)
3742 ;;
3743 esac
3744}
3745
3746osHandler_frugalware() {
3747 local APACHE_PHP_INI=/etc/php.ini
3748 case $1 in
3749 init)
3750 INSTALL="pacman -S --noconfirm"
3751 FEATURES="service rtorrent apache nginx lighttpd vsftpd webmin"
3752 BUILD_TOOLS="gcc gcc-g++ make kernel-headers pkgconfig file libtool m4"
3753 ;;
3754 init2)
3755 # If we don't update all, there may be some library problems. Also sometimes
3756 # pacman is updated, so run the update twice.
3757 pacman -Sy
3758 pacman -Su --noconfirm
3759 pacman -Su --noconfirm
3760 ;;
3761 installTools)
3762 PACKAGES=
3763 addProgram svn subversion
3764 addProgram wget
3765 addProgram unzip
3766 addProgram screen
3767 installPackages
3768 ;;
3769 installAutodlTools)
3770 PACKAGES=
3771 addProgram perl
3772 addProgram irssi
3773 addPerlModule Archive::Zip perl-archive-zip
3774 addPerlModule HTML::Parser perl-html-parser
3775 addPerlModule Digest::SHA1 perl-digest-sha1
3776 installPackages
3777
3778 installPerlModule Net::SSLeay perl-net-ssleay
3779 installPerlModule XML::LibXML perl-xml-libxml
3780 # 'common::sense' isn't installed automatically, so force it. There's no
3781 # perl-common-sense package, so use CPAN
3782 REQUIRED_PERL_MODULES="common::sense $REQUIRED_PERL_MODULES"
3783 installPerlModule JSON::XS perl-json-xs
3784 installPerlModule JSON perl-json
3785 ;;
3786 installCpanTools)
3787 PACKAGES=
3788 if echo "$MISSING_PERL_MODULES" | grep -q 'XML::LibXML'; then
3789 PACKAGES="$PACKAGES libxml2 zlib"
3790 fi
3791 if echo "$MISSING_PERL_MODULES" | grep -q 'Net::SSLeay'; then
3792 PACKAGES="$PACKAGES openssl zlib"
3793 fi
3794 installPackages
3795 ;;
3796 installRtorrentBuildTools)
3797 PACKAGES="libsigc++2 openssl ncurses curl"
3798 installPackages
3799 ;;
3800 installPhpModules)
3801 enablePhpIniModules "$APACHE_PHP_INI" $MISSING_PHP_MODULES
3802 ;;
3803 _installService)
3804 local serviceName="$2"
3805 local desc="$3"
3806 local headerCommand="$4"
3807 local serviceFile="/etc/rc.d/rc.$serviceName"
3808 cat > "$serviceFile" << EOF
3809#!/bin/bash
3810$(getChkconfigScriptContents "$desc")
3811
3812. /lib/initscripts/functions
3813
3814$(eval $headerCommand)
3815
3816actions=(restart start stop status)
3817daemon="$serviceName"
3818
3819rc_start() {
3820 start_msg
3821 startIt
3822 ok \$?
3823}
3824
3825rc_stop() {
3826 stop_msg
3827 stopIt
3828 ok \$?
3829}
3830
3831rc_restart() {
3832 rc_stop
3833 rc_start
3834}
3835
3836rc_status() {
3837 status_msg
3838 if isStarted; then
3839 ok 997
3840 exit 0
3841 else
3842 ok 998
3843 exit 1
3844 fi
3845}
3846
3847rc_exec \$1
3848EOF
3849 [ $? -eq 0 ] || errorExit "Could not write to file $serviceFile. Run this script as root."
3850 chmod +x "$serviceFile"
3851 service $serviceName add || errorExit "Could not add service $serviceName"
3852 service $serviceName restart
3853 ;;
3854 installAutodlService)
3855 local user="$2"
3856 osHandler_$os _installService autodl_$user "$AUTODL_STARTUP_DESC" "getCommonStartupScriptContents_autodl \"$user\" \"\$serviceName\""
3857 ;;
3858 _installCommonWebServerStuff)
3859 # Also add some extra tools for ruTorrent and some of its plugins
3860 PACKAGES="php gzip curl openssl logrotate"
3861 installPackages
3862 PACKAGES="unrar"
3863 installPackages
3864 ;;
3865 installApache)
3866 osHandler_$os _installCommonWebServerStuff
3867 PACKAGES="apache"
3868 installPackages
3869
3870 WWW_PHP_INI=$APACHE_PHP_INI
3871 APACHE_DIR=/etc/httpd/conf
3872 local APACHE_CONF=$APACHE_DIR/httpd.conf
3873 APACHE_SCGI_FILE="$APACHE_DIR/modules.d/scgi.conf"
3874 initializeApacheVars www www "$APACHE_DIR/modules.d"
3875 apacheCommonInitialization "" /usr/lib/apache
3876
3877 # Remove an Apache warning by commenting out the default SSL VirtualHost
3878 sed_i '/^<VirtualHost _default_:443>/,/^<\/VirtualHost>/s/^/#/' $APACHE_DIR/ssl.conf
3879 if ! grep -qE '^[ ]*Include .*/ssl.conf' $APACHE_CONF; then
3880 echo "Include $APACHE_DIR/ssl.conf" >> $APACHE_CONF
3881 fi
3882
3883 createWebServerUserGroup
3884
3885 sed_i 'g/^[ ]*User[ ]/d' $APACHE_CONF
3886 sed_i 'g/^[ ]*Group[ ]/d' $APACHE_CONF
3887 echo "User $WWW_USER" >> $APACHE_CONF
3888 echo "Group $WWW_GROUP" >> $APACHE_CONF
3889
3890 resetWebServerPermissions
3891 service httpd add
3892 osHandler_$os restart_$INSTALL_WEB_SERVER
3893 ;;
3894 restart_apache)
3895 # restart won't work if it's not started
3896 service httpd stop
3897 sleep 5 # Important! 'start' may fail otherwise ("SKIPPING")
3898 service httpd start || errorExit "Could not start $INSTALL_WEB_SERVER"
3899 ;;
3900 installVsftpd)
3901 installProgram vsftpd
3902 updateVsftpdConf /etc/vsftpd.conf
3903 service vsftpd add
3904 service vsftpd stop
3905 sleep 5
3906 service vsftpd start
3907 ;;
3908 preWebminInstall)
3909 sed_i 's!^init_dir=.*!init_dir=/etc/rc.d!' init/config-generic-linux
3910 sed_i 's!^boot_levels=.*!boot_levels=2 3 4 5!' init/config-generic-linux
3911 ;;
3912 postWebminInstall)
3913 if [ -x /etc/rc.d/webmin ]; then
3914 cat << EOF - /etc/rc.d/webmin > /etc/rc.d/rc.webmin
3915#!/bin/sh
3916# chkconfig: 2345 85 15
3917# description: webmin
3918EOF
3919 chmod +x /etc/rc.d/rc.webmin
3920 rm -f /etc/rc.d/webmin
3921 service webmin add
3922 fi
3923 ;;
3924 preNginxInstall)
3925 WWW_PHP_INI=/etc/php.ini
3926 osHandler_$os _installCommonWebServerStuff
3927 PACKAGES="pcre openssl zlib php-cgi"
3928 installPackages
3929 ;;
3930 installPhpCgiService)
3931 osHandler_$os _installService phpcgi "$PHPCGI_STARTUP_DESC" "getCommonStartupScriptContents_phpcgi \"$WWW_USER\" \"$WWW_PHP_CGI\""
3932 ;;
3933 installNginxService)
3934 osHandler_$os _installService nginx "$NGINX_STARTUP_DESC" "getCommonStartupScriptContents_nginx \"$NGINX_BIN\""
3935 ;;
3936 restart_nginx)
3937 service phpcgi restart || errorExit "Could not start php-cgi"
3938 service nginx restart || errorExit "Could not start $INSTALL_WEB_SERVER"
3939 ;;
3940 preLighttpdInstall)
3941 WWW_PHP_INI=/etc/php.ini
3942 osHandler_$os _installCommonWebServerStuff
3943 PACKAGES="pcre openssl zlib php-cgi"
3944 installPackages
3945 ;;
3946 installLighttpdService)
3947 osHandler_$os _installService lighttpd "$LIGHTTPD_STARTUP_DESC" "getCommonStartupScriptContents_lighttpd \"$LIGHTTPD_BIN\""
3948 ;;
3949 restart_lighttpd)
3950 service phpcgi restart || errorExit "Could not start php-cgi"
3951 service lighttpd restart || errorExit "Could not start $INSTALL_WEB_SERVER"
3952 ;;
3953 *)
3954 ;;
3955 esac
3956}
3957
3958osHandler_unity() {
3959 case $1 in
3960 init)
3961 INSTALL="smart install -y"
3962 FEATURES="service rtorrent apache nginx lighttpd vsftpd webmin"
3963 BUILD_TOOLS="gcc gcc-c++ make pkgconfig file libtool m4"
3964 ;;
3965 init2)
3966 smart update
3967 installProgram ed
3968 ;;
3969 installTools)
3970 PACKAGES=
3971 addProgram svn subversion
3972 addProgram wget
3973 addProgram unzip
3974 addProgram screen
3975 installPackages
3976 ;;
3977 installAutodlTools)
3978 IRSSI_LOAD_PERL=y
3979 PACKAGES=
3980 addProgram perl
3981 addProgram irssi
3982 rpm -q --quiet irssi-perl || PACKAGES="$PACKAGES irssi-perl"
3983 addPerlModule Archive::Zip perl-Archive-Zip
3984 addPerlModule HTML::Parser perl-HTML-Parser
3985 addPerlModule Digest::SHA1 perl-Digest-SHA1
3986 installPackages
3987
3988 installPerlModule Net::SSLeay perl-Net-SSLeay
3989 installPerlModule XML::LibXML perl-XML-LibXML
3990 # It doesn't install the dependency 'common::sense' so force install it
3991 installPerlModule JSON::XS "perl-common-sense perl-JSON-XS"
3992 installPerlModule JSON perl-JSON
3993 ;;
3994 installCpanTools)
3995 PACKAGES="perl-devel"
3996 if echo "$MISSING_PERL_MODULES" | grep -q 'XML::LibXML'; then
3997 PACKAGES="$PACKAGES libxml2 libxml2-devel zlib1 zlib1-devel"
3998 fi
3999 if echo "$MISSING_PERL_MODULES" | grep -q 'Net::SSLeay'; then
4000 PACKAGES="$PACKAGES openssl libopenssl-devel zlib1 zlib1-devel"
4001 fi
4002 installPackages
4003 ;;
4004 installRtorrentBuildTools)
4005 PACKAGES="libsigc++2.0-devel openssl libncurses-devel libcurl-devel"
4006 installPackages
4007 ;;
4008 installPhpModules)
4009 installMissingPhpPackages
4010 ;;
4011 installAutodlService)
4012 installService_mandriva_autodl $2
4013 ;;
4014 installApache)
4015 installApache_mandriva
4016 ;;
4017 restart_apache)
4018 service httpd restart || errorExit "Could not start $INSTALL_WEB_SERVER"
4019 ;;
4020 installVsftpd)
4021 installVsftpd_chkconfig /etc/vsftpd/vsftpd.conf
4022 ;;
4023 preNginxInstall)
4024 WWW_PHP_INI=/etc/php-cgi-fcgi.ini
4025 installCommonWebServerStuff_mandriva
4026 PACKAGES="pcre-devel libopenssl-devel zlib1-devel php-cgi"
4027 installPackages
4028 ;;
4029 installPhpCgiService)
4030 installService_mandriva_phpcgi
4031 ;;
4032 installNginxService)
4033 installService_mandriva_nginx
4034 ;;
4035 restart_nginx)
4036 service phpcgi restart || errorExit "Could not start php-cgi"
4037 service nginx restart || errorExit "Could not start $INSTALL_WEB_SERVER"
4038 ;;
4039 preLighttpdInstall)
4040 WWW_PHP_INI=/etc/php-cgi-fcgi.ini
4041 installCommonWebServerStuff_mandriva
4042 PACKAGES="pcre-devel libopenssl-devel zlib1-devel php-cgi"
4043 installPackages
4044 ;;
4045 installLighttpdService)
4046 installService_mandriva_lighttpd
4047 ;;
4048 restart_lighttpd)
4049 service phpcgi restart || errorExit "Could not start php-cgi"
4050 service lighttpd restart || errorExit "Could not start $INSTALL_WEB_SERVER"
4051 ;;
4052 *)
4053 ;;
4054 esac
4055}
4056
4057osHandler_sabayon() {
4058 BUILD_TOOLS="sys-kernel/linux-headers dev-util/pkgconfig file libtool m4"
4059 isProgramInstalled gcc || BUILD_TOOLS="sys-devel/gcc $BUILD_TOOLS"
4060 isProgramInstalled make || BUILD_TOOLS="sys-devel/make $BUILD_TOOLS"
4061
4062 case $1 in
4063 init)
4064 INSTALL="equo install"
4065 FEATURES="service rtorrent apache nginx lighttpd vsftpd webmin"
4066 ;;
4067 init2)
4068 equo update
4069 ;;
4070 installTools)
4071 PACKAGES=
4072 addProgram svn subversion
4073 addProgram wget
4074 addProgram unzip
4075 addProgram screen
4076 installPackages
4077 ;;
4078 installAutodlTools)
4079 PACKAGES=
4080 addProgram perl
4081 addProgram irssi
4082 addPerlModule Archive::Zip dev-perl/Archive-Zip
4083 addPerlModule Net::SSLeay dev-perl/Net-SSLeay
4084 addPerlModule HTML::Parser dev-perl/HTML-Parser
4085 # XML::LibXML needs XML::SAX and XML::NamespaceSupport but they're not auto
4086 # installed as dependencies.
4087 addPerlModule XML::SAX dev-perl/XML-SAX
4088 addPerlModule XML::NamespaceSupport dev-perl/XML-NamespaceSupport
4089 addPerlModule XML::LibXML dev-perl/XML-LibXML
4090 addPerlModule Digest::SHA1 dev-perl/Digest-SHA1
4091 addPerlModule JSON::XS dev-perl/JSON-XS
4092 addPerlModule JSON dev-perl/JSON
4093 installPackages
4094 ;;
4095 installCpanTools)
4096 PACKAGES=
4097 if echo "$MISSING_PERL_MODULES" | grep -q 'XML::LibXML'; then
4098 PACKAGES="$PACKAGES dev-libs/libxml2 sys-libs/zlib"
4099 fi
4100 if echo "$MISSING_PERL_MODULES" | grep -q 'Net::SSLeay'; then
4101 PACKAGES="$PACKAGES dev-libs/openssl sys-libs/zlib"
4102 fi
4103 installPackages
4104 ;;
4105 installRtorrentBuildTools)
4106 PACKAGES="dev-libs/libsigc++-2* dev-libs/openssl sys-libs/ncurses net-misc/curl"
4107 installPackages
4108 ;;
4109 installPhpModules)
4110 ;;
4111 installAutodlService)
4112 installService_gentoo_autodl "$2"
4113 rc-update --update
4114 ;;
4115 installApache)
4116 installApache_gentoo
4117 rc-update --update
4118 ;;
4119 restart_apache)
4120 /etc/init.d/apache2 restart || errorExit "Could not start $INSTALL_WEB_SERVER"
4121 ;;
4122 installVsftpd)
4123 installVsftpd_gentoo
4124 rc-update --update
4125 ;;
4126 preNginxInstall)
4127 preNginxInstall_gentoo
4128 ;;
4129 installPhpCgiService)
4130 installService_gentoo_phpcgi
4131 rc-update --update
4132 ;;
4133 installNginxService)
4134 installService_gentoo_nginx
4135 rc-update --update
4136 ;;
4137 restart_nginx)
4138 /etc/init.d/phpcgi restart || errorExit "Could not start php-cgi"
4139 /etc/init.d/nginx restart || errorExit "Could not start $INSTALL_WEB_SERVER"
4140 ;;
4141 preLighttpdInstall)
4142 preLighttpdInstall_gentoo
4143 ;;
4144 installLighttpdService)
4145 installService_gentoo_lighttpd
4146 rc-update --update
4147 ;;
4148 restart_lighttpd)
4149 /etc/init.d/phpcgi restart || errorExit "Could not start php-cgi"
4150 /etc/init.d/lighttpd restart || errorExit "Could not start $INSTALL_WEB_SERVER"
4151 ;;
4152 *)
4153 ;;
4154 esac
4155}
4156
4157osHandler_gentoo() {
4158 case $1 in
4159 init)
4160 INSTALL="emerge --update"
4161 FEATURES="service rtorrent apache nginx lighttpd vsftpd webmin"
4162 BUILD_TOOLS="sys-kernel/linux-headers"
4163 ;;
4164 init2)
4165 emerge --sync
4166 installProgram ed sys-apps/ed
4167
4168 # Do this AFTER installing ed since we require ed...
4169 for useFlag in perl ssl auth_basic xmlrpc gd xml sockets json apache2 zlib cli cgi; do
4170 appendFileStringVar /etc/make.conf USE $useFlag
4171 done
4172 ;;
4173 installTools)
4174 PACKAGES=
4175 addProgram svn subversion
4176 addProgram wget
4177 addProgram unzip
4178 addProgram screen
4179 installPackages
4180 ;;
4181 installAutodlTools)
4182 PACKAGES=
4183 addProgram perl
4184 addProgram irssi
4185 addPerlModule Archive::Zip dev-perl/Archive-Zip
4186 addPerlModule Net::SSLeay dev-perl/Net-SSLeay
4187 addPerlModule HTML::Parser dev-perl/HTML-Parser
4188 addPerlModule XML::LibXML dev-perl/XML-LibXML
4189 addPerlModule Digest::SHA1 dev-perl/Digest-SHA1
4190 addPerlModule JSON dev-perl/JSON
4191 installPackages
4192
4193 echo "Trying to install JSON::XS but it's probably masked. Ignore the error."
4194 installPerlModule JSON::XS dev-perl/JSON-XS
4195 ;;
4196 installCpanTools)
4197 PACKAGES=
4198 if echo "$MISSING_PERL_MODULES" | grep -q 'XML::LibXML'; then
4199 PACKAGES="$PACKAGES dev-libs/libxml2 sys-libs/zlib"
4200 fi
4201 if echo "$MISSING_PERL_MODULES" | grep -q 'Net::SSLeay'; then
4202 PACKAGES="$PACKAGES dev-libs/openssl sys-libs/zlib"
4203 fi
4204 installPackages
4205 ;;
4206 installRtorrentBuildTools)
4207 emerge rtorrent
4208 ;;
4209 installPhpModules)
4210 ;;
4211 installAutodlService)
4212 installService_gentoo_autodl "$2"
4213 ;;
4214 installApache)
4215 installApache_gentoo
4216 ;;
4217 restart_apache)
4218 /etc/init.d/apache2 restart || errorExit "Could not start $INSTALL_WEB_SERVER"
4219 ;;
4220 installVsftpd)
4221 installVsftpd_gentoo
4222 ;;
4223 preNginxInstall)
4224 preNginxInstall_gentoo
4225 ;;
4226 installPhpCgiService)
4227 installService_gentoo_phpcgi
4228 ;;
4229 installNginxService)
4230 installService_gentoo_nginx
4231 ;;
4232 restart_nginx)
4233 /etc/init.d/phpcgi restart || errorExit "Could not start php-cgi"
4234 /etc/init.d/nginx restart || errorExit "Could not start $INSTALL_WEB_SERVER"
4235 ;;
4236 preLighttpdInstall)
4237 preLighttpdInstall_gentoo
4238 ;;
4239 installLighttpdService)
4240 installService_gentoo_lighttpd
4241 ;;
4242 restart_lighttpd)
4243 /etc/init.d/phpcgi restart || errorExit "Could not start php-cgi"
4244 /etc/init.d/lighttpd restart || errorExit "Could not start $INSTALL_WEB_SERVER"
4245 ;;
4246 *)
4247 ;;
4248 esac
4249}
4250
4251# Slackware-based Linux distros with the slapt-get tool, eg. Vector Linux, Salix OS
4252osHandler_slaptget() {
4253 case $1 in
4254 init)
4255 INSTALL="slapt-get -y --install"
4256 FEATURES="rtorrent webmin"
4257 BUILD_TOOLS="gcc gcc-g++ make kernel-headers pkg-config file libtool"
4258 ;;
4259 init2)
4260 slapt-get --update
4261 installProgram ed
4262 ;;
4263 installTools)
4264 PACKAGES=
4265 addProgram svn subversion
4266 addProgram wget
4267 addProgram unzip
4268 addProgram screen
4269 installPackages
4270 ;;
4271 installAutodlTools)
4272 PACKAGES=
4273 addProgram perl
4274 addProgram irssi
4275 installPackages
4276 ;;
4277 installCpanTools)
4278 PACKAGES=
4279 if echo "$MISSING_PERL_MODULES" | grep -q 'XML::LibXML'; then
4280 PACKAGES="$PACKAGES libxml2 zlib"
4281 fi
4282 if echo "$MISSING_PERL_MODULES" | grep -q 'Net::SSLeay'; then
4283 PACKAGES="$PACKAGES openssl zlib"
4284 fi
4285 installPackages
4286 ;;
4287 installRtorrentBuildTools)
4288 ;;
4289 installPhpModules)
4290 ;;
4291 installAutodlService)
4292 ;;
4293 *)
4294 ;;
4295 esac
4296}
4297
4298osHandler_other() {
4299 case $1 in
4300 init)
4301 INSTALL=""
4302 FEATURES=""
4303 ;;
4304 init2)
4305 ;;
4306 installTools)
4307 ;;
4308 installAutodlTools)
4309 ;;
4310 installCpanTools)
4311 ;;
4312 installRtorrentBuildTools)
4313 ;;
4314 installPhpModules)
4315 ;;
4316 installAutodlService)
4317 ;;
4318 *)
4319 ;;
4320 esac
4321}
4322
4323isWebServerRpcModule() {
4324 ! arrayIsPresent rpc $RUTORRENT_PLUGINS && ! arrayIsPresent httprpc $RUTORRENT_PLUGINS && return 0
4325 return 1
4326}
4327
4328canInstallService() {
4329 return $(arrayIsPresent service $FEATURES)
4330}
4331
4332canInstallRtorrent() {
4333 return $(arrayIsPresent rtorrent $FEATURES)
4334}
4335
4336canInstallApache() {
4337 return $(arrayIsPresent apache $FEATURES)
4338}
4339
4340canInstallNginx() {
4341 return $(arrayIsPresent nginx $FEATURES)
4342}
4343
4344canInstallLighttpd() {
4345 return $(arrayIsPresent lighttpd $FEATURES)
4346}
4347
4348canInstallVsftpd() {
4349 return $(arrayIsPresent vsftpd $FEATURES)
4350}
4351
4352canInstallWebmin() {
4353 return $(arrayIsPresent webmin $FEATURES)
4354}
4355
4356getRequiredPrograms() {
4357 REQUIRED_PROGRAMS="which svn wget unzip ed sed grep tar expr ps awk kill printf"
4358
4359 if [ "$INSTALL_AUTODL_IRSSI" = y ]; then
4360 REQUIRED_PROGRAMS="$REQUIRED_PROGRAMS perl"
4361
4362 # NetBSD and DragonFly BSD don't compile Irssi with Perl support by default
4363 [ "$IGNORE_IRSSI" != y ] && REQUIRED_PROGRAMS="$REQUIRED_PROGRAMS irssi"
4364 fi
4365}
4366
4367verifyInstalledPrograms() {
4368 getRequiredPrograms
4369
4370 local MISSING_PROGRAMS=
4371 for prog in $REQUIRED_PROGRAMS; do
4372 local name=$prog
4373 [ "$prog" = svn ] && name=subversion
4374 isProgramInstalled "$prog" || MISSING_PROGRAMS="$MISSING_PROGRAMS $name"
4375 done
4376 [ -n "$MISSING_PROGRAMS" ] && errorExit "Can't continue. The following programs are not installed: $MISSING_PROGRAMS"
4377}
4378
4379initPluginDirVar() {
4380 AUTODL_IRSSI_PLUGIN_DIR="$RUTORRENT_BASE_PATH/plugins/autodl-irssi"
4381}
4382
4383getRtorrentDirs() {
4384 local user="$1"
4385 getUserDir "$user"
4386 RTORRENT_DOWNLOAD_DIR="$userDir/$RTORRENT_REL_DOWNLOAD_DIR"
4387 RTORRENT_WATCH_DIR="$userDir/$RTORRENT_REL_WATCH_DIR"
4388 RTORRENT_SESSION_DIR="$userDir/$RTORRENT_REL_SESSION_DIR"
4389}
4390
4391getUserScgiSocketPath() {
4392 local user="$1"
4393 getRtorrentDirs "$user"
4394 scgiSocketPath="$RTORRENT_SESSION_DIR/rpc.socket"
4395}
4396
4397waitenter() {
4398 local msg="${1-Press ENTER to continue...}"
4399 echo -n "$CCYAN$msg$CEND"
4400 read dummy
4401}
4402
4403askQuestion() {
4404 local question="$1"
4405 local default="$2"
4406
4407 if [ -z "$default" ]; then
4408 echo -n "$CQUESTION$question$CEND "
4409 read answer
4410 else
4411 echo -n "$CQUESTION$question$CEND [$CGREEN$default$CEND] "
4412 read answer
4413 fi
4414 if [ -z "$answer" ]; then
4415 answer="$default"
4416 fi
4417}
4418
4419# Asks the user a question, and sets answer to y or n depending on the user's answer
4420askYesNo() {
4421 local question="$1"
4422 local default="$2"
4423
4424 while true; do
4425 askQuestion "$question" "$default"
4426 if echo "$answer" | grep -qiE '^y(es)?$'; then
4427 answer=y
4428 return 1
4429 elif echo "$answer" | grep -qiE '^no?$'; then
4430 answer=n
4431 return 0
4432 fi
4433 done
4434}
4435
4436askOsUser() {
4437 local stopIfEmpty=${1:-n}
4438 local user=
4439 while true; do
4440 askQuestion "Enter name of user:" ""
4441 user="$answer"
4442 [ -z "$user" ] && [ "$stopIfEmpty" = y ] && break
4443 userExists "$user" && break
4444
4445 echo "${CWARNING}User $user does not exist.$CEND"
4446 askYesNo "Do you want to create user $user?" "No"
4447 [ "$answer" = n ] && continue
4448
4449 echo "${CMSG}Creating user $user.$CEND"
4450 if ! useradd -m -s /bin/sh "$user"; then
4451 echo "${CWARNING}Could not create user $user.$CEND"
4452 continue
4453 fi
4454 echo "${CMSG}Enter the user's password:$CEND"
4455 if ! passwd "$user"; then
4456 echo "${CWARNING}Failed to set password.$CEND"
4457 continue
4458 fi
4459 userExists "$user" && break
4460 done
4461 answer="$user"
4462}
4463
4464# Adds another user to USERS
4465addUser() {
4466 local osUser="$1"
4467 local webUser="$2"
4468 local autodlPassword=
4469 local webpass=
4470
4471 if [ "$INSTALL_RUTORRENT" = y ] || [ "$USE_RUTORRENT_PLUGIN" = y ]; then
4472 if ! canGeneratePasswords; then
4473 cat << EOF
4474$CQUESTION
4475The password makes sure only you can change your autodl-irssi settings. This is
4476NOT your login password. Use any password, but each user should use a unique
4477password. The password is used by the PHP code to access autodl-irssi settings.
4478You don't need to remember this password. It can't contain any spaces or a
4479colon ':'.$CEND
4480EOF
4481 while true; do
4482 askQuestion "Enter the autodl-irssi password (this is not your login password):" ""
4483 autodlPassword="$answer"
4484 isValidPassword "$autodlPassword" && break
4485 echo "${CWARNING}Invalid password. Try again.$CEND"
4486 done
4487 fi
4488
4489 if [ "$RUTORRENT_PASSWORD_PROTECTED" = y ]; then
4490 while true; do
4491 askQuestion "Enter your ruTorrent password:" ""
4492 webpass="$answer"
4493 isValidPassword "$webpass" && break
4494 echo "${CWARNING}Invalid password. Try again.$CEND"
4495 done
4496 fi
4497
4498 USERS="$USERS $osUser:$autodlPassword:$webUser:$webpass"
4499 else
4500 USERS="$USERS $osUser"
4501 fi
4502}
4503
4504installUser() {
4505 local userPluginDir="$1"
4506 local osUser="$2"
4507 local webUser="${3:-$osUser}"
4508 local port="$4"
4509 local autodlPassword="$5"
4510
4511 getUserGroup "$osUser"
4512 getUserDir "$osUser"
4513
4514 cat << EOF
4515
4516========================= ${CGREEN}Installing autodl-irssi$CEND =========================
4517Use the ruTorrent plugin: $CGREEN$USE_RUTORRENT_PLUGIN$CEND
4518OS user: $CGREEN$osUser$CEND
4519EOF
4520 if [ "$USE_RUTORRENT_PLUGIN" = y ]; then
4521 [ "$RUTORRENT_PASSWORD_PROTECTED" = y ] && echo "ruTorrent user: $CGREEN$webUser$CEND"
4522 echo "port: $CGREEN$port$CEND"
4523 echo "password: $CGREEN$autodlPassword$CEND"
4524 fi
4525 cat << EOF
4526group: $CGREEN$group$CEND
4527home: $CGREEN$userDir$CEND
4528
4529EOF
4530 if [ "$USE_RUTORRENT_PLUGIN" = y ]; then
4531 isValidPortNumber "$port" || errorExit "Invalid port number: $port"
4532 isValidPassword "$autodlPassword" || errorExit "Invalid password: $autodlPassword"
4533 isValidWebUser "$webUser" || errorExit "Invalid web user: $webUser"
4534 fi
4535
4536 mkdir -p "$userDir/.irssi/scripts/autorun"
4537 cd "$userDir/.irssi/scripts" || errorExit "Could not CD into user dir. Run the script as root."
4538 echo "${CMSG}Downloading autodl-irssi.zip...$CEND"
4539 if ! downloadFile autodl-irssi.zip "$AUTODL_IRSSI_ZIP_URL"; then
4540 errorExit "Could not download autodl-irssi zip file"
4541 fi
4542 echo "${CMSG}Unpacking autodl-irssi...$CEND"
4543 unzip -o autodl-irssi.zip > /dev/null || errorExit "Could not unpack autodl-irssi zip file"
4544 rm -f autodl-irssi.zip
4545 cp autodl-irssi.pl autorun/ || errorExit "Could not copy autodl-irssi.pl to Irssi autorun dir."
4546 mkdir -p "$userDir/.autodl"
4547 touch "$userDir/.autodl/autodl.cfg"
4548 if ! [ -s "$userDir/.autodl/autodl.cfg" ]; then
4549 [ "$INSTALL_RUTORRENT" = y ] && cat > "$userDir/.autodl/autodl.cfg" << EOF
4550[options]
4551upload-type = rtorrent
4552EOF
4553 fi
4554
4555 if [ "$USE_RUTORRENT_PLUGIN" = y ]; then
4556 if [ ! -d "$AUTODL_IRSSI_PLUGIN_DIR" ]; then
4557 errorExit "The autodl-irssi ruTorrent plugin has not been installed. Install it."
4558 fi
4559
4560 cat > "$userDir/.autodl/autodl2.cfg" << EOF
4561[options]
4562gui-server-port = $port
4563gui-server-password = $autodlPassword
4564EOF
4565
4566 rm -f "$AUTODL_IRSSI_PLUGIN_DIR/conf.php"
4567 mkdir -p "$userPluginDir"
4568 cat > "$userPluginDir/conf.php" << EOF
4569<?php
4570\$autodlPort = $port;
4571\$autodlPassword = "$autodlPassword";
4572?>
4573EOF
4574 [ $? -eq 0 ] || errorExit "Could not write to $userPluginDir/conf.php. Run this script as root."
4575 # Only set perms to 0400 if the code knows the owner (web server owner) and will reset it
4576 [ "$ISROOT" = y ] && [ "$INSTALL_RUTORRENT" = y ] && chmod 0400 "$userPluginDir/conf.php"
4577 else
4578 # Don't use the autodl-irssi ruTorrent plugin
4579 : > "$userDir/.autodl/autodl2.cfg"
4580 fi
4581
4582 # The Perl module isn't loaded by default
4583 if [ "$IRSSI_LOAD_PERL" = y ]; then
4584 if [ ! -f "$userDir/.irssi/startup" ] || ! grep -q 'load perl' "$userDir/.irssi/startup"; then
4585 echo "load perl" >> "$userDir/.irssi/startup"
4586 fi
4587 fi
4588
4589 # Make sure we redownload the tracker files since the ones in the zip file are possibly
4590 # old versions.
4591 local autodlStateFile="$userDir/.autodl/AutodlState.xml"
4592 [ -f "$autodlStateFile" ] && sed_i 'g/<trackers-version>/d' "$autodlStateFile"
4593
4594 resetOwner "$osUser" "$userDir/.autodl" "$userDir/.irssi"
4595 chmod 0700 "$userDir/.autodl" "$userDir/.irssi"
4596}
4597
4598getRutorrentUserConfDir() {
4599 userConfDir="$RUTORRENT_BASE_PATH/conf/users/$webUser"
4600}
4601
4602getRutorrentUserShareDir() {
4603 userShareDir="$RUTORRENT_BASE_PATH/share/users/$webUser"
4604}
4605
4606resetRutorrentUserPermissions() {
4607 for packedUser in $USERS; do
4608 extractPackedUser $packedUser
4609 getRutorrentUserConfDir
4610 getRutorrentUserShareDir
4611 # Make sure only the web server and the user itself can access its share/conf dirs
4612 chown $osUser:$WWW_GROUP "$userShareDir" "$userConfDir"
4613 chmod 0770 "$userShareDir" "$userConfDir"
4614 done
4615}
4616
4617############################################################################
4618#
4619# This is where we start
4620#
4621############################################################################
4622
4623SELINUX_ENABLED=n
4624isProgramInstalled selinuxenabled && selinuxenabled && SELINUX_ENABLED=y
4625echo "SELinux enabled: $SELINUX_ENABLED"
4626
4627ISROOT=n
4628[ $(id -u) -eq 0 ] && ISROOT=y
4629echo "Is root user: $ISROOT"
4630
4631if [ $# -gt 0 ]; then
4632 parseCommandLine "$@"
4633 INTERACTIVE=n
4634else
4635 INTERACTIVE=y
4636fi
4637
4638detectOs
4639cat << EOF
4640Detected OS: $CGREEN$os_long$CEND
4641Type: $CGREEN$os$CEND
4642
4643Type sh $0 --help for all command line options.
4644EOF
4645
4646osHandler_$os init
4647
4648if [ "$INTERACTIVE" = y ]; then
4649 if [ "$ISROOT" = n ]; then
4650 cat << EOF
4651$CRED
4652You're not the root user! This install script may fail if you're not the root
4653user. To start it as the root user do one of the following:
4654
4655Ubuntu and Ubuntu clones:
4656 ${CGREEN}sudo sh $0$CRED
4657
4658Any other OS:
4659 ${CGREEN}su
4660 sh $0$CRED
4661$CEND
4662EOF
4663 waitenter "Press Ctrl+C to exit or ENTER to continue..."
4664 fi
4665
4666 cat << EOF
4667$CMSG
4668Press ENTER to use the default answer in [brackets].$CEND
4669EOF
4670
4671 webServers=
4672 canInstallApache && webServers="$webServers apache"
4673 canInstallNginx && webServers="$webServers nginx"
4674 canInstallLighttpd && webServers="$webServers lighttpd"
4675 if [ -n "$webServers" ]; then
4676 cat << EOF
4677$CQUESTION
4678If you want to install ruTorrent you must install a web server, eg. Apache.
4679If you've already installed another web server, you must first uninstall it or
4680disable it. List of supported web servers:$CEND
4681EOF
4682 canInstallApache && echo " ${CGREEN}apache$CEND ${CQUESTION}Apache web server$CEND"
4683 canInstallNginx && echo " ${CGREEN}nginx$CEND ${CQUESTION}nginx web server (lightweight)$CEND"
4684 canInstallLighttpd && echo " ${CGREEN}lighttpd$CEND ${CQUESTION}lighttpd web server (lightweight)$CEND"
4685 echo " ${CGREEN}none$CEND ${CQUESTION}Don't install a web server$CEND"
4686 while true; do
4687 INSTALL_WEB_SERVER=
4688 echo "${CQUESTION}Select one of:$CGREEN$webServers none$CEND"
4689 askQuestion "Enter name of web server" "$(getFirst $webServers)"
4690 [ "$answer" = none ] && break
4691 INSTALL_WEB_SERVER="$answer"
4692 arrayIsPresent $INSTALL_WEB_SERVER $webServers && break
4693 done
4694 if [ -n "$INSTALL_WEB_SERVER" ]; then
4695 askYesNo "Do you want to install ruTorrent?" "Yes"
4696 INSTALL_RUTORRENT="$answer"
4697 else
4698 INSTALL_RUTORRENT=n
4699 fi
4700 fi
4701
4702 if canInstallRtorrent; then
4703 cat << EOF
4704$CQUESTION
4705ruTorrent requires a working rtorrent built with XML-RPC support.$CEND
4706EOF
4707 askYesNo "Do you want to build rtorrent?" "Yes"
4708 BUILD_RTORRENT="$answer"
4709 fi
4710
4711 askYesNo "Do you want to install the autodl-irssi ruTorrent plugin?" "Yes"
4712 USE_RUTORRENT_PLUGIN="$answer"
4713
4714 if [ "$INSTALL_RUTORRENT" = y ]; then
4715 REINSTALL_RUTORRENT_PLUGIN=n
4716 RUTORRENT_PASSWORD_PROTECTED=y
4717 elif [ "$USE_RUTORRENT_PLUGIN" = y ]; then
4718 echo ""
4719 while true; do
4720 echo "${CQUESTION}The ruTorrent www base path is where you installed ruTorrent.$CEND"
4721 askQuestion "What is the ruTorrent www base path, eg. /var/www/rutorrent:" ""
4722 RUTORRENT_BASE_PATH="$answer"
4723 isValidRutorrentBasePath "$RUTORRENT_BASE_PATH" && break
4724
4725 echo "$CWARNING$RUTORRENT_BASE_PATH is not the ruTorrent base path.$CEND"
4726 done
4727
4728 initPluginDirVar
4729 if [ -d "$AUTODL_IRSSI_PLUGIN_DIR" ]; then
4730 echo ""
4731 askYesNo "The autodl-irssi ruTorrent plugin seems to be installed. Do you want to re-install it?" "No"
4732 REINSTALL_RUTORRENT_PLUGIN="$answer"
4733 else
4734 REINSTALL_RUTORRENT_PLUGIN=n
4735 fi
4736
4737 cat << EOF
4738$CQUESTION
4739To use more than one ruTorrent user, you must password protect ruTorrent.$CEND
4740EOF
4741 askYesNo "Is ruTorrent password protected?" "No"
4742 RUTORRENT_PASSWORD_PROTECTED="$answer"
4743 else
4744 RUTORRENT_PASSWORD_PROTECTED=n
4745 fi
4746
4747 if [ "$USE_RUTORRENT_PLUGIN" = y ]; then
4748 INSTALL_AUTODL_IRSSI=y
4749 else
4750 askYesNo "Do you want to install autodl-irssi?" "Yes"
4751 INSTALL_AUTODL_IRSSI="$answer"
4752 fi
4753
4754 if canInstallService && ([ "$INSTALL_AUTODL_IRSSI" = y ] || [ "$INSTALL_RUTORRENT" = y ]); then
4755 cat << EOF
4756$CQUESTION
4757If you want to automatically start Irssi and rtorrent when the computer boots,
4758install the startup script.$CEND
4759EOF
4760 askYesNo "Do you want to install the startup script?" "Yes"
4761 INSTALL_STARTUP_SCRIPT="$answer"
4762 fi
4763
4764 askUser=n
4765 if [ "$USE_RUTORRENT_PLUGIN" = y ] || [ "$INSTALL_AUTODL_IRSSI" = y ] || \
4766 [ "$INSTALL_STARTUP_SCRIPT" = y ] || [ "$INSTALL_RUTORRENT" = y ]; then
4767 askUser=y
4768 fi
4769 if [ "$askUser" = y ]; then
4770 if [ "$RUTORRENT_PASSWORD_PROTECTED" = n ]; then
4771 cat << EOF
4772$CQUESTION
4773This is the user running rtorrent and/or Irssi.$CEND
4774${CWARNING}Don't use the root user. Use a normal user!$CEND
4775EOF
4776 askOsUser
4777 addUser "$answer" ""
4778 else
4779 while true; do
4780 cat << EOF
4781$CQUESTION
4782===================== USER =====================
4783This is the user running rtorrent and/or Irssi.
4784${CWARNING}Don't use the root user. Use a normal user!$CEND
4785${CCYAN}Press ENTER to stop adding users.$CEND
4786EOF
4787 askOsUser y
4788 osUser="$answer"
4789 [ -z "$osUser" ] && break
4790
4791 while true; do
4792 cat << EOF
4793$CQUESTION
4794The ruTorrent user is the name you use to log in to ruTorrent.$CEND
4795EOF
4796 askQuestion "Enter ruTorrent user:" "$osUser"
4797 webUser="$answer"
4798 isValidWebUser "$webUser" && break
4799 echo "${CWARNING}Invalid web user name '$webUser'. Use only lower case letters."
4800 done
4801
4802 addUser "$osUser" "$webUser"
4803 done
4804 fi
4805 fi
4806
4807 if canInstallVsftpd; then
4808 cat << EOF
4809$CQUESTION
4810vsftpd is a very secure FTP daemon.$CEND
4811EOF
4812 askYesNo "Do you want to install vsftpd?" "Yes"
4813 INSTALL_VSFTPD="$answer"
4814
4815 if [ "$INSTALL_VSFTPD" = y ]; then
4816 askYesNo "Do you want to use encrypted FTP (FTPES)" "Yes"
4817 USE_ENCRYPTED_FTP="$answer"
4818
4819 port=$DEFAULT_PORT_FTP
4820 [ "$USE_ENCRYPTED_FTP" = y ] && port=$DEFAULT_PORT_FTPES
4821 askQuestion "Enter FTP port number" "$port"
4822 FTP_PORT="$answer"
4823 fi
4824 fi
4825
4826 if canInstallWebmin; then
4827 cat << EOF
4828$CQUESTION
4829Webmin is a web-based administration tool for your OS.$CEND
4830EOF
4831 askYesNo "Do you want to install Webmin?" "Yes"
4832 INSTALL_WEBMIN="$answer"
4833 fi
4834fi
4835
4836cmdline="sh $0"
4837[ "$USE_RUTORRENT_PLUGIN" = y ] && cmdline="$cmdline -p"
4838[ "$REINSTALL_RUTORRENT_PLUGIN" = y ] && cmdline="$cmdline -i"
4839[ "$INSTALL_AUTODL_IRSSI" = y ] && cmdline="$cmdline -a"
4840for user in $USERS; do cmdline="$cmdline -u $user"; done
4841[ "$RUTORRENT_PASSWORD_PROTECTED" = y ] && cmdline="$cmdline -w"
4842[ -n "$RUTORRENT_BASE_PATH" ] && cmdline="$cmdline -r '$RUTORRENT_BASE_PATH'"
4843[ "$INSTALL_STARTUP_SCRIPT" = y ] && cmdline="$cmdline -s"
4844if [ -z "$INSTALL_WEB_SERVER" ]; then
4845 :
4846elif [ "$INSTALL_WEB_SERVER" = apache ]; then
4847 cmdline="$cmdline --apache"
4848elif [ "$INSTALL_WEB_SERVER" = nginx ]; then
4849 cmdline="$cmdline --nginx"
4850elif [ "$INSTALL_WEB_SERVER" = lighttpd ]; then
4851 cmdline="$cmdline --lighttpd"
4852else
4853 errorExit "Invalid web server: $INSTALL_WEB_SERVER"
4854fi
4855[ "$BUILD_RTORRENT" = y ] && cmdline="$cmdline --rtorrent"
4856[ "$INSTALL_RUTORRENT" = y ] && cmdline="$cmdline --rutorrent"
4857[ "$INSTALL_VSFTPD" = y ] && cmdline="$cmdline --vsftpd"
4858[ -n "$FTP_PORT" ] && cmdline="$cmdline --ftp-port $FTP_PORT"
4859[ "$USE_ENCRYPTED_FTP" = y ] && cmdline="$cmdline --ftpes"
4860[ "$INSTALL_WEBMIN" = y ] && cmdline="$cmdline --webmin"
4861
4862cat << EOF
4863
4864You can execute this command as the root user (Ubuntu: use ${CRED}sudo$CEND):
4865 $CGREEN$cmdline$CEND
4866
4867Use the autodl-irssi ruTorrent plugin: $USE_RUTORRENT_PLUGIN
4868Re-install the autodl-irssi ruTorrent plugin: $REINSTALL_RUTORRENT_PLUGIN
4869Install autodl-irssi: $INSTALL_AUTODL_IRSSI
4870Users: $USERS
4871ruTorrent is password protected: $RUTORRENT_PASSWORD_PROTECTED
4872ruTorrent base path: $RUTORRENT_BASE_PATH
4873Install startup script: $INSTALL_STARTUP_SCRIPT
4874Install web server: $INSTALL_WEB_SERVER
4875Build rtorrent: $BUILD_RTORRENT
4876Install ruTorrent: $INSTALL_RUTORRENT
4877Install vsftpd: $INSTALL_VSFTPD
4878FTP port: $FTP_PORT
4879Use FTPES: $USE_ENCRYPTED_FTP
4880Install Webmin: $INSTALL_WEBMIN
4881EOF
4882
4883if [ -n "$INSTALL_WEB_SERVER" ]; then
4884 for port in $HTTP_PORT $HTTPS_PORT; do
4885 isPortUsed $port || continue
4886 cat << EOF
4887$CWARNING
4888Port $port is in use. If it's not used by $INSTALL_WEB_SERVER, you may need to disable or
4889uninstall that other web server before continuing.$CEND
4890EOF
4891 done
4892fi
4893
4894if [ "$INTERACTIVE" = y ]; then
4895 echo ""
4896 waitenter "Press Ctrl+C to cancel or ENTER to install."
4897fi
4898
4899osHandler_$os init2
4900initUsers
4901initPluginDirVar
4902
4903[ -n "$INSTALL_WEB_SERVER" ] || [ "$INSTALL_RUTORRENT" = y ] && RUTORRENT_PASSWORD_PROTECTED=y
4904[ "$INSTALL_RUTORRENT" = y ] && [ -z "$INSTALL_WEB_SERVER" ] && errorExit "You must install a web server if you want to install ruTorrent, eg. use --apache --rutorrent"
4905[ "$INSTALL_RUTORRENT" = y ] && REINSTALL_RUTORRENT_PLUGIN=n
4906
4907[ "$BUILD_RTORRENT" = y ] && ! canInstallRtorrent && errorExit "Can't build rtorrent."
4908[ "$INSTALL_STARTUP_SCRIPT" = y ] && ! canInstallService && errorExit "Can't install startup script."
4909[ "$INSTALL_VSFTPD" = y ] && ! canInstallVsftpd && errorExit "Can't install vsftpd."
4910[ "$INSTALL_WEBMIN" = y ] && ! canInstallWebmin && errorExit "Can't install webmin."
4911
4912if [ -z "$INSTALL_WEB_SERVER" ]; then
4913 :
4914elif [ "$INSTALL_WEB_SERVER" = apache ]; then
4915 canInstallApache || errorExit "Can't install Apache."
4916elif [ "$INSTALL_WEB_SERVER" = nginx ]; then
4917 canInstallNginx || errorExit "Can't install nginx."
4918elif [ "$INSTALL_WEB_SERVER" = lighttpd ]; then
4919 canInstallLighttpd || errorExit "Can't install lighttpd."
4920else
4921 errorExit "Invalid web server: $INSTALL_WEB_SERVER"
4922fi
4923
4924[ -n "$FTP_PORT" ] && [ "$FTP_PORT" -lt 1 -o "$FTP_PORT" -gt 65535 ] && errorExit "Invalid FTP port: $FTP_PORT"
4925
4926if [ "$USE_RUTORRENT_PLUGIN" = y ]; then
4927 if [ -z "$INSTALL_WEB_SERVER" ] && ! isValidRutorrentBasePath "$RUTORRENT_BASE_PATH"; then
4928 errorExit "$RUTORRENT_BASE_PATH is not a valid ruTorrent base path."
4929 fi
4930fi
4931
4932if [ "$INSTALL_AUTODL_IRSSI" = y ]; then
4933 cat << EOF
4934${CMSG}Installing required tools and Perl modules...
4935Some Perl modules may not be present, but will be installed from CPAN.$CEND
4936EOF
4937else
4938 echo "${CMSG}Installing required tools...$CEND"
4939fi
4940osHandler_$os installTools
4941setSvnOpts
4942[ "$INSTALL_AUTODL_IRSSI" = y ] && osHandler_$os installAutodlTools
4943
4944verifyInstalledPrograms
4945
4946[ "$INSTALL_AUTODL_IRSSI" = y ] && installMissingPerlModules
4947
4948cat << EOF
4949$CMSG
4950All required programs and Perl modules are now installed. Ignore any errors you
4951saw.$CEND
4952EOF
4953
4954INSTALLED_RTORRENT=n
4955if [ "$BUILD_RTORRENT" = y ]; then
4956 cat << EOF
4957$CMSG
4958Building rtorrent and dependencies...$CEND
4959EOF
4960 installRtorrent
4961 INSTALLED_RTORRENT=y
4962fi
4963
4964if [ -z "$INSTALL_WEB_SERVER" ]; then
4965 :
4966elif [ "$INSTALL_WEB_SERVER" = apache ]; then
4967 echo ""
4968 echo "${CMSG}Installing Apache$CEND"
4969 osHandler_$os installApache
4970 installUnrar
4971elif [ "$INSTALL_WEB_SERVER" = nginx ]; then
4972 echo ""
4973 echo "${CMSG}Installing nginx$CEND"
4974 installNginx
4975elif [ "$INSTALL_WEB_SERVER" = lighttpd ]; then
4976 echo ""
4977 echo "${CMSG}Installing lighttpd$CEND"
4978 installLighttpd
4979else
4980 errorExit "Invalid web server: $INSTALL_WEB_SERVER"
4981fi
4982
4983if [ "$USE_RUTORRENT_PLUGIN" = y ]; then
4984 if isProgramInstalled php; then
4985 installMissingPhpModules
4986 else
4987 cat << EOF
4988$CWARNING
4989Could not find the php executable. PHP is not installed or the PHP CLI version
4990is not installed. The autodl-irssi ruTorrent plugin requires the following PHP
4991modules:
4992 $CGREEN$REQUIRED_PHP_MODULES$CWARNING
4993They're normally installed and enabled by default. If not you will need to
4994install them (if needed) and then enable each one in php.ini, eg.
4995extension=MODULE.so and then restart your web server.$CEND
4996EOF
4997 fi
4998fi
4999
5000if [ "$INSTALL_RUTORRENT" = y ]; then
5001 isProgramInstalled php || errorExit "php is not installed!"
5002 verifyWebServerVars
5003 echo ""
5004 echo "${CMSG}Installing ruTorrent$CEND"
5005 [ -d "$WWW_ROOT" ] || errorExit "Invalid web root: '$WWW_ROOT' (does not exist)"
5006 RUTORRENT_DIRNAME=rutorrent
5007
5008 [ -f "$WWW_ROOT/index.html" ] || cat > "$WWW_ROOT/index.html" << EOF
5009<html><head><title>Root page</title></head><body>
5010<a href="$RUTORRENT_DIRNAME/">ruTorrent</a>
5011</body></html>
5012EOF
5013
5014 cd "$WWW_ROOT"
5015 rm -rf "$RUTORRENT_DIRNAME"
5016 tmpName=rutorrent-tmp
5017 rm -rf $tmpName
5018 if ! svn co $SVN_OPTS "$RUTORRENT_TRUNK_DIR" $tmpName >/dev/null; then
5019 # Subversion failed. Try the official tar balls
5020 mkdir -p $tmpName
5021 cd $tmpName
5022 downloadFile "$RUTORRENT_CORE_NAME" "$RUTORRENT_CORE_URL" "$RUTORRENT_CORE_URL2" || errorExit "Could not download ruTorrent."
5023 downloadFile "$RUTORRENT_PLUGINS_NAME" "$RUTORRENT_PLUGINS_URL" "$RUTORRENT_PLUGINS_URL2" || errorExit "Could not download ruTorrent plugins."
5024 for name in "$RUTORRENT_CORE_NAME" "$RUTORRENT_PLUGINS_NAME"; do
5025 tar xzf "$name" || errorExit "Could not unpack $name"
5026 rm -f "$name"
5027 done
5028 cd ..
5029 fi
5030 cd $tmpName
5031 RUTORRENT_BASE_PATH="$WWW_ROOT/$RUTORRENT_DIRNAME"
5032 initPluginDirVar
5033 mv rutorrent/ "$RUTORRENT_BASE_PATH"
5034 mkdir -p "$RUTORRENT_BASE_PATH/plugins"
5035 for plugin in $RUTORRENT_PLUGINS; do
5036 if [ -d "plugins/$plugin/" ]; then
5037 echo "${CMSG}Installing ruTorrent plugin: $plugin$CEND..."
5038 mv plugins/$plugin/ "$RUTORRENT_BASE_PATH/plugins/" || errorExit "Could not install plugin '$plugin'."
5039 else
5040 echo "${CWARNING}Can't install missing plugin $plugin!$CEND"
5041 fi
5042 done
5043 cd ..
5044 rm -rf $tmpName
5045 cp "$RUTORRENT_BASE_PATH/favicon.ico" "$WWW_ROOT"
5046
5047 i=1
5048 touch "$WWW_PASSWORD_FILE"
5049 resetAuthPasswordFilePermissions
5050 detectHtpasswd
5051 for packedUser in $USERS; do
5052 extractPackedUser $packedUser
5053 getRutorrentUserConfDir
5054 getRutorrentUserShareDir
5055 getUserScgiSocketPath "$osUser"
5056 getRtorrentDirs "$osUser"
5057
5058 # Create user's ruTorrent config.php
5059 rpcMount="$(getUserRpcMount $i)"
5060 mkdir -p "$userConfDir"
5061
5062 rutConfigFile="$userConfDir/config.php"
5063 if [ "$SCGI_USE_UNIX_DOMAIN_SOCKET" = y ]; then
5064 cat > "$rutConfigFile" << EOF
5065<?php
5066\$scgi_port = 0;
5067\$scgi_host = "unix://$scgiSocketPath";
5068\$XMLRPCMountPoint = "$rpcMount";
5069?>
5070EOF
5071 exitCode=$?
5072 else
5073 cat > "$rutConfigFile" << EOF
5074<?php
5075\$scgi_port = $scgiPort;
5076\$scgi_host = "$SCGI_HOST";
5077\$XMLRPCMountPoint = "$rpcMount";
5078?>
5079EOF
5080 exitCode=$?
5081 fi
5082 [ $exitCode -eq 0 ] || errorExit "Could not write to file $rutConfigFile"
5083
5084 # Create user's directory to prevent certain errors the first time ruTorrent is started
5085 mkdir -p "$userShareDir/settings"
5086 mkdir -p "$userShareDir/torrents"
5087 chmod 0777 "$userShareDir/settings" "$userShareDir/torrents"
5088
5089 # Setup rtorrent
5090 mkdir -p "$RTORRENT_DOWNLOAD_DIR"
5091 mkdir -p "$RTORRENT_WATCH_DIR"
5092 mkdir -p "$RTORRENT_SESSION_DIR"
5093 rtorrentRc="$userDir/.rtorrent.rc"
5094 [ -f "$rtorrentRc" ] && mv -f "$rtorrentRc" "$rtorrentRc-backup"
5095 cat > "$rtorrentRc" << EOF
5096$(if [ "$SCGI_USE_UNIX_DOMAIN_SOCKET" = y ]; then
5097 cat << EOF2
5098execute = {sh,-c,rm -f $scgiSocketPath}
5099scgi_local = $scgiSocketPath
5100execute = {sh,-c,chmod 0666 $scgiSocketPath}
5101EOF2
5102else
5103 echo "scgi_port = $SCGI_HOST:$scgiPort"
5104fi)
5105encoding_list = UTF-8
5106system.umask.set = $DEFAULT_UMASK
5107port_range = $rtorrentPort-$rtorrentPort
5108port_random = no
5109check_hash = no
5110directory = $RTORRENT_DOWNLOAD_DIR
5111session = $RTORRENT_SESSION_DIR
5112encryption = allow_incoming, try_outgoing, enable_retry
5113schedule = watch_directory,1,1,"load_start=$RTORRENT_WATCH_DIR/*.torrent"
5114#schedule = untied_directory,5,5,"stop_untied=$RTORRENT_WATCH_DIR/*.torrent"
5115trackers.enable = 1
5116#min_peers = 40
5117#max_peers = 100
5118#min_peers_seed = 10
5119#max_peers_seed = 50
5120#max_uploads = 15
5121#download_rate = 0
5122#upload_rate = 0
5123use_udp_trackers = yes
5124dht = auto
5125dht_port = 6881
5126peer_exchange = yes
5127#hash_read_ahead = 10
5128#hash_interval = 100
5129#hash_max_tries = 10
5130EOF
5131 PHP_BIN_PATH=$(which php 2> /dev/null)
5132 COMMENT=
5133 [ -x "$PHP_BIN_PATH" ] || COMMENT="#" PHP_BIN_PATH=/path/to/php
5134 cat >> "$rtorrentRc" << EOF
5135${COMMENT}execute = {sh,-c,$PHP_BIN_PATH $RUTORRENT_BASE_PATH/php/initplugins.php $webUser &}
5136EOF
5137
5138 # Add user to web server's password file
5139 sed_i "g/^$webUser:/d" "$WWW_PASSWORD_FILE"
5140 $htpasswd -b "$WWW_PASSWORD_FILE" "$webUser" "$webPass" || errorExit "Could not add user to password file"
5141 resetAuthPasswordFilePermissions
5142
5143 resetOwner "$osUser" "$rtorrentRc" "$userDir" "$RTORRENT_DOWNLOAD_DIR" "$RTORRENT_WATCH_DIR" "$RTORRENT_SESSION_DIR"
5144
5145 # Required so some ruTorrent plugins work, eg. _getdir
5146 chmod 0755 "$userDir"
5147
5148 # Protect some dirs and files, giving only the user and the web server
5149 # access. We need to do this since we set perms to 0755 above, or if
5150 # the perms already were 0755 to begin with.
5151 if [ -n "$WWW_GROUP" ]; then
5152 chmod 0600 "$rtorrentRc"
5153 for dir in $RTORRENT_REL_DOWNLOAD_DIR $RTORRENT_REL_WATCH_DIR $RTORRENT_REL_SESSION_DIR; do
5154 chown $osUser:$WWW_GROUP "$userDir/$dir"
5155 chmod 0770 "$userDir/$dir"
5156 done
5157 fi
5158
5159 i=$(expr $i + 1)
5160 done
5161
5162 [ "$CREATE_ONE_PASSWORD_FILE_PER_USER" = y ] && createOnePasswordFilePerUser
5163fi
5164
5165if [ "$USE_RUTORRENT_PLUGIN" = y ]; then
5166 [ -z "$RUTORRENT_BASE_PATH" ] && errorExit "Invalid ruTorrent base path."
5167
5168 [ "$REINSTALL_RUTORRENT_PLUGIN" = y ] && rm -rf "$AUTODL_IRSSI_PLUGIN_DIR"
5169 mkdir -p "$RUTORRENT_BASE_PATH/plugins"
5170 cd "$RUTORRENT_BASE_PATH/plugins"
5171
5172 if [ -d "$AUTODL_IRSSI_PLUGIN_DIR" ]; then
5173 echo "${CMSG}The autodl-irssi ruTorrent plugin dir already exists. Updating it...$CEND"
5174 cd "$AUTODL_IRSSI_PLUGIN_DIR"
5175 if ! svn up $SVN_OPTS > /dev/null; then
5176 errorExit "Could not update the autodl-irssi ruTorrent plugin. Run the script as root."
5177 fi
5178 else
5179 echo "${CMSG}Downloading the autodl-irssi ruTorrent plugin...$CEND"
5180 if ! svn co $SVN_OPTS "$SVN_PATH_RUTORRENT_PLUGIN" autodl-irssi > /dev/null; then
5181 errorExit "Could not check out the autodl-irssi ruTorrent plugin"
5182 fi
5183 fi
5184fi
5185
5186if [ "$INSTALL_AUTODL_IRSSI" = y ]; then
5187 if [ "$RUTORRENT_PASSWORD_PROTECTED" = y ]; then
5188 for packedUser in $USERS; do
5189 extractPackedUser $packedUser
5190 installUser "$RUTORRENT_BASE_PATH/conf/users/$webUser/plugins/autodl-irssi" "$osUser" "$webUser" "$autodlPort" "$autodlPassword"
5191 done
5192 else
5193 for packedUser in $USERS; do
5194 extractPackedUser $packedUser
5195 installUser "$AUTODL_IRSSI_PLUGIN_DIR" "$osUser" "$webUser" "$autodlPort" "$autodlPassword"
5196 [ "$USE_RUTORRENT_PLUGIN" = y ] && break
5197 done
5198 fi
5199fi
5200
5201if [ "$INSTALL_RUTORRENT" = y ]; then
5202 verifyWebServerVars
5203 resetWebServerPermissions
5204 resetRutorrentUserPermissions
5205 # Restart it just in case we enabled/installed PHP modules.
5206 osHandler_$os restart_$INSTALL_WEB_SERVER
5207fi
5208
5209if [ "$INSTALL_VSFTPD" = y ]; then
5210 echo "${CMSG}Installing vsftpd...$CEND"
5211 osHandler_$os installVsftpd
5212fi
5213
5214if [ "$INSTALL_WEBMIN" = y ]; then
5215 cd
5216 rm -rf webmin-*/ webmin*.tar.gz
5217 if ! downloadFile webmin.tar.gz "$WEBMIN_URL"; then
5218 errorExit "Could not download Webmin."
5219 fi
5220 tar xzf webmin.tar.gz
5221 rm -f webmin.tar.gz
5222 cd webmin-*/ || errorExit "Could not CD to webmin dir"
5223 osHandler_$os preWebminInstall
5224 [ -x "setup.sh" ] || errorExit "Missing Webmin setup.sh file or not executable."
5225 cat << EOF
5226$CMSG
5227Starting Webmin installer. Use another port than 10000, enable SSL, start webmin
5228at boot, and use a strong admin password.$CEND
5229$CWARNING
5230When it asks you if it should use SSL and whether it should start at boot,
5231type y.$CEND
5232EOF
5233 ./setup.sh /usr/local/webmin
5234 osHandler_$os postWebminInstall
5235 cd
5236 rm -rf webmin-*/
5237fi
5238
5239if [ "$INSTALL_RUTORRENT" = y ]; then
5240 # Some plugins will fail unless they can write to the /tmp directory
5241 # We MUST do this AFTER installing Webmin since it will reset the perms!
5242 chmod 1777 /tmp
5243fi
5244
5245if [ "$INSTALL_STARTUP_SCRIPT" = y ]; then
5246 for packedUser in $USERS; do
5247 extractPackedUser $packedUser
5248 echo "${CMSG}Installing service for user $osUser.$CEND"
5249 osHandler_$os installAutodlService $osUser
5250 done
5251fi
5252
5253echo ""
5254echo "${CGREEN}================================= DONE =================================$CEND"
5255[ "$INSTALLED_RTORRENT" = y ] && echo "${CDGREEN}[+]$CEND ${CGREEN}Built and installed rtorrent with XML-RPC support$CEND"
5256[ -n "$INSTALL_WEB_SERVER" ] && echo "${CDGREEN}[+]$CEND ${CGREEN}Installed and configured web server ($INSTALL_WEB_SERVER)$CEND"
5257[ "$INSTALL_VSFTPD" = y ] && echo "${CDGREEN}[+]$CEND ${CGREEN}Installed and configured FTP server (vsftpd)$CEND"
5258[ "$INSTALL_RUTORRENT" = y ] && echo "${CDGREEN}[+]$CEND ${CGREEN}Installed ruTorrent$CEND"
5259[ "$USE_RUTORRENT_PLUGIN" = y ] && echo "${CDGREEN}[+]$CEND ${CGREEN}Installed/updated the autodl-irssi ruTorrent plugin$CEND"
5260[ "$INSTALL_AUTODL_IRSSI" = y ] && echo "${CDGREEN}[+]$CEND ${CGREEN}Installed autodl-irssi$CEND"
5261[ "$INSTALL_STARTUP_SCRIPT" = y ] && echo "${CDGREEN}[+]$CEND ${CGREEN}Installed and started Irssi and rtorrent service$CEND"
5262[ "$INSTALL_WEBMIN" = y ] && echo "${CDGREEN}[+]$CEND ${CGREEN}Installed Webmin$CEND"
5263
5264if [ "$INSTALL_RUTORRENT" = y ]; then
5265 getIpAddress
5266 cat << EOF
5267
5268${CMSG}ruTorrent URLs.$CEND ${CWARNING}Verify that the IP address below is correct!$CEND
5269 ${CMAGENTA}http://$OUR_IP_ADDRESS/$RUTORRENT_DIRNAME/$CEND
5270 ${CMAGENTA}https://$OUR_IP_ADDRESS/$RUTORRENT_DIRNAME/$CEND
5271EOF
5272fi
5273
5274if [ "$INSTALL_RUTORRENT" = y ]; then
5275 cat << EOF
5276
5277${CMSG}rtorrent directories$CEND:
5278EOF
5279 for packedUser in $USERS; do
5280 extractPackedUser $packedUser
5281 getRtorrentDirs "$osUser"
5282 cat << EOF
5283${CMSG}User $CGREEN$osUser$CEND:
5284 ${CGREEN}Downloads$CEND : $CMAGENTA$RTORRENT_DOWNLOAD_DIR$CEND
5285 ${CGREEN}Watch dir$CEND : $CMAGENTA$RTORRENT_WATCH_DIR$CEND
5286 ${CGREEN}Session dir$CEND : $CMAGENTA$RTORRENT_SESSION_DIR$CEND
5287 ${CGREEN}rtorrent port$CEND: $CMAGENTA$rtorrentPort$CEND
5288EOF
5289 done
5290fi
5291
5292if [ -n "$INSTALL_WEB_SERVER" ]; then
5293 cat << EOF
5294
5295${CMSG}Web server info$CEND:
5296 ${CGREEN}Web server root$CEND: ${CMAGENTA}$WWW_ROOT$CEND
5297 ${CGREEN}ruTorrent dir$CEND : ${CMAGENTA}$RUTORRENT_BASE_PATH$CEND
5298EOF
5299fi
5300
5301if [ "$INSTALL_VSFTPD" = y ]; then
5302 getIpAddress
5303 cat << EOF
5304$CMSG
5305To log in to the FTP server, use your $(uname -s) login name and password. I
5306guessed the IP address below. Make sure it's correct.$CEND
5307 ${CGREEN}FTP IP address$CEND: ${CMAGENTA}$OUR_IP_ADDRESS$CEND
5308 ${CGREEN}FTP port$CEND: ${CMAGENTA}$FTP_PORT$CEND
5309 ${CGREEN}FTP server type$CEND: $CMAGENTA$FTP_SERVER_TYPE$CEND
5310EOF
5311fi
5312
5313if [ -n "$RUTORRENT_BASE_PATH" ] && [ "$INSTALL_AUTODL_IRSSI" = y ]; then
5314 RTORRENT_VERSION=$(sed -n -e "s/^[ ]*version:[^\"']*['\"]\\([0-9]\.[0-9]\\)['\"].*/\\1/p" $RUTORRENT_BASE_PATH/js/webui.js)
5315 major=$(echo $RTORRENT_VERSION | cut -d. -f1)
5316 minor=$(echo $RTORRENT_VERSION | cut -d. -f2)
5317 if [ $major -lt 3 ] || [ $minor -lt 2 ]; then
5318 cat << EOF
5319$CWARNING
5320You're using an old version of ruTorrent. I detected version $RTORRENT_VERSION.
5321You need at least version 3.2 for the autodl-irssi plugin to work correctly.$CEND
5322EOF
5323 fi
5324fi
5325
5326if [ "$INSTALL_WEBMIN" = y ]; then
5327 getIpAddress
5328
5329 WEBMIN_PORT=
5330 WEBMIN_SSL=
5331 WEBMIN_NAME=
5332 WEBMIN_CONFIG=/etc/webmin/miniserv.conf
5333 WEBMIN_USERS=/etc/webmin/miniserv.users
5334 if [ -f $WEBMIN_CONFIG ]; then
5335 WEBMIN_PORT=$(grep '^port=' $WEBMIN_CONFIG | tail -n1 | sed -e 's/^port=\([0-9]*\).*/\1/')
5336 WEBMIN_SSL=$(grep '^ssl=' $WEBMIN_CONFIG | tail -n1 | sed -e 's/^ssl=\([0-9]*\).*/\1/')
5337 WEBMIN_NAME=$(head -n1 $WEBMIN_USERS | cut -d: -f1)
5338 fi
5339 WEBMIN_PORT=${WEBMIN_PORT:-UNKNOWN}
5340 WEBMIN_NAME=${WEBMIN_NAME:-UNKNOWN}
5341
5342 cat << EOF
5343$CMSG
5344Webmin was installed. Port is $WEBMIN_PORT and the user is $WEBMIN_NAME.
5345${CRED}Verify the IP address below.$CEND
5346EOF
5347 if [ -z "$WEBMIN_SSL" ]; then
5348 echo " ${CMAGENTA}http://$OUR_IP_ADDRESS:$WEBMIN_PORT/$CEND"
5349 echo "${CMSG}or:$CEND"
5350 echo " ${CMAGENTA}https://$OUR_IP_ADDRESS:$WEBMIN_PORT/$CEND"
5351 elif [ "$WEBMIN_SSL" = 0 ]; then
5352 echo " ${CMAGENTA}http://$OUR_IP_ADDRESS:$WEBMIN_PORT/$CEND"
5353 else
5354 echo " ${CMAGENTA}https://$OUR_IP_ADDRESS:$WEBMIN_PORT/$CEND"
5355 fi
5356fi
5357
5358if [ -n "$INSTALL_WEB_SERVER" ] || [ "$INSTALL_VSFTPD" = y ] || \
5359 [ "$INSTALL_RUTORRENT" = y ] || [ "$USE_RUTORRENT_PLUGIN" = y ]; then
5360 if [ "$SELINUX_ENABLED" = y ]; then
5361 cat << EOF
5362$CWARNING
5363SELinux is enabled. It could cause some problems with the web server, vsftpd or
5364ruTorrent.
5365EOF
5366 fi
5367fi
5368
5369if [ "$CREATED_CERT_FILE" = y ]; then
5370 cat << EOF
5371$CWARNING
5372A self-signed certificate was created. Your browser or FTP client will most
5373likely warn you about a non-trusted certificate.$CEND
5374EOF
5375fi
5376
5377if [ "$USE_RUTORRENT_PLUGIN" = y ]; then
5378 if isProgramInstalled php; then
5379 detectMissingPhpModules
5380 if [ -n "$MISSING_PHP_MODULES" ]; then
5381 cat << EOF
5382$CWARNING
5383The following PHP modules seem to be missing. It's possible that the
5384autodl-irssi ruTorrent plugin won't work. Missing PHP modules:
5385 $MISSING_PHP_MODULES$CEND
5386EOF
5387 fi
5388 else
5389 cat << EOF
5390$CWARNING
5391Could not find the php executable. Make sure the following PHP modules are
5392enabled or the autodl-irssi ruTorrent plugin won't work:
5393 $REQUIRED_PHP_MODULES$CEND
5394EOF
5395 fi
5396fi