Advertisement
Guest User

Untitled

a guest
May 6th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 16.52 KB | None | 0 0
  1. Debian wheezy is advised for this guide
  2.  
  3. installs apache2/php5, rtorrent, rutorrent, autodl-irssi/plugin and proftpd.
  4. in putty just type..
  5. wget -O install.sh http://sprunge.us/OYHe
  6. then
  7. bash install.sh NewUsername NewPassword
  8. done
  9.  
  10. info on what it does..
  11.  
  12.  
  13. # by Dan39
  14. # installs apache2/php5, rtorrent, rutorrent, autodl-irssi/plugin, proftpd, mediainfo
  15.  
  16. # version 3.00
  17.  
  18.  
  19. error() {
  20. echo "$1"
  21. echo 'exiting'
  22. exit 1
  23. }
  24.  
  25. set -e
  26.  
  27. [ $USER = 'root' ] || error 'Must run script as root'
  28. [ 'x' = "x$1" ] && error 'Must supply 1st arg which will be ussername for system user and rutorrent user'
  29. [ 'x' = "x$2" ] && error 'Must supply 2nd arg which will be password used for rutorrent and ssh/ftp etc.'
  30.  
  31. ltv='0.13.4'
  32. rtv='0.9.4'
  33.  
  34. grep '^Debian' /etc/issue.net || error 'Only run this script on Debian!'
  35.  
  36. echo 'Creating user, please enter password for system user when it prompts'
  37. useradd -m -s /bin/bash "$1" || error 'Problem adding new user, maybe this user already exists?!'
  38. echo "$1:$2" | chpasswd
  39.  
  40. echo 'Running user script..'
  41. su -s /bin/bash "$1" <<'EOSCRIPT'
  42.  
  43. echo 'Creating directories for rtorrent'
  44. cd ~
  45. mkdir .session
  46. mkdir watch
  47. mkdir downloads
  48.  
  49. echo 'Writing .rtorrent.rc'
  50. cat > '.rtorrent.rc' <<'EOF'
  51. scgi_port = 127.0.0.1:5009
  52.  
  53. throttle.max_uploads.set = 100
  54. throttle.max_peers.normal.set = 500
  55.  
  56. throttle.global_down.max_rate.set_kb = 0
  57. throttle.global_up.max_rate.set_kb = 0
  58.  
  59. directory.default.set = ~/downloads
  60. session.path.set = ~/.session
  61.  
  62. schedule = low_diskspace,5,60,close_low_diskspace=100M
  63. schedule = watch_directory,5,5,load.start=~/watch/*.torrent
  64.  
  65. network.port_range.set = 57300-57400
  66. network.port_random.set = yes
  67.  
  68. trackers.use_udp.set = yes
  69. protocol.encryption.set = require_RC4
  70. dht.mode.set = off
  71. protocol.pex.set = no
  72. pieces.hash.on_completion.set = no
  73. EOF
  74.  
  75. echo 'Installing conrtab to start rtorrent/irssi on reboot'
  76. echo -e '@reboot /usr/bin/screen -fa -d -m -S rtorrent /usr/local/bin/rtorrent\n@reboot /usr/bin/screen -fa -d -m -S irssi /usr/bin/irssi' | crontab -
  77. EOSCRIPT
  78.  
  79. cd ~
  80. mkdir rtorrentbuild
  81. cd rtorrentbuild
  82.  
  83. echo 'Editing sources.list'
  84. grep -e 'non-free' -e 'contrib' /etc/apt/sources.list || sed -i 's/\(deb.*\)/\1 contrib non-free/' /etc/apt/sources.list
  85.  
  86. echo 'Configuring proftpd to run standalone'
  87. echo 'proftpd-basic shared/proftpd/inetd_or_standalone select standalone' | debconf-set-selections
  88.  
  89. echo 'Updating and installing packages'
  90. apt-get -qy update
  91. apt-get -qy build-dep xmlrpc-c
  92. apt-get -qy build-dep libtorrent
  93. apt-get -qy install git screen subversion libncurses5-dev libncursesw5-dev build-essential curl apache2 php5 php5-dev php5-geoip unzip unrar rar mktorrent ffmpeg proftpd
  94.  
  95. echo 'Editing proftpd configs'
  96. echo -e '\n<Global>\nAllowForeignAddress on\n</Global>' >> /etc/proftpd/proftpd.conf
  97. sed -i 's@#Include /etc/proftpd/tls.conf@Include /etc/proftpd/tls.conf@' /etc/proftpd/proftpd.conf
  98. sed -i 's/inetd/standalone/' /etc/proftpd/proftpd.conf
  99. cat > /etc/proftpd/tls.conf <<'EOF'
  100. #
  101. # Proftpd sample configuration for FTPS connections.
  102. #
  103. # Note that FTPS impose some limitations in NAT traversing.
  104. # See http://www.castaglia.org/proftpd/doc/contrib/ProFTPD-mini-HOWTO-TLS.html
  105. # for more information.
  106. #
  107.  
  108. <IfModule mod_tls.c>
  109. TLSEngine on
  110. TLSLog /var/log/proftpd/tls.log
  111. TLSProtocol SSLv23
  112. #
  113. # Server SSL certificate. You can generate a self-signed certificate using
  114. # a command like:
  115. #
  116. # openssl req -x509 -newkey rsa:1024 \
  117. # -keyout /etc/ssl/private/proftpd.key -out /etc/ssl/certs/proftpd.crt \
  118. # -nodes -days 365
  119. #
  120. # The proftpd.key file must be readable by root only. The other file can be
  121. # readable by anyone.
  122. #
  123. # chmod 0600 /etc/ssl/private/proftpd.key
  124. # chmod 0640 /etc/ssl/private/proftpd.key
  125. #
  126. #TLSRSACertificateFile /etc/ssl/certs/proftpd.crt
  127. #TLSRSACertificateKeyFile /etc/ssl/private/proftpd.key
  128. #
  129. TLSRSACertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
  130. TLSRSACertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
  131. #
  132. # CA the server trusts
  133. #TLSCACertificateFile /etc/ssl/certs/CA.pem
  134. # or avoid CA cert and be verbose
  135. #TLSRSACertificateFileSOptions NoCertRequest EnableDiags
  136. #
  137. # Per default drop connection if client tries to start a renegotiate
  138. # This is a fix for CVE-2009-3555 but could break some clients.
  139. #
  140. #TLSOptions AllowowClientRenegotiations
  141. #
  142. TLSOptions NoCertRequest NoSessionReuseRequired AllowClientRenegotiations EnableDiags
  143. #
  144. # Authenticate clients that want to use FTP over TLS?
  145. #
  146. TLSVerifyClient off
  147. #
  148. # Are clients required to use FTP over TLS when talking to this server?
  149. #
  150. TLSRequired off
  151. #
  152. # Allow SSL/TLS renegotiations when the client requests them, but
  153. # do not force the renegotations. Some clients do not support
  154. # SSL/TLS renegotiations; when mod_tls forces a renegotiation, these
  155. # clients will close the data connection, or there will be a timeout
  156. # on an idle data connection.
  157. #
  158. TLSRenegotiate required off
  159. </IfModule>
  160. EOF
  161.  
  162. echo 'Restarting proftpd'
  163. service proftpd restart
  164.  
  165. echo 'Downloading xmlrpc-c/libtorrent/rtorrent sources'
  166. wget "http://libtorrent.rakshasa.no/downloads/libtorrent-$ltv.tar.gz" "http://libtorrent.rakshasa.no/downloads/rtorrent-$rtv.tar.gz"
  167.  
  168. tar -xzf libtorrent-$ltv.tar.gz
  169. tar -xzf rtorrent-$rtv.tar.gz
  170.  
  171. svn checkout http://svn.code.sf.net/p/xmlrpc-c/code/advanced xmlrpc-c-code
  172.  
  173. echo 'Compiling/installing xmlrpc-c'
  174. cd xmlrpc-c-code
  175. ./configure
  176. make
  177. make install
  178. cd ..
  179.  
  180. echo 'Compiling/installing libtorrent'
  181. cd libtorrent-$ltv
  182. ./configure
  183. make
  184. make install
  185. cd ..
  186.  
  187. echo 'Compiling/installing rtorrent'
  188. cd rtorrent-$rtv
  189. ./configure --with-xmlrpc-c=/usr/local/bin/xmlrpc-c-config
  190. make
  191. make install
  192.  
  193. echo 'Running ldconfig since we installed to /usr/local/'
  194. ldconfig
  195.  
  196. cd ~
  197. rm -r rtorrentbuild
  198.  
  199. echo 'Writing apache2 site config to allow htaccess password setup'
  200. cat > /etc/apache2/sites-available/default <<'EOF'
  201. <VirtualHost *:80>
  202. ServerAdmin webmaster@localhost
  203.  
  204. DocumentRoot /var/www
  205. <Directory />
  206. Options FollowSymLinks
  207. AllowOverride None
  208. </Directory>
  209. <Directory /var/www/>
  210. Options Indexes FollowSymLinks MultiViews
  211. AllowOverride AuthConfig
  212. Order allow,deny
  213. allow from all
  214. </Directory>
  215.  
  216. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  217. <Directory "/usr/lib/cgi-bin">
  218. AllowOverride None
  219. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  220. Order allow,deny
  221. Allow from all
  222. </Directory>
  223.  
  224. ErrorLog ${APACHE_LOG_DIR}/error.log
  225.  
  226. # Possible values include: debug, info, notice, warn, error, crit,
  227. # alert, emerg.
  228. LogLevel warn
  229.  
  230. CustomLog ${APACHE_LOG_DIR}/access.log combined
  231. </VirtualHost>
  232. EOF
  233.  
  234.  
  235. cat > /etc/apache2/sites-available/default-ssl <<'EOF'
  236. <IfModule mod_ssl.c>
  237. <VirtualHost _default_:443>
  238. ServerAdmin webmaster@localhost
  239.  
  240. DocumentRoot /var/www
  241. <Directory />
  242. Options FollowSymLinks
  243. AllowOverride None
  244. </Directory>
  245. <Directory /var/www/>
  246. Options Indexes FollowSymLinks MultiViews
  247. AllowOverride AuthConfig
  248. Order allow,deny
  249. allow from all
  250. </Directory>
  251.  
  252. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  253. <Directory "/usr/lib/cgi-bin">
  254. AllowOverride None
  255. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  256. Order allow,deny
  257. Allow from all
  258. </Directory>
  259.  
  260. ErrorLog ${APACHE_LOG_DIR}/error.log
  261.  
  262. # Possible values include: debug, info, notice, warn, error, crit,
  263. # alert, emerg.
  264. LogLevel warn
  265.  
  266. CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
  267.  
  268. # SSL Engine Switch:
  269. # Enable/Disable SSL for this virtual host.
  270. SSLEngine on
  271.  
  272. # A self-signed (snakeoil) certificate can be created by installing
  273. # the ssl-cert package. See
  274. # /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
  275. # If both key and certificate are stored in the same file, only the
  276. # SSLCertificateFile directive is needed.
  277. SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
  278. SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
  279.  
  280. # Server Certificate Chain:
  281. # Point SSLCertificateChainFile at a file containing the
  282. # concatenation of PEM encoded CA certificates which form the
  283. # certificate chain for the server certificate. Alternatively
  284. # the referenced file can be the same as SSLCertificateFile
  285. # when the CA certificates are directly appended to the server
  286. # certificate for convinience.
  287. #SSLCertificateChainFile /etc/apache2/ssl.crt/server-ca.crt
  288.  
  289. # Certificate Authority (CA):
  290. # Set the CA certificate verification path where to find CA
  291. # certificates for client authentication or alternatively one
  292. # huge file containing all of them (file must be PEM encoded)
  293. # Note: Inside SSLCACertificatePath you need hash symlinks
  294. # to point to the certificate files. Use the provided
  295. # Makefile to update the hash symlinks after changes.
  296. #SSLCACertificatePath /etc/ssl/certs/
  297. #SSLCACertificateFile /etc/apache2/ssl.crt/ca-bundle.crt
  298.  
  299. # Certificate Revocation Lists (CRL):
  300. # Set the CA revocation path where to find CA CRLs for client
  301. # authentication or alternatively one huge file containing all
  302. # of them (file must be PEM encoded)
  303. # Note: Inside SSLCARevocationPath you need hash symlinks
  304. # to point to the certificate files. Use the provided
  305. # Makefile to update the hash symlinks after changes.
  306. #SSLCARevocationPath /etc/apache2/ssl.crl/
  307. #SSLCARevocationFile /etc/apache2/ssl.crl/ca-bundle.crl
  308.  
  309. # Client Authentication (Type):
  310. # Client certificate verification type and depth. Types are
  311. # none, optional, require and optional_no_ca. Depth is a
  312. # number which specifies how deeply to verify the certificate
  313. # issuer chain before deciding the certificate is not valid.
  314. #SSLVerifyClient require
  315. #SSLVerifyDepth 10
  316.  
  317. # Access Control:
  318. # With SSLRequire you can do per-directory access control based
  319. # on arbitrary complex boolean expressions containing server
  320. # variable checks and other lookup directives. The syntax is a
  321. # mixture between C and Perl. See the mod_ssl documentation
  322. # for more details.
  323. #<Location />
  324. #SSLRequire ( %{SSL_CIPHER} !~ m/^(EXP|NULL)/ \
  325. # and %{SSL_CLIENT_S_DN_O} eq "Snake Oil, Ltd." \
  326. # and %{SSL_CLIENT_S_DN_OU} in {"Staff", "CA", "Dev"} \
  327. # and %{TIME_WDAY} >= 1 and %{TIME_WDAY} <= 5 \
  328. # and %{TIME_HOUR} >= 8 and %{TIME_HOUR} <= 20 ) \
  329. # or %{REMOTE_ADDR} =~ m/^192\.76\.162\.[0-9]+$/
  330. #</Location>
  331.  
  332. # SSL Engine Options:
  333. # Set various options for the SSL engine.
  334. # o FakeBasicAuth:
  335. # Translate the client X.509 into a Basic Authorisation. This means that
  336. # the standard Auth/DBMAuth methods can be used for access control. The
  337. # user name is the `one line' version of the client's X.509 certificate.
  338. # Note that no password is obtained from the user. Every entry in the user
  339. # file needs this password: `xxj31ZMTZzkVA'.
  340. # o ExportCertData:
  341. # This exports two additional environment variables: SSL_CLIENT_CERT and
  342. # SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
  343. # server (always existing) and the client (only existing when client
  344. # authentication is used). This can be used to import the certificates
  345. # into CGI scripts.
  346. # o StdEnvVars:
  347. # This exports the standard SSL/TLS related `SSL_*' environment variables.
  348. # Per default this exportation is switched off for performance reasons,
  349. # because the extraction step is an expensive operation and is usually
  350. # useless for serving static content. So one usually enables the
  351. # exportation for CGI and SSI requests only.
  352. # o StrictRequire:
  353. # This denies access when "SSLRequireSSL" or "SSLRequire" applied even
  354. # under a "Satisfy any" situation, i.e. when it applies access is denied
  355. # and no other module can change it.
  356. # o OptRenegotiate:
  357. # This enables optimized SSL connection renegotiation handling when SSL
  358. # directives are used in per-directory context.
  359. #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
  360. <FilesMatch "\.(cgi|shtml|phtml|php)$">
  361. SSLOptions +StdEnvVars
  362. </FilesMatch>
  363. <Directory /usr/lib/cgi-bin>
  364. SSLOptions +StdEnvVars
  365. </Directory>
  366.  
  367. # SSL Protocol Adjustments:
  368. # The safe and default but still SSL/TLS standard compliant shutdown
  369. # approach is that mod_ssl sends the close notify alert but doesn't wait for
  370. # the close notify alert from client. When you need a different shutdown
  371. # approach you can use one of the following variables:
  372. # o ssl-unclean-shutdown:
  373. # This forces an unclean shutdown when the connection is closed, i.e. no
  374. # SSL close notify alert is send or allowed to received. This violates
  375. # the SSL/TLS standard but is needed for some brain-dead browsers. Use
  376. # this when you receive I/O errors because of the standard approach where
  377. # mod_ssl sends the close notify alert.
  378. # o ssl-accurate-shutdown:
  379. # This forces an accurate shutdown when the connection is closed, i.e. a
  380. # SSL close notify alert is send and mod_ssl waits for the close notify
  381. # alert of the client. This is 100% SSL/TLS standard compliant, but in
  382. # practice often causes hanging connections with brain-dead browsers. Use
  383. # this only for browsers where you know that their SSL implementation
  384. # works correctly.
  385. # Notice: Most problems of broken clients are also related to the HTTP
  386. # keep-alive facility, so you usually additionally want to disable
  387. # keep-alive for those clients, too. Use variable "nokeepalive" for this.
  388. # Similarly, one has to force some clients to use HTTP/1.0 to workaround
  389. # their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
  390. # "force-response-1.0" for this.
  391. BrowserMatch "MSIE [2-6]" \
  392. nokeepalive ssl-unclean-shutdown \
  393. downgrade-1.0 force-response-1.0
  394. # MSIE 7 and newer should be able to use keepalive
  395. BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
  396.  
  397. </VirtualHost>
  398. </IfModule>
  399. EOF
  400.  
  401. echo 'Enable ssl mod/site'
  402. a2enmod ssl
  403. a2ensite default-ssl
  404.  
  405. echo 'Restarting apache2'
  406. service apache2 restart
  407.  
  408. echo 'Downloading and unpacking rutorrent'
  409. cd /var/www
  410. wget 'http://dl.bintray.com/novik65/generic/rutorrent-3.6.tar.gz'
  411. tar -xzf rutorrent-3.6.tar.gz
  412. rm rutorrent-3.6.tar.gz
  413. cd rutorrent
  414.  
  415. echo 'Downloading and unpacking plugins'
  416. wget 'http://dl.bintray.com/novik65/generic/plugins-3.6.tar.gz'
  417. tar -xzf plugins-3.6.tar.gz
  418. rm plugins-3.6.tar.gz
  419. cd plugins
  420. echo 'Removing dumb plugins'
  421. rm -r extratio/ extsearch/ ipad/ show_peers_like_wtorrent/ rpc/ feeds/ retrackers/ throttle/ rutracker_check/ loginmgr/ check_port/
  422. echo 'Editing create plugin conf to use mktorrent'
  423. sed -i 's/$useExternal = false;/$useExternal = "mktorrent";/' create/conf.php
  424. cd ..
  425. echo 'Setting correct permissions for share directory'
  426. chown -R root:root ./
  427. chmod -R u=rwX,go=rX ./
  428. chown -R www-data:www-data share/
  429. find share/ -type d -exec chmod 777 {} \;
  430. find share/ -type f -exec chmod 666 {} \;
  431. echo 'Setting up user config'
  432. cd conf/users/
  433. mkdir -p "$1/plugins/autodl-irssi/"
  434. cd "$1"
  435. cp ../../config.php ./
  436. sed -i 's/scgi_port = 5000/scgi_port = 5009/' config.php
  437. sed -i "s_\$topDirectory = '/'_\$topDirectory = '/home/$1/'_" config.php
  438.  
  439. cd /var/www/rutorrent/
  440. echo 'Writing htaccess/htpasswd for user login'
  441. cat > .htaccess <<'EOF'
  442. AuthName "Restricted Area"
  443. AuthType Basic
  444. AuthUserFile /var/www/rutorrent/.htpasswd
  445. AuthGroupFile /dev/null
  446. require valid-user
  447. EOF
  448.  
  449. htpasswd -cb .htpasswd "$1" "$2"
  450.  
  451. echo 'Install autodl-irssi/rutorrent plugin'
  452. apt-get -qy install perl irssi irssi-scripts libdigest-sha-perl libarchive-zip-perl libnet-ssleay-perl libjson-perl libjson-xs-perl libxml-libxml-perl
  453.  
  454. pw=$(cat /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c17)
  455.  
  456. echo 'Running user script..'
  457. su -s /bin/bash "$1" <<EOSCRIPT
  458.  
  459. mkdir -p ~/.irssi/scripts/autorun
  460. cd ~/.irssi/scripts
  461. wget -O autodl-irssi.zip http://update.autodl-community.com/autodl-irssi-community.zip
  462. unzip -o autodl-irssi.zip
  463. rm autodl-irssi.zip
  464. cp autodl-irssi.pl autorun/
  465. mkdir ~/.autodl
  466. touch ~/.autodl/autodl.cfg
  467. cat > ~/.autodl/autodl2.cfg <<EOF
  468. [options]
  469. gui-server-port = 23760
  470. gui-server-password = $pw
  471. EOF
  472. EOSCRIPT
  473.  
  474. cd /var/www/rutorrent/plugins/
  475. git clone https://github.com/autodl-community/autodl-rutorrent.git autodl-irssi
  476. chown -R www-data:www-data autodl-irssi
  477. cd ../
  478. cat > "conf/users/$1/plugins/autodl-irssi/conf.php" <<EOF
  479. <?php
  480. \$autodlPort = 23760;
  481. \$autodlPassword = "$pw";
  482. ?>
  483. EOF
  484.  
  485. echo 'Installing mediainfo'
  486. wget 'http://mediaarea.net/download/binary/libzen0/0.4.29/libzen0_0.4.29-1_amd64.Debian_7.0.deb'
  487. dpkg -i libzen0_0.4.29-1_amd64.Debian_7.0.deb
  488. rm libzen0_0.4.29-1_amd64.Debian_7.0.deb
  489.  
  490. wget 'http://mediaarea.net/download/binary/libmediainfo0/0.7.69/libmediainfo0_0.7.69-1_amd64.Debian_7.0.deb'
  491. dpkg -i libmediainfo0_0.7.69-1_amd64.Debian_7.0.deb
  492. rm libmediainfo0_0.7.69-1_amd64.Debian_7.0.deb
  493.  
  494. wget 'http://mediaarea.net/download/binary/mediainfo/0.7.69/mediainfo_0.7.69-1_amd64.Debian_7.0.deb'
  495. dpkg -i mediainfo_0.7.69-1_amd64.Debian_7.0.deb
  496. rm mediainfo_0.7.69-1_amd64.Debian_7.0.deb
  497.  
  498. su -s /bin/bash -c "cd ~; screen -dmS rtorrent rtorrent; screen -dmS irssi irssi" "$1"
  499.  
  500.  
  501. thanks to Dan39 for his work.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement