Bonjour

je voudrais vos avis sur mon script

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#!/bin/bash
 
  clear
 
    if [ $(id -u) -ne 0 ]
    then
       echo
       echo "This script must be run as root." 1>&2
       echo
       exit 1
    fi
 
    # demander nom et mot de passe
    read -p "Adding user now, please type your user name: " user
    read -s -p "Enter password: " pwd
    echo
 
    # ajout utilisateur
    useradd -m  -s /bin/bash "$user"
 
    # creation du mot de passe pour cet utilisateur
    echo "${user}:${pwd}" | chpasswd
 
 # gestionnaire de paquet
if [ "`dpkg --status aptitude | grep Status:`" == "Status: install ok installed" ]
then
        packetg="aptitude"
else
        packetg="apt-get"
fi
 
ip=$(ip addr | grep eth0 | grep inet | awk '{print $2}' | cut -d/ -f1)
 
if [ -z $homedir ]
then
        homedir="/home"
fi
 
 
if [ -z $wwwdir ]
then
        wwwdir="/var/www"
fi
 
if [ -z $apachedir ]
then
        apachedir="/etc/apache2"
fi
 
if [ -z $initd ]
then
        initd="/etc/init.d"
fi
 
##Log de l'instalation
exec 2>/$homedir/$user/log
 
# Ajoute des depots non-free
echo "deb http://ftp.fr.debian.org/debian/ wheezy main contrib non-free
deb-src http://ftp.fr.debian.org/debian/ wheezy main contrib non-free" >> /etc/apt/sources.list
 
# Installation des paquets vitaux
$packetg update
$packetg install -y  apache2 apache2-utils autoconf build-essential ca-certificates comerr-dev libapache2-mod-php5 libcloog-ppl-dev libcppunit-dev libcurl3 libcurl4-openssl-dev libncurses5-dev ncurses-base ncurses-term libterm-readline-gnu-perl libsigc++-2.0-dev libssl-dev libtool libxml2-dev ntp openssl patch libperl-dev php5 php5-cli php5-dev php5-fpm php5-curl php5-geoip php5-mcrypt php5-xmlrpc pkg-config python-scgi dtach ssl-cert subversion unrar zlib1g-dev pkg-config unzip htop irssi curl cfv rar zip ffmpeg mediainfo git screen perl libapache2-mod-scgi
 
##  Installation XMLRPC Libtorrent Rtorrent Plowshare
 
    # XMLRPC
 
    svn checkout http://svn.code.sf.net/p/xmlrpc-c/code/stable xmlrpc-c
    cd xmlrpc-c
    ./configure --prefix=/usr --enable-libxml2-backend --disable-libwww-client --disable-wininet-client --disable-abyss-server --disable-cgi-server
    make
    make install
    cd ..
    rm -rv xmlrpc-c
 
    # Libtorrent
 
    wget http://libtorrent.rakshasa.no/downloads/libtorrent-0.13.2.tar.gz
    tar -zxvf libtorrent-0.13.2.tar.gz
    cd libtorrent-0.13.2
    ./autogen.sh
    ./configure
    make
    make install
    cd ..
    rm -rv libtorrent-0.13.2*
 
    # Rtorrent
 
    wget http://libtorrent.rakshasa.no/downloads/rtorrent-0.9.2.tar.gz
    tar -zxvf rtorrent-0.9.2.tar.gz
    cd rtorrent-0.9.2
    ./autogen.sh
    ./configure --with-xmlrpc-c
    make
    make install
    ldconfig
    cd  ..
    rm -rv rtorrent-0.9.2*
 
# Plowshare
cd    /$homedir
    git clone https://code.google.com/p/plowshare/ plowshare4
    cd plowshare4
    make install
 
#------------Instalation de Rutorrent--------
#--------------------------------------------
 
cd $wwwdir/
svn checkout http://rutorrent.googlecode.com/svn/trunk/rutorrent
svn checkout http://rutorrent.googlecode.com/svn/trunk/plugins
 
find $wwwdir/rutorrent -depth -name plugins -type d -exec rm -rf '{}' \;
mv plugins rutorrent/
 
#-----Fichier Configuration Config.php--------
#---------------------------------------------
cat <<'EOF' > $wwwdir/rutorrent/conf/config.php
<?php
	// configuration parameters
 
	// for snoopy client
	@define('HTTP_USER_AGENT', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0', true);
	@define('HTTP_TIME_OUT', 30, true);	// in seconds
	@define('HTTP_USE_GZIP', true, true);
	$httpIP = null;				// IP string. Or null for any.
 
	@define('RPC_TIME_OUT', 5, true);	// in seconds
 
	@define('LOG_RPC_CALLS', false, true);
	@define('LOG_RPC_FAULTS', true, true);
 
	// for php
	@define('PHP_USE_GZIP', false, true);
	@define('PHP_GZIP_LEVEL', 2, true);
 
	$do_diagnostic = true;
	$log_file = '/tmp/rutorrent_errors.log';		// path to log file (comment or leave blank to disable logging)
 
	$saveUploadedTorrents = true;		// Save uploaded torrents to profile/torrents directory or not
	$overwriteUploadedTorrents = false;     // Overwrite existing uploaded torrents in profile/torrents directory or make unique name
 
	$topDirectory = '/home/@user@/downloads';			// Upper available directory. Absolute path with trail slash.
	$forbidUserSettings = false;
 
	$scgi_port = 5000;
	$scgi_host = "127.0.0.1";
 
	// For web->rtorrent link through unix domain socket
	// (scgi_local in rtorrent conf file), change variables
	// above to something like this:
	//
    //$scgi_port = 0;
	//$scgi_host = "unix:///tmp/rtorrent.sock";
 
	$XMLRPCMountPoint = "/RPC2";		// DO NOT DELETE THIS LINE!!! DO NOT COMMENT THIS LINE!!!
 
	$pathToExternals = array(
		"php"  => '/usr/bin/php',			// Something like /usr/bin/php. If empty, will be found in PATH.
		"curl" => '/usr/bin/curl',			// Something like /usr/bin/curl. If empty, will be found in PATH.
		"gzip" => '/bin/gzip',			// Something like /usr/bin/gzip. If empty, will be found in PATH.
		"id"   => '/usr/bin/id',			// Something like /usr/bin/id. If empty, will be found in PATH.
		"stat" => '/usr/bin/stat',			// Something like /usr/bin/stat. If empty, will be found in PATH.
	);
 
	$localhosts = array( 			// list of local interfaces
		"127.0.0.1",
		"localhost",
	);
 
	$profilePath = '../share';		// Path to user profiles
	$profileMask = 0777;			// Mask for files and directory creation in user profiles.
						// Both Webserver and rtorrent users must have read-write access to it.
						// For example, if Webserver and rtorrent users are in the same group then the value may be 0770.
 
?>
EOF
sed -i.bak "s/@user@/$user/g;" /$wwwdir/rutorrent/conf/config.php
 
#----Fin du fichier configuration------------- 
#---------------------------------------------
 
#-----Fichier Configuration plugins.ini-------
#---------------------------------------------
cat <<'EOF' > /$wwwdir/rutorrent/conf/plugins.ini
;; Plugins' permissions.
;; If flag is not found in plugin section, corresponding flag from "default" section is used.
;; If flag is not found in "default" section, it is assumed to be "yes".
;;
;; For setting individual plugin permissions you must write something like that:
;;
;; [ratio]
;; enabled = yes			;; also may be "user-defined", in this case user can control plugin's state from UI
;; canChangeToolbar = yes
;; canChangeMenu = yes
;; canChangeOptions = no
;; canChangeTabs = yes
;; canChangeColumns = yes
;; canChangeStatusBar = yes
;; canChangeCategory = yes
;; canBeShutdowned = yes
 
[default]
enabled = user-defined
canChangeToolbar = yes
canChangeMenu = yes
canChangeOptions = yes
canChangeTabs = yes
canChangeColumns = yes
canChangeStatusBar = yes
canChangeCategory = yes
canBeShutdowned = yes
 
;; Default
 
[_getdir]
enabled = yes
[cpuload]
enabled = user-defined
[create]
enabled = user-defined
[datadir]
enabled = yes
[diskspace]
enabled = user-defined
[erasedata]
enabled = user-defined
[show_peers_like_wtorrent]
enabled = user-defined
[theme]
enabled = yes
[tracklabels]
enabled = user-defined
[trafic]
enabled = user-defined
 
;; Enabled
 
[autotools]
enabled = user-defined
[cookies]
enabled = user-defined
[data]
enabled = user-defined
[edit]
enabled = user-defined
[extratio]
enabled = user-defined
[extsearch]
enabled = user-defined
[filedrop]
enabled = user-defined
[filemanager]
enabled = user-defined
[geoip]
enabled = user-defined
[httprpc]
enabled = yes
canBeShutdowned = no
[pausewebui]
enabled = yes
[ratio]
enabled = user-defined
[ratiocolor]
enabled = user-defined
[rss]
enabled = user-defined
[_task]
enabled = yes
[throttle]
enabled = user-defined
[titlebar]
enabled = user-defined
[unpack]
enabled = user-defined
 
;; Disabled
 
[chat]
enabled = no
[chunks]
enabled = no
[feeds]
enabled = no
[fileshare]
enabled = no
[fileupload]
enabled = no
[history]
enabled = no
[instantsearch]
enabled = no
[ipad]
enabled = no
[logoff]
enabled = no
[loginmgr]
enabled = no
[mediainfo]
enabled = no
[mediastream]
enabled = no
[check_port]
enabled = no
[retrackers]
enabled = no
[rpc]
enabled = no
[rssurlrewrite]
enabled = no
[rutracker_check]
enabled = no
[scheduler]
enabled = no
[screenshots]
enabled = no
[seedingtime]
enabled = no
[source]
enabled = no
EOF
#----Fin du fichier configuration-------------
#---------------------------------------------
 
#-----Fichier Configuration .rtorrent.rc------
#---------------------------------------------
cat <<'EOF' > /$homedir/$user/.rtorrent.rc
# Fichier de configuration de rtorrent.
 
download_rate = 0
upload_rate = 0
 
directory = /home/@user@/downloads/complete
session = /home/@user@/downloads/.session
schedule = watch_directory,5,5,load_start=/home/@user@/downloads/watch/*.torrent
schedule = untied_directory,5,5,stop_untied=
 
port_range = 55995-56000
port_random = no
 
# check_hack sur 'yes' peut faire ramer le serveur
check_hash = yes
 
dht = disable
peer_exchange = no
 
#encryption = allow_incoming,require,require_rc4
encryption = allow_incoming,enable_retry,prefer_plaintext
 
# Ca, c'est nécessaire pour que rutorrent fonctionne
scgi_port = localhost:5000
EOF
sed -i.bak "s/@user@/$user/g;" /$homedir/$user/.rtorrent.rc
#----Fin du fichier configuration-------------
#---------------------------------------------
 
#---Creation du mot de passe de l'interface Rutorrent---
#-------------------------------------------------------
a2enmod auth_digest
echo "${user}:rutorrent:"$(printf "${user}:rutorrent:${pwd}" | md5sum | awk '{print $1}') > $apachedir/htpasswd
 
 
#----Debut de Creation des dossier------------
#---------------------------------------------
if [ ! -d $homedir/$user/downloads ]; then
mkdir $homedir/$user/downloads
chown $user:$user $homedir/$user/downloads
 
else
chown $user:$user $homedir/$user/downloads
fi
 
 
if [ ! -d $homedir/$user/downloads/complete ]; then
mkdir $homedir/$user/downloads/complete
chown $user:$user $homedir/$user/downloads/complete
 
else
chown $user:$user $homedir/$user/downloads/complete
fi
 
if [ ! -d $homedir/$user/downloads/watch ]; then
mkdir $homedir/$user/downloads/watch
chown $user:$user $homedir/$user/downloads/watch
 
else
chown $user:$user $homedir/$user/downloads/watch
fi
 
if [ ! -d $homedir/$user/downloads/.session ]; then
mkdir $homedir/$user/downloads/.session
chown $user:$user $homedir/$user/downloads/.session
 
else
chown $user:$user $homedir/$user/downloads/.session
fi
#--------------Fin de Creation des dossier---------
#--------------------------------------------------
 
# On instal Filemanager et  MediaStream
 
cd $wwwdir/rutorrent/plugins
svn co http://svn.rutorrent.org/svn/filemanager/trunk/mediastream
svn co http://svn.rutorrent.org/svn/filemanager/trunk/filemanager
mkdir -p $wwwdir/stream/
ln -s $wwwdir/rutorrent/plugins/mediastream/view.php $wwwdir/stream/view.php
sed -i.bak "s/mydomain.com/$ip/g;" /$wwwdir/rutorrent/plugins/mediastream/conf.php
 
# FILEUPLOAD
 
svn co http://svn.rutorrent.org/svn/filemanager/trunk/fileupload
#----Permission Rutorrent-------------------- 
#--------------------------------------------
 
chown www-data: $wwwdir/stream
chown www-data: $wwwdir/stream/view.php
chown -R www-data:www-data $wwwdir/rutorrent
chmod 775 fileupload/scripts/upload
 
#---Configuration apache2--------------------
#--------------------------------------------
echo "
# security
ServerSignature Off
ServerTokens Prod" >> $apachedir/apache2.conf
sed -i.bak "s/Timeout 300/Timeout 30/g;" /$apachedir/apache2.conf
 
# Installation du mode SGCI d'Apache (obligatoire pour rtorrent et rutorrent)
echo SCGIMount /RPC2 127.0.0.1:5000 >> $apachedir/apache2.conf
 
# SSl Configuration
 
#Configuration du certificat ssl
openssl req -new -x509 -days 3658 -nodes -newkey rsa:2048 -out /etc/apache2/apache.pem -keyout /etc/apache2/apache.pem<<EOF
RU
Russia
Moskva
wrty
wrty LTD
wrty.com
contact@wrty.com
EOF
 
chmod 600 $apachedir/apache.pem
 
#Activation des module apache
 
a2ensite default-ssl
a2enmod ssl
a2enmod scgi
 
#-----Fichier Configuration default-----------
#---------------------------------------------
cat <<'EOF' > /$apachedir/sites-available/default
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
 
        DocumentRoot /var/www/
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
 
        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>
 
        ErrorLog /var/log/apache2/error.log
 
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
 
        CustomLog /var/log/apache2/access.log combined
 
    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
 
    <Location /rutorrent>
        AuthType Digest
        AuthName "rutorrent"
        AuthDigestDomain /var/www/rutorrent/ http://@ip@/rutorrent
 
        AuthDigestProvider file
        AuthUserFile /etc/apache2/htpasswd
        Require valid-user
        SetEnv R_ENV "/var/www/rutorrent"
    </Location>
 
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerAdmin webmaster@localhost
 
        SSLEngine on
        SSLCertificateFile /etc/apache2/apache.pem
 
        DocumentRoot /var/www/
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
 
        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>
 
        ErrorLog /var/log/apache2/error.log
 
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
 
        CustomLog /var/log/apache2/access.log combined
 
    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
    <Location /rutorrent>
        AuthType Digest
        AuthName "rutorrent"
        AuthDigestDomain /var/www/rutorrent/ http://<servername or IP>/rutorrent
 
        AuthDigestProvider file
        AuthUserFile /etc/apache2/htpasswd
        Require valid-user
        SetEnv R_ENV "/var/www/rutorrent"
     </Location>
</VirtualHost>
</IfModule>
EOF
sed -i.bak "s/@ip@/$ip/g;" /$apachedir/sites-available/default
#----Fin du fichier configuration-------------
#---------------------------------------------
 
#-----Fichier Configuration rtorrent deamon---
#---------------------------------------------
cat <<'EOF' > /$initd/rtorrent
### BEGIN INIT INFO
# Provides: chillispot et freeradius dans le chroot
# Required-Start: \$local_fs \$network
# Required-Stop: \$local_fs \$remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Wireless & LAN Access Point Controller
# Description: ChilliSpot is an open source captive portal
# or wireless LAN access point controller.
### END INIT INFO
#!/bin/sh -e
# Start/Stop rtorrent sous forme de daemon.
 
NAME=rtorrent
SCRIPTNAME=/etc/init.d/$NAME
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
 
case $1 in
        start)
                echo "Starting rtorrent... "
                su -l @USER@ -c "screen -fn -dmS rtd nice -19 rtorrent"
                echo "Terminated"
        ;;
        stop)
                if [ "$(ps aux | grep -e '.*rtorrent$' -c)" != 0  ]; then
                {
                        echo "Shutting down rtorrent... "
                        killall -r "^.*rtorrent$"
                        echo "Terminated"
                }
                else
                {
                        echo "rtorrent not yet started !"
                        echo "Terminated"
                }
                fi
        ;;
        restart)
                if [ "$(ps aux | grep -e '.*rtorrent$' -c)" != 0  ]; then
                {
                        echo "Shutting down rtorrent... "
                        killall -r "^.*rtorrent$"
                        echo "Starting rtorrent... "
                        su -l @USER@ -c "screen -fn -dmS rtd nice -19 rtorrent"
                        echo "Terminated"
                }
                else
                {
                        echo "rtorrent not yet started !"
                        echo "Starting rtorrent... "
                        su -l @USER@ -c "screen -fn -dmS rtd nice -19 rtorrent"
                        echo "Terminated"
                }
                fi
        ;;
        *)
                echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2
                exit 2
        ;;
esac
EOF
sed -i.bak "s/@user@/$user/g;" /$initd/rtorrent
#----Fin du fichier configuration-------------
#---------------------------------------------
 
#Configuration rtorrent deamon
chmod +x /$initd/rtorrent
update-rc.d rtorrent defaults 99
 
 
 
 
service apache2 reload
clear
 
# Demarrage de rtorrent
su $user -c 'screen -d -m -U -fa -S rtorrent rtorrent'
echo "--"
echo " =========== FIN DE L'INSTALLATION ! On dirait que tout a fonctionne ! ==="
echo "Username :$user"
echo "Password :${pwd}"
echo "-------------------------------"
echo "-------------------------------"
echo "Maintenant, rendez-vous sur Rutorrent"
echo "https://$ip/rutorrent/"
je début et ouvert a apprendre et au critique constructive