Advertisement
Guest User

Seedbox

a guest
Apr 21st, 2016
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 106.35 KB | None | 0 0
  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.  
  26. AUTODL_IRSSI_ZIP_URL="https://autodl-irssi-community.googlecode.com/files/autodl-irssi-community.zip"
  27. GIT_PATH_RUTORRENT_PLUGIN="https://github.com/autodl-community/autodl-rutorrent.git"
  28.  
  29. WEBMIN_URL="http://www.webmin.com/download/webmin-current.tar.gz"
  30.  
  31. RUTORRENT_TRUNK_DIR="https://rutorrent.googlecode.com/svn/trunk"
  32.  
  33. # The official tarballs are tried if subversion fails.
  34. RUTORRENT_VERSION="3.6"
  35. RUTORRENT_CORE_NAME="rutorrent-$RUTORRENT_VERSION.tar.gz"
  36. RUTORRENT_CORE_URL="http://rutorrent.googlecode.com/files/$RUTORRENT_CORE_NAME"
  37. RUTORRENT_PLUGINS_NAME="plugins-$RUTORRENT_VERSION.tar.gz"
  38. RUTORRENT_PLUGINS_URL="http://rutorrent.googlecode.com/files/$RUTORRENT_PLUGINS_NAME"
  39. RUTORRENT_CORE_URL2="http://sourceforge.net/projects/autodl-irssi/files/inst-files/$RUTORRENT_CORE_NAME/download"
  40. RUTORRENT_PLUGINS_URL2="http://sourceforge.net/projects/autodl-irssi/files/inst-files/$RUTORRENT_PLUGINS_NAME/download"
  41.  
  42. RUTORRENT_PLUGINS=
  43.  
  44. # These are the ruTorrent plugins that will get installed. To remove one, either
  45. # remove the whole line or comment it (prepend a '#' to the start of the line).
  46. # If the line starts with '#', the plugin is not installed.
  47. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS _getdir"
  48. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS _task"
  49. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS autotools"
  50. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS chunks"
  51. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS cookies"
  52. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS cpuload"
  53. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS create"
  54. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS data"
  55. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS datadir"
  56. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS diskspace"
  57. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS edit"
  58. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS erasedata"
  59. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS extsearch"
  60. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS feeds"
  61. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS geoip"
  62. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS httprpc"
  63. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS ipad"
  64. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS loginmgr"
  65. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS logoff"
  66. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS mediainfo"
  67. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS ratio"
  68. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS retrackers"
  69. #RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS rpc"
  70. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS rss"
  71. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS rssurlrewrite"
  72. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS scheduler"
  73. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS seedingtime"
  74. #RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS show_peers_like_wtorrent"
  75. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS source"
  76. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS theme"
  77. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS throttle"
  78. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS tracklabels"
  79. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS trafic"
  80. RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS unpack"
  81.  
  82.  
  83. # For building rtorrent
  84. LIBCURL_NAME="curl-7.33.0"
  85. LIBCURL_URL="http://curl.haxx.se/download/$LIBCURL_NAME.tar.gz"
  86. SIGCPP20_NAME="libsigc++-2.3.1"
  87. SIGCPP20_URL="http://ftp.gnome.org/pub/GNOME/sources/libsigc++/2.3/$SIGCPP20_NAME.tar.gz"
  88. XMLRPC_SVN_DIR="https://svn.code.sf.net/p/xmlrpc-c/code/stable"
  89. LIBTORRENT_VERSION="0.13.3"
  90. LIBTORRENT_NAME="libtorrent-$LIBTORRENT_VERSION"
  91. LIBTORRENT_URL="http://libtorrent.rakshasa.no/downloads/$LIBTORRENT_NAME.tar.gz"
  92. LIBTORRENT_URL2="http://sourceforge.net/projects/autodl-irssi/files/inst-files/$LIBTORRENT_NAME.tar.gz/download"
  93. RTORRENT_VERSION="0.9.3"
  94. RTORRENT_NAME="rtorrent-$RTORRENT_VERSION"
  95. RTORRENT_URL="http://libtorrent.rakshasa.no/downloads/$RTORRENT_NAME.tar.gz"
  96. RTORRENT_URL2="http://sourceforge.net/projects/autodl-irssi/files/inst-files/$RTORRENT_NAME.tar.gz/download"
  97.  
  98. HTPASSWD_PY_SCRIPT_URL="http://trac.edgewall.org/export/10433/trunk/contrib/htpasswd.py"
  99. HTPASSWD_PY_SCRIPT_URL2="http://sourceforge.net/projects/autodl-irssi/files/inst-files/htpasswd.py/download"
  100.  
  101. NGINX_NAME="nginx-1.5.7"
  102. NGINX_URL="http://nginx.org/download/$NGINX_NAME.tar.gz"
  103.  
  104. LIGHTTPD_NAME="lighttpd-1.4.33"
  105. LIGHTTPD_URL="http://download.lighttpd.net/lighttpd/releases-1.4.x/$LIGHTTPD_NAME.tar.gz"
  106.  
  107. MOD_SCGI_VERSION="1.14"
  108. MOD_SCGI_URL="http://python.ca/scgi/releases/scgi-$MOD_SCGI_VERSION.tar.gz"
  109.  
  110. UNRAR_VERSION="4.0.7"
  111. UNRAR_URL="http://www.rarlab.com/rar/unrarsrc-$UNRAR_VERSION.tar.gz"
  112.  
  113. # Dirs relative to user's home directory
  114. RTORRENT_REL_DOWNLOAD_DIR="downloads"
  115. RTORRENT_REL_WATCH_DIR="rtorrent/watch"
  116. RTORRENT_REL_SESSION_DIR="rtorrent/session"
  117.  
  118. REQUIRED_PERL_MODULES="Time::HiRes XML::LibXML Archive::Zip Net::SSLeay HTML::Parser Digest::SHA1 JSON"
  119. REQUIRED_PHP_MODULES="json xml sockets"
  120.  
  121. # If set to y, add 'load perl' to .irssi/startup
  122. IRSSI_LOAD_PERL=n
  123. IGNORE_IRSSI=n
  124.  
  125. # Start port. When we need a new port number, this port is incremented by one.
  126. CURRENT_PORT=23875
  127. DEFAULT_PORT_FTP=21
  128. DEFAULT_PORT_FTPES=990
  129. DEFAULT_UMASK=022
  130. RPC_PREFIX=RPC
  131.  
  132. LSB_DEFAULT_START="2 3 4 5"
  133. LSB_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).
  137. HTTP_PORT=80
  138. HTTPS_PORT=443
  139.  
  140. SCGI_HOST="127.0.0.1"
  141.  
  142. INTERACTIVE=n
  143. USE_RUTORRENT_PLUGIN=n
  144. REINSTALL_RUTORRENT_PLUGIN=n
  145. INSTALL_AUTODL_IRSSI=n
  146. RUTORRENT_PASSWORD_PROTECTED=n
  147. USERS=
  148. RUTORRENT_BASE_PATH=
  149. INSTALL_STARTUP_SCRIPT=n
  150. BUILD_RTORRENT=n
  151. INSTALL_WEB_SERVER=
  152. INSTALL_RUTORRENT=n
  153. INSTALL_VSFTPD=n
  154. FTP_PORT=
  155. USE_ENCRYPTED_FTP=n
  156. INSTALL_WEBMIN=n
  157. USER_TIMEZONE=
  158.  
  159. RUTORRENT_SITE_REALM="My ruTorrent web site"
  160. AUTODL_STARTUP_DESC="Start autodl-irssi and rtorrent"
  161. PHPCGI_STARTUP_DESC="Start php-cgi"
  162. NGINX_STARTUP_DESC="Start nginx"
  163. LIGHTTPD_STARTUP_DESC="Start lighttpd"
  164.  
  165. PATH="$PATH:/usr/local/bin"
  166.  
  167. # Find an echo that supports -e
  168. echo=echo
  169. for cmd in echo /bin/echo; do
  170. $cmd >/dev/null 2>&1 || continue
  171. if ! $cmd -e "" | grep -qE '^-e'; then
  172. echo=$cmd
  173. break
  174. fi
  175. done
  176.  
  177. CSI=$($echo -e "\033[")
  178. CEND="${CSI}0m"
  179. CDGREEN="${CSI}32m"
  180. CRED="${CSI}1;31m"
  181. CGREEN="${CSI}1;32m"
  182. CYELLOW="${CSI}1;33m"
  183. CBLUE="${CSI}1;34m"
  184. CMAGENTA="${CSI}1;35m"
  185. CCYAN="${CSI}1;36m"
  186. CQUESTION="$CMAGENTA"
  187. CWARNING="$CRED"
  188. CMSG="$CCYAN"
  189.  
  190. errorExit() {
  191. cat << EOF
  192. $CWARNING
  193. ***ERROR***
  194. $*
  195. ***ERROR***
  196. $CEND
  197. Help channel: ${CGREEN}#autodl-community@irc.p2p-network.net$CEND
  198. EOF
  199. exit 1
  200. }
  201.  
  202. exitHelp() {
  203. cat << EOF
  204.  
  205. autodl-irssi and ruTorrent plugin installer
  206.  
  207. sh $0 [options]
  208.  
  209. Options:
  210.  
  211. --rtorrent
  212. Will build and install rtorrent, libtorrent and xmlrpc-c from source code.
  213.  
  214. --rtorrent-noexec-patch
  215. Patch rtorrent to disallow remote users from executing code.
  216.  
  217. --apache
  218. Install Apache web server.
  219.  
  220. --nginx
  221. Install nginx web server.
  222.  
  223. --lighttpd
  224. Install lighttpd web server.
  225.  
  226. --rutorrent
  227. Install ruTorrent. Requires a web server, eg. --apache.
  228.  
  229. --vsftpd
  230. Install vsftpd.
  231.  
  232. --ftpes
  233. Use encrypted FTP (FTPES).
  234.  
  235. --ftp-port <port>
  236. FTP server port.
  237.  
  238. --webmin
  239. Install Webmin.
  240.  
  241. -p
  242. --rutorrent-plugin
  243. Use or install the autodl-irssi ruTorrent plugin. If it's already installed,
  244. it will be updated (svn up), unless --reinstall-plugin option is used in
  245. which case it will be re-installed.
  246.  
  247. -i
  248. --reinstall-plugin
  249. Re-install the autodl-irssi ruTorrent plugin if it's already installed.
  250.  
  251. -a
  252. --install-autodl
  253. Install autodl-irssi.
  254.  
  255. -u user:autodlPass:webUser:webPass
  256. --user user:autodlPass:webUser:webPass
  257. The $(uname -s) user, autodl-irssi password, ruTorrent user, ruTorrent password.
  258. You can use more than one -u option. If autodlPassword is not set, a random
  259. password will be used.
  260.  
  261. -w
  262. --password-protected
  263. Use this option if ruTorrent is password protected. It's required if you
  264. want to use more than one ruTorrent user. Not needed if you install
  265. ruTorrent.
  266.  
  267. -r PATH
  268. --rutorrent-base-path PATH
  269. Path to ruTorrent, eg. /var/www/rutorrent. Not needed if you install
  270. ruTorrent.
  271.  
  272. -s
  273. --install-startup-script
  274. Install a startup script (service) which will start Irssi and rtorrent when
  275. the computer boots.
  276.  
  277. -h
  278. --help
  279. Show this help text
  280.  
  281. Examples (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.  
  285. Installs rtorrent, Apache, ruTorrent, vsftpd (encrypted), Webmin the
  286. autodl-irssi plugin, autodl-irssi, installs a service (starting Irssi and
  287. rtorrent) for both users.
  288.  
  289. sh $0 -p -a -u user::user:pass -r /var/www/rutorrent -s
  290.  
  291. Installs autodl-irssi + ruTorrent plugin for user 'user'. ruTorrent has not been
  292. password 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.  
  296. Installs autodl-irssi + ruTorrent plugin for users 'user1' and 'user2'.
  297. ruTorrent 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.  
  301. Installs rtorrent, autodl-irssi and the startup script.
  302.  
  303. Help fchannel: #autodl-community@irc.p2p-network.net
  304. EOF
  305. exit 1
  306. }
  307.  
  308. parseCommandLine() {
  309. while [ $# -gt 0 ]; do
  310. local arg="$1"
  311. shift
  312.  
  313. if [ "$arg" = "-p" ] || [ "$arg" = "--rutorrent-plugin" ]; then
  314. USE_RUTORRENT_PLUGIN=y
  315. elif [ "$arg" = "-i" ] || [ "$arg" = "--reinstall-plugin" ]; then
  316. REINSTALL_RUTORRENT_PLUGIN=y
  317. elif [ "$arg" = "-a" ] || [ "$arg" = "--install-autodl" ]; then
  318. INSTALL_AUTODL_IRSSI=y
  319. elif [ "$arg" = "-u" ] || [ "$arg" = "--user" ]; then
  320. USERS="$USERS $1"
  321. shift
  322. elif [ "$arg" = "-w" ] || [ "$arg" = "--password-protected" ]; then
  323. RUTORRENT_PASSWORD_PROTECTED=y
  324. elif [ "$arg" = "-r" ] || [ "$arg" = "--rutorrent-base-path" ]; then
  325. RUTORRENT_BASE_PATH="$1"
  326. shift
  327. elif [ "$arg" = "-s" ] || [ "$arg" = "--install-startup-script" ]; then
  328. INSTALL_STARTUP_SCRIPT=y
  329. elif [ "$arg" = "--rtorrent" ]; then
  330. BUILD_RTORRENT=y
  331. elif [ "$arg" = "--apache" ]; then
  332. INSTALL_WEB_SERVER=apache
  333. elif [ "$arg" = "--nginx" ]; then
  334. INSTALL_WEB_SERVER=nginx
  335. elif [ "$arg" = "--lighttpd" ]; then
  336. INSTALL_WEB_SERVER=lighttpd
  337. elif [ "$arg" = "--rutorrent" ]; then
  338. INSTALL_RUTORRENT=y
  339. elif [ "$arg" = "--vsftpd" ]; then
  340. INSTALL_VSFTPD=y
  341. elif [ "$arg" = "--ftpes" ]; then
  342. USE_ENCRYPTED_FTP=y
  343. elif [ "$arg" = "--ftp-port" ]; then
  344. FTP_PORT="$1"
  345. shift
  346. elif [ "$arg" = "--webmin" ]; then
  347. INSTALL_WEBMIN=y
  348. else
  349. exitHelp
  350. fi
  351. done
  352. }
  353.  
  354. # Sets os and os_long to the OS type and OS name respectively
  355. detectOs() {
  356. local DISTRIB_ID=
  357. local DISTRIB_DESCRIPTION=
  358. if [ -f /etc/lsb-release ]; then
  359. . /etc/lsb-release
  360. fi
  361.  
  362. if [ -f /etc/fedora-release ]; then
  363. os=fedora
  364. os_long="$(cat /etc/fedora-release)"
  365. # Must be before a whole bunch of other OS tests
  366. elif [ "$DISTRIB_ID" = "Ubuntu" ]; then
  367. os=debian
  368. os_long="$DISTRIB_DESCRIPTION"
  369. elif [ "$DISTRIB_ID" = "LinuxMint" ]; then
  370. os=debian
  371. os_long="$DISTRIB_DESCRIPTION"
  372. # Must be before Debian
  373. elif [ "$DISTRIB_ID" = "Peppermint" ]; then
  374. os=debian
  375. os_long="$DISTRIB_DESCRIPTION"
  376. elif [ "$DISTRIB_ID" = "MEPIS" ]; then
  377. os=debian
  378. os_long="$DISTRIB_DESCRIPTION"
  379. elif [ -f /etc/clearos-release ]; then
  380. os=fedora
  381. os_long="$(cat /etc/clearos-release)"
  382. elif [ -f /etc/debian_version ]; then
  383. os=debian
  384. local prefix=
  385. if ! uname -s | grep -q GNU; then
  386. prefix="GNU/"
  387. fi
  388. os_long="Debian $prefix$(uname -s) $(cat /etc/debian_version)"
  389. elif [ -f /etc/redhat-release ]; then
  390. os=fedora
  391. os_long="$(cat /etc/redhat-release)"
  392. else
  393. echo -e "\e[1;31mYour OS is not detected as an OS supported by this script. This script only supports \e[5;32mDebian and Fedora\e[0m \e[1;31mbased OSes.\e[0m"
  394. exit 1
  395.  
  396. fi
  397.  
  398. os_long="${os_long:-$(uname -s)}"
  399. }
  400.  
  401. # In-place editing like sed -i but more portable...
  402. sed_i() {
  403. local cmd="$1"
  404. local file="$2"
  405. isProgramInstalled ed || errorExit "ed is not installed!"
  406. local addr=","
  407. echo "$cmd" | grep -qE '^/' && addr=
  408. ed -s "$file" > /dev/null 2>&1 << EOF
  409. $addr$cmd
  410. w
  411. q
  412. EOF
  413. }
  414.  
  415. getFirst() {
  416. echo $1
  417. }
  418.  
  419. # Returns true if $1 is one of $2..$n
  420. arrayIsPresent() {
  421. local val="$1"
  422. shift
  423. for v in "$@"; do
  424. [ "$v" = "$val" ] && return 0
  425. done
  426. return 1
  427. }
  428.  
  429. canGeneratePasswords() {
  430. [ -c /dev/urandom ]
  431. }
  432.  
  433. generatePassword() {
  434. newPassword=$(cat /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c17)
  435. }
  436.  
  437. isProgramInstalled() {
  438. which "$1" > /dev/null 2>&1 && return 0
  439. return 1
  440. }
  441.  
  442. isPerlModuleInstalled() {
  443. perl -M$1 -e '' > /dev/null 2>&1 && return 0
  444. return 1
  445. }
  446.  
  447. # Add $1 or $2 if it exists, to PACKAGES if program $1 isn't present
  448. addProgram() {
  449. isProgramInstalled $1 || PACKAGES="$PACKAGES ${2:-$1}"
  450. }
  451.  
  452. # Add $2 to PACKAGES if perl module $1 isn't present
  453. addPerlModule() {
  454. isPerlModuleInstalled $1 || PACKAGES="$PACKAGES $2"
  455. }
  456.  
  457. installPackages() {
  458. [ -z "$INSTALL" ] && return
  459. [ -z "$PACKAGES" ] && return
  460. $INSTALL $PACKAGES
  461. PACKAGES=
  462. }
  463.  
  464. installPerlModule() {
  465. isPerlModuleInstalled $1 || $INSTALL $2
  466. }
  467.  
  468. installProgram() {
  469. isProgramInstalled $1 || $INSTALL ${2:-$1}
  470. }
  471.  
  472. installBuildTools() {
  473. [ "$BUILD_TOOLS_INSTALLED" = y ] && return
  474. PACKAGES="$BUILD_TOOLS"
  475. installPackages
  476. BUILD_TOOLS_INSTALLED=y
  477. }
  478.  
  479. # Detects missing Perl modules and stores them in MISSING_PERL_MODULES
  480. detectMissingPerlModules() {
  481. OLD_PERL_MODULES=
  482. MISSING_PERL_MODULES=
  483. for module in $REQUIRED_PERL_MODULES; do
  484. isPerlModuleInstalled $module || MISSING_PERL_MODULES="$MISSING_PERL_MODULES $module"
  485. done
  486.  
  487. # Make sure the JSON module is new
  488. if isPerlModuleInstalled JSON && ! perl -MJSON -e '&decode_json("{}")' > /dev/null 2>&1; then
  489. echo "${CWARNING}Old JSON module is installed. Need to install from CPAN.$CEND"
  490. MISSING_PERL_MODULES="$MISSING_PERL_MODULES JSON"
  491. OLD_PERL_MODULES="$OLD_PERL_MODULES JSON"
  492. fi
  493.  
  494. if echo "$MISSING_PERL_MODULES" | grep -wq JSON; then
  495. MISSING_PERL_MODULES="JSON::XS $MISSING_PERL_MODULES"
  496. fi
  497. if echo "$MISSING_PERL_MODULES" | grep -q 'XML::LibXML'; then
  498. # Sometimes the cpan script doesn't install the required dependencies
  499. MISSING_PERL_MODULES="XML::NamespaceSupport XML::SAX $MISSING_PERL_MODULES"
  500. fi
  501. }
  502.  
  503. # Detect where cpan is installed and place the path in the CPAN variable.
  504. # PCLinuxOS/Mandriva append the version number...
  505. detectCpanBin() {
  506. for file in $(which cpan 2> /dev/null) $(ls /usr/bin/cpan-* 2> /dev/null); do
  507. if [ -x "$file" ]; then
  508. CPAN="$file"
  509. return
  510. fi
  511. done
  512. isPerlModuleInstalled CPAN && return
  513. errorExit "Could not find the cpan script or the CPAN Perl module. Can't install missing Perl modules."
  514. }
  515.  
  516. isValidTzName() {
  517. echo "$1" | LC_ALL=C grep -qE '^[A-Z][^/ ]*(/[A-Z][^/ ]*)?$' && return 0
  518. return 1
  519. }
  520.  
  521. detectTimeZone() {
  522. [ -n "$USER_TIMEZONE" ] && return
  523.  
  524. local hash=
  525. local hasher=
  526. local files=
  527. local zoneinfoPath=/usr/share/zoneinfo
  528. [ -d "$zoneinfoPath" ] || return
  529. if hasher=md5sum; isProgramInstalled $hasher || hasher=sha1sum; isProgramInstalled $hasher; then
  530. hash=$($hasher /etc/localtime | awk '{print $1}')
  531. files="$(find $zoneinfoPath -type f -print | xargs $hasher | grep -E "^$hash\\>" | awk '{print $2}')"
  532. elif hasher=md5; isProgramInstalled $hasher || hasher=sha1; isProgramInstalled $hasher; then
  533. hash=$($hasher /etc/localtime | sed -e 's/^.* = \([a-zA-Z0-9]*\)$/\1/')
  534. files="$(find $zoneinfoPath -type f -print | xargs $hasher | grep -E "$hash\$" | sed -e 's/^[^ ]* (\([^)]*\)).*/\1/')"
  535. else
  536. return
  537. fi
  538.  
  539. # Detect all possible timezone names
  540. local timezones=
  541. for path in $files; do
  542. local tz="${path#$zoneinfoPath/}"
  543. while true; do
  544. isValidTzName "$tz" && break
  545. local newTz="${tz#*/}"
  546. [ "$newTz" = "$tz" ] && tz= && break
  547. tz="$newTz"
  548. done
  549. isValidTzName "$tz" && timezones="$timezones $tz"
  550. done
  551.  
  552. # Now find the ones PHP likes...
  553. local okRegions="(Africa|America|Antarctica|Arctic|Asia|Atlantic|Australia|Europe|Indian|Pacific)"
  554. for tz in $timezones; do
  555. echo "$tz" | grep -qE "^$okRegions/" && USER_TIMEZONE="$tz" && return
  556. done
  557.  
  558. # Return the first one we found
  559. for tz in $timezones; do
  560. USER_TIMEZONE="$tz"
  561. return
  562. done
  563. }
  564.  
  565. getNumCpus() {
  566. [ -n "$NUMCPUS" ] && return
  567. [ -f /proc/cpuinfo ] && NUMCPUS=$(cat /proc/cpuinfo | grep '^processor' | wc -l) && return
  568. isProgramInstalled sysctl && sysctl -n hw.ncpu | grep -qE '^[1-9][0-9]*$' && NUMCPUS=$(sysctl -n hw.ncpu) && return
  569. NUMCPUS=1
  570. }
  571.  
  572. # Appends $value to $varName in $file, creating the var if it doesn't exist. The
  573. # value is not appended if it already exists.
  574. appendFileStringVar() {
  575. local file="$1"
  576. local varName="$2"
  577. local value="$3"
  578.  
  579. [ -f "$file" ] || errorExit "File '$file' does not exist"
  580.  
  581. local varLine=$(grep -E "^$varName=" "$file" | tail -n1)
  582. if [ -z "$varLine" ]; then
  583. echo "$varName=\"$value\"" >> "$file"
  584. else
  585. echo "$varLine" | grep -qE "[='\" ]$value(\"|'| |$)" && return
  586.  
  587. local q=
  588. echo "$varLine" | grep -qE "^$varName='" && q="'"
  589. echo "$varLine" | grep -qE "^$varName=\"" && q='"'
  590. sed_i "s#^\\($varName=\\)$q\\(.*\\)$q#\\1\"\\2 $value\"#" "$file"
  591. fi
  592. }
  593.  
  594. # Set a variable in a script file to a new value. The variable is created if it does not exist
  595. setScriptVariable() {
  596. local file="$1"
  597. local name=$2
  598. local value="$3"
  599.  
  600. [ -f "$file" ] || errorExit "File does not exist: $file"
  601.  
  602. local newLine="$name=\"$value\""
  603. if grep -qE "^$name=" $file; then
  604. sed_i "s!^$name=.*\$!$newLine!" "$file"
  605. else
  606. echo "$newLine" >> "$file"
  607. fi
  608. }
  609.  
  610. userExists() {
  611. id -rg "$1" > /dev/null 2>&1 && return 0
  612. return 1
  613. }
  614.  
  615. setSvnOpts() {
  616. SVN_OPTS=
  617. isProgramInstalled svn || return
  618. # svn sometimes gives an error message 'broken pipe'. Ignore it.
  619. if svn help co 2>/dev/null | grep -q 'non-interactive' && svn help co 2>/dev/null | grep -q 'trust-server-cert'; then
  620. SVN_OPTS="--non-interactive --trust-server-cert"
  621. fi
  622. }
  623.  
  624. downloadFile() {
  625. local filename="$1"
  626. shift
  627. for url in "$@"; do
  628. for i in 1 2 3 4 5; do
  629. wget --no-check-certificate -O "$filename" "$url" && return 0
  630. done
  631. done
  632. return 1
  633. }
  634.  
  635. buildMakeProgram() {
  636. local url="$1"
  637. local name="$2"
  638. local builddir="$3"
  639. local srcdir="$4"
  640. local makefile="${5:-Makefile}"
  641.  
  642. buildStart
  643. echo "${CMSG}Downloading $name source code...$CEND"
  644. cd "$BUILD_DIR"
  645. local filename="${url##*/}"
  646. downloadFile "$filename" "$url" || errorExit "Could not download $name source code."
  647. tar xzf "$filename"
  648. srcdir="${srcdir:-${filename%.tar.gz}}"
  649. cd "$srcdir/$builddir"
  650. local make=${MAKE:-make}
  651. echo "${CMSG}Building $name...$CEND"
  652. $make -f $makefile all || errorExit "Could not build $name."
  653. $make -f $makefile install || errorExit "Could not install $name."
  654. echo "${CMSG}$name is now installed$CEND"
  655. buildEnd
  656. }
  657.  
  658. buildProgram() {
  659. local prog="$1"
  660.  
  661. echo "${CMSG}Building $prog...$CEND"
  662.  
  663. ./configure --prefix=$PREFIX $2 || errorExit "Could not configure $prog. Try again, or try logging out and in and try again."
  664.  
  665. getNumCpus
  666. local make=${MAKE:-make}
  667. local makeopts="-j$NUMCPUS"
  668. $make $makeopts || $make || errorExit "Could not build $prog"
  669. $make install || errorExit "Could not install $prog"
  670.  
  671. local ldsoconf=/etc/ld.so.conf
  672. touch "$ldsoconf"
  673. grep -qE "^$PREFIX/lib$" $ldsoconf || echo "$PREFIX/lib" >> $ldsoconf
  674. ldconfig || errorExit "ldconfig failed"
  675.  
  676. echo "${CMSG}$prog is now installed.$CEND"
  677. }
  678.  
  679. downloadAndBuild() {
  680. local prog="$1"
  681. local urls="$2"
  682. local name="$3"
  683. local configOptions="$4"
  684. local patchUrl="$5"
  685.  
  686. cd "$BUILD_DIR"
  687. echo "${CMSG}Downloading $prog source code...$CEND"
  688. downloadFile "$name.tar.gz" $urls || errorExit "Could not download $prog source code."
  689. tar xzf $name.tar.gz
  690.  
  691. if echo "$patchUrl" | grep '^[a-z]*://'; then
  692. echo "${CMSG}Patching $prog...$CEND"
  693. PACKAGES="patch"
  694. installPackages
  695. isProgramInstalled patch || errorExit "patch is not installed!"
  696. downloadFile the.patch "$patchUrl" || errorExit "Could not download the patch file."
  697. patch -p1 -d $name < the.patch || errorExit "Could not patch $prog."
  698. elif [ -n "$patchUrl" ]; then
  699. echo "${CMSG}Patching $prog...$CEND"
  700. cd $name
  701. eval $patchUrl
  702. cd ..
  703. fi
  704.  
  705. cd $name
  706. buildProgram "$prog" "$configOptions"
  707. }
  708.  
  709. checkoutAndBuild() {
  710. local prog="$1"
  711. local url="$2"
  712. local configOptions="$3"
  713. cd "$BUILD_DIR"
  714. echo "${CMSG}Downloading $prog source code...$CEND"
  715. svn export $SVN_OPTS "$url" "$prog" || errorExit "Could not download $prog source code."
  716. cd "$prog"
  717. buildProgram "$prog" "$configOptions"
  718. }
  719.  
  720. buildStart() {
  721. PREFIX=/usr/local
  722. OLD_PATH="$PATH"
  723. PATH="$PATH:$PREFIX/bin"
  724. PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig
  725. export PKG_CONFIG_PATH
  726. BUILD_DIR="$(echo ~)/build-tmp"
  727.  
  728. rm -rf "$BUILD_DIR"
  729. mkdir "$BUILD_DIR" || errorExit "Could not create build directory."
  730. }
  731.  
  732. buildEnd() {
  733. cd
  734. rm -rf "$BUILD_DIR"
  735.  
  736. [ -n "$OLD_PATH" ] && PATH="$OLD_PATH"
  737. unset OLD_PATH
  738. unset PKG_CONFIG_PATH
  739. }
  740.  
  741. buildRtorrent() {
  742. installBuildTools
  743. osHandler_$os installRtorrentBuildTools
  744. isProgramInstalled pkg-config || errorExit "pkg-config is not installed."
  745.  
  746. # Minimum version is 7.15.4 but I had problems with 7.15.5 on CentOS. Set
  747. # it to 7.18.0 (the version Ubuntu Server 8.04 is using).
  748. if ! pkg-config --atleast-version=7.18.0 libcurl; then
  749. downloadAndBuild "libcurl" "$LIBCURL_URL" "$LIBCURL_NAME" ""
  750. # Prevent 'Unknown keyword 'URL' in ....' error
  751. sed_i 's/^URL:/#URL:/' $PREFIX/lib/pkgconfig/libcurl.pc
  752. fi
  753. if ! pkg-config --exists sigc++-2.0; then
  754. downloadAndBuild "sigc++-2.0" "$SIGCPP20_URL" "$SIGCPP20_NAME" ""
  755. fi
  756. checkoutAndBuild "xmlrpc-c" "$XMLRPC_SVN_DIR" "--disable-cplusplus"
  757. downloadAndBuild "libtorrent" "$LIBTORRENT_URL $LIBTORRENT_URL2" "$LIBTORRENT_NAME" "" patchLibtorrent
  758. downloadAndBuild "rtorrent" "$RTORRENT_URL $RTORRENT_URL2" "$RTORRENT_NAME" "--with-xmlrpc-c" ""
  759. }
  760.  
  761. patchLibtorrent() {
  762. # For gcc 4.6.0
  763. ed -s "src/torrent/data/block_transfer.h" > /dev/null 2>&1 << EOF
  764. /#define LIBTORRENT_BLOCK_TRANSFER_H
  765. a
  766. #include <stddef.h>
  767. .
  768. w
  769. q
  770. EOF
  771. ed -s "src/data/memory_chunk.cc" > /dev/null 2>&1 << EOF
  772. /#include "config.h"
  773. a
  774. #include <stddef.h>
  775. .
  776. w
  777. q
  778. EOF
  779. }
  780.  
  781. installRtorrent() {
  782. buildStart
  783. buildRtorrent
  784. buildEnd
  785. }
  786.  
  787. installUnrar() {
  788. isProgramInstalled unrar && return
  789. installBuildTools
  790. buildMakeProgram "$UNRAR_URL" "unrar" "" "unrar" "makefile.unix"
  791. }
  792.  
  793. installModScgi() {
  794. local modScgiFile="$1"
  795. local modulesPath="$2"
  796. [ -f "$modScgiFile" ] && errorExit "mod_scgi file already exists."
  797. [ -d "$modulesPath" ] || errorExit "Apache modules path '$modulesPath' does not exist."
  798.  
  799. buildMakeProgram "$MOD_SCGI_URL" "mod_scgi" "apache2"
  800. echo "LoadModule scgi_module $modulesPath/mod_scgi.so" > $modScgiFile
  801. }
  802.  
  803. isPortUsed() {
  804. local port="$1"
  805. netstat -an | grep tcp | grep -w LISTEN | grep -qE "[.:]$port[ ]" && return 0
  806. return 1
  807. }
  808.  
  809. isValidIpAddress() {
  810. # It's not 100% accurate ... ;)
  811. echo $1 | grep -qE '^[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?$'
  812. }
  813.  
  814. getIpAddress() {
  815. isValidIpAddress "$OUR_IP_ADDRESS" && return
  816. echo "${CMSG}Detecting your IP address...$CEND"
  817. isValidIpAddress "$OUR_IP_ADDRESS" || OUR_IP_ADDRESS=$(wget --no-check-certificate http://www.whatismyip.com/automation/n09230945.asp -O - -o /dev/null)
  818. isValidIpAddress "$OUR_IP_ADDRESS" || OUR_IP_ADDRESS=$(ifconfig -a | grep "inet addr" | head -n1 | awk -F: '{print $2}' | awk '{print $1}')
  819. isValidIpAddress "$OUR_IP_ADDRESS" || OUR_IP_ADDRESS="1.2.3.4"
  820. }
  821.  
  822. getNewPortNumber() {
  823. while true; do
  824. newPortNumber=$CURRENT_PORT
  825. CURRENT_PORT=$(expr $CURRENT_PORT + 1)
  826. isValidPortNumber $newPortNumber || errorExit "Invalid port number. Change CURRENT_PORT."
  827. isPortUsed $newPortNumber || break
  828. echo "${CWARNING}Port $newPortNumber is in use, trying next port...$CEND"
  829. done
  830. }
  831.  
  832. # Returns true if it's a valid ruTorrent base path
  833. isValidRutorrentBasePath() {
  834. [ -n "$1" ] && [ -d "$1/conf" ]
  835. }
  836.  
  837. isValidPassword() {
  838. echo "$1" | grep -qE "^ " && return 1
  839. echo "$1" | grep -qE " \$" && return 1
  840. echo "$1" | grep -qE '^$' && return 1
  841. echo "$1" | grep -q ':' && return 1
  842. echo "'$1'" | grep -q ' ' && return 1
  843. return 0
  844. }
  845.  
  846. isValidPortNumber() {
  847. echo "$1" | grep -qiE '^[0-9]+$' || return 1
  848. echo "$1" | grep -qiE '[0-9][0-9][0-9][0-9][0-9][0-9]' && return 1
  849. [ $1 -ge 1024 ] && [ $1 -le 65535 ]
  850. }
  851.  
  852. isValidWebUser() {
  853. [ -z "$1" ] && return 1
  854. echo "$1" | LC_ALL=C grep -qE '[A-Z:]' && return 1
  855. return 0
  856. }
  857.  
  858. initUsers() {
  859. local users=
  860. for packedUser in $USERS; do
  861. extractPackedUser $packedUser
  862.  
  863. if [ -z "$autodlPort" ]; then
  864. getNewPortNumber
  865. autodlPort=$newPortNumber
  866. fi
  867. if [ -z "$scgiPort" ]; then
  868. getNewPortNumber
  869. scgiPort=$newPortNumber
  870. fi
  871. if [ -z "$rtorrentPort" ]; then
  872. getNewPortNumber
  873. rtorrentPort=$newPortNumber
  874. fi
  875. if canGeneratePasswords; then
  876. if [ -z "$autodlPassword" ]; then
  877. generatePassword
  878. autodlPassword="$newPassword"
  879. fi
  880. fi
  881.  
  882. users="$users $osUser:$autodlPassword:$webUser:$webPass:$autodlPort:$scgiPort:$rtorrentPort"
  883. done
  884. USERS="$users"
  885. }
  886.  
  887. extractPackedUser() {
  888. local packedUser="$1"
  889.  
  890. osUser="$(echo $packedUser | cut -d: -f1)"
  891. autodlPassword="$(echo $packedUser | cut -d: -f2)"
  892. webUser="$(echo $packedUser | cut -d: -f3)"
  893. webPass="$(echo $packedUser | cut -d: -f4)"
  894. autodlPort="$(echo $packedUser | cut -d: -f5)"
  895. scgiPort="$(echo $packedUser | cut -d: -f6)"
  896. rtorrentPort="$(echo $packedUser | cut -d: -f7)"
  897. }
  898.  
  899. getUserGroup() {
  900. local user="$1"
  901.  
  902. userExists "$user" || errorExit "The user '$user' does not exist."
  903. group=$(grep -w $(id -rg $user) /etc/group | cut -d: -f1)
  904. [ -z "$group" ] && group="$user"
  905. }
  906.  
  907. getUserDir() {
  908. local user="$1"
  909.  
  910. [ -z "$user" ] && errorExit "Invalid user (blank)."
  911. userDir="$(eval echo ~$user)"
  912. [ -d "$userDir" ] || errorExit "User $user's home directory does not exist."
  913. }
  914.  
  915. resetOwner() {
  916. local user="$1"
  917. shift
  918.  
  919. if [ "$ISROOT" = y ]; then
  920. getUserGroup "$user"
  921. chown -R $user:$group "$@"
  922. fi
  923. }
  924.  
  925. # Updates MISSING_PHP_MODULES with all missing required PHP modules
  926. detectMissingPhpModules() {
  927. MISSING_PHP_MODULES=
  928. local php=${WWW_PHP_CGI:-php}
  929. for module in $REQUIRED_PHP_MODULES; do
  930. $php -m 2> /dev/null | grep -wq $module || MISSING_PHP_MODULES="$MISSING_PHP_MODULES $module"
  931. done
  932. }
  933.  
  934. installMissingPhpPackages() {
  935. PACKAGES=
  936. for module in $MISSING_PHP_MODULES; do
  937. PACKAGES="$PACKAGES php-$module"
  938. done
  939. installPackages
  940. }
  941.  
  942. installMissingPhp5Packages() {
  943. PACKAGES=
  944. for module in $MISSING_PHP_MODULES; do
  945. PACKAGES="$PACKAGES php5-$module"
  946. done
  947. installPackages
  948. }
  949.  
  950. enablePhpIniModules() {
  951. local phpIni="$1"
  952. shift
  953. for module in "$@"; do
  954. grep -qE "^extension=$module.so" "$phpIni" && continue
  955. sed_i "s/^; *\\(extension=$module.so.*\\)/\\1/" "$phpIni"
  956. grep -qE "^extension=$module.so" "$phpIni" && continue
  957. echo "extension=$module.so" >> "$phpIni"
  958. done
  959. }
  960.  
  961. installMissingPhpModules() {
  962. detectMissingPhpModules
  963. [ -z "$MISSING_PHP_MODULES" ] && return
  964.  
  965. osHandler_$os installPhpModules
  966.  
  967. detectMissingPhpModules
  968. [ -z "$MISSING_PHP_MODULES" ] && return
  969. cat << EOF
  970. $CWARNING
  971. The following PHP modules appear to be missing:
  972. $MISSING_PHP_MODULES
  973. If the autodl-irssi ruTorrent plugin isn't working, you now know why. Install
  974. them using your package manager or enable them in your php.ini file, and
  975. restart your web server.$CEND
  976. EOF
  977. }
  978.  
  979. addLogrotateConfig() {
  980. local serviceName="$1"
  981. local logFiles="$2"
  982. local postrotateScript="$3"
  983.  
  984. local logrotate_d=/etc/logrotate.d
  985. [ -d "$logrotate_d" ] || errorExit "Missing logrotate dir: $logrotate_d"
  986.  
  987. cat > "$logrotate_d/$serviceName" << EOF
  988. $logFiles {
  989. missingok
  990. daily
  991. rotate 14
  992. notifempty
  993. compress
  994. delaycompress
  995. sharedscripts
  996. postrotate
  997. $postrotateScript
  998. endscript
  999. }
  1000. EOF
  1001. [ $? -eq 0 ] || errorExit "Could not write logrotate file $logrotate_d/$serviceName"
  1002. }
  1003.  
  1004. detectPhpCgi() {
  1005. WWW_PHP_CGI=${WWW_PHP_CGI:-$(which php-cgi | head -n1)}
  1006. [ -x "$WWW_PHP_CGI" ] || errorExit "Could not find php-cgi"
  1007. "$WWW_PHP_CGI" -v | grep -q 'cgi-fcgi' || errorExit "$WWW_PHP_CGI does not support FastCGI"
  1008. }
  1009.  
  1010. # $i is the i'th user number
  1011. getUserRpcMount() {
  1012. local i=$1
  1013. verifyWebServerVars
  1014. # Make sure /RPC10 accesses aren't going to /RPC1 by padding with zeros. This is
  1015. # easier than making sure every web server handles it correctly. Eg., lighttpd's
  1016. # scgi.server table is read in order, so if you add /RPC1 before /RPC10, then
  1017. # /RPC10 accesses will go to /RPC1. A fix would of course be to place /RPC10
  1018. # before /RPC1 but it's easy to forget. Now we use /RPC00001 .. /RPC99999
  1019. echo "/$RPC_PREFIX$(printf '%05d' $i)"
  1020. }
  1021.  
  1022. createSelfSignedCertFile() {
  1023. local pemfile="$1"
  1024.  
  1025. if [ ! -f "$OTHER_PEM_FILE" ]; then
  1026. echo "${CMSG}Creating the self-signed certificate.$CEND"
  1027. rm -f "$pemfile"
  1028. openssl req -new -newkey rsa:1024 -days 1000 -nodes -x509 -keyout "$pemfile" -out "$pemfile" -batch \
  1029. || errorExit "Failed to create self-signed certificate."
  1030. OTHER_PEM_FILE="$pemfile"
  1031. CREATED_CERT_FILE=y
  1032. else
  1033. rm -f "$pemfile"
  1034. cp "$OTHER_PEM_FILE" "$pemfile" || errorExit "Failed to copy self-signed certificate."
  1035. fi
  1036.  
  1037. chmod 0600 "$pemfile"
  1038. }
  1039.  
  1040. detectHtpasswd() {
  1041. [ -z "$htpasswd" ] && isProgramInstalled htpasswd && htpasswd=htpasswd
  1042. [ -z "$htpasswd" ] && isProgramInstalled htpasswd2 && htpasswd=htpasswd2
  1043. if [ -z "$htpasswd" ]; then
  1044. installProgram python
  1045. if isProgramInstalled python; then
  1046. cd
  1047. downloadFile "htpasswd.py" "$HTPASSWD_PY_SCRIPT_URL" "$HTPASSWD_PY_SCRIPT_URL2" \
  1048. && htpasswd="python $(pwd)/htpasswd.py"
  1049. fi
  1050. fi
  1051. [ -z "$htpasswd" ] && errorExit "Could not find htpasswd"
  1052. }
  1053.  
  1054. verifyWebServerVars() {
  1055. [ -z "$WWW_PEMFILE" ] && errorExit "You have not initialized WWW_PEMFILE"
  1056. [ -z "$WWW_PASSWORD_FILE" ] && errorExit "You have not initialized WWW_PASSWORD_FILE"
  1057. [ -z "$WWW_ROOT" ] && errorExit "You have not initialized WWW_ROOT"
  1058. [ -z "$WWW_USER" ] && errorExit "You have not initialized WWW_USER"
  1059. [ -z "$WWW_GROUP" ] && errorExit "You have not initialized WWW_GROUP"
  1060. }
  1061.  
  1062. initializeWwwRootVar() {
  1063. WWW_ROOT=${WWW_ROOT:-/var/rutorrent}
  1064. }
  1065.  
  1066. createWebServerUserGroup() {
  1067. verifyWebServerVars
  1068. if ! grep -qE "^$WWW_GROUP:" /etc/group; then
  1069. groupadd -r $WWW_GROUP 2>/dev/null || groupadd $WWW_GROUP || errorExit "Could not create web server group."
  1070. fi
  1071. if ! grep -qE "^$WWW_USER:" /etc/passwd; then
  1072. local useradd="useradd -d $WWW_ROOT -g $WWW_GROUP -s /bin/sh"
  1073. $useradd -M -r $WWW_USER 2>/dev/null || $useradd $WWW_USER || errorExit "Could not create web server user."
  1074. fi
  1075. }
  1076.  
  1077. resetAuthPasswordFilePermissions() {
  1078. [ -n "$WWW_USER" ] || errorExit "WWW_USER not initialized"
  1079. [ -n "$WWW_GROUP" ] || errorExit "WWW_GROUP not initialized"
  1080. chmod 0400 "$WWW_PASSWORD_FILE"*
  1081. chown $WWW_USER:$WWW_GROUP "$WWW_PASSWORD_FILE"*
  1082. }
  1083.  
  1084. createAuthPasswordFile() {
  1085. verifyWebServerVars
  1086. : > "$WWW_PASSWORD_FILE"
  1087. resetAuthPasswordFilePermissions
  1088. }
  1089.  
  1090. # Some web servers (eg. nginx) can't allow just ONE user access to a certain
  1091. # location. To fix that, create one password file per user.
  1092. createOnePasswordFilePerUser() {
  1093. for packedUser in $USERS; do
  1094. extractPackedUser $packedUser
  1095. grep "^$webUser:" "$WWW_PASSWORD_FILE" > "${WWW_PASSWORD_FILE}_$webUser"
  1096. done
  1097. resetAuthPasswordFilePermissions
  1098. }
  1099.  
  1100. updatePhpTimezone() {
  1101. if [ ! -f "$WWW_PHP_INI" ]; then
  1102. echo "${CWARNING}Could not find php.ini file: $WWW_PHP_INI$CEND"
  1103. return
  1104. fi
  1105. [ -z "$USER_TIMEZONE" ] && return
  1106.  
  1107. local zws="[ ]*"
  1108. local newLine="date.timezone = $USER_TIMEZONE"
  1109. if grep -qE "^${zws}date\\.timezone[ =]" "$WWW_PHP_INI"; then
  1110. return
  1111. elif grep -qE "^${zws}[;#]${zws}date\\.timezone[ =]" "$WWW_PHP_INI"; then
  1112. sed_i "s!^${zws}[;#]${zws}date\\.timezone[ =].*\$!$newLine!" "$WWW_PHP_INI"
  1113. else
  1114. cat >> "$WWW_PHP_INI" << EOF
  1115. [Date]
  1116. $newLine
  1117. EOF
  1118. fi
  1119. }
  1120.  
  1121. doDetectTimeZone() {
  1122. echo "${CMSG}Detecting timezone...$CEND"
  1123. detectTimeZone
  1124. if [ -n "$USER_TIMEZONE" ]; then
  1125. echo "${CMSG}Timezone: $USER_TIMEZONE$CEND"
  1126.  
  1127. updatePhpTimezone
  1128. else
  1129. echo "${CWARNING}Could not detect timezone!$CEND"
  1130. fi
  1131. }
  1132.  
  1133. webServerCommonInitialization() {
  1134. mkdir -p $WWW_ROOT
  1135. doDetectTimeZone
  1136. createSelfSignedCertFile "$WWW_PEMFILE"
  1137. createAuthPasswordFile
  1138. }
  1139.  
  1140. resetWebServerPermissions() {
  1141. verifyWebServerVars
  1142. chown -R $WWW_USER:$WWW_GROUP $WWW_ROOT || errorExit "Could not set web server as owner of $WWW_ROOT"
  1143. }
  1144.  
  1145. createPhpcgiSocket() {
  1146. PHPCGI_SOCKET_DIR=/etc/phpcgi
  1147. PHPCGI_SOCKET_FILE="$PHPCGI_SOCKET_DIR/php-cgi.socket"
  1148. mkdir -p "$PHPCGI_SOCKET_DIR"
  1149. chown $WWW_USER:$WWW_GROUP "$PHPCGI_SOCKET_DIR"
  1150. chmod 0770 "$PHPCGI_SOCKET_DIR"
  1151. }
  1152.  
  1153. verifyApacheServerVars() {
  1154. verifyWebServerVars
  1155. [ -z "$APACHE_SITE_FILE" ] && errorExit "You have not initialized APACHE_SITE_FILE"
  1156. }
  1157.  
  1158. apacheCreateApxs2Symlink() {
  1159. # The makefile uses apxs2, so make a symlink
  1160. if ! isProgramInstalled apxs2; then
  1161. local apxs=$(which apxs 2>/dev/null) && ln -s "$apxs" "${apxs}2"
  1162. fi
  1163. }
  1164.  
  1165. initializeApacheVars() {
  1166. local apacheUser="$1"
  1167. local apacheGroup="$2"
  1168. local apacheSitesDir="$3"
  1169.  
  1170. [ -n "$apacheUser" ] || errorExit "Invalid apache user: $apacheUser"
  1171. [ -n "$apacheGroup" ] || errorExit "Invalid apache group: $apacheGroup"
  1172. [ -d "$apacheSitesDir" ] || errorExit "Invalid apache sites dir: $apacheSitesDir"
  1173. [ -d "$APACHE_DIR" ] || errorExit "Invalid apache dir: $APACHE_DIR"
  1174.  
  1175. APACHE_SITE_NAME=${APACHE_SITE_NAME:-rutorrent.conf}
  1176. APACHE_SITE_FILE=$apacheSitesDir/$APACHE_SITE_NAME
  1177. initializeWwwRootVar
  1178. WWW_PASSWORD_FILE=$APACHE_DIR/rutorrent_passwd
  1179. WWW_PEMFILE=$APACHE_DIR/rutorrent.pem
  1180. WWW_USER="$apacheUser"
  1181. WWW_GROUP="$apacheGroup"
  1182. }
  1183.  
  1184. apacheGetRpcLocationDirectives() {
  1185. if [ "$INSTALL_RUTORRENT" = y ]; then
  1186. local i=1
  1187. for packedUser in $USERS; do
  1188. extractPackedUser $packedUser
  1189. local rpcMount="$(getUserRpcMount $i)"
  1190. cat << EOF
  1191. <Location "$rpcMount">
  1192. AuthType Basic
  1193. AuthName "$RUTORRENT_SITE_REALM"
  1194. AuthUserFile "$WWW_PASSWORD_FILE"
  1195. Require user $webUser
  1196. </Location>
  1197. EOF
  1198. i=$(expr $i + 1)
  1199. done
  1200. fi
  1201. }
  1202.  
  1203. apacheGetVirtualHost() {
  1204. local port=$1
  1205. local ssl=$2
  1206. cat << EOF
  1207. <VirtualHost *:$port>
  1208. $(if [ "$ssl" = y ]; then
  1209. echo " SSLEngine On"
  1210. echo " SSLCertificateFile $WWW_PEMFILE"
  1211. fi)
  1212. ServerAdmin admin@rutorrent
  1213. ServerName localhost
  1214. DocumentRoot $WWW_ROOT
  1215.  
  1216. <Directory />
  1217. AllowOverride None
  1218. Order deny,allow
  1219. Deny from all
  1220. </Directory>
  1221. <Location />
  1222. AuthType Basic
  1223. AuthName "$RUTORRENT_SITE_REALM"
  1224. AuthUserFile "$WWW_PASSWORD_FILE"
  1225. Require valid-user
  1226. Order allow,deny
  1227. Allow from all
  1228. </Location>
  1229. <Location ~ "^/rutorrent/(conf|share)">
  1230. Order deny,allow
  1231. Deny from all
  1232. </Location>
  1233. <Location ~ "/\\\\.svn">
  1234. Order deny,allow
  1235. Deny from all
  1236. </Location>
  1237. $(apacheGetRpcLocationDirectives)
  1238. </VirtualHost>
  1239. EOF
  1240. }
  1241.  
  1242. apacheWriteSiteFile() {
  1243. verifyApacheServerVars
  1244. cat > "$APACHE_SITE_FILE" << EOF
  1245. ServerName localhost
  1246.  
  1247. $(apacheGetVirtualHost $HTTP_PORT n)
  1248. $(apacheGetVirtualHost $HTTPS_PORT y)
  1249. EOF
  1250.  
  1251. if [ "$INSTALL_RUTORRENT" = y ]; then
  1252. local i=1
  1253. local lp=; isWebServerRpcModule || lp='#'
  1254. for packedUser in $USERS; do
  1255. extractPackedUser $packedUser
  1256. local rpcMount="$(getUserRpcMount $i)"
  1257. echo "${lp}SCGIMount $rpcMount $SCGI_HOST:$scgiPort" >> "$APACHE_SITE_FILE"
  1258.  
  1259. i=$(expr $i + 1)
  1260. done
  1261. fi
  1262. }
  1263.  
  1264. apacheCommonInitialization() {
  1265. local buildTools="$1"
  1266. local modulesDir="$2"
  1267.  
  1268. webServerCommonInitialization
  1269. apacheWriteSiteFile
  1270.  
  1271. if [ -n "$APACHE_SCGI_FILE" ] && [ ! -f "$APACHE_SCGI_FILE" ]; then
  1272. installBuildTools
  1273. PACKAGES="$buildTools"
  1274. installPackages
  1275. apacheCreateApxs2Symlink
  1276.  
  1277. # Compiling mod_scgi will fail unless we remove this warning-as-error flag
  1278. local configVarsFile="$APACHE_DIR/modules/build/config_vars.mk"
  1279. [ -f "$configVarsFile" ] && sed_i 's/-Werror=format-security//g' "$configVarsFile"
  1280.  
  1281. installModScgi "$APACHE_SCGI_FILE" "$modulesDir"
  1282. fi
  1283. }
  1284.  
  1285. installCommonWebServerStuff_mandriva() {
  1286. # Also add some extra tools for ruTorrent and some of its plugins
  1287. PACKAGES="php-cli gzip curl openssl logrotate"
  1288. installPackages
  1289. PACKAGE="unrar"
  1290. installPackages
  1291. PACKAGES="php-geoip"
  1292. installPackages
  1293. }
  1294.  
  1295. # Used by Mandriva, Unity Linux, and PCLinuxOS
  1296. installApache_mandriva() {
  1297. installCommonWebServerStuff_mandriva
  1298. PACKAGES="apache-mpm-prefork apache-mod_ssl apache-mod_php"
  1299. installPackages
  1300.  
  1301. WWW_PHP_INI=/etc/php.ini
  1302. APACHE_DIR=/etc/httpd
  1303. local APACHE_CONF_D=$APACHE_DIR/conf.d
  1304. local APACHE_SITES_DIR=$APACHE_DIR/conf/vhosts.d
  1305. APACHE_SCGI_FILE=$APACHE_CONF_D/scgi.conf
  1306. initializeApacheVars apache apache "$APACHE_SITES_DIR"
  1307. apacheCommonInitialization "libopenssl-devel apache-devel" $APACHE_DIR/modules
  1308.  
  1309. for file in 00_default_vhosts.conf 01_default_ssl_vhost.conf; do
  1310. [ -f "$APACHE_SITES_DIR/$file" ] && mv -f "$APACHE_SITES_DIR/$file" "$APACHE_SITES_DIR/$file-bak"
  1311. done
  1312.  
  1313. resetWebServerPermissions
  1314. chkconfig httpd on
  1315. service httpd restart || errorExit "Could not start $INSTALL_WEB_SERVER"
  1316. }
  1317.  
  1318. installCommonWebServerStuff_gentoo() {
  1319. # Also add some extra tools for ruTorrent and some of its plugins
  1320. PACKAGES="dev-lang/php logrotate"
  1321. addProgram gzip app-arch/gzip
  1322. addProgram curl net-misc/curl
  1323. addProgram openssl dev-libs/openssl
  1324. addProgram unrar app-arch/unrar
  1325. installPackages
  1326.  
  1327. ACCEPT_LICENSE=MaxMind
  1328. export ACCEPT_LICENSE
  1329. PACKAGES="dev-php5/pecl-geoip"
  1330. installPackages
  1331. unset ACCEPT_LICENSE
  1332. }
  1333.  
  1334. installApache_gentoo() {
  1335. installCommonWebServerStuff_gentoo
  1336. PACKAGES="www-servers/apache app-admin/apache-tools"
  1337. installPackages
  1338. PACKAGES="www-apache/mod_scgi"
  1339. installPackages
  1340.  
  1341. WWW_PHP_INI=$(ls /etc/php/apache2-php5*/php.ini | tail -n1)
  1342. [ -f "$WWW_PHP_INI" ] || errorExit "Could not find Apache php.ini file"
  1343. APACHE_DIR=/etc/apache2
  1344. local APACHE_CONF=$APACHE_DIR/httpd.conf
  1345. local APACHE_SITES_DIR=$APACHE_DIR/vhosts.d
  1346. local SERVER_ROOT=$(grep -E ^ServerRoot $APACHE_CONF | head -n1 | sed -e 's!^.*[ ][^/]*\(/[^"]*\).*!\1!')
  1347. APACHE_SCGI_FILE="$APACHE_DIR/modules.d/scgi.conf"
  1348. [ -d "$SERVER_ROOT" ] || errorExit "Apache server root dir does not exist: $SERVER_ROOT"
  1349. initializeApacheVars apache apache "$APACHE_SITES_DIR"
  1350. apacheCommonInitialization "" $SERVER_ROOT/modules
  1351.  
  1352. for file in 00_default_ssl_vhost.conf 00_default_vhost.conf; do
  1353. [ -f "$APACHE_SITES_DIR/$file" ] && mv -f "$APACHE_SITES_DIR/$file" "$APACHE_SITES_DIR/$file-bak"
  1354. done
  1355.  
  1356. appendFileStringVar /etc/conf.d/apache2 APACHE2_OPTS "-D SCGI"
  1357. appendFileStringVar /etc/conf.d/apache2 APACHE2_OPTS "-D PHP5"
  1358. appendFileStringVar /etc/conf.d/apache2 APACHE2_OPTS "-D SSL"
  1359. cat >> $APACHE_SITE_FILE << EOF
  1360. Listen $HTTP_PORT
  1361. Listen $HTTPS_PORT
  1362. EOF
  1363.  
  1364. resetWebServerPermissions
  1365. rc-update add apache2 default
  1366. osHandler_$os restart_$INSTALL_WEB_SERVER
  1367. }
  1368.  
  1369. nginxGetRpcMounts() {
  1370. if [ "$INSTALL_RUTORRENT" = y ]; then
  1371. local i=1
  1372. local lp=; isWebServerRpcModule || lp='#'
  1373. for packedUser in $USERS; do
  1374. extractPackedUser $packedUser
  1375. getUserScgiSocketPath "$osUser"
  1376. local rpcMount="$(getUserRpcMount $i)"
  1377.  
  1378. cat << EOF
  1379. $lp location ~ ^$rpcMount\$ {
  1380. $lp include scgi_params;
  1381. $lp scgi_pass unix:$scgiSocketPath;
  1382. $lp auth_basic "$RUTORRENT_SITE_REALM";
  1383. $lp auth_basic_user_file "${WWW_PASSWORD_FILE}_$webUser";
  1384. $lp }
  1385. EOF
  1386.  
  1387. i=$(expr $i + 1)
  1388. done
  1389. fi
  1390. }
  1391.  
  1392. nginxGetServerSection() {
  1393. local port=$1
  1394. local ssl=$2
  1395.  
  1396. cat << EOF
  1397. server {
  1398. listen $port;
  1399. server_name localhost;
  1400. auth_basic "$RUTORRENT_SITE_REALM";
  1401. auth_basic_user_file "$WWW_PASSWORD_FILE";
  1402.  
  1403. $(if [ "$ssl" = y ]; then
  1404. cat << EOF2
  1405. ssl on;
  1406. ssl_certificate $WWW_PEMFILE;
  1407. ssl_certificate_key $WWW_PEMFILE;
  1408. EOF2
  1409. fi)
  1410.  
  1411. location ~ ^/rutorrent/(?:share|conf) {
  1412. deny all;
  1413. }
  1414.  
  1415. location ~ /\.ht {
  1416. deny all;
  1417. }
  1418.  
  1419. location ~ /\.svn {
  1420. deny all;
  1421. }
  1422.  
  1423. location / {
  1424. root $WWW_ROOT;
  1425. index index.php index.html index.htm;
  1426. }
  1427.  
  1428. location ~ \.php$ {
  1429. root "$WWW_ROOT";
  1430. fastcgi_pass unix:$PHPCGI_SOCKET_FILE;
  1431. fastcgi_index index.php;
  1432. fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
  1433. include fastcgi_params;
  1434. }
  1435.  
  1436. $(nginxGetRpcMounts)
  1437. }
  1438. EOF
  1439. }
  1440.  
  1441. nginxWriteConfFile() {
  1442. getNumCpus
  1443. cat > $NGINX_CONF << EOF
  1444. worker_processes $NUMCPUS;
  1445. user $WWW_USER $WWW_GROUP;
  1446. events {
  1447. worker_connections 1024;
  1448. }
  1449.  
  1450. http {
  1451. include mime.types;
  1452. default_type application/octet-stream;
  1453. sendfile on;
  1454. keepalive_timeout 65;
  1455.  
  1456. # I have to set min length to 0 and http version to 1.0 or it won't compress
  1457. # the XML-RPC (SCGI) responses. Those responses can be quite large if you're
  1458. # using many torrent files.
  1459. gzip on;
  1460. gzip_min_length 0;
  1461. gzip_http_version 1.0;
  1462. gzip_types text/plain text/xml application/xml application/json text/css application/x-javascript text/javascript application/javascript;
  1463.  
  1464. $(nginxGetServerSection $HTTP_PORT n)
  1465. $(nginxGetServerSection $HTTPS_PORT y)
  1466. }
  1467. EOF
  1468. [ $? -eq 0 ] || errorExit "Could not write to file $NGINX_CONF"
  1469. }
  1470.  
  1471. buildNginx() {
  1472. buildStart
  1473. PREFIX=$NGINX_DIR
  1474. NGINX_BIN=$PREFIX/sbin/nginx
  1475. NGINX_CONF=$PREFIX/conf/nginx.conf
  1476. NGINX_PID_FILE=$PREFIX/nginx.pid
  1477. NGINX_ACCESS_LOG=$PREFIX/logs/access.log
  1478. NGINX_ERROR_LOG=$PREFIX/logs/error.log
  1479. local configureFlags="\
  1480. --prefix=$PREFIX \
  1481. --sbin-path=$NGINX_BIN \
  1482. --conf-path=$NGINX_CONF \
  1483. --pid-path=$NGINX_PID_FILE \
  1484. --lock-path=$PREFIX/logs/nginx.lock \
  1485. --error-log-path=$NGINX_ERROR_LOG \
  1486. --http-log-path=$NGINX_ACCESS_LOG \
  1487. --user=$WWW_USER \
  1488. --group=$WWW_GROUP \
  1489. --with-http_ssl_module"
  1490. export CFLAGS="$NGINX_CFLAGS"
  1491. downloadAndBuild "nginx" "$NGINX_URL" "$NGINX_NAME" "$configureFlags" patchNginx
  1492. unset CFLAGS
  1493. buildEnd
  1494. }
  1495.  
  1496. patchNginx() {
  1497. # Get rid of the -Werror flag for gcc 4.6.0
  1498. sed_i "s!-Werror[a-zA-Z0-9=-]*!!" "auto/cc/gcc"
  1499. }
  1500.  
  1501. installNginx() {
  1502. SCGI_USE_UNIX_DOMAIN_SOCKET=y
  1503. CREATE_ONE_PASSWORD_FILE_PER_USER=y
  1504. installBuildTools
  1505. osHandler_$os preNginxInstall
  1506. installUnrar
  1507.  
  1508. NGINX_DIR=/usr/local/nginx
  1509. initializeWwwRootVar
  1510. WWW_PASSWORD_FILE=$NGINX_DIR/rutorrent_passwd
  1511. WWW_PEMFILE=$NGINX_DIR/rutorrent.pem
  1512. WWW_USER=${WWW_USER:-nginx}
  1513. WWW_GROUP=${WWW_GROUP:-nginx}
  1514.  
  1515. detectPhpCgi
  1516. createWebServerUserGroup
  1517. createPhpcgiSocket
  1518.  
  1519. buildNginx
  1520. webServerCommonInitialization
  1521. nginxWriteConfFile
  1522.  
  1523. addLogrotateConfig nginx \
  1524. "$NGINX_ACCESS_LOG $NGINX_ERROR_LOG" \
  1525. "[ -f \"$NGINX_PID_FILE\" ] && kill -USR1 \$(cat \"$NGINX_PID_FILE\") >/dev/null 2>&1; true"
  1526.  
  1527. resetWebServerPermissions
  1528. osHandler_$os installPhpCgiService
  1529. osHandler_$os installNginxService
  1530. }
  1531.  
  1532. preNginxInstall_gentoo() {
  1533. installCommonWebServerStuff_gentoo
  1534. PACKAGES="libpcre openssl zlib php"
  1535. installPackages
  1536. WWW_PHP_INI=$(ls /etc/php/cgi-php5*/php.ini | tail -n1)
  1537. [ -f "$WWW_PHP_INI" ] || errorExit "Could not find php-cgi php.ini file"
  1538. }
  1539.  
  1540. preLighttpdInstall_gentoo() {
  1541. preNginxInstall_gentoo
  1542. }
  1543.  
  1544. lighttpdGetRpcRequire() {
  1545. if [ "$INSTALL_RUTORRENT" = y ]; then
  1546. local i=1
  1547. for packedUser in $USERS; do
  1548. extractPackedUser $packedUser
  1549. local rpcMount="$(getUserRpcMount $i)"
  1550.  
  1551. cat << EOF
  1552. "$rpcMount" => (
  1553. "method" => "basic",
  1554. "realm" => "$RUTORRENT_SITE_REALM",
  1555. "require" => "user=$webUser",
  1556. ),
  1557. EOF
  1558. i=$(expr $i + 1)
  1559. done
  1560. fi
  1561. }
  1562.  
  1563. lighttpdGetScgiServerTable() {
  1564. echo 'scgi.server = ('
  1565.  
  1566. if [ "$INSTALL_RUTORRENT" = y ]; then
  1567. local i=1
  1568. local lp=; isWebServerRpcModule || lp='#'
  1569. for packedUser in $USERS; do
  1570. extractPackedUser $packedUser
  1571. getUserScgiSocketPath "$osUser"
  1572. local rpcMount="$(getUserRpcMount $i)"
  1573.  
  1574. cat << EOF
  1575. $lp "$rpcMount" => (
  1576. $lp (
  1577. $lp "socket" => "$scgiSocketPath",
  1578. $lp "check-local" => "disable",
  1579. $lp "disable-time" => 0,
  1580. $lp ),
  1581. $lp ),
  1582. EOF
  1583. i=$(expr $i + 1)
  1584. done
  1585. fi
  1586.  
  1587. echo ')'
  1588. }
  1589.  
  1590. lighttpdWriteConfFile() {
  1591. cat > $LIGHTTPD_CONF << EOF
  1592. server.follow-symlink = "disable"
  1593. server.max-connections = 512
  1594. server.max-fds = 1024
  1595. server.max-keep-alive-idle = 15
  1596. dir-listing.activate = "disable"
  1597. server.pid-file = "$LIGHTTPD_PID_FILE"
  1598. server.errorlog = "$LIGHTTPD_ERROR_LOG"
  1599. accesslog.filename = "$LIGHTTPD_ACCESS_LOG"
  1600.  
  1601. $(if [ $(uname -s) = Linux ]; then
  1602. echo 'server.event-handler = "linux-sysepoll"'
  1603. echo 'server.network-backend = "linux-sendfile"'
  1604. fi)
  1605.  
  1606. server.username = "$WWW_USER"
  1607. server.groupname = "$WWW_GROUP"
  1608.  
  1609. server.modules = (
  1610. # "mod_rewrite",
  1611. # "mod_redirect",
  1612. # "mod_alias",
  1613. "mod_access",
  1614. "mod_auth",
  1615. # "mod_status",
  1616. # "mod_simple_vhost",
  1617. # "mod_evhost",
  1618. # "mod_userdir",
  1619. # "mod_secdownload",
  1620. "mod_fastcgi",
  1621. # "mod_proxy",
  1622. # "mod_cgi",
  1623. "mod_scgi",
  1624. # "mod_ssi",
  1625. # "mod_compress",
  1626. # "mod_usertrack",
  1627. # "mod_expire",
  1628. # "mod_rrdtool",
  1629. "mod_accesslog",
  1630. )
  1631.  
  1632. fastcgi.server = (
  1633. ".php" => (
  1634. (
  1635. "socket" => "$PHPCGI_SOCKET_FILE",
  1636. ),
  1637. ),
  1638. )
  1639.  
  1640. index-file.names = ( "index.php", "index.html", "index.htm" )
  1641. static-file.exclude-extensions = ( ".fcgi", ".php", ".rb", "~", ".inc" )
  1642.  
  1643. mimetype.assign = (
  1644. ".html" => "text/html",
  1645. ".htm" => "text/html",
  1646. ".txt" => "text/plain",
  1647. ".csv" => "text/plain",
  1648. ".ini" => "text/plain",
  1649. ".jpg" => "image/jpeg",
  1650. ".jpeg" => "image/jpeg",
  1651. ".gif" => "image/gif",
  1652. ".png" => "image/png",
  1653. ".bmp" => "image/bmp",
  1654. ".css" => "text/css",
  1655. ".js" => "application/javascript",
  1656. ".ico" => "image/x-icon",
  1657. ".json" => "application/json",
  1658. ".torrent" => "application/x-bittorrent",
  1659. ".pdf" => "application/pdf",
  1660. ".bz2" => "application/x-bzip2",
  1661. ".gz" => "application/x-gzip",
  1662. ".tar.gz" => "application/x-tgz",
  1663. ".tar" => "application/x-tar",
  1664. ".tar.bz2" => "application/x-bzip-compressed-tar",
  1665. ".tbz" => "application/x-bzip-compressed-tar",
  1666. ".tgz" => "application/x-tgz",
  1667. ".zip" => "application/zip",
  1668. ".mp3" => "audio/mpeg",
  1669. ".flac" => "audio/x-flac",
  1670. ".m3u" => "audio/x-mpegurl",
  1671. ".wma" => "audio/x-ms-wma",
  1672. ".wax" => "audio/x-ms-wax",
  1673. ".ogg" => "audio/ogg",
  1674. ".wav" => "audio/x-wav",
  1675. ".dtd" => "text/xml",
  1676. ".xml" => "text/xml",
  1677. ".mpeg" => "video/mpeg",
  1678. ".mpg" => "video/mpeg",
  1679. ".mp4" => "video/mp4",
  1680. ".wmv" => "video/x-ms-wmv",
  1681. ".avi" => "video/x-msvideo",
  1682. )
  1683.  
  1684. server.document-root = "$WWW_ROOT"
  1685. server.port = $HTTP_PORT
  1686.  
  1687. \$SERVER["socket"] == ":$HTTPS_PORT" {
  1688. ssl.engine = "enable"
  1689. ssl.pemfile = "$WWW_PEMFILE"
  1690. }
  1691.  
  1692. url.access-deny = (".htaccess")
  1693. \$HTTP["url"] =~ "^/rutorrent/(?:share|conf)" {
  1694. url.access-deny = ("")
  1695. }
  1696. \$HTTP["url"] =~ "/\\.svn" {
  1697. url.access-deny = ("")
  1698. }
  1699.  
  1700. auth.backend = "htpasswd"
  1701. auth.backend.htpasswd.userfile = "$WWW_PASSWORD_FILE"
  1702. auth.require = (
  1703. $(lighttpdGetRpcRequire)
  1704. "/" => (
  1705. "method" => "basic",
  1706. "realm" => "$RUTORRENT_SITE_REALM",
  1707. "require" => "valid-user",
  1708. ),
  1709. )
  1710.  
  1711. $(lighttpdGetScgiServerTable)
  1712. EOF
  1713. [ $? -eq 0 ] || errorExit "Could not write to file $LIGHTTPD_CONF"
  1714. }
  1715.  
  1716. buildLighttpd() {
  1717. buildStart
  1718. PREFIX=$LIGHTTPD_DIR
  1719. LIGHTTPD_BIN=$PREFIX/sbin/lighttpd
  1720. LIGHTTPD_CONF=$PREFIX/lighttpd.conf
  1721.  
  1722. # The log dir will be set to owner lighttpd since it's started as non-root.
  1723. # Put the pid file there so it can write to it.
  1724. LIGHTTPD_LOG_DIR=$PREFIX/logs
  1725. LIGHTTPD_PID_FILE=$LIGHTTPD_LOG_DIR/lighttpd.pid
  1726. LIGHTTPD_ERROR_LOG=$LIGHTTPD_LOG_DIR/error.log
  1727. LIGHTTPD_ACCESS_LOG=$LIGHTTPD_LOG_DIR/access.log
  1728.  
  1729. local configureFlags="\
  1730. --prefix=$PREFIX \
  1731. --with-openssl \
  1732. --with-pcre \
  1733. --with-zlib \
  1734. --without-bzip2"
  1735. downloadAndBuild "lighttpd" "$LIGHTTPD_URL" "$LIGHTTPD_NAME" "$configureFlags"
  1736. buildEnd
  1737. }
  1738.  
  1739. installLighttpd() {
  1740. SCGI_USE_UNIX_DOMAIN_SOCKET=y
  1741. installBuildTools
  1742. osHandler_$os preLighttpdInstall
  1743. installUnrar
  1744.  
  1745. LIGHTTPD_DIR=/usr/local/lighttpd
  1746. initializeWwwRootVar
  1747. WWW_PASSWORD_FILE=$LIGHTTPD_DIR/rutorrent_passwd
  1748. WWW_PEMFILE=$LIGHTTPD_DIR/rutorrent.pem
  1749. WWW_USER=${WWW_USER:-lighttpd}
  1750. WWW_GROUP=${WWW_GROUP:-lighttpd}
  1751.  
  1752. detectPhpCgi
  1753. createWebServerUserGroup
  1754. createPhpcgiSocket
  1755.  
  1756. buildLighttpd
  1757. webServerCommonInitialization
  1758. lighttpdWriteConfFile
  1759.  
  1760. addLogrotateConfig lighttpd \
  1761. "$LIGHTTPD_ACCESS_LOG $LIGHTTPD_ERROR_LOG" \
  1762. "[ -f \"$LIGHTTPD_PID_FILE\" ] && kill -HUP \$(cat \"$LIGHTTPD_PID_FILE\") >/dev/null 2>&1; true"
  1763.  
  1764. mkdir -p "$LIGHTTPD_LOG_DIR"
  1765. chown -R $WWW_USER:$WWW_GROUP "$LIGHTTPD_LOG_DIR"
  1766.  
  1767. resetWebServerPermissions
  1768. osHandler_$os installPhpCgiService
  1769. osHandler_$os installLighttpdService
  1770. }
  1771.  
  1772. # Add $name=$value to the file, or modify an existing line if present in the file
  1773. setVsftpdValue() {
  1774. local confFile="$1"
  1775. local name="$2"
  1776. local value="$3"
  1777. local newLine="$name=$value"
  1778.  
  1779. sed_i "s!^[ ]*$name[ =:].*\$!$newLine!" "$confFile"
  1780. grep -qE "^$newLine$" "$confFile" || echo "$newLine" >> "$confFile"
  1781. }
  1782.  
  1783. # Same as setVsftpdValue but makes sure the option exists
  1784. setVsftpdValue2() {
  1785. local confFile="$1"
  1786. local name="$2"
  1787. local value="$3"
  1788.  
  1789. [ -z "$VSFTPD_PATH" ] && return
  1790. grep -q "$name" "$VSFTPD_PATH" && setVsftpdValue "$confFile" "$name" "$value"
  1791. }
  1792.  
  1793. updateVsftpdConf() {
  1794. local confFile="$1"
  1795. touch "$confFile"
  1796.  
  1797. VSFTPD_PATH=$(which vsftpd 2>/dev/null)
  1798.  
  1799. setVsftpdValue "$confFile" anonymous_enable NO
  1800. setVsftpdValue "$confFile" dirlist_enable YES
  1801. setVsftpdValue "$confFile" download_enable YES
  1802. setVsftpdValue "$confFile" guest_enable NO
  1803. setVsftpdValue "$confFile" listen YES
  1804. setVsftpdValue "$confFile" listen_ipv6 NO
  1805. setVsftpdValue "$confFile" local_enable YES
  1806. setVsftpdValue "$confFile" local_umask $DEFAULT_UMASK
  1807. setVsftpdValue "$confFile" max_per_ip 0
  1808. setVsftpdValue "$confFile" pasv_enable YES
  1809. setVsftpdValue "$confFile" port_enable YES
  1810. setVsftpdValue "$confFile" pasv_promiscuous NO
  1811. setVsftpdValue "$confFile" port_promiscuous NO
  1812. setVsftpdValue "$confFile" pasv_min_port 0
  1813. setVsftpdValue "$confFile" pasv_max_port 0
  1814. setVsftpdValue "$confFile" write_enable YES
  1815.  
  1816. if [ "$USE_ENCRYPTED_FTP" = y ]; then
  1817. local pemfile=/etc/vsftpd.pem
  1818. createSelfSignedCertFile "$pemfile"
  1819.  
  1820. FTP_SERVER_TYPE="FTPES - Encrypted (FTP over explicit TLS/SSL)"
  1821. FTP_PORT=${FTP_PORT:-$DEFAULT_PORT_FTPES}
  1822. setVsftpdValue "$confFile" listen_port $FTP_PORT
  1823. setVsftpdValue "$confFile" ssl_enable YES
  1824.  
  1825. setVsftpdValue "$confFile" allow_anon_ssl NO
  1826. setVsftpdValue "$confFile" force_local_data_ssl YES
  1827. setVsftpdValue "$confFile" force_local_logins_ssl YES
  1828. setVsftpdValue "$confFile" ssl_sslv2 NO
  1829. setVsftpdValue "$confFile" ssl_sslv3 NO
  1830. setVsftpdValue "$confFile" ssl_tlsv1 YES
  1831. setVsftpdValue "$confFile" rsa_cert_file "$pemfile"
  1832.  
  1833. setVsftpdValue2 "$confFile" implicit_ssl NO
  1834. setVsftpdValue2 "$confFile" require_cert NO
  1835. setVsftpdValue2 "$confFile" require_ssl_reuse NO
  1836. setVsftpdValue2 "$confFile" ssl_request_cert YES
  1837. setVsftpdValue2 "$confFile" strict_ssl_read_eof NO
  1838. setVsftpdValue2 "$confFile" strict_ssl_write_shutdown NO
  1839. setVsftpdValue2 "$confFile" validate_cert NO
  1840. else
  1841. FTP_SERVER_TYPE="FTP - Non-encrypted"
  1842. FTP_PORT=${FTP_PORT:-$DEFAULT_PORT_FTP}
  1843. setVsftpdValue "$confFile" listen_port $FTP_PORT
  1844. setVsftpdValue "$confFile" ssl_enable NO
  1845. fi
  1846.  
  1847. # The private key is in rsa_cert_file
  1848. sed_i 'g/rsa_private_key_file/d' "$confFile"
  1849. }
  1850.  
  1851. installVsftpd_chkconfig() {
  1852. local vsftpdConf="$1"
  1853. installProgram vsftpd
  1854. [ -f "$vsftpdConf" ] || errorExit "Invalid vsftpd.conf file: $vsftpdConf"
  1855. updateVsftpdConf "$vsftpdConf"
  1856. chkconfig vsftpd on
  1857. if ! service vsftpd restart; then
  1858. if [ "$SELINUX_ENABLED" = y ]; then
  1859. errorExit "Could not restart vsftpd. SELinux could be the reason."
  1860. else
  1861. errorExit "Could not restart vsftpd"
  1862. fi
  1863. fi
  1864. }
  1865.  
  1866. installVsftpd_gentoo() {
  1867. installProgram net-ftp/vsftpd
  1868. local vsftpdConf=/etc/vsftpd/vsftpd.conf
  1869. if ! [ -f $vsftpdConf ]; then
  1870. touch $vsftpdConf
  1871. [ -f $vsftpdConf.example ] && cp $vsftpdConf.example $vsftpdConf
  1872. fi
  1873. updateVsftpdConf $vsftpdConf
  1874. rc-update add vsftpd default
  1875. /etc/init.d/vsftpd restart
  1876. }
  1877.  
  1878. installService_chkconfig1() {
  1879. CHKCONFIG_SERVICE_NAME=$1
  1880. CHKCONFIG_SERVICE_FILE=/etc/init.d/$CHKCONFIG_SERVICE_NAME
  1881. CHKCONFIG_LOCK_FILE=/var/lock/subsys/$CHKCONFIG_SERVICE_NAME
  1882. }
  1883.  
  1884. installService_chkconfig2() {
  1885. chmod +x "$CHKCONFIG_SERVICE_FILE" || errorExit "Could not set +x bit, file $CHKCONFIG_SERVICE_FILE."
  1886. chkconfig --add $CHKCONFIG_SERVICE_NAME || errorExit "Could not install service $CHKCONFIG_SERVICE_FILE. Run this script as root."
  1887. service $CHKCONFIG_SERVICE_NAME restart
  1888. }
  1889.  
  1890. getChkconfigScriptContents() {
  1891. local desc="$1"
  1892. cat << EOF
  1893. # chkconfig: 2345 85 15
  1894. # description: $desc
  1895. EOF
  1896. }
  1897.  
  1898. getLsbStartupScriptContents() {
  1899. local startupName="$1"
  1900. local desc="$2"
  1901. cat << EOF
  1902. ### BEGIN INIT INFO
  1903. # Provides: $startupName
  1904. # Required-Start: \$local_fs \$network \$syslog
  1905. # Required-Stop: \$local_fs \$syslog
  1906. # Default-Start: $LSB_DEFAULT_START
  1907. # Default-Stop: $LSB_DEFAULT_STOP
  1908. # Short-Description: $desc
  1909. # Description: $desc
  1910. ### END INIT INFO
  1911. EOF
  1912. }
  1913.  
  1914. # You must define v_{startIt,stopIt,restartIt,showStatus} and isStarted funcs
  1915. getLsbStartupFooter() {
  1916. cat << EOF
  1917. resetPath # Some include files may have reset it
  1918. LOCKFILE=$1
  1919. updateLock() {
  1920. [ -z "\$LOCKFILE" ] && return
  1921. if isStarted; then
  1922. touch \$LOCKFILE
  1923. else
  1924. rm -f \$LOCKFILE
  1925. fi
  1926. }
  1927.  
  1928. RETVAL=0
  1929. case \$1 in
  1930. start)
  1931. v_startIt
  1932. ;;
  1933. stop)
  1934. v_stopIt
  1935. ;;
  1936. force-reload|restart)
  1937. v_restartIt
  1938. ;;
  1939. try-restart)
  1940. isStarted && v_restartIt
  1941. ;;
  1942. status)
  1943. v_showStatus
  1944. ;;
  1945. *)
  1946. echo "Usage: \$0 {start|stop|restart|try-restart|force-reload|status}"
  1947. RETVAL=1
  1948. ;;
  1949. esac
  1950.  
  1951. updateLock
  1952. exit \$RETVAL
  1953. EOF
  1954. }
  1955.  
  1956. getCommonStartupScriptContents_autodl() {
  1957. local USER="$1"
  1958. local STARTUPNAME="$2"
  1959. cat << EOF
  1960. NAME=$STARTUPNAME
  1961. USER=$USER
  1962. SESSIONNAME=autodl
  1963.  
  1964. resetPath() {
  1965. PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:\$PATH"
  1966. }
  1967. resetPath
  1968.  
  1969. # Make sure the path is correct, and make sure we're in the home dir.
  1970. USER_INIT="umask $DEFAULT_UMASK; cd; PATH=\\\$PATH:\$PATH"
  1971.  
  1972. # Run user command, ignoring any messages sent to stdout (eg. 'No mail.')
  1973. runUserCmd() {
  1974. su - \$USER -c "\$USER_INIT; \$1" >/dev/null && return 0
  1975. return 1
  1976. }
  1977.  
  1978. isStarted() {
  1979. su - \$USER -c "\$USER_INIT; screen -ls | grep -qE \\"[ ][0-9]+\\\\.\$SESSIONNAME[ ]\\"" >/dev/null && return 0
  1980. return 1
  1981. }
  1982.  
  1983. startIt() {
  1984. isStarted && return 0
  1985.  
  1986. local START_IRSSI=n
  1987. local START_RTORRENT=n
  1988. which irssi > /dev/null 2>&1 && START_IRSSI=y
  1989. which rtorrent > /dev/null 2>&1 && START_RTORRENT=y
  1990.  
  1991. case \$START_IRSSI\$START_RTORRENT in
  1992. yy)
  1993. runUserCmd "screen -S \$SESSIONNAME -d -t rtorrent -m rtorrent"
  1994. runUserCmd "screen -d -r \$SESSIONNAME -X screen -t irssi irssi"
  1995. ;;
  1996. yn)
  1997. runUserCmd "screen -S \$SESSIONNAME -d -t irssi -m irssi"
  1998. ;;
  1999. ny)
  2000. runUserCmd "screen -S \$SESSIONNAME -d -t rtorrent -m rtorrent"
  2001. ;;
  2002. nn)
  2003. ;;
  2004. esac
  2005. return 0
  2006. }
  2007.  
  2008. stopIt() {
  2009. isStarted || return 0
  2010.  
  2011. runUserCmd "screen -d -r \$SESSIONNAME -p irssi -X stuff \\"/quit
  2012. /quit
  2013. \\""
  2014. runUserCmd "screen -d -r \$SESSIONNAME -p rtorrent -X xon"
  2015.  
  2016. for i in 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4; do
  2017. isStarted || break
  2018. sleep 1
  2019. done
  2020.  
  2021. # If it's still not stopped, kill the whole screen session
  2022. if isStarted; then
  2023. echo -n "Couldn't stop it. Killing screen session..."
  2024. runUserCmd "screen -d -r \$SESSIONNAME -p rtorrent -X xon"
  2025. sleep 2
  2026. runUserCmd "screen -d -r \$SESSIONNAME -X quit"
  2027. echo "Done."
  2028. fi
  2029.  
  2030. return 0
  2031. }
  2032.  
  2033. v_restartIt() {
  2034. v_stopIt
  2035. v_startIt
  2036. }
  2037.  
  2038. v_showStatus() {
  2039. if isStarted; then
  2040. echo "\$NAME is running."
  2041. else
  2042. echo "\$NAME is stopped."
  2043. fi
  2044. }
  2045. EOF
  2046. }
  2047.  
  2048. getChkconfigScriptContents_autodl() {
  2049. getChkconfigScriptContents "$AUTODL_STARTUP_DESC"
  2050. }
  2051.  
  2052. # LSB style script, also supports chkconfig
  2053. # $1 = user name
  2054. # $2 = service name
  2055. getLsbStartupHeader_autodl() {
  2056. local USER="$1"
  2057. local STARTUPNAME="$2"
  2058. cat << EOF
  2059. $(getChkconfigScriptContents_autodl)
  2060. $(getLsbStartupScriptContents "$STARTUPNAME" "$AUTODL_STARTUP_DESC")
  2061.  
  2062. $(getCommonStartupScriptContents_autodl "$USER" "$STARTUPNAME")
  2063. EOF
  2064. }
  2065.  
  2066. installService_mandriva() {
  2067. local serviceName="$1"
  2068. local headerCommand="$2"
  2069. installService_chkconfig1 $serviceName
  2070. cat > "$CHKCONFIG_SERVICE_FILE" << EOF
  2071. #!/bin/bash
  2072. $(eval $headerCommand)
  2073.  
  2074. . /etc/rc.d/init.d/functions
  2075.  
  2076. v_startIt() {
  2077. gprintf "Starting %s:" "\$NAME"
  2078. startIt && success "startup" || failure "startup"
  2079. echo
  2080. }
  2081.  
  2082. v_stopIt() {
  2083. gprintf "Stopping %s:" "\$NAME"
  2084. stopIt && success "stop" || failure "stop"
  2085. echo
  2086. }
  2087.  
  2088. $(getLsbStartupFooter "$CHKCONFIG_LOCK_FILE")
  2089. EOF
  2090. [ $? -eq 0 ] || errorExit "Could not write to file $CHKCONFIG_SERVICE_FILE. Run this script as root."
  2091. installService_chkconfig2
  2092. }
  2093.  
  2094. installService_mandriva_autodl() {
  2095. local user=$1
  2096. installService_mandriva autodl_$user "getLsbStartupHeader_autodl \"$user\" \"\$CHKCONFIG_SERVICE_NAME\""
  2097. }
  2098.  
  2099. installService_mandriva_phpcgi() {
  2100. installService_mandriva phpcgi getLsbStartupHeader_phpcgi
  2101. }
  2102.  
  2103. installService_mandriva_nginx() {
  2104. installService_mandriva nginx getLsbStartupHeader_nginx
  2105. }
  2106.  
  2107. installService_mandriva_lighttpd() {
  2108. installService_mandriva lighttpd getLsbStartupHeader_lighttpd
  2109. }
  2110.  
  2111. installService_gentoo() {
  2112. local scriptName="$1"
  2113. local desc="$2"
  2114. local headerCommand="$3"
  2115. local serviceFile="/etc/init.d/$scriptName"
  2116.  
  2117. cat > "$serviceFile" << EOF
  2118. #!/sbin/runscript
  2119.  
  2120. name=$scriptName
  2121. description="$desc"
  2122.  
  2123. depend() {
  2124. need localmount
  2125. need net
  2126. }
  2127.  
  2128. $(eval $headerCommand)
  2129.  
  2130. start() {
  2131. ebegin "Starting \$name"
  2132. startIt
  2133. eend \$?
  2134. }
  2135.  
  2136. stop() {
  2137. ebegin "Stopping \$name"
  2138. stopIt
  2139. eend \$?
  2140. }
  2141.  
  2142. status() {
  2143. if isStarted; then
  2144. einfo "status: started"
  2145. return 0
  2146. else
  2147. einfo "status: stopped"
  2148. return 1
  2149. fi
  2150. }
  2151. EOF
  2152. [ $? -eq 0 ] || errorExit "Could not write to file $serviceFile. Run this script as root."
  2153. chmod +x "$serviceFile"
  2154. rc-update add $scriptName default || errorExit "Could not add service $scriptName"
  2155. $serviceFile restart
  2156. }
  2157.  
  2158. installService_gentoo_autodl() {
  2159. local user="$1"
  2160. installService_gentoo autodl_$user "$AUTODL_STARTUP_DESC" "getCommonStartupScriptContents_autodl \"$user\" \"\$scriptName\""
  2161. }
  2162.  
  2163. installService_gentoo_phpcgi() {
  2164. installService_gentoo phpcgi "$PHPCGI_STARTUP_DESC" "getCommonStartupScriptContents_phpcgi \"$WWW_USER\" \"$WWW_PHP_CGI\""
  2165. }
  2166.  
  2167. installService_gentoo_nginx() {
  2168. installService_gentoo nginx "$NGINX_STARTUP_DESC" "getCommonStartupScriptContents_nginx \"$NGINX_BIN\""
  2169. }
  2170.  
  2171. installService_gentoo_lighttpd() {
  2172. installService_gentoo lighttpd "$LIGHTTPD_STARTUP_DESC" "getCommonStartupScriptContents_lighttpd \"$LIGHTTPD_BIN\""
  2173. }
  2174.  
  2175. installService_bsd_autodl() {
  2176. local user="$1"
  2177. local scriptName="$2"
  2178. local file="$3"
  2179.  
  2180. cat > "$file" << EOF
  2181. #!/bin/sh
  2182. # PROVIDE: autodl_$user
  2183. # REQUIRE: FILESYSTEMS NETWORKING
  2184. # KEYWORD: shutdown
  2185.  
  2186. . /etc/rc.subr
  2187.  
  2188. name=$scriptName
  2189. desc="$AUTODL_STARTUP_DESC"
  2190. start_cmd=v_startIt
  2191. stop_cmd=v_stopIt
  2192. restart_cmd=v_restartIt
  2193. reload_cmd=v_restartIt
  2194. status_cmd=v_showStatus
  2195. extra_commands="status"
  2196.  
  2197. v_startIt() {
  2198. echo -n "Starting \$NAME"
  2199. startIt && echo "." || echo ". ERROR."
  2200. }
  2201.  
  2202. v_stopIt() {
  2203. echo -n "Stopping \$NAME..."
  2204. stopIt && echo "done." || echo "ERROR."
  2205. }
  2206.  
  2207. $(getCommonStartupScriptContents_autodl "$user" "$scriptName")
  2208.  
  2209. load_rc_config \$name
  2210. run_rc_command "\$1"
  2211. EOF
  2212. [ $? -eq 0 ] || errorExit "Could not write to file $file. Run this script as root."
  2213. chmod +x "$file"
  2214. }
  2215.  
  2216. getCommonStartupScriptContents_simpleService() {
  2217. local USER="$1"
  2218. local BINPATH="$2"
  2219. local START_CMD="$3"
  2220. local PID_FILE="$4"
  2221. cat << EOF
  2222. USER=$USER
  2223. BINPATH="$BINPATH"
  2224. NAME=\${BINPATH##*/}
  2225. PID_FILE="$PID_FILE"
  2226.  
  2227. resetPath() {
  2228. PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:\$PATH"
  2229. }
  2230. resetPath
  2231.  
  2232. getPids() {
  2233. if [ -n "\$PID_FILE" ]; then
  2234. pids=
  2235. [ -f "\$PID_FILE" ] || return
  2236. local the_pids="\$(cat "\$PID_FILE" 2>/dev/null)"
  2237. for pid in \$the_pids; do
  2238. PS_FORMAT= LINES= COLUMNS= ps ax | grep -qE "^[ ]*\$pid[ ]" && pids="\$pids \$pid"
  2239. done
  2240. [ -z "\$pids" ] && rm -f "\$PID_FILE"
  2241. else
  2242. # ps uses the COLUMNS variable... Make sure it's off so we get the full path.
  2243. pids=\$(PS_FORMAT= LINES= COLUMNS= ps aux | grep -v grep | grep \$BINPATH | awk '{print \$2}')
  2244. fi
  2245. }
  2246.  
  2247. isStarted() {
  2248. getPids
  2249. [ -n "\$pids" ] && return 0
  2250. return 1
  2251. }
  2252.  
  2253. startIt() {
  2254. isStarted && return 0
  2255.  
  2256. if [ \$USER = root ]; then
  2257. $START_CMD
  2258. else
  2259. su - \$USER "-c $START_CMD"
  2260. fi
  2261. [ -n "\$PID_FILE" ] && sleep 2 # Allow it some time to create the pid file
  2262. if ! isStarted; then
  2263. for i in 1 2 3 4 5; do
  2264. sleep 1
  2265. isStarted && break
  2266. done
  2267. isStarted || return 1
  2268. fi
  2269.  
  2270. return 0
  2271. }
  2272.  
  2273. stopIt() {
  2274. isStarted || return 0
  2275.  
  2276. kill \$pids 2>/dev/null
  2277.  
  2278. for i in 0 1 2 3 4 5 6 7 8 9; do
  2279. isStarted || break
  2280. sleep 1
  2281. done
  2282.  
  2283. isStarted && kill -KILL \$pids 2>/dev/null
  2284.  
  2285. return 0
  2286. }
  2287.  
  2288. v_startIt() {
  2289. startIt
  2290. }
  2291.  
  2292. v_stopIt() {
  2293. stopIt
  2294. }
  2295.  
  2296. v_restartIt() {
  2297. v_stopIt
  2298. v_startIt
  2299. }
  2300.  
  2301. v_showStatus() {
  2302. if isStarted; then
  2303. echo "\$NAME is running."
  2304. else
  2305. echo "\$NAME is stopped."
  2306. fi
  2307. }
  2308. EOF
  2309. }
  2310.  
  2311. getCommonStartupScriptContents_phpcgi() {
  2312. [ -n "$PHPCGI_SOCKET_FILE" ] || errorExit "PHPCGI_SOCKET_FILE is not initialized"
  2313. getCommonStartupScriptContents_simpleService "$1" "$2" \
  2314. "PHP_FCGI_CHILDREN=5 PHP_FCGI_MAX_REQUESTS=125 \$BINPATH -q -b \"$PHPCGI_SOCKET_FILE\" &"
  2315. }
  2316.  
  2317. getLsbStartupHeader_phpcgi() {
  2318. getChkconfigScriptContents "$PHPCGI_STARTUP_DESC"
  2319. getLsbStartupScriptContents phpcgi "$PHPCGI_STARTUP_DESC"
  2320.  
  2321. getCommonStartupScriptContents_phpcgi "$WWW_USER" "$WWW_PHP_CGI"
  2322. }
  2323.  
  2324. getCommonStartupScriptContents_nginx() {
  2325. getCommonStartupScriptContents_simpleService "root" "$1" "\$BINPATH" "$NGINX_PID_FILE"
  2326. }
  2327.  
  2328. getLsbStartupHeader_nginx() {
  2329. getChkconfigScriptContents "$NGINX_STARTUP_DESC"
  2330. getLsbStartupScriptContents nginx "$NGINX_STARTUP_DESC"
  2331.  
  2332. getCommonStartupScriptContents_nginx "$NGINX_BIN"
  2333. }
  2334.  
  2335. getCommonStartupScriptContents_lighttpd() {
  2336. getCommonStartupScriptContents_simpleService "root" "$1" "\$BINPATH -f $LIGHTTPD_CONF 2>/dev/null" "$LIGHTTPD_PID_FILE"
  2337. }
  2338.  
  2339. getLsbStartupHeader_lighttpd() {
  2340. getChkconfigScriptContents "$LIGHTTPD_STARTUP_DESC"
  2341. getLsbStartupScriptContents lighttpd "$LIGHTTPD_STARTUP_DESC"
  2342.  
  2343. getCommonStartupScriptContents_lighttpd "$LIGHTTPD_BIN"
  2344. }
  2345.  
  2346. addLsbHeaderToStartupScript() {
  2347. local scriptPath="$1"
  2348. local provides="${2:-$scriptPath}"
  2349. local desc="${3:-$provides}"
  2350. [ -x "$scriptPath" ] || return
  2351. grep -qE '^### BEGIN INIT INFO' "$scriptPath" && return
  2352. ed -s "$scriptPath" > /dev/null 2>&1 << EOF
  2353. 1a
  2354. $(getLsbStartupScriptContents "$provides" "$desc")
  2355. .
  2356. w
  2357. q
  2358. EOF
  2359. }
  2360.  
  2361. installMissingPerlModules() {
  2362. detectMissingPerlModules
  2363. [ -z "$MISSING_PERL_MODULES" ] && return
  2364. cat << EOF
  2365. $CWARNING
  2366. The following Perl modules are still missing:
  2367. $MISSING_PERL_MODULES
  2368. I'll try to use the cpan script to install them.$CEND
  2369. EOF
  2370.  
  2371. # Some Perl modules will fail to build unless Test::More is installed
  2372. MISSING_PERL_MODULES="Test::More $MISSING_PERL_MODULES"
  2373.  
  2374. echo "${CMSG}Installing cpan and required build tools...$CEND"
  2375. installBuildTools
  2376. osHandler_$os installCpanTools
  2377. detectCpanBin
  2378. if [ -n "$CPAN" ]; then
  2379. $CPAN $MISSING_PERL_MODULES
  2380. else
  2381. local mods=
  2382. for mod in $MISSING_PERL_MODULES; do
  2383. [ -n "$mods" ] && mods="$mods,"
  2384. mods="$mods \"$mod\""
  2385. done
  2386. perl -MCPAN -e "CPAN::Shell->install($mods)"
  2387. fi
  2388.  
  2389. detectMissingPerlModules
  2390. [ -z "$MISSING_PERL_MODULES" ] && return
  2391. errorExit "CPAN somehow failed to install the missing Perl modules. Missing: $MISSING_PERL_MODULES"
  2392. }
  2393.  
  2394. osHandler_debian() {
  2395. case $1 in
  2396. init)
  2397. INSTALL="apt-get -y install"
  2398. FEATURES="service rtorrent apache nginx lighttpd vsftpd webmin"
  2399. BUILD_TOOLS="build-essential make file pkg-config libtool m4"
  2400. ;;
  2401. init2)
  2402. apt-get update
  2403. installProgram ed
  2404.  
  2405. # Make sure Debian 6 doesn't fail when adding new services. We need ed for this
  2406. # so run it after installing ed...
  2407. addLsbHeaderToStartupScript /etc/init.d/webmin "webmin" "webmin"
  2408. ;;
  2409. installTools)
  2410. PACKAGES=
  2411. addProgram irssi
  2412. addProgram mediainfo
  2413. addProgram git-core
  2414. addProgram svn subversion
  2415. addProgram wget
  2416. addProgram unzip
  2417. addProgram screen
  2418. installPackages
  2419. # Make sure subversion won't complain about invalid certs
  2420. $INSTALL ca-certificates
  2421. ;;
  2422. installAutodlTools)
  2423. PACKAGES=
  2424. addProgram perl
  2425. addPerlModule Archive::Zip libarchive-zip-perl
  2426. addPerlModule HTML::Parser libhtml-parser-perl
  2427. addPerlModule Digest::SHA1 libdigest-sha1-perl
  2428. installPackages
  2429.  
  2430. installPerlModule Net::SSLeay libnet-ssleay-perl
  2431. installPerlModule XML::LibXML libxml-libxml-perl
  2432. installPerlModule JSON::XS libjson-xs-perl
  2433. installPerlModule JSON libjson-perl
  2434. ;;
  2435. installCpanTools)
  2436. # Need to remove the old JSON or cpan may fail to build the modules
  2437. if echo "$OLD_PERL_MODULES" | grep -qE '(^| )JSON( |$)'; then
  2438. apt-get -y remove libjson-perl
  2439. fi
  2440.  
  2441. PACKAGES=
  2442. if echo "$MISSING_PERL_MODULES" | grep -q 'XML::LibXML'; then
  2443. PACKAGES="$PACKAGES libxml2 libxml2-dev zlib1g zlib1g-dev"
  2444. fi
  2445. if echo "$MISSING_PERL_MODULES" | grep -q 'Net::SSLeay'; then
  2446. # There's no libssl package
  2447. PACKAGES="$PACKAGES openssl libssl-dev zlib1g zlib1g-dev"
  2448. fi
  2449. installPackages
  2450. ;;
  2451. installRtorrentBuildTools)
  2452. PACKAGES="libsigc++-2.0-dev libssl-dev libncurses-dev"
  2453. if apt-cache search libcurl4-openssl-dev 2> /dev/null | grep -q 'libcurl4-openssl-dev'; then
  2454. PACKAGES="$PACKAGES libcurl4-openssl-dev"
  2455. else
  2456. PACKAGES="$PACKAGES libcurl3-openssl-dev"
  2457. fi
  2458. installPackages
  2459. ;;
  2460. installPhpModules)
  2461. installMissingPhp5Packages
  2462. ;;
  2463. _installService)
  2464. local serviceName="$2"
  2465. local headerCommand="$3"
  2466. local serviceFile=/etc/init.d/$serviceName
  2467. local lockFile=
  2468. cat > "$serviceFile" << EOF
  2469. #!/bin/sh
  2470. $(eval $headerCommand)
  2471.  
  2472. . /lib/lsb/init-functions
  2473.  
  2474. v_startIt() {
  2475. log_begin_msg "Starting \$NAME..."
  2476. startIt
  2477. log_end_msg \$?
  2478. }
  2479.  
  2480. v_stopIt() {
  2481. log_begin_msg "Stopping \$NAME..."
  2482. stopIt
  2483. log_end_msg \$?
  2484. }
  2485.  
  2486. $(getLsbStartupFooter "$lockFile")
  2487. EOF
  2488. [ $? -eq 0 ] || errorExit "Could not write to file $serviceFile. Run this script as root."
  2489. chmod +x "$serviceFile" || errorExit "Could not set +x bit, file $serviceFile."
  2490. update-rc.d $serviceName defaults || errorExit "Could not install service $serviceFile. Run this script as root."
  2491. invoke-rc.d $serviceName restart
  2492. ;;
  2493. installAutodlService)
  2494. local user=$2
  2495. osHandler_$os _installService autodl_$user "getLsbStartupHeader_autodl \"$user\" \"\$serviceName\""
  2496. ;;
  2497. _installCommonWebServerStuff)
  2498. # Also add some extra tools for ruTorrent and some of its plugins
  2499. PACKAGES="php5-cli gzip curl openssl logrotate"
  2500. installPackages
  2501. # Ubuntu 8 doesn't have php5-geoip
  2502. PACKAGES="php5-geoip"
  2503. installPackages
  2504. PACKAGES="unrar"
  2505. installPackages
  2506. ;;
  2507. installApache)
  2508. osHandler_$os _installCommonWebServerStuff
  2509. PACKAGES="apache2-mpm-prefork libapache2-mod-php5 php5 "
  2510. installPackages
  2511. PACKAGES="libapache2-mod-scgi"; installPackages
  2512.  
  2513. WWW_PHP_INI=/etc/php5/apache2/php.ini
  2514. APACHE_DIR=/etc/apache2
  2515. APACHE_SITE_NAME=rutorrent
  2516. APACHE_SCGI_FILE=$APACHE_DIR/mods-available/scgi.load
  2517. initializeApacheVars www-data www-data "$APACHE_DIR/sites-available"
  2518. apacheCommonInitialization "apache2-prefork-dev" /usr/lib/apache2/modules
  2519.  
  2520. a2enmod ssl || errorExit "Could not enable mod_ssl"
  2521. a2enmod scgi || errorExit "Could not enable mod_scgi"
  2522. # Ubuntu Server 6 doesn't come with this module
  2523. a2enmod auth_basic
  2524. a2dissite default
  2525. a2dissite default-ssl
  2526. a2ensite $APACHE_SITE_NAME || errorExit "Could not enable site"
  2527. if ! grep -qE "^[ ]*Listen.*[: ]$HTTPS_PORT\\>" "$APACHE_DIR/ports.conf"; then
  2528. echo "Listen $HTTPS_PORT" >> "$APACHE_DIR/ports.conf"
  2529. fi
  2530. resetWebServerPermissions
  2531. invoke-rc.d apache2 restart || errorExit "Could not start $INSTALL_WEB_SERVER"
  2532. ;;
  2533. restart_apache)
  2534. invoke-rc.d apache2 restart || errorExit "Could not start $INSTALL_WEB_SERVER"
  2535. ;;
  2536. installVsftpd)
  2537. installProgram vsftpd
  2538. updateVsftpdConf /etc/vsftpd.conf
  2539. invoke-rc.d vsftpd restart || errorExit "Could not restart vsftpd"
  2540. ;;
  2541. preNginxInstall)
  2542. WWW_PHP_INI=/etc/php5/cgi/php.ini
  2543. osHandler_$os _installCommonWebServerStuff
  2544. PACKAGES="libpcre3-dev libssl-dev zlib1g-dev php5-cgi"
  2545. installPackages
  2546.  
  2547. # Make sure it builds on Debian GNU/kFreeBSD 6.0.
  2548. if [ "$(uname -s)" != Linux ]; then
  2549. NGINX_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64"
  2550. fi
  2551. ;;
  2552. installPhpCgiService)
  2553. osHandler_$os _installService phpcgi getLsbStartupHeader_phpcgi
  2554. ;;
  2555. installNginxService)
  2556. osHandler_$os _installService nginx getLsbStartupHeader_nginx
  2557. ;;
  2558. restart_nginx)
  2559. invoke-rc.d phpcgi restart || errorExit "Could not start php-cgi"
  2560. invoke-rc.d nginx restart || errorExit "Could not start $INSTALL_WEB_SERVER"
  2561. ;;
  2562. preLighttpdInstall)
  2563. WWW_PHP_INI=/etc/php5/cgi/php.ini
  2564. osHandler_$os _installCommonWebServerStuff
  2565. PACKAGES="libpcre3-dev libssl-dev zlib1g-dev php5-cgi"
  2566. installPackages
  2567. ;;
  2568. installLighttpdService)
  2569. osHandler_$os _installService lighttpd getLsbStartupHeader_lighttpd
  2570. ;;
  2571. restart_lighttpd)
  2572. invoke-rc.d phpcgi restart || errorExit "Could not start php-cgi"
  2573. invoke-rc.d lighttpd restart || errorExit "Could not start $INSTALL_WEB_SERVER"
  2574. ;;
  2575. postWebminInstall)
  2576. addLsbHeaderToStartupScript /etc/init.d/webmin "webmin" "webmin"
  2577. ;;
  2578. *)
  2579. ;;
  2580. esac
  2581. }
  2582.  
  2583. osHandler_fedora() {
  2584. case $1 in
  2585. init)
  2586. INSTALL="yum -y install"
  2587. FEATURES="service rtorrent apache nginx lighttpd vsftpd webmin"
  2588. BUILD_TOOLS="gcc gcc-c++ make kernel-headers pkgconfig file libtool m4"
  2589. ;;
  2590. init2)
  2591. installProgram which
  2592. installProgram ed
  2593. ;;
  2594. installTools)
  2595. PACKAGES=
  2596. addProgram svn subversion
  2597. addProgram wget
  2598. addProgram unzip
  2599. addProgram screen
  2600. addProgram git
  2601. installPackages
  2602. ;;
  2603. installAutodlTools)
  2604. if grep -q "release 4[. ]" /etc/redhat-release; then
  2605. IRSSI_LOAD_PERL=y
  2606. fi
  2607. PACKAGES=
  2608. addProgram perl
  2609. addProgram irssi
  2610. addPerlModule Time::HiRes perl-Time-HiRes
  2611. addPerlModule Archive::Zip perl-Archive-Zip
  2612. addPerlModule Net::SSLeay perl-Net-SSLeay
  2613. addPerlModule HTML::Parser perl-HTML-Parser
  2614. addPerlModule XML::LibXML perl-XML-LibXML
  2615. addPerlModule Digest::SHA1 perl-Digest-SHA1
  2616. addPerlModule JSON::XS perl-JSON-XS
  2617. addPerlModule JSON perl-JSON
  2618. installPackages
  2619. ;;
  2620. installCpanTools)
  2621. # Need to remove the old JSON or cpan may fail to build the modules
  2622. if echo "$OLD_PERL_MODULES" | grep -qE '(^| )JSON( |$)'; then
  2623. yum -y remove perl-JSON
  2624. fi
  2625.  
  2626. # CentOS doesn't have 'perl-CPAN'. It's in the 'perl' package though.
  2627. PACKAGES="perl-CPAN"
  2628. if echo "$MISSING_PERL_MODULES" | grep -q 'XML::LibXML'; then
  2629. PACKAGES="$PACKAGES libxml2 libxml2-devel zlib zlib-devel"
  2630. fi
  2631. if echo "$MISSING_PERL_MODULES" | grep -q 'Net::SSLeay'; then
  2632. PACKAGES="$PACKAGES openssl openssl-devel zlib zlib-devel"
  2633. fi
  2634. installPackages
  2635. ;;
  2636. installRtorrentBuildTools)
  2637. # CentOS 5: curl-devel, no libsigc++20
  2638. # Fedora 14: libcurl-devel
  2639. PACKAGES="libsigc++20-devel ncurses-devel openssl-devel libcurl-devel curl-devel"
  2640. installPackages
  2641. ;;
  2642. installPhpModules)
  2643. ;;
  2644. _installService)
  2645. local serviceName="$2"
  2646. local headerCommand="$3"
  2647. installService_chkconfig1 $serviceName
  2648. cat > "$CHKCONFIG_SERVICE_FILE" << EOF
  2649. #!/bin/bash
  2650. $(eval $headerCommand)
  2651.  
  2652. . /etc/rc.d/init.d/functions
  2653.  
  2654. v_startIt() {
  2655. echo -n "Starting \$NAME: "
  2656. startIt && success || failure
  2657. echo
  2658. }
  2659.  
  2660. v_stopIt() {
  2661. echo -n "Stopping \$NAME: "
  2662. stopIt && success || failure
  2663. echo
  2664. }
  2665.  
  2666. $(getLsbStartupFooter "$CHKCONFIG_LOCK_FILE")
  2667. EOF
  2668. [ $? -eq 0 ] || errorExit "Could not write to file $CHKCONFIG_SERVICE_FILE. Run this script as root."
  2669. installService_chkconfig2
  2670. ;;
  2671. installAutodlService)
  2672. local user=$2
  2673. osHandler_$os _installService autodl_$user "getLsbStartupHeader_autodl \"$user\" \"\$CHKCONFIG_SERVICE_NAME\""
  2674. ;;
  2675. _installCommonWebServerStuff)
  2676. PACKAGE="php-cli gzip curl openssl unrar logrotate"
  2677. installPackages
  2678. # CentOS 4: will get an error about a php v4 dependency, so can't put it in above PACKAGE var
  2679. PACKAGES="php-pecl-geoip"
  2680. installPackages
  2681. ;;
  2682. installApache)
  2683. osHandler_$os _installCommonWebServerStuff
  2684. # Also add some extra tools for ruTorrent and some of its plugins
  2685. PACKAGES="httpd httpd-tools mod_ssl mod_scgi php"
  2686. installPackages
  2687.  
  2688. WWW_PHP_INI=/etc/php.ini
  2689. APACHE_DIR=/etc/httpd
  2690. local APACHE_CONF_D=$APACHE_DIR/conf.d
  2691. APACHE_SCGI_FILE=$APACHE_CONF_D/scgi.conf
  2692. initializeApacheVars apache apache "$APACHE_CONF_D"
  2693. apacheCommonInitialization "httpd-devel" $APACHE_DIR/modules
  2694.  
  2695. [ -f "$APACHE_CONF_D/welcome.conf" ] && mv -f "$APACHE_CONF_D/welcome.conf" "$APACHE_CONF_D/welcome.conf-bak"
  2696. # Remove an Apache warning by commenting out the default SSL VirtualHost
  2697. sed_i '/^<VirtualHost _default_:443>/,/^<\/VirtualHost>/s/^/#/' $APACHE_CONF_D/ssl.conf
  2698.  
  2699. resetWebServerPermissions
  2700. chkconfig httpd on
  2701. service httpd restart || errorExit "Could not start $INSTALL_WEB_SERVER"
  2702. ;;
  2703. restart_apache)
  2704. service httpd restart || errorExit "Could not start $INSTALL_WEB_SERVER"
  2705. ;;
  2706. installVsftpd)
  2707. installVsftpd_chkconfig /etc/vsftpd/vsftpd.conf
  2708. ;;
  2709. preNginxInstall)
  2710. WWW_PHP_INI=/etc/php.ini
  2711. osHandler_$os _installCommonWebServerStuff
  2712. PACKAGES="pcre-devel openssl-devel zlib-devel php-cgi"
  2713. installPackages
  2714. ;;
  2715. installPhpCgiService)
  2716. osHandler_$os _installService phpcgi getLsbStartupHeader_phpcgi
  2717. ;;
  2718. installNginxService)
  2719. osHandler_$os _installService nginx getLsbStartupHeader_nginx
  2720. ;;
  2721. restart_nginx)
  2722. service phpcgi restart || errorExit "Could not start php-cgi"
  2723. service nginx restart || errorExit "Could not start $INSTALL_WEB_SERVER"
  2724. ;;
  2725. preLighttpdInstall)
  2726. WWW_PHP_INI=/etc/php.ini
  2727. osHandler_$os _installCommonWebServerStuff
  2728. PACKAGES="pcre-devel openssl-devel zlib-devel php-cgi"
  2729. installPackages
  2730. ;;
  2731. installLighttpdService)
  2732. osHandler_$os _installService lighttpd getLsbStartupHeader_lighttpd
  2733. ;;
  2734. restart_lighttpd)
  2735. service phpcgi restart || errorExit "Could not start php-cgi"
  2736. service lighttpd restart || errorExit "Could not start $INSTALL_WEB_SERVER"
  2737. ;;
  2738. *)
  2739. ;;
  2740. esac
  2741. }
  2742.  
  2743. isWebServerRpcModule() {
  2744. ! arrayIsPresent rpc $RUTORRENT_PLUGINS && ! arrayIsPresent httprpc $RUTORRENT_PLUGINS && return 0
  2745. return 1
  2746. }
  2747.  
  2748. canInstallService() {
  2749. return $(arrayIsPresent service $FEATURES)
  2750. }
  2751.  
  2752. canInstallRtorrent() {
  2753. return $(arrayIsPresent rtorrent $FEATURES)
  2754. }
  2755.  
  2756. canInstallApache() {
  2757. return $(arrayIsPresent apache $FEATURES)
  2758. }
  2759.  
  2760. canInstallNginx() {
  2761. return $(arrayIsPresent nginx $FEATURES)
  2762. }
  2763.  
  2764. canInstallLighttpd() {
  2765. return $(arrayIsPresent lighttpd $FEATURES)
  2766. }
  2767.  
  2768. canInstallVsftpd() {
  2769. return $(arrayIsPresent vsftpd $FEATURES)
  2770. }
  2771.  
  2772. canInstallWebmin() {
  2773. return $(arrayIsPresent webmin $FEATURES)
  2774. }
  2775.  
  2776. getRequiredPrograms() {
  2777. REQUIRED_PROGRAMS="which svn wget unzip ed sed grep tar expr ps awk kill printf"
  2778.  
  2779. if [ "$INSTALL_AUTODL_IRSSI" = y ]; then
  2780. REQUIRED_PROGRAMS="$REQUIRED_PROGRAMS perl"
  2781.  
  2782. # NetBSD and DragonFly BSD don't compile Irssi with Perl support by default
  2783. [ "$IGNORE_IRSSI" != y ] && REQUIRED_PROGRAMS="$REQUIRED_PROGRAMS irssi"
  2784. fi
  2785. }
  2786.  
  2787. verifyInstalledPrograms() {
  2788. getRequiredPrograms
  2789.  
  2790. local MISSING_PROGRAMS=
  2791. for prog in $REQUIRED_PROGRAMS; do
  2792. local name=$prog
  2793. [ "$prog" = svn ] && name=subversion
  2794. isProgramInstalled "$prog" || MISSING_PROGRAMS="$MISSING_PROGRAMS $name"
  2795. done
  2796. [ -n "$MISSING_PROGRAMS" ] && errorExit "Can't continue. The following programs are not installed: $MISSING_PROGRAMS"
  2797. }
  2798.  
  2799. initPluginDirVar() {
  2800. AUTODL_IRSSI_PLUGIN_DIR="$RUTORRENT_BASE_PATH/plugins/autodl-irssi"
  2801. }
  2802.  
  2803. getRtorrentDirs() {
  2804. local user="$1"
  2805. getUserDir "$user"
  2806. RTORRENT_DOWNLOAD_DIR="$userDir/$RTORRENT_REL_DOWNLOAD_DIR"
  2807. RTORRENT_WATCH_DIR="$userDir/$RTORRENT_REL_WATCH_DIR"
  2808. RTORRENT_SESSION_DIR="$userDir/$RTORRENT_REL_SESSION_DIR"
  2809. }
  2810.  
  2811. getUserScgiSocketPath() {
  2812. local user="$1"
  2813. getRtorrentDirs "$user"
  2814. scgiSocketPath="$RTORRENT_SESSION_DIR/rpc.socket"
  2815. }
  2816.  
  2817. waitenter() {
  2818. local msg="${1-Press ENTER to continue...}"
  2819. echo -n "$CCYAN$msg$CEND"
  2820. read dummy
  2821. }
  2822.  
  2823. askQuestion() {
  2824. local question="$1"
  2825. local default="$2"
  2826.  
  2827. if [ -z "$default" ]; then
  2828. echo -n "$CQUESTION$question$CEND "
  2829. read answer
  2830. else
  2831. echo -n "$CQUESTION$question$CEND [$CGREEN$default$CEND] "
  2832. read answer
  2833. fi
  2834. if [ -z "$answer" ]; then
  2835. answer="$default"
  2836. fi
  2837. }
  2838.  
  2839. # Asks the user a question, and sets answer to y or n depending on the user's answer
  2840. askYesNo() {
  2841. local question="$1"
  2842. local default="$2"
  2843.  
  2844. while true; do
  2845. askQuestion "$question" "$default"
  2846. if echo "$answer" | grep -qiE '^y(es)?$'; then
  2847. answer=y
  2848. return 1
  2849. elif echo "$answer" | grep -qiE '^no?$'; then
  2850. answer=n
  2851. return 0
  2852. fi
  2853. done
  2854. }
  2855.  
  2856. askOsUser() {
  2857. local stopIfEmpty=${1:-n}
  2858. local user=
  2859. while true; do
  2860. askQuestion "Enter name of user:" ""
  2861. user="$answer"
  2862. [ -z "$user" ] && [ "$stopIfEmpty" = y ] && break
  2863. userExists "$user" && break
  2864.  
  2865. echo "${CWARNING}User $user does not exist.$CEND"
  2866. askYesNo "Do you want to create user $user?" "No"
  2867. [ "$answer" = n ] && continue
  2868.  
  2869. echo "${CMSG}Creating user $user.$CEND"
  2870. if ! useradd -m -s /bin/sh "$user"; then
  2871. echo "${CWARNING}Could not create user $user.$CEND"
  2872. continue
  2873. fi
  2874. echo "${CMSG}Enter the user's password:$CEND"
  2875. if ! passwd "$user"; then
  2876. echo "${CWARNING}Failed to set password.$CEND"
  2877. continue
  2878. fi
  2879. userExists "$user" && break
  2880. done
  2881. answer="$user"
  2882. }
  2883.  
  2884. # Adds another user to USERS
  2885. addUser() {
  2886. local osUser="$1"
  2887. local webUser="$2"
  2888. local autodlPassword=
  2889. local webpass=
  2890.  
  2891. if [ "$INSTALL_RUTORRENT" = y ] || [ "$USE_RUTORRENT_PLUGIN" = y ]; then
  2892. if ! canGeneratePasswords; then
  2893. cat << EOF
  2894. $CQUESTION
  2895. The password makes sure only you can change your autodl-irssi settings. This is
  2896. NOT your login password. Use any password, but each user should use a unique
  2897. password. The password is used by the PHP code to access autodl-irssi settings.
  2898. You don't need to remember this password. It can't contain any spaces or a
  2899. colon ':'.$CEND
  2900. EOF
  2901. while true; do
  2902. askQuestion "Enter the autodl-irssi password (this is not your login password):" ""
  2903. autodlPassword="$answer"
  2904. isValidPassword "$autodlPassword" && break
  2905. echo "${CWARNING}Invalid password. Try again.$CEND"
  2906. done
  2907. fi
  2908.  
  2909. if [ "$RUTORRENT_PASSWORD_PROTECTED" = y ]; then
  2910. while true; do
  2911. askQuestion "Enter your ruTorrent password:" ""
  2912. webpass="$answer"
  2913. isValidPassword "$webpass" && break
  2914. echo "${CWARNING}Invalid password. Try again.$CEND"
  2915. done
  2916. fi
  2917.  
  2918. USERS="$USERS $osUser:$autodlPassword:$webUser:$webpass"
  2919. else
  2920. USERS="$USERS $osUser"
  2921. fi
  2922. }
  2923.  
  2924. installUser() {
  2925. local userPluginDir="$1"
  2926. local osUser="$2"
  2927. local webUser="${3:-$osUser}"
  2928. local port="$4"
  2929. local autodlPassword="$5"
  2930.  
  2931. getUserGroup "$osUser"
  2932. getUserDir "$osUser"
  2933.  
  2934. cat << EOF
  2935.  
  2936. ========================= ${CGREEN}Installing autodl-irssi$CEND =========================
  2937. Use the ruTorrent plugin: $CGREEN$USE_RUTORRENT_PLUGIN$CEND
  2938. OS user: $CGREEN$osUser$CEND
  2939. EOF
  2940. if [ "$USE_RUTORRENT_PLUGIN" = y ]; then
  2941. [ "$RUTORRENT_PASSWORD_PROTECTED" = y ] && echo "ruTorrent user: $CGREEN$webUser$CEND"
  2942. echo "port: $CGREEN$port$CEND"
  2943. echo "password: $CGREEN$autodlPassword$CEND"
  2944. fi
  2945. cat << EOF
  2946. group: $CGREEN$group$CEND
  2947. home: $CGREEN$userDir$CEND
  2948.  
  2949. EOF
  2950. if [ "$USE_RUTORRENT_PLUGIN" = y ]; then
  2951. isValidPortNumber "$port" || errorExit "Invalid port number: $port"
  2952. isValidPassword "$autodlPassword" || errorExit "Invalid password: $autodlPassword"
  2953. isValidWebUser "$webUser" || errorExit "Invalid web user: $webUser"
  2954. fi
  2955.  
  2956. mkdir -p "$userDir/.irssi/scripts/autorun"
  2957. cd "$userDir/.irssi/scripts" || errorExit "Could not CD into user dir. Run the script as root."
  2958. echo "${CMSG}Downloading autodl-irssi.zip...$CEND"
  2959. if ! downloadFile autodl-irssi.zip "$AUTODL_IRSSI_ZIP_URL"; then
  2960. errorExit "Could not download autodl-irssi zip file"
  2961. fi
  2962. echo "${CMSG}Unpacking autodl-irssi...$CEND"
  2963. unzip -o autodl-irssi.zip > /dev/null || errorExit "Could not unpack autodl-irssi zip file"
  2964. rm -f autodl-irssi.zip
  2965. cp autodl-irssi.pl autorun/ || errorExit "Could not copy autodl-irssi.pl to Irssi autorun dir."
  2966. mkdir -p "$userDir/.autodl"
  2967. touch "$userDir/.autodl/autodl.cfg"
  2968. if ! [ -s "$userDir/.autodl/autodl.cfg" ]; then
  2969. [ "$INSTALL_RUTORRENT" = y ] && cat > "$userDir/.autodl/autodl.cfg" << EOF
  2970. [options]
  2971. upload-type = rtorrent
  2972. EOF
  2973. fi
  2974.  
  2975. if [ "$USE_RUTORRENT_PLUGIN" = y ]; then
  2976. if [ ! -d "$AUTODL_IRSSI_PLUGIN_DIR" ]; then
  2977. errorExit "The autodl-irssi ruTorrent plugin has not been installed. Install it."
  2978. fi
  2979.  
  2980. cat > "$userDir/.autodl/autodl2.cfg" << EOF
  2981. [options]
  2982. gui-server-port = $port
  2983. gui-server-password = $autodlPassword
  2984. EOF
  2985.  
  2986. rm -f "$AUTODL_IRSSI_PLUGIN_DIR/conf.php"
  2987. mkdir -p "$userPluginDir"
  2988. cat > "$userPluginDir/conf.php" << EOF
  2989. <?php
  2990. \$autodlPort = $port;
  2991. \$autodlPassword = "$autodlPassword";
  2992. ?>
  2993. EOF
  2994. [ $? -eq 0 ] || errorExit "Could not write to $userPluginDir/conf.php. Run this script as root."
  2995. # Only set perms to 0400 if the code knows the owner (web server owner) and will reset it
  2996. [ "$ISROOT" = y ] && [ "$INSTALL_RUTORRENT" = y ] && chmod 0400 "$userPluginDir/conf.php"
  2997. else
  2998. # Don't use the autodl-irssi ruTorrent plugin
  2999. : > "$userDir/.autodl/autodl2.cfg"
  3000. fi
  3001.  
  3002. # The Perl module isn't loaded by default
  3003. if [ "$IRSSI_LOAD_PERL" = y ]; then
  3004. if [ ! -f "$userDir/.irssi/startup" ] || ! grep -q 'load perl' "$userDir/.irssi/startup"; then
  3005. echo "load perl" >> "$userDir/.irssi/startup"
  3006. fi
  3007. fi
  3008.  
  3009. # Make sure we redownload the tracker files since the ones in the zip file are possibly
  3010. # old versions.
  3011. local autodlStateFile="$userDir/.autodl/AutodlState.xml"
  3012. [ -f "$autodlStateFile" ] && sed_i 'g/<trackers-version>/d' "$autodlStateFile"
  3013.  
  3014. resetOwner "$osUser" "$userDir/.autodl" "$userDir/.irssi"
  3015. chmod 0700 "$userDir/.autodl" "$userDir/.irssi"
  3016. }
  3017.  
  3018. getRutorrentUserConfDir() {
  3019. userConfDir="$RUTORRENT_BASE_PATH/conf/users/$webUser"
  3020. }
  3021.  
  3022. getRutorrentUserShareDir() {
  3023. userShareDir="$RUTORRENT_BASE_PATH/share/users/$webUser"
  3024. }
  3025.  
  3026. resetRutorrentUserPermissions() {
  3027. for packedUser in $USERS; do
  3028. extractPackedUser $packedUser
  3029. getRutorrentUserConfDir
  3030. getRutorrentUserShareDir
  3031. # Make sure only the web server and the user itself can access its share/conf dirs
  3032. chown $osUser:$WWW_GROUP "$userShareDir" "$userConfDir"
  3033. chmod 0770 "$userShareDir" "$userConfDir"
  3034. done
  3035. }
  3036.  
  3037. ############################################################################
  3038. #
  3039. # This is where we start
  3040. #
  3041. ############################################################################
  3042.  
  3043. SELINUX_ENABLED=n
  3044. isProgramInstalled selinuxenabled && selinuxenabled && SELINUX_ENABLED=y
  3045. echo "SELinux enabled: $SELINUX_ENABLED"
  3046.  
  3047. ISROOT=n
  3048. [ $(id -u) -eq 0 ] && ISROOT=y
  3049. echo "Is root user: $ISROOT"
  3050.  
  3051. if [ $# -gt 0 ]; then
  3052. parseCommandLine "$@"
  3053. INTERACTIVE=n
  3054. else
  3055. INTERACTIVE=y
  3056. fi
  3057.  
  3058. detectOs
  3059. cat << EOF
  3060. Detected OS: $CGREEN$os_long$CEND
  3061. Type: $CGREEN$os$CEND
  3062.  
  3063. Type sh $0 --help for all command line options.
  3064. EOF
  3065.  
  3066. osHandler_$os init
  3067.  
  3068. if [ "$INTERACTIVE" = y ]; then
  3069. if [ "$ISROOT" = n ]; then
  3070. cat << EOF
  3071. $CRED
  3072. You're not the root user! This install script may fail if you're not the root
  3073. user. To start it as the root user do one of the following:
  3074.  
  3075. Ubuntu and Ubuntu clones:
  3076. ${CGREEN}sudo sh $0$CRED
  3077.  
  3078. Any other OS:
  3079. ${CGREEN}su
  3080. sh $0$CRED
  3081. $CEND
  3082. EOF
  3083. waitenter "Press Ctrl+C to exit or ENTER to continue..."
  3084. fi
  3085.  
  3086. cat << EOF
  3087. $CMSG
  3088. Press ENTER to use the default answer in [brackets].$CEND
  3089. EOF
  3090.  
  3091. webServers=
  3092. canInstallLighttpd && webServers="$webServers lighttpd"
  3093. canInstallNginx && webServers="$webServers nginx"
  3094. canInstallApache && webServers="$webServers apache"
  3095. if [ -n "$webServers" ]; then
  3096. cat << EOF
  3097. $CQUESTION
  3098. If you want to install ruTorrent you must install a web server, eg. Apache.
  3099. If you've already installed another web server, you must first uninstall it or
  3100. disable it. List of supported web servers:$CEND
  3101. EOF
  3102. canInstallLighttpd && echo " ${CGREEN}lighttpd$CEND ${CQUESTION}lighttpd web server (lightweight)$CEND"
  3103. canInstallNginx && echo " ${CGREEN}nginx$CEND ${CQUESTION}nginx web server (lightweight)$CEND"
  3104. canInstallApache && echo " ${CGREEN}apache$CEND ${CQUESTION}Apache web server$CEND"
  3105. echo " ${CGREEN}none$CEND ${CQUESTION}Don't install a web server$CEND"
  3106. while true; do
  3107. INSTALL_WEB_SERVER=
  3108. echo "${CQUESTION}Select one of:$CGREEN$webServers none$CEND"
  3109. askQuestion "Enter name of web server" "$(getFirst $webServers)"
  3110. [ "$answer" = none ] && break
  3111. INSTALL_WEB_SERVER="$answer"
  3112. arrayIsPresent $INSTALL_WEB_SERVER $webServers && break
  3113. done
  3114. if [ -n "$INSTALL_WEB_SERVER" ]; then
  3115. askYesNo "Do you want to install ruTorrent?" "Yes"
  3116. INSTALL_RUTORRENT="$answer"
  3117. else
  3118. INSTALL_RUTORRENT=n
  3119. fi
  3120. fi
  3121.  
  3122. if canInstallRtorrent; then
  3123. cat << EOF
  3124. $CQUESTION
  3125. ruTorrent requires a working rtorrent built with XML-RPC support.$CEND
  3126. EOF
  3127. askYesNo "Do you want to build rtorrent?" "Yes"
  3128. BUILD_RTORRENT="$answer"
  3129. fi
  3130.  
  3131. askYesNo "Do you want to install the autodl-irssi ruTorrent plugin?" "Yes"
  3132. USE_RUTORRENT_PLUGIN="$answer"
  3133.  
  3134. if [ "$INSTALL_RUTORRENT" = y ]; then
  3135. REINSTALL_RUTORRENT_PLUGIN=n
  3136. RUTORRENT_PASSWORD_PROTECTED=y
  3137. elif [ "$USE_RUTORRENT_PLUGIN" = y ]; then
  3138. echo ""
  3139. while true; do
  3140. echo "${CQUESTION}The ruTorrent www base path is where you installed ruTorrent.$CEND"
  3141. askQuestion "What is the ruTorrent www base path, eg. /var/www/rutorrent:" ""
  3142. RUTORRENT_BASE_PATH="$answer"
  3143. isValidRutorrentBasePath "$RUTORRENT_BASE_PATH" && break
  3144.  
  3145. echo "$CWARNING$RUTORRENT_BASE_PATH is not the ruTorrent base path.$CEND"
  3146. done
  3147.  
  3148. initPluginDirVar
  3149. if [ -d "$AUTODL_IRSSI_PLUGIN_DIR" ]; then
  3150. echo ""
  3151. askYesNo "The autodl-irssi ruTorrent plugin seems to be installed. Do you want to re-install it?" "No"
  3152. REINSTALL_RUTORRENT_PLUGIN="$answer"
  3153. else
  3154. REINSTALL_RUTORRENT_PLUGIN=n
  3155. fi
  3156.  
  3157. cat << EOF
  3158. $CQUESTION
  3159. To use more than one ruTorrent user, you must password protect ruTorrent.$CEND
  3160. EOF
  3161. askYesNo "Is ruTorrent password protected?" "No"
  3162. RUTORRENT_PASSWORD_PROTECTED="$answer"
  3163. else
  3164. RUTORRENT_PASSWORD_PROTECTED=n
  3165. fi
  3166.  
  3167. if [ "$USE_RUTORRENT_PLUGIN" = y ]; then
  3168. INSTALL_AUTODL_IRSSI=y
  3169. else
  3170. askYesNo "Do you want to install autodl-irssi?" "Yes"
  3171. INSTALL_AUTODL_IRSSI="$answer"
  3172. fi
  3173.  
  3174. if canInstallService && ([ "$INSTALL_AUTODL_IRSSI" = y ] || [ "$INSTALL_RUTORRENT" = y ]); then
  3175. cat << EOF
  3176. $CQUESTION
  3177. If you want to automatically start Irssi and rtorrent when the computer boots,
  3178. install the startup script.$CEND
  3179. EOF
  3180. askYesNo "Do you want to install the startup script?" "Yes"
  3181. INSTALL_STARTUP_SCRIPT="$answer"
  3182. fi
  3183.  
  3184. askUser=n
  3185. if [ "$USE_RUTORRENT_PLUGIN" = y ] || [ "$INSTALL_AUTODL_IRSSI" = y ] || \
  3186. [ "$INSTALL_STARTUP_SCRIPT" = y ] || [ "$INSTALL_RUTORRENT" = y ]; then
  3187. askUser=y
  3188. fi
  3189. if [ "$askUser" = y ]; then
  3190. if [ "$RUTORRENT_PASSWORD_PROTECTED" = n ]; then
  3191. cat << EOF
  3192. $CQUESTION
  3193. This is the user running rtorrent and/or Irssi.$CEND
  3194. ${CWARNING}Don't use the root user. Use a normal user!$CEND
  3195. EOF
  3196. askOsUser
  3197. addUser "$answer" ""
  3198. else
  3199. while true; do
  3200. cat << EOF
  3201. $CQUESTION
  3202. ===================== USER =====================
  3203. This is the user running rtorrent and/or Irssi.
  3204. ${CWARNING}Don't use the root user. Use a normal user!$CEND
  3205. ${CCYAN}Press ENTER to stop adding users.$CEND
  3206. EOF
  3207. askOsUser y
  3208. osUser="$answer"
  3209. [ -z "$osUser" ] && break
  3210.  
  3211. while true; do
  3212. cat << EOF
  3213. $CQUESTION
  3214. The ruTorrent user is the name you use to log in to ruTorrent.$CEND
  3215. EOF
  3216. askQuestion "Enter ruTorrent user:" "$osUser"
  3217. webUser="$answer"
  3218. isValidWebUser "$webUser" && break
  3219. echo "${CWARNING}Invalid web user name '$webUser'. Use only lower case letters."
  3220. done
  3221.  
  3222. addUser "$osUser" "$webUser"
  3223. done
  3224. fi
  3225. fi
  3226.  
  3227. if canInstallVsftpd; then
  3228. cat << EOF
  3229. $CQUESTION
  3230. vsftpd is a very secure FTP daemon.$CEND
  3231. EOF
  3232. askYesNo "Do you want to install vsftpd?" "Yes"
  3233. INSTALL_VSFTPD="$answer"
  3234.  
  3235. if [ "$INSTALL_VSFTPD" = y ]; then
  3236. askYesNo "Do you want to use encrypted FTP (FTPES)" "Yes"
  3237. USE_ENCRYPTED_FTP="$answer"
  3238.  
  3239. port=$DEFAULT_PORT_FTP
  3240. [ "$USE_ENCRYPTED_FTP" = y ] && port=$DEFAULT_PORT_FTPES
  3241. askQuestion "Enter FTP port number" "$port"
  3242. FTP_PORT="$answer"
  3243. fi
  3244. fi
  3245.  
  3246. if canInstallWebmin; then
  3247. cat << EOF
  3248. $CQUESTION
  3249. Webmin is a web-based administration tool for your OS.$CEND
  3250. EOF
  3251. askYesNo "Do you want to install Webmin?" "Yes"
  3252. INSTALL_WEBMIN="$answer"
  3253. fi
  3254. fi
  3255.  
  3256. cmdline="sh $0"
  3257. [ "$USE_RUTORRENT_PLUGIN" = y ] && cmdline="$cmdline -p"
  3258. [ "$REINSTALL_RUTORRENT_PLUGIN" = y ] && cmdline="$cmdline -i"
  3259. [ "$INSTALL_AUTODL_IRSSI" = y ] && cmdline="$cmdline -a"
  3260. for user in $USERS; do cmdline="$cmdline -u $user"; done
  3261. [ "$RUTORRENT_PASSWORD_PROTECTED" = y ] && cmdline="$cmdline -w"
  3262. [ -n "$RUTORRENT_BASE_PATH" ] && cmdline="$cmdline -r '$RUTORRENT_BASE_PATH'"
  3263. [ "$INSTALL_STARTUP_SCRIPT" = y ] && cmdline="$cmdline -s"
  3264. if [ -z "$INSTALL_WEB_SERVER" ]; then
  3265. :
  3266. elif [ "$INSTALL_WEB_SERVER" = apache ]; then
  3267. cmdline="$cmdline --apache"
  3268. elif [ "$INSTALL_WEB_SERVER" = nginx ]; then
  3269. cmdline="$cmdline --nginx"
  3270. elif [ "$INSTALL_WEB_SERVER" = lighttpd ]; then
  3271. cmdline="$cmdline --lighttpd"
  3272. else
  3273. errorExit "Invalid web server: $INSTALL_WEB_SERVER"
  3274. fi
  3275. [ "$BUILD_RTORRENT" = y ] && cmdline="$cmdline --rtorrent"
  3276. [ "$INSTALL_RUTORRENT" = y ] && cmdline="$cmdline --rutorrent"
  3277. [ "$INSTALL_VSFTPD" = y ] && cmdline="$cmdline --vsftpd"
  3278. [ -n "$FTP_PORT" ] && cmdline="$cmdline --ftp-port $FTP_PORT"
  3279. [ "$USE_ENCRYPTED_FTP" = y ] && cmdline="$cmdline --ftpes"
  3280. [ "$INSTALL_WEBMIN" = y ] && cmdline="$cmdline --webmin"
  3281.  
  3282. cat << EOF
  3283.  
  3284. You can execute this command as the root user (Ubuntu: use ${CRED}sudo$CEND):
  3285. $CGREEN$cmdline$CEND
  3286.  
  3287. Use the autodl-irssi ruTorrent plugin: $USE_RUTORRENT_PLUGIN
  3288. Re-install the autodl-irssi ruTorrent plugin: $REINSTALL_RUTORRENT_PLUGIN
  3289. Install autodl-irssi: $INSTALL_AUTODL_IRSSI
  3290. Users: $USERS
  3291. ruTorrent is password protected: $RUTORRENT_PASSWORD_PROTECTED
  3292. ruTorrent base path: $RUTORRENT_BASE_PATH
  3293. Install startup script: $INSTALL_STARTUP_SCRIPT
  3294. Install web server: $INSTALL_WEB_SERVER
  3295. Build rtorrent: $BUILD_RTORRENT
  3296. Install ruTorrent: $INSTALL_RUTORRENT
  3297. Install vsftpd: $INSTALL_VSFTPD
  3298. FTP port: $FTP_PORT
  3299. Use FTPES: $USE_ENCRYPTED_FTP
  3300. Install Webmin: $INSTALL_WEBMIN
  3301. EOF
  3302.  
  3303. if [ -n "$INSTALL_WEB_SERVER" ]; then
  3304. for port in $HTTP_PORT $HTTPS_PORT; do
  3305. isPortUsed $port || continue
  3306. cat << EOF
  3307. $CWARNING
  3308. Port $port is in use. If it's not used by $INSTALL_WEB_SERVER, you may need to disable or
  3309. uninstall that other web server before continuing.$CEND
  3310. EOF
  3311. done
  3312. fi
  3313.  
  3314. if [ "$INTERACTIVE" = y ]; then
  3315. echo ""
  3316. waitenter "Press Ctrl+C to cancel or ENTER to install."
  3317. fi
  3318.  
  3319. osHandler_$os init2
  3320. initUsers
  3321. initPluginDirVar
  3322.  
  3323. [ -n "$INSTALL_WEB_SERVER" ] || [ "$INSTALL_RUTORRENT" = y ] && RUTORRENT_PASSWORD_PROTECTED=y
  3324. [ "$INSTALL_RUTORRENT" = y ] && [ -z "$INSTALL_WEB_SERVER" ] && errorExit "You must install a web server if you want to install ruTorrent, eg. use --apache --rutorrent"
  3325. [ "$INSTALL_RUTORRENT" = y ] && REINSTALL_RUTORRENT_PLUGIN=n
  3326.  
  3327. [ "$BUILD_RTORRENT" = y ] && ! canInstallRtorrent && errorExit "Can't build rtorrent."
  3328. [ "$INSTALL_STARTUP_SCRIPT" = y ] && ! canInstallService && errorExit "Can't install startup script."
  3329. [ "$INSTALL_VSFTPD" = y ] && ! canInstallVsftpd && errorExit "Can't install vsftpd."
  3330. [ "$INSTALL_WEBMIN" = y ] && ! canInstallWebmin && errorExit "Can't install webmin."
  3331.  
  3332. if [ -z "$INSTALL_WEB_SERVER" ]; then
  3333. :
  3334. elif [ "$INSTALL_WEB_SERVER" = apache ]; then
  3335. canInstallApache || errorExit "Can't install Apache."
  3336. elif [ "$INSTALL_WEB_SERVER" = nginx ]; then
  3337. canInstallNginx || errorExit "Can't install nginx."
  3338. elif [ "$INSTALL_WEB_SERVER" = lighttpd ]; then
  3339. canInstallLighttpd || errorExit "Can't install lighttpd."
  3340. else
  3341. errorExit "Invalid web server: $INSTALL_WEB_SERVER"
  3342. fi
  3343.  
  3344. [ -n "$FTP_PORT" ] && [ "$FTP_PORT" -lt 1 -o "$FTP_PORT" -gt 65535 ] && errorExit "Invalid FTP port: $FTP_PORT"
  3345.  
  3346. if [ "$USE_RUTORRENT_PLUGIN" = y ]; then
  3347. if [ -z "$INSTALL_WEB_SERVER" ] && ! isValidRutorrentBasePath "$RUTORRENT_BASE_PATH"; then
  3348. errorExit "$RUTORRENT_BASE_PATH is not a valid ruTorrent base path."
  3349. fi
  3350. fi
  3351.  
  3352. if [ "$INSTALL_AUTODL_IRSSI" = y ]; then
  3353. cat << EOF
  3354. ${CMSG}Installing required tools and Perl modules...
  3355. Some Perl modules may not be present, but will be installed from CPAN.$CEND
  3356. EOF
  3357. else
  3358. echo "${CMSG}Installing required tools...$CEND"
  3359. fi
  3360. osHandler_$os installTools
  3361. setSvnOpts
  3362. [ "$INSTALL_AUTODL_IRSSI" = y ] && osHandler_$os installAutodlTools
  3363.  
  3364. verifyInstalledPrograms
  3365.  
  3366. [ "$INSTALL_AUTODL_IRSSI" = y ] && installMissingPerlModules
  3367.  
  3368. cat << EOF
  3369. $CMSG
  3370. All required programs and Perl modules are now installed. Ignore any errors you
  3371. saw.$CEND
  3372. EOF
  3373.  
  3374. INSTALLED_RTORRENT=n
  3375. if [ "$BUILD_RTORRENT" = y ]; then
  3376. cat << EOF
  3377. $CMSG
  3378. Building rtorrent and dependencies...$CEND
  3379. EOF
  3380. installRtorrent
  3381. INSTALLED_RTORRENT=y
  3382. fi
  3383.  
  3384. if [ -z "$INSTALL_WEB_SERVER" ]; then
  3385. :
  3386. elif [ "$INSTALL_WEB_SERVER" = apache ]; then
  3387. echo ""
  3388. echo "${CMSG}Installing Apache$CEND"
  3389. osHandler_$os installApache
  3390. installUnrar
  3391. elif [ "$INSTALL_WEB_SERVER" = nginx ]; then
  3392. echo ""
  3393. echo "${CMSG}Installing nginx$CEND"
  3394. installNginx
  3395. elif [ "$INSTALL_WEB_SERVER" = lighttpd ]; then
  3396. echo ""
  3397. echo "${CMSG}Installing lighttpd$CEND"
  3398. installLighttpd
  3399. else
  3400. errorExit "Invalid web server: $INSTALL_WEB_SERVER"
  3401. fi
  3402.  
  3403. if [ "$USE_RUTORRENT_PLUGIN" = y ]; then
  3404. if isProgramInstalled php; then
  3405. installMissingPhpModules
  3406. else
  3407. cat << EOF
  3408. $CWARNING
  3409. Could not find the php executable. PHP is not installed or the PHP CLI version
  3410. is not installed. The autodl-irssi ruTorrent plugin requires the following PHP
  3411. modules:
  3412. $CGREEN$REQUIRED_PHP_MODULES$CWARNING
  3413. They're normally installed and enabled by default. If not you will need to
  3414. install them (if needed) and then enable each one in php.ini, eg.
  3415. extension=MODULE.so and then restart your web server.$CEND
  3416. EOF
  3417. fi
  3418. fi
  3419.  
  3420. if [ "$INSTALL_RUTORRENT" = y ]; then
  3421. isProgramInstalled php || errorExit "php is not installed!"
  3422. verifyWebServerVars
  3423. echo ""
  3424. echo "${CMSG}Installing ruTorrent$CEND"
  3425. [ -d "$WWW_ROOT" ] || errorExit "Invalid web root: '$WWW_ROOT' (does not exist)"
  3426. RUTORRENT_DIRNAME=rutorrent
  3427.  
  3428. [ -f "$WWW_ROOT/index.html" ] || cat > "$WWW_ROOT/index.html" << EOF
  3429. <html><head><title>Root page</title></head><body>
  3430. <a href="$RUTORRENT_DIRNAME/">ruTorrent</a>
  3431. </body></html>
  3432. EOF
  3433.  
  3434. cd "$WWW_ROOT"
  3435. rm -rf "$RUTORRENT_DIRNAME"
  3436. tmpName=rutorrent-tmp
  3437. rm -rf $tmpName
  3438. if ! svn co $SVN_OPTS "$RUTORRENT_TRUNK_DIR" $tmpName >/dev/null; then
  3439. # Subversion failed. Try the official tar balls
  3440. mkdir -p $tmpName
  3441. cd $tmpName
  3442. downloadFile "$RUTORRENT_CORE_NAME" "$RUTORRENT_CORE_URL" "$RUTORRENT_CORE_URL2" || errorExit "Could not download ruTorrent."
  3443. downloadFile "$RUTORRENT_PLUGINS_NAME" "$RUTORRENT_PLUGINS_URL" "$RUTORRENT_PLUGINS_URL2" || errorExit "Could not download ruTorrent plugins."
  3444. for name in "$RUTORRENT_CORE_NAME" "$RUTORRENT_PLUGINS_NAME"; do
  3445. tar xzf "$name" || errorExit "Could not unpack $name"
  3446. rm -f "$name"
  3447. done
  3448. cd ..
  3449. fi
  3450. cd $tmpName
  3451. RUTORRENT_BASE_PATH="$WWW_ROOT/$RUTORRENT_DIRNAME"
  3452. initPluginDirVar
  3453. mv rutorrent/ "$RUTORRENT_BASE_PATH"
  3454. mkdir -p "$RUTORRENT_BASE_PATH/plugins"
  3455. for plugin in $RUTORRENT_PLUGINS; do
  3456. if [ -d "plugins/$plugin/" ]; then
  3457. echo "${CMSG}Installing ruTorrent plugin: $plugin$CEND..."
  3458. mv plugins/$plugin/ "$RUTORRENT_BASE_PATH/plugins/" || errorExit "Could not install plugin '$plugin'."
  3459. else
  3460. echo "${CWARNING}Can't install missing plugin $plugin!$CEND"
  3461. fi
  3462. done
  3463. cd ..
  3464. rm -rf $tmpName
  3465. cp "$RUTORRENT_BASE_PATH/favicon.ico" "$WWW_ROOT"
  3466.  
  3467. i=1
  3468. touch "$WWW_PASSWORD_FILE"
  3469. resetAuthPasswordFilePermissions
  3470. detectHtpasswd
  3471. for packedUser in $USERS; do
  3472. extractPackedUser $packedUser
  3473. getRutorrentUserConfDir
  3474. getRutorrentUserShareDir
  3475. getUserScgiSocketPath "$osUser"
  3476. getRtorrentDirs "$osUser"
  3477.  
  3478. # Create user's ruTorrent config.php
  3479. rpcMount="$(getUserRpcMount $i)"
  3480. mkdir -p "$userConfDir"
  3481.  
  3482. rutConfigFile="$userConfDir/config.php"
  3483. if [ "$SCGI_USE_UNIX_DOMAIN_SOCKET" = y ]; then
  3484. cat > "$rutConfigFile" << EOF
  3485. <?php
  3486. \$scgi_port = 0;
  3487. \$scgi_host = "unix://$scgiSocketPath";
  3488. \$XMLRPCMountPoint = "$rpcMount";
  3489. ?>
  3490. EOF
  3491. exitCode=$?
  3492. else
  3493. cat > "$rutConfigFile" << EOF
  3494. <?php
  3495. \$scgi_port = $scgiPort;
  3496. \$scgi_host = "$SCGI_HOST";
  3497. \$XMLRPCMountPoint = "$rpcMount";
  3498. ?>
  3499. EOF
  3500. exitCode=$?
  3501. fi
  3502. [ $exitCode -eq 0 ] || errorExit "Could not write to file $rutConfigFile"
  3503.  
  3504. # Create user's directory to prevent certain errors the first time ruTorrent is started
  3505. mkdir -p "$userShareDir/settings"
  3506. mkdir -p "$userShareDir/torrents"
  3507. chmod 0777 "$userShareDir/settings" "$userShareDir/torrents"
  3508.  
  3509. # Setup rtorrent
  3510. mkdir -p "$RTORRENT_DOWNLOAD_DIR"
  3511. mkdir -p "$RTORRENT_WATCH_DIR"
  3512. mkdir -p "$RTORRENT_SESSION_DIR"
  3513. rtorrentRc="$userDir/.rtorrent.rc"
  3514. [ -f "$rtorrentRc" ] && mv -f "$rtorrentRc" "$rtorrentRc-backup"
  3515. cat > "$rtorrentRc" << EOF
  3516. $(if [ "$SCGI_USE_UNIX_DOMAIN_SOCKET" = y ]; then
  3517. cat << EOF2
  3518. execute = {sh,-c,rm -f $scgiSocketPath}
  3519. scgi_local = $scgiSocketPath
  3520. execute = {sh,-c,chmod 0666 $scgiSocketPath}
  3521. EOF2
  3522. else
  3523. echo "scgi_port = $SCGI_HOST:$scgiPort"
  3524. fi)
  3525. encoding_list = UTF-8
  3526. system.umask.set = $DEFAULT_UMASK
  3527. port_range = $rtorrentPort-$rtorrentPort
  3528. port_random = no
  3529. check_hash = no
  3530. directory = $RTORRENT_DOWNLOAD_DIR
  3531. session = $RTORRENT_SESSION_DIR
  3532. encryption = allow_incoming, try_outgoing, enable_retry
  3533. schedule = watch_directory,1,1,"load_start=$RTORRENT_WATCH_DIR/*.torrent"
  3534. #schedule = untied_directory,5,5,"stop_untied=$RTORRENT_WATCH_DIR/*.torrent"
  3535. trackers.enable = 1
  3536. #min_peers = 40
  3537. #max_peers = 100
  3538. #min_peers_seed = 10
  3539. #max_peers_seed = 50
  3540. #max_uploads = 15
  3541. #download_rate = 0
  3542. #upload_rate = 0
  3543. use_udp_trackers = yes
  3544. dht = auto
  3545. dht_port = 6881
  3546. peer_exchange = yes
  3547. #hash_read_ahead = 10
  3548. #hash_interval = 100
  3549. #hash_max_tries = 10
  3550. EOF
  3551. PHP_BIN_PATH=$(which php 2> /dev/null)
  3552. COMMENT=
  3553. [ -x "$PHP_BIN_PATH" ] || COMMENT="#" PHP_BIN_PATH=/path/to/php
  3554. cat >> "$rtorrentRc" << EOF
  3555. ${COMMENT}execute = {sh,-c,$PHP_BIN_PATH $RUTORRENT_BASE_PATH/php/initplugins.php $webUser &}
  3556. EOF
  3557.  
  3558. # Add user to web server's password file
  3559. sed_i "g/^$webUser:/d" "$WWW_PASSWORD_FILE"
  3560. $htpasswd -b "$WWW_PASSWORD_FILE" "$webUser" "$webPass" || errorExit "Could not add user to password file"
  3561. resetAuthPasswordFilePermissions
  3562.  
  3563. resetOwner "$osUser" "$rtorrentRc" "$userDir" "$RTORRENT_DOWNLOAD_DIR" "$RTORRENT_WATCH_DIR" "$RTORRENT_SESSION_DIR"
  3564.  
  3565. # Required so some ruTorrent plugins work, eg. _getdir
  3566. chmod 0755 "$userDir"
  3567.  
  3568. # Protect some dirs and files, giving only the user and the web server
  3569. # access. We need to do this since we set perms to 0755 above, or if
  3570. # the perms already were 0755 to begin with.
  3571. if [ -n "$WWW_GROUP" ]; then
  3572. chmod 0600 "$rtorrentRc"
  3573. for dir in $RTORRENT_REL_DOWNLOAD_DIR $RTORRENT_REL_WATCH_DIR $RTORRENT_REL_SESSION_DIR; do
  3574. chown $osUser:$WWW_GROUP "$userDir/$dir"
  3575. chmod 0770 "$userDir/$dir"
  3576. done
  3577. fi
  3578.  
  3579. i=$(expr $i + 1)
  3580. done
  3581.  
  3582. [ "$CREATE_ONE_PASSWORD_FILE_PER_USER" = y ] && createOnePasswordFilePerUser
  3583. fi
  3584.  
  3585. if [ "$USE_RUTORRENT_PLUGIN" = y ]; then
  3586. [ -z "$RUTORRENT_BASE_PATH" ] && errorExit "Invalid ruTorrent base path."
  3587.  
  3588. [ "$REINSTALL_RUTORRENT_PLUGIN" = y ] && rm -rf "$AUTODL_IRSSI_PLUGIN_DIR"
  3589. mkdir -p "$RUTORRENT_BASE_PATH/plugins"
  3590. cd "$RUTORRENT_BASE_PATH/plugins"
  3591.  
  3592. if [ -d "$AUTODL_IRSSI_PLUGIN_DIR" ]; then
  3593. echo "${CMSG}The autodl-irssi ruTorrent plugin dir already exists. Updating it...$CEND"
  3594. cd "$AUTODL_IRSSI_PLUGIN_DIR"
  3595. if ! svn up $SVN_OPTS > /dev/null; then
  3596. errorExit "Could not update the autodl-irssi ruTorrent plugin. Run the script as root."
  3597. fi
  3598. else
  3599. echo "${CMSG}Downloading the autodl-irssi ruTorrent plugin...$CEND"
  3600. if ! git clone "$GIT_PATH_RUTORRENT_PLUGIN" autodl-irssi > /dev/null; then
  3601. errorExit "Could not check out the autodl-irssi ruTorrent plugin"
  3602. fi
  3603. fi
  3604. fi
  3605.  
  3606. if [ "$INSTALL_AUTODL_IRSSI" = y ]; then
  3607. if [ "$RUTORRENT_PASSWORD_PROTECTED" = y ]; then
  3608. for packedUser in $USERS; do
  3609. extractPackedUser $packedUser
  3610. installUser "$RUTORRENT_BASE_PATH/conf/users/$webUser/plugins/autodl-irssi" "$osUser" "$webUser" "$autodlPort" "$autodlPassword"
  3611. done
  3612. else
  3613. for packedUser in $USERS; do
  3614. extractPackedUser $packedUser
  3615. installUser "$AUTODL_IRSSI_PLUGIN_DIR" "$osUser" "$webUser" "$autodlPort" "$autodlPassword"
  3616. [ "$USE_RUTORRENT_PLUGIN" = y ] && break
  3617. done
  3618. fi
  3619. fi
  3620.  
  3621. if [ "$INSTALL_RUTORRENT" = y ]; then
  3622. verifyWebServerVars
  3623. resetWebServerPermissions
  3624. resetRutorrentUserPermissions
  3625. # Restart it just in case we enabled/installed PHP modules.
  3626. osHandler_$os restart_$INSTALL_WEB_SERVER
  3627. fi
  3628.  
  3629. if [ "$INSTALL_VSFTPD" = y ]; then
  3630. echo "${CMSG}Installing vsftpd...$CEND"
  3631. osHandler_$os installVsftpd
  3632. fi
  3633.  
  3634. if [ "$INSTALL_WEBMIN" = y ]; then
  3635. cd
  3636. rm -rf webmin-*/ webmin*.tar.gz
  3637. if ! downloadFile webmin.tar.gz "$WEBMIN_URL"; then
  3638. errorExit "Could not download Webmin."
  3639. fi
  3640. tar xzf webmin.tar.gz
  3641. rm -f webmin.tar.gz
  3642. cd webmin-*/ || errorExit "Could not CD to webmin dir"
  3643. osHandler_$os preWebminInstall
  3644. [ -x "setup.sh" ] || errorExit "Missing Webmin setup.sh file or not executable."
  3645. cat << EOF
  3646. $CMSG
  3647. Starting Webmin installer. Use another port than 10000, enable SSL, start webmin
  3648. at boot, and use a strong admin password.$CEND
  3649. $CWARNING
  3650. When it asks you if it should use SSL and whether it should start at boot,
  3651. type y.$CEND
  3652. EOF
  3653. ./setup.sh /usr/local/webmin
  3654. osHandler_$os postWebminInstall
  3655. cd
  3656. rm -rf webmin-*/
  3657. fi
  3658.  
  3659. if [ "$INSTALL_RUTORRENT" = y ]; then
  3660. # Some plugins will fail unless they can write to the /tmp directory
  3661. # We MUST do this AFTER installing Webmin since it will reset the perms!
  3662. chmod 1777 /tmp
  3663. fi
  3664.  
  3665. if [ "$INSTALL_STARTUP_SCRIPT" = y ]; then
  3666. for packedUser in $USERS; do
  3667. extractPackedUser $packedUser
  3668. echo "${CMSG}Installing service for user $osUser.$CEND"
  3669. osHandler_$os installAutodlService $osUser
  3670. done
  3671. fi
  3672.  
  3673. echo ""
  3674. echo "${CGREEN}================================= DONE =================================$CEND"
  3675. [ "$INSTALLED_RTORRENT" = y ] && echo "${CDGREEN}[+]$CEND ${CGREEN}Built and installed rtorrent with XML-RPC support$CEND"
  3676. [ -n "$INSTALL_WEB_SERVER" ] && echo "${CDGREEN}[+]$CEND ${CGREEN}Installed and configured web server ($INSTALL_WEB_SERVER)$CEND"
  3677. [ "$INSTALL_VSFTPD" = y ] && echo "${CDGREEN}[+]$CEND ${CGREEN}Installed and configured FTP server (vsftpd)$CEND"
  3678. [ "$INSTALL_RUTORRENT" = y ] && echo "${CDGREEN}[+]$CEND ${CGREEN}Installed ruTorrent$CEND"
  3679. [ "$USE_RUTORRENT_PLUGIN" = y ] && echo "${CDGREEN}[+]$CEND ${CGREEN}Installed/updated the autodl-irssi ruTorrent plugin$CEND"
  3680. [ "$INSTALL_AUTODL_IRSSI" = y ] && echo "${CDGREEN}[+]$CEND ${CGREEN}Installed autodl-irssi$CEND"
  3681. [ "$INSTALL_STARTUP_SCRIPT" = y ] && echo "${CDGREEN}[+]$CEND ${CGREEN}Installed and started Irssi and rtorrent service$CEND"
  3682. [ "$INSTALL_WEBMIN" = y ] && echo "${CDGREEN}[+]$CEND ${CGREEN}Installed Webmin$CEND"
  3683.  
  3684. if [ "$INSTALL_RUTORRENT" = y ]; then
  3685. getIpAddress
  3686. cat << EOF
  3687.  
  3688. ${CMSG}ruTorrent URLs.$CEND ${CWARNING}Verify that the IP address below is correct!$CEND
  3689. ${CMAGENTA}http://$OUR_IP_ADDRESS/$RUTORRENT_DIRNAME/$CEND
  3690. ${CMAGENTA}https://$OUR_IP_ADDRESS/$RUTORRENT_DIRNAME/$CEND
  3691. EOF
  3692. fi
  3693.  
  3694. if [ "$INSTALL_RUTORRENT" = y ]; then
  3695. cat << EOF
  3696.  
  3697. ${CMSG}rtorrent directories$CEND:
  3698. EOF
  3699. for packedUser in $USERS; do
  3700. extractPackedUser $packedUser
  3701. getRtorrentDirs "$osUser"
  3702. cat << EOF
  3703. ${CMSG}User $CGREEN$osUser$CEND:
  3704. ${CGREEN}Downloads$CEND : $CMAGENTA$RTORRENT_DOWNLOAD_DIR$CEND
  3705. ${CGREEN}Watch dir$CEND : $CMAGENTA$RTORRENT_WATCH_DIR$CEND
  3706. ${CGREEN}Session dir$CEND : $CMAGENTA$RTORRENT_SESSION_DIR$CEND
  3707. ${CGREEN}rtorrent port$CEND: $CMAGENTA$rtorrentPort$CEND
  3708. EOF
  3709. done
  3710. fi
  3711.  
  3712. if [ -n "$INSTALL_WEB_SERVER" ]; then
  3713. cat << EOF
  3714.  
  3715. ${CMSG}Web server info$CEND:
  3716. ${CGREEN}Web server root$CEND: ${CMAGENTA}$WWW_ROOT$CEND
  3717. ${CGREEN}ruTorrent dir$CEND : ${CMAGENTA}$RUTORRENT_BASE_PATH$CEND
  3718. EOF
  3719. fi
  3720.  
  3721. if [ "$INSTALL_VSFTPD" = y ]; then
  3722. getIpAddress
  3723. cat << EOF
  3724. $CMSG
  3725. To log in to the FTP server, use your $(uname -s) login name and password. I
  3726. guessed the IP address below. Make sure it's correct.$CEND
  3727. ${CGREEN}FTP IP address$CEND: ${CMAGENTA}$OUR_IP_ADDRESS$CEND
  3728. ${CGREEN}FTP port$CEND: ${CMAGENTA}$FTP_PORT$CEND
  3729. ${CGREEN}FTP server type$CEND: $CMAGENTA$FTP_SERVER_TYPE$CEND
  3730. EOF
  3731. fi
  3732.  
  3733. if [ "$INSTALL_WEBMIN" = y ]; then
  3734. getIpAddress
  3735.  
  3736. WEBMIN_PORT=
  3737. WEBMIN_SSL=
  3738. WEBMIN_NAME=
  3739. WEBMIN_CONFIG=/etc/webmin/miniserv.conf
  3740. WEBMIN_USERS=/etc/webmin/miniserv.users
  3741. if [ -f $WEBMIN_CONFIG ]; then
  3742. WEBMIN_PORT=$(grep '^port=' $WEBMIN_CONFIG | tail -n1 | sed -e 's/^port=\([0-9]*\).*/\1/')
  3743. WEBMIN_SSL=$(grep '^ssl=' $WEBMIN_CONFIG | tail -n1 | sed -e 's/^ssl=\([0-9]*\).*/\1/')
  3744. WEBMIN_NAME=$(head -n1 $WEBMIN_USERS | cut -d: -f1)
  3745. fi
  3746. WEBMIN_PORT=${WEBMIN_PORT:-UNKNOWN}
  3747. WEBMIN_NAME=${WEBMIN_NAME:-UNKNOWN}
  3748.  
  3749. cat << EOF
  3750. $CMSG
  3751. Webmin was installed. Port is $WEBMIN_PORT and the user is $WEBMIN_NAME.
  3752. ${CRED}Verify the IP address below.$CEND
  3753. EOF
  3754. if [ -z "$WEBMIN_SSL" ]; then
  3755. echo " ${CMAGENTA}http://$OUR_IP_ADDRESS:$WEBMIN_PORT/$CEND"
  3756. echo "${CMSG}or:$CEND"
  3757. echo " ${CMAGENTA}https://$OUR_IP_ADDRESS:$WEBMIN_PORT/$CEND"
  3758. elif [ "$WEBMIN_SSL" = 0 ]; then
  3759. echo " ${CMAGENTA}http://$OUR_IP_ADDRESS:$WEBMIN_PORT/$CEND"
  3760. else
  3761. echo " ${CMAGENTA}https://$OUR_IP_ADDRESS:$WEBMIN_PORT/$CEND"
  3762. fi
  3763. fi
  3764.  
  3765. if [ -n "$INSTALL_WEB_SERVER" ] || [ "$INSTALL_VSFTPD" = y ] || \
  3766. [ "$INSTALL_RUTORRENT" = y ] || [ "$USE_RUTORRENT_PLUGIN" = y ]; then
  3767. if [ "$SELINUX_ENABLED" = y ]; then
  3768. cat << EOF
  3769. $CWARNING
  3770. SELinux is enabled. It could cause some problems with the web server, vsftpd or
  3771. ruTorrent.
  3772. EOF
  3773. fi
  3774. fi
  3775.  
  3776. if [ "$CREATED_CERT_FILE" = y ]; then
  3777. cat << EOF
  3778. $CWARNING
  3779. A self-signed certificate was created. Your browser or FTP client will most
  3780. likely warn you about a non-trusted certificate.$CEND
  3781. EOF
  3782. fi
  3783.  
  3784. if [ "$USE_RUTORRENT_PLUGIN" = y ]; then
  3785. if isProgramInstalled php; then
  3786. detectMissingPhpModules
  3787. if [ -n "$MISSING_PHP_MODULES" ]; then
  3788. cat << EOF
  3789. $CWARNING
  3790. The following PHP modules seem to be missing. It's possible that the
  3791. autodl-irssi ruTorrent plugin won't work. Missing PHP modules:
  3792. $MISSING_PHP_MODULES$CEND
  3793. EOF
  3794. fi
  3795. else
  3796. cat << EOF
  3797. $CWARNING
  3798. Could not find the php executable. Make sure the following PHP modules are
  3799. enabled or the autodl-irssi ruTorrent plugin won't work:
  3800. $REQUIRED_PHP_MODULES$CEND
  3801. EOF
  3802. fi
  3803. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement