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