forked from jackleaks/all-in-one-seedbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup
5392 lines (4817 loc) · 144 KB
/
setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is IRC Auto Downloader
#
# The Initial Developer of the Original Code is
# David Nilsson.
# Portions created by the Initial Developer are Copyright (C) 2010, 2011
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# ***** END LICENSE BLOCK *****
AUTODL_IRSSI_ZIP_URL="http://sourceforge.net/projects/autodl-irssi/files/autodl-irssi-v1.31.zip/download"
SVN_PATH_RUTORRENT_PLUGIN="https://svn.code.sf.net/p/autodl-irssi/code/trunk/rutorrent/autodl-irssi/"
WEBMIN_URL="http://www.webmin.com/download/webmin-current.tar.gz"
RUTORRENT_TRUNK_DIR="https://rutorrent.googlecode.com/svn/trunk"
# The official tarballs are tried if subversion fails.
RUTORRENT_VERSION="3.3"
RUTORRENT_CORE_NAME="rutorrent-$RUTORRENT_VERSION.tar.gz"
RUTORRENT_CORE_URL="http://rutorrent.googlecode.com/files/$RUTORRENT_CORE_NAME"
RUTORRENT_PLUGINS_NAME="plugins-$RUTORRENT_VERSION.tar.gz"
RUTORRENT_PLUGINS_URL="http://rutorrent.googlecode.com/files/$RUTORRENT_PLUGINS_NAME"
RUTORRENT_CORE_URL2="http://sourceforge.net/projects/autodl-irssi/files/inst-files/$RUTORRENT_CORE_NAME/download"
RUTORRENT_PLUGINS_URL2="http://sourceforge.net/projects/autodl-irssi/files/inst-files/$RUTORRENT_PLUGINS_NAME/download"
RUTORRENT_PLUGINS=
# These are the ruTorrent plugins that will get installed. To remove one, either
# remove the whole line or comment it (prepend a '#' to the start of the line).
# If the line starts with '#', the plugin is not installed.
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS _getdir"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS autotools"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS chunks"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS cookies"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS cpuload"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS create"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS data"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS datadir"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS diskspace"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS edit"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS erasedata"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS extsearch"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS feeds"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS geoip"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS httprpc"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS ipad"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS loginmgr"
#RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS mediainfo"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS ratio"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS retrackers"
#RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS rpc"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS rss"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS rssurlrewrite"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS scheduler"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS seedingtime"
#RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS show_peers_like_wtorrent"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS source"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS theme"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS throttle"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS tracklabels"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS trafic"
RUTORRENT_PLUGINS="$RUTORRENT_PLUGINS unpack"
# For building rtorrent
LIBCURL_NAME="curl-7.21.3"
LIBCURL_URL="http://curl.haxx.se/download/$LIBCURL_NAME.tar.gz"
SIGCPP20_NAME="libsigc++-2.2.8"
SIGCPP20_URL="http://ftp.gnome.org/pub/GNOME/sources/libsigc++/2.2/$SIGCPP20_NAME.tar.gz"
XMLRPC_SVN_DIR="http://svn.code.sf.net/p/xmlrpc-c/code/stable"
LIBTORRENT_VERSION="0.12.9"
LIBTORRENT_NAME="libtorrent-$LIBTORRENT_VERSION"
LIBTORRENT_URL="http://libtorrent.rakshasa.no/downloads/$LIBTORRENT_NAME.tar.gz"
LIBTORRENT_URL2="http://sourceforge.net/projects/autodl-irssi/files/inst-files/$LIBTORRENT_NAME.tar.gz/download"
RTORRENT_VERSION="0.8.9"
RTORRENT_NAME="rtorrent-$RTORRENT_VERSION"
RTORRENT_URL="http://libtorrent.rakshasa.no/downloads/$RTORRENT_NAME.tar.gz"
RTORRENT_URL2="http://sourceforge.net/projects/autodl-irssi/files/inst-files/$RTORRENT_NAME.tar.gz/download"
HTPASSWD_PY_SCRIPT_URL="http://trac.edgewall.org/export/10433/trunk/contrib/htpasswd.py"
HTPASSWD_PY_SCRIPT_URL2="http://sourceforge.net/projects/autodl-irssi/files/inst-files/htpasswd.py/download"
NGINX_NAME="nginx-1.0.5"
NGINX_URL="http://nginx.org/download/$NGINX_NAME.tar.gz"
LIGHTTPD_NAME="lighttpd-1.4.29"
LIGHTTPD_URL="http://download.lighttpd.net/lighttpd/releases-1.4.x/$LIGHTTPD_NAME.tar.gz"
MOD_SCGI_VERSION="1.14"
MOD_SCGI_URL="http://python.ca/scgi/releases/scgi-$MOD_SCGI_VERSION.tar.gz"
UNRAR_VERSION="4.0.7"
UNRAR_URL="http://www.rarlab.com/rar/unrarsrc-$UNRAR_VERSION.tar.gz"
# Dirs relative to user's home directory
RTORRENT_REL_DOWNLOAD_DIR="downloads"
RTORRENT_REL_WATCH_DIR="rtorrent/watch"
RTORRENT_REL_SESSION_DIR="rtorrent/session"
REQUIRED_PERL_MODULES="Time::HiRes XML::LibXML Archive::Zip Net::SSLeay HTML::Parser Digest::SHA1 JSON"
REQUIRED_PHP_MODULES="json xml sockets"
# If set to y, add 'load perl' to .irssi/startup
IRSSI_LOAD_PERL=n
IGNORE_IRSSI=n
# Start port. When we need a new port number, this port is incremented by one.
CURRENT_PORT=23875
DEFAULT_PORT_FTP=21
DEFAULT_PORT_FTPES=990
DEFAULT_UMASK=022
RPC_PREFIX=RPC
LSB_DEFAULT_START="2 3 4 5"
LSB_DEFAULT_STOP="0 1 6"
# Setting these to anything other than 80 and 443 may not work with Apache (since the
# code assumed it would always be 80 and 443).
HTTP_PORT=80
HTTPS_PORT=443
SCGI_HOST="127.0.0.1"
INTERACTIVE=n
USE_RUTORRENT_PLUGIN=n
REINSTALL_RUTORRENT_PLUGIN=n
INSTALL_AUTODL_IRSSI=n
RUTORRENT_PASSWORD_PROTECTED=n
USERS=
RUTORRENT_BASE_PATH=
INSTALL_STARTUP_SCRIPT=n
BUILD_RTORRENT=n
INSTALL_WEB_SERVER=
INSTALL_RUTORRENT=n
INSTALL_VSFTPD=n
FTP_PORT=
USE_ENCRYPTED_FTP=n
INSTALL_WEBMIN=n
USER_TIMEZONE=
RUTORRENT_SITE_REALM="My ruTorrent web site"
AUTODL_STARTUP_DESC="Start autodl-irssi and rtorrent"
PHPCGI_STARTUP_DESC="Start php-cgi"
NGINX_STARTUP_DESC="Start nginx"
LIGHTTPD_STARTUP_DESC="Start lighttpd"
PATH="$PATH:/usr/local/bin"
# Find an echo that supports -e
echo=echo
for cmd in echo /bin/echo; do
$cmd >/dev/null 2>&1 || continue
if ! $cmd -e "" | grep -qE '^-e'; then
echo=$cmd
break
fi
done
CSI=$($echo -e "\033[")
CEND="${CSI}0m"
CDGREEN="${CSI}32m"
CRED="${CSI}1;31m"
CGREEN="${CSI}1;32m"
CYELLOW="${CSI}1;33m"
CBLUE="${CSI}1;34m"
CMAGENTA="${CSI}1;35m"
CCYAN="${CSI}1;36m"
CQUESTION="$CMAGENTA"
CWARNING="$CRED"
CMSG="$CCYAN"
errorExit() {
cat << EOF
$CWARNING
***ERROR***
$*
***ERROR***
$CEND
Help forum: ${CGREEN}http://sourceforge.net/apps/phpbb/autodl-irssi/$CEND
EOF
exit 1
}
exitHelp() {
cat << EOF
autodl-irssi and ruTorrent plugin installer
sh $0 [options]
Options:
--rtorrent
Will build and install rtorrent, libtorrent and xmlrpc-c from source code.
--rtorrent-noexec-patch
Patch rtorrent to disallow remote users from executing code.
--apache
Install Apache web server.
--nginx
Install nginx web server.
--lighttpd
Install lighttpd web server.
--rutorrent
Install ruTorrent. Requires a web server, eg. --apache.
--vsftpd
Install vsftpd.
--ftpes
Use encrypted FTP (FTPES).
--ftp-port <port>
FTP server port.
--webmin
Install Webmin.
-p
--rutorrent-plugin
Use or install the autodl-irssi ruTorrent plugin. If it's already installed,
it will be updated (svn up), unless --reinstall-plugin option is used in
which case it will be re-installed.
-i
--reinstall-plugin
Re-install the autodl-irssi ruTorrent plugin if it's already installed.
-a
--install-autodl
Install autodl-irssi.
-u user:autodlPass:webUser:webPass
--user user:autodlPass:webUser:webPass
The $(uname -s) user, autodl-irssi password, ruTorrent user, ruTorrent password.
You can use more than one -u option. If autodlPassword is not set, a random
password will be used.
-w
--password-protected
Use this option if ruTorrent is password protected. It's required if you
want to use more than one ruTorrent user. Not needed if you install
ruTorrent.
-r PATH
--rutorrent-base-path PATH
Path to ruTorrent, eg. /var/www/rutorrent. Not needed if you install
ruTorrent.
-s
--install-startup-script
Install a startup script (service) which will start Irssi and rtorrent when
the computer boots.
-h
--help
Show this help text
Examples (as root user):
sh $0 --rtorrent --apache --rutorrent --vsftpd --ftpes --webmin -p -a -s -u user1::user1:pass1 -u user2::user2:pass2
Installs rtorrent, Apache, ruTorrent, vsftpd (encrypted), Webmin the
autodl-irssi plugin, autodl-irssi, installs a service (starting Irssi and
rtorrent) for both users.
sh $0 -p -a -u user::user:pass -r /var/www/rutorrent -s
Installs autodl-irssi + ruTorrent plugin for user 'user'. ruTorrent has not been
password protected. Also installs the startup script.
sh $0 -p -a -u user1::user1:pass1 -u user2::user2:pass2 -w -r /var/www/rutorrent -s
Installs autodl-irssi + ruTorrent plugin for users 'user1' and 'user2'.
ruTorrent has been password protected. Also installs the startup script.
sh $0 --rtorrent -a -u user1 -u user2 -u user3 -u user4 -s
Installs rtorrent, autodl-irssi and the startup script.
Help forum: http://sourceforge.net/apps/phpbb/autodl-irssi/
EOF
exit 1
}
parseCommandLine() {
while [ $# -gt 0 ]; do
local arg="$1"
shift
if [ "$arg" = "-p" ] || [ "$arg" = "--rutorrent-plugin" ]; then
USE_RUTORRENT_PLUGIN=y
elif [ "$arg" = "-i" ] || [ "$arg" = "--reinstall-plugin" ]; then
REINSTALL_RUTORRENT_PLUGIN=y
elif [ "$arg" = "-a" ] || [ "$arg" = "--install-autodl" ]; then
INSTALL_AUTODL_IRSSI=y
elif [ "$arg" = "-u" ] || [ "$arg" = "--user" ]; then
USERS="$USERS $1"
shift
elif [ "$arg" = "-w" ] || [ "$arg" = "--password-protected" ]; then
RUTORRENT_PASSWORD_PROTECTED=y
elif [ "$arg" = "-r" ] || [ "$arg" = "--rutorrent-base-path" ]; then
RUTORRENT_BASE_PATH="$1"
shift
elif [ "$arg" = "-s" ] || [ "$arg" = "--install-startup-script" ]; then
INSTALL_STARTUP_SCRIPT=y
elif [ "$arg" = "--rtorrent" ]; then
BUILD_RTORRENT=y
elif [ "$arg" = "--apache" ]; then
INSTALL_WEB_SERVER=apache
elif [ "$arg" = "--nginx" ]; then
INSTALL_WEB_SERVER=nginx
elif [ "$arg" = "--lighttpd" ]; then
INSTALL_WEB_SERVER=lighttpd
elif [ "$arg" = "--rutorrent" ]; then
INSTALL_RUTORRENT=y
elif [ "$arg" = "--vsftpd" ]; then
INSTALL_VSFTPD=y
elif [ "$arg" = "--ftpes" ]; then
USE_ENCRYPTED_FTP=y
elif [ "$arg" = "--ftp-port" ]; then
FTP_PORT="$1"
shift
elif [ "$arg" = "--webmin" ]; then
INSTALL_WEBMIN=y
else
exitHelp
fi
done
}
# Sets os and os_long to the OS type and OS name respectively
detectOs() {
local DISTRIB_ID=
local DISTRIB_DESCRIPTION=
if [ -f /etc/lsb-release ]; then
. /etc/lsb-release
fi
if [ -f /etc/fedora-release ]; then
os=fedora
os_long="$(cat /etc/fedora-release)"
# Must be before PCLinuxOS, Mandriva, and a whole bunch of other OS tests
elif [ -f /etc/unity-release ]; then
os=unity
os_long="$(cat /etc/unity-release)"
elif [ -f /etc/pclinuxos-release ]; then
os=pclinuxos
os_long="$(cat /etc/pclinuxos-release)"
elif [ "$DISTRIB_ID" = "Ubuntu" ]; then
os=debian
os_long="$DISTRIB_DESCRIPTION"
elif [ "$DISTRIB_ID" = "LinuxMint" ]; then
os=debian
os_long="$DISTRIB_DESCRIPTION"
# Must be before Debian
elif [ "$DISTRIB_ID" = "Peppermint" ]; then
os=debian
os_long="$DISTRIB_DESCRIPTION"
elif [ "$DISTRIB_ID" = "MEPIS" ]; then
os=debian
os_long="$DISTRIB_DESCRIPTION"
elif [ -f /etc/clearos-release ]; then
os=fedora
os_long="$(cat /etc/clearos-release)"
elif [ -f /etc/pardus-release ]; then
os=pardus
os_long="$(cat /etc/pardus-release)"
elif [ -f /etc/chakra-release ]; then
os=arch
os_long="Chakra $(cat /etc/chakra-release)"
elif [ -f /etc/frugalware-release ]; then
os=frugalware
os_long="$(cat /etc/frugalware-release)"
# Must test this before Gentoo
elif [ -f /etc/sabayon-release ]; then
os=sabayon
os_long="$(cat /etc/sabayon-release)"
elif [ -f /etc/arch-release ]; then
os=arch
os_long="Arch Linux"
elif [ -f /etc/gentoo-release ]; then
os=gentoo
os_long="$(cat /etc/gentoo-release)"
elif [ -f /etc/SuSE-release ]; then
os=opensuse
os_long="$(grep SUSE /etc/SuSE-release | head -n1)"
elif [ -f /etc/debian_version ]; then
os=debian
local prefix=
if ! uname -s | grep -q GNU; then
prefix="GNU/"
fi
os_long="Debian $prefix$(uname -s) $(cat /etc/debian_version)"
# Must test for mandriva before centos since it also has /etc/redhad-release
elif [ -f /etc/mandriva-release ]; then
os=mandriva
os_long="$(cat /etc/mandriva-release)"
elif [ -f /etc/redhat-release ]; then
os=fedora
os_long="$(cat /etc/redhat-release)"
elif [ -f /etc/vector-version ]; then
os=slaptget
os_long="VectorLinux $(cat /etc/vector-version)"
elif [ -f /etc/slackware-version ]; then
if isProgramInstalled slapt-get; then
os=slaptget
os_long="$(cat /etc/slackware-version)"
else
os=other
os_long="$(cat /etc/slackware-version)"
fi
elif [ $(uname -s) = "FreeBSD" ]; then
os=freebsd
os_long=FreeBSD
elif [ $(uname -s) = "DragonFly" ]; then
os=dragonfly
os_long="DragonFly BSD"
elif [ $(uname -s) = "OpenBSD" ]; then
os=openbsd
os_long=OpenBSD
elif [ $(uname -s) = "NetBSD" ]; then
os=netbsd
os_long=NetBSD
else
os=other
os_long="$(uname -s)"
fi
os_long="${os_long:-$(uname -s)}"
}
# In-place editing like sed -i but more portable...
sed_i() {
local cmd="$1"
local file="$2"
isProgramInstalled ed || errorExit "ed is not installed!"
local addr=","
echo "$cmd" | grep -qE '^/' && addr=
ed -s "$file" > /dev/null 2>&1 << EOF
$addr$cmd
w
q
EOF
}
getFirst() {
echo $1
}
# Returns true if $1 is one of $2..$n
arrayIsPresent() {
local val="$1"
shift
for v in "$@"; do
[ "$v" = "$val" ] && return 0
done
return 1
}
canGeneratePasswords() {
[ -c /dev/urandom ]
}
generatePassword() {
newPassword=$(cat /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c17)
}
isProgramInstalled() {
which "$1" > /dev/null 2>&1 && return 0
return 1
}
isPerlModuleInstalled() {
perl -M$1 -e '' > /dev/null 2>&1 && return 0
return 1
}
# Add $1 or $2 if it exists, to PACKAGES if program $1 isn't present
addProgram() {
isProgramInstalled $1 || PACKAGES="$PACKAGES ${2:-$1}"
}
# Add $2 to PACKAGES if perl module $1 isn't present
addPerlModule() {
isPerlModuleInstalled $1 || PACKAGES="$PACKAGES $2"
}
installPackages() {
[ -z "$INSTALL" ] && return
[ -z "$PACKAGES" ] && return
$INSTALL $PACKAGES
PACKAGES=
}
installPerlModule() {
isPerlModuleInstalled $1 || $INSTALL $2
}
installProgram() {
isProgramInstalled $1 || $INSTALL ${2:-$1}
}
installBuildTools() {
[ "$BUILD_TOOLS_INSTALLED" = y ] && return
PACKAGES="$BUILD_TOOLS"
installPackages
BUILD_TOOLS_INSTALLED=y
}
# Detects missing Perl modules and stores them in MISSING_PERL_MODULES
detectMissingPerlModules() {
OLD_PERL_MODULES=
MISSING_PERL_MODULES=
for module in $REQUIRED_PERL_MODULES; do
isPerlModuleInstalled $module || MISSING_PERL_MODULES="$MISSING_PERL_MODULES $module"
done
# Make sure the JSON module is new
if isPerlModuleInstalled JSON && ! perl -MJSON -e '&decode_json("{}")' > /dev/null 2>&1; then
echo "${CWARNING}Old JSON module is installed. Need to install from CPAN.$CEND"
MISSING_PERL_MODULES="$MISSING_PERL_MODULES JSON"
OLD_PERL_MODULES="$OLD_PERL_MODULES JSON"
fi
if echo "$MISSING_PERL_MODULES" | grep -wq JSON; then
MISSING_PERL_MODULES="JSON::XS $MISSING_PERL_MODULES"
fi
if echo "$MISSING_PERL_MODULES" | grep -q 'XML::LibXML'; then
# Sometimes the cpan script doesn't install the required dependencies
MISSING_PERL_MODULES="XML::NamespaceSupport XML::SAX $MISSING_PERL_MODULES"
fi
}
# Detect where cpan is installed and place the path in the CPAN variable.
# PCLinuxOS/Mandriva append the version number...
detectCpanBin() {
for file in $(which cpan 2> /dev/null) $(ls /usr/bin/cpan-* 2> /dev/null); do
if [ -x "$file" ]; then
CPAN="$file"
return
fi
done
isPerlModuleInstalled CPAN && return
errorExit "Could not find the cpan script or the CPAN Perl module. Can't install missing Perl modules."
}
isValidTzName() {
echo "$1" | LC_ALL=C grep -qE '^[A-Z][^/ ]*(/[A-Z][^/ ]*)?$' && return 0
return 1
}
detectTimeZone() {
[ -n "$USER_TIMEZONE" ] && return
local hash=
local hasher=
local files=
local zoneinfoPath=/usr/share/zoneinfo
[ -d "$zoneinfoPath" ] || return
if hasher=md5sum; isProgramInstalled $hasher || hasher=sha1sum; isProgramInstalled $hasher; then
hash=$($hasher /etc/localtime | awk '{print $1}')
files="$(find $zoneinfoPath -type f -print | xargs $hasher | grep -E "^$hash\\>" | awk '{print $2}')"
elif hasher=md5; isProgramInstalled $hasher || hasher=sha1; isProgramInstalled $hasher; then
hash=$($hasher /etc/localtime | sed -e 's/^.* = \([a-zA-Z0-9]*\)$/\1/')
files="$(find $zoneinfoPath -type f -print | xargs $hasher | grep -E "$hash\$" | sed -e 's/^[^ ]* (\([^)]*\)).*/\1/')"
else
return
fi
# Detect all possible timezone names
local timezones=
for path in $files; do
local tz="${path#$zoneinfoPath/}"
while true; do
isValidTzName "$tz" && break
local newTz="${tz#*/}"
[ "$newTz" = "$tz" ] && tz= && break
tz="$newTz"
done
isValidTzName "$tz" && timezones="$timezones $tz"
done
# Now find the ones PHP likes...
local okRegions="(Africa|America|Antarctica|Arctic|Asia|Atlantic|Australia|Europe|Indian|Pacific)"
for tz in $timezones; do
echo "$tz" | grep -qE "^$okRegions/" && USER_TIMEZONE="$tz" && return
done
# Return the first one we found
for tz in $timezones; do
USER_TIMEZONE="$tz"
return
done
}
getNumCpus() {
[ -n "$NUMCPUS" ] && return
[ -f /proc/cpuinfo ] && NUMCPUS=$(cat /proc/cpuinfo | grep '^processor' | wc -l) && return
isProgramInstalled sysctl && sysctl -n hw.ncpu | grep -qE '^[1-9][0-9]*$' && NUMCPUS=$(sysctl -n hw.ncpu) && return
NUMCPUS=1
}
# Appends $value to $varName in $file, creating the var if it doesn't exist. The
# value is not appended if it already exists.
appendFileStringVar() {
local file="$1"
local varName="$2"
local value="$3"
[ -f "$file" ] || errorExit "File '$file' does not exist"
local varLine=$(grep -E "^$varName=" "$file" | tail -n1)
if [ -z "$varLine" ]; then
echo "$varName=\"$value\"" >> "$file"
else
echo "$varLine" | grep -qE "[='\" ]$value(\"|'| |$)" && return
local q=
echo "$varLine" | grep -qE "^$varName='" && q="'"
echo "$varLine" | grep -qE "^$varName=\"" && q='"'
sed_i "s#^\\($varName=\\)$q\\(.*\\)$q#\\1\"\\2 $value\"#" "$file"
fi
}
# Set a variable in a script file to a new value. The variable is created if it does not exist
setScriptVariable() {
local file="$1"
local name=$2
local value="$3"
[ -f "$file" ] || errorExit "File does not exist: $file"
local newLine="$name=\"$value\""
if grep -qE "^$name=" $file; then
sed_i "s!^$name=.*\$!$newLine!" "$file"
else
echo "$newLine" >> "$file"
fi
}
userExists() {
id -rg "$1" > /dev/null 2>&1 && return 0
return 1
}
setSvnOpts() {
SVN_OPTS=
isProgramInstalled svn || return
# svn sometimes gives an error message 'broken pipe'. Ignore it.
if svn help co 2>/dev/null | grep -q 'non-interactive' && svn help co 2>/dev/null | grep -q 'trust-server-cert'; then
SVN_OPTS="--non-interactive --trust-server-cert"
fi
}
downloadFile() {
local filename="$1"
shift
for url in "$@"; do
for i in 1 2 3 4 5; do
wget --no-check-certificate -O "$filename" "$url" && return 0
done
done
return 1
}
buildMakeProgram() {
local url="$1"
local name="$2"
local builddir="$3"
local srcdir="$4"
local makefile="${5:-Makefile}"
buildStart
echo "${CMSG}Downloading $name source code...$CEND"
cd "$BUILD_DIR"
local filename="${url##*/}"
downloadFile "$filename" "$url" || errorExit "Could not download $name source code."
tar xzf "$filename"
srcdir="${srcdir:-${filename%.tar.gz}}"
cd "$srcdir/$builddir"
local make=${MAKE:-make}
echo "${CMSG}Building $name...$CEND"
$make -f $makefile all || errorExit "Could not build $name."
$make -f $makefile install || errorExit "Could not install $name."
echo "${CMSG}$name is now installed$CEND"
buildEnd
}
buildProgram() {
local prog="$1"
echo "${CMSG}Building $prog...$CEND"
./configure --prefix=$PREFIX $2 || errorExit "Could not configure $prog. Try again, or try logging out and in and try again."
getNumCpus
local make=${MAKE:-make}
local makeopts="-j$NUMCPUS"
$make $makeopts || $make || errorExit "Could not build $prog"
$make install || errorExit "Could not install $prog"
local ldsoconf=/etc/ld.so.conf
touch "$ldsoconf"
grep -qE "^$PREFIX/lib$" $ldsoconf || echo "$PREFIX/lib" >> $ldsoconf
ldconfig || errorExit "ldconfig failed"
echo "${CMSG}$prog is now installed.$CEND"
}
downloadAndBuild() {
local prog="$1"
local urls="$2"
local name="$3"
local configOptions="$4"
local patchUrl="$5"
cd "$BUILD_DIR"
echo "${CMSG}Downloading $prog source code...$CEND"
downloadFile "$name.tar.gz" $urls || errorExit "Could not download $prog source code."
tar xzf $name.tar.gz
if echo "$patchUrl" | grep '^[a-z]*://'; then
echo "${CMSG}Patching $prog...$CEND"
PACKAGES="patch"
installPackages
isProgramInstalled patch || errorExit "patch is not installed!"
downloadFile the.patch "$patchUrl" || errorExit "Could not download the patch file."
patch -p1 -d $name < the.patch || errorExit "Could not patch $prog."
elif [ -n "$patchUrl" ]; then
echo "${CMSG}Patching $prog...$CEND"
cd $name
eval $patchUrl
cd ..
fi
cd $name
buildProgram "$prog" "$configOptions"
}
checkoutAndBuild() {
local prog="$1"
local url="$2"
local configOptions="$3"
cd "$BUILD_DIR"
echo "${CMSG}Downloading $prog source code...$CEND"
svn export $SVN_OPTS "$url" "$prog" || errorExit "Could not download $prog source code."
cd "$prog"
buildProgram "$prog" "$configOptions"
}
buildStart() {
PREFIX=/usr/local
OLD_PATH="$PATH"
PATH="$PATH:$PREFIX/bin"
PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig
export PKG_CONFIG_PATH
BUILD_DIR="$(echo ~)/build-tmp"
rm -rf "$BUILD_DIR"
mkdir "$BUILD_DIR" || errorExit "Could not create build directory."
}
buildEnd() {
cd
rm -rf "$BUILD_DIR"
[ -n "$OLD_PATH" ] && PATH="$OLD_PATH"
unset OLD_PATH
unset PKG_CONFIG_PATH
}
buildRtorrent() {
installBuildTools
osHandler_$os installRtorrentBuildTools
isProgramInstalled pkg-config || errorExit "pkg-config is not installed."
# Minimum version is 7.15.4 but I had problems with 7.15.5 on CentOS. Set
# it to 7.18.0 (the version Ubuntu Server 8.04 is using).
if ! pkg-config --atleast-version=7.18.0 libcurl; then
downloadAndBuild "libcurl" "$LIBCURL_URL" "$LIBCURL_NAME" ""
# Prevent 'Unknown keyword 'URL' in ....' error
sed_i 's/^URL:/#URL:/' $PREFIX/lib/pkgconfig/libcurl.pc
fi
if ! pkg-config --exists sigc++-2.0; then
downloadAndBuild "sigc++-2.0" "$SIGCPP20_URL" "$SIGCPP20_NAME" ""
fi
checkoutAndBuild "xmlrpc-c" "$XMLRPC_SVN_DIR" "--disable-cplusplus"
downloadAndBuild "libtorrent" "$LIBTORRENT_URL $LIBTORRENT_URL2" "$LIBTORRENT_NAME" "" patchLibtorrent
downloadAndBuild "rtorrent" "$RTORRENT_URL $RTORRENT_URL2" "$RTORRENT_NAME" "--with-xmlrpc-c" ""
}
patchLibtorrent() {
# For gcc 4.6.0
ed -s "src/torrent/data/block_transfer.h" > /dev/null 2>&1 << EOF
/#define LIBTORRENT_BLOCK_TRANSFER_H
a
#include <stddef.h>
.
w
q
EOF
ed -s "src/data/memory_chunk.cc" > /dev/null 2>&1 << EOF
/#include "config.h"
a
#include <stddef.h>
.
w
q
EOF
}
installRtorrent() {
buildStart
buildRtorrent
buildEnd
}
installUnrar() {
isProgramInstalled unrar && return
installBuildTools
buildMakeProgram "$UNRAR_URL" "unrar" "" "unrar" "makefile.unix"
}
installModScgi() {
local modScgiFile="$1"
local modulesPath="$2"
[ -f "$modScgiFile" ] && errorExit "mod_scgi file already exists."
[ -d "$modulesPath" ] || errorExit "Apache modules path '$modulesPath' does not exist."
buildMakeProgram "$MOD_SCGI_URL" "mod_scgi" "apache2"
echo "LoadModule scgi_module $modulesPath/mod_scgi.so" > $modScgiFile
}
isPortUsed() {
local port="$1"
netstat -an | grep tcp | grep -w LISTEN | grep -qE "[.:]$port[ ]" && return 0
return 1
}
isValidIpAddress() {
# It's not 100% accurate ... ;)
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]?$'
}
getIpAddress() {
isValidIpAddress "$OUR_IP_ADDRESS" && return
echo "${CMSG}Detecting your IP address...$CEND"
isValidIpAddress "$OUR_IP_ADDRESS" || OUR_IP_ADDRESS=$(wget --no-check-certificate http://www.whatismyip.com/automation/n09230945.asp -O - -o /dev/null)
isValidIpAddress "$OUR_IP_ADDRESS" || OUR_IP_ADDRESS=$(ifconfig -a | grep "inet addr" | head -n1 | awk -F: '{print $2}' | awk '{print $1}')
isValidIpAddress "$OUR_IP_ADDRESS" || OUR_IP_ADDRESS="1.2.3.4"
}
getNewPortNumber() {
while true; do
newPortNumber=$CURRENT_PORT
CURRENT_PORT=$(expr $CURRENT_PORT + 1)
isValidPortNumber $newPortNumber || errorExit "Invalid port number. Change CURRENT_PORT."
isPortUsed $newPortNumber || break
echo "${CWARNING}Port $newPortNumber is in use, trying next port...$CEND"
done
}
# Returns true if it's a valid ruTorrent base path
isValidRutorrentBasePath() {
[ -n "$1" ] && [ -d "$1/conf" ]
}
isValidPassword() {
echo "$1" | grep -qE "^ " && return 1
echo "$1" | grep -qE " \$" && return 1
echo "$1" | grep -qE '^$' && return 1
echo "$1" | grep -q ':' && return 1
echo "'$1'" | grep -q ' ' && return 1
return 0
}
isValidPortNumber() {
echo "$1" | grep -qiE '^[0-9]+$' || return 1
echo "$1" | grep -qiE '[0-9][0-9][0-9][0-9][0-9][0-9]' && return 1
[ $1 -ge 1024 ] && [ $1 -le 65535 ]
}
isValidWebUser() {
[ -z "$1" ] && return 1
echo "$1" | LC_ALL=C grep -qE '[A-Z:]' && return 1
return 0
}
initUsers() {
local users=
for packedUser in $USERS; do
extractPackedUser $packedUser
if [ -z "$autodlPort" ]; then
getNewPortNumber
autodlPort=$newPortNumber
fi
if [ -z "$scgiPort" ]; then
getNewPortNumber
scgiPort=$newPortNumber
fi
if [ -z "$rtorrentPort" ]; then
getNewPortNumber
rtorrentPort=$newPortNumber
fi
if canGeneratePasswords; then
if [ -z "$autodlPassword" ]; then
generatePassword
autodlPassword="$newPassword"
fi
fi
users="$users $osUser:$autodlPassword:$webUser:$webPass:$autodlPort:$scgiPort:$rtorrentPort"
done
USERS="$users"
}
extractPackedUser() {
local packedUser="$1"
osUser="$(echo $packedUser | cut -d: -f1)"
autodlPassword="$(echo $packedUser | cut -d: -f2)"
webUser="$(echo $packedUser | cut -d: -f3)"
webPass="$(echo $packedUser | cut -d: -f4)"
autodlPort="$(echo $packedUser | cut -d: -f5)"
scgiPort="$(echo $packedUser | cut -d: -f6)"
rtorrentPort="$(echo $packedUser | cut -d: -f7)"
}
getUserGroup() {
local user="$1"
userExists "$user" || errorExit "The user '$user' does not exist."
group=$(grep -w $(id -rg $user) /etc/group | cut -d: -f1)
[ -z "$group" ] && group="$user"
}
getUserDir() {
local user="$1"
[ -z "$user" ] && errorExit "Invalid user (blank)."
userDir="$(eval echo ~$user)"
[ -d "$userDir" ] || errorExit "User $user's home directory does not exist."
}
resetOwner() {
local user="$1"
shift
if [ "$ISROOT" = y ]; then
getUserGroup "$user"
chown -R $user:$group "$@"
fi
}
# Updates MISSING_PHP_MODULES with all missing required PHP modules
detectMissingPhpModules() {
MISSING_PHP_MODULES=
local php=${WWW_PHP_CGI:-php}
for module in $REQUIRED_PHP_MODULES; do
$php -m 2> /dev/null | grep -wq $module || MISSING_PHP_MODULES="$MISSING_PHP_MODULES $module"
done
}
installMissingPhpPackages() {
PACKAGES=
for module in $MISSING_PHP_MODULES; do
PACKAGES="$PACKAGES php-$module"
done
installPackages
}
installMissingPhp5Packages() {
PACKAGES=
for module in $MISSING_PHP_MODULES; do
PACKAGES="$PACKAGES php5-$module"
done
installPackages
}