forked from centos-bz/ezhttp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ez
753 lines (676 loc) · 21.5 KB
/
ez
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
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#===============================================================================
# SYSTEM REQUIRED: Linux
# DESCRIPTION: automatic deploy your linux
# AUTHOR: Zhu Maohai.
# website: http://www.centos.bz/ezhttp/
#===============================================================================
#保证是在根用户下运行
rootness(){
# Make sure only root can run our script
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
}
#判断路径输入是否合法
filter_location(){
local location=$1
if ! echo $location | grep -q "^/";then
while true
do
read -p "input error,please input location again." location
echo $location | grep -q "^/" && echo $location && break
done
else
echo $location
fi
}
yes_or_no(){
local prompt=$1
local yaction=$2
local naction=$3
while true; do
read -p "${prompt}?[Y/n]: " yn
yn=`upcase_to_lowcase $yn`
case $yn in
y ) eval "$yaction";break;;
n ) eval "$naction";break;;
* ) echo "input error,please only input y or n."
esac
done
}
vhost(){
local action=$1
case $action in
add ) vhost_add;;
list ) vhost_list;;
del ) vhost_del;;
*) echo "action $action not found";exit 1;;
esac
}
vhost_add(){
if [ "$stack" == "lnmp" ];then
nginx_vhost_add
elif [ "$stack" == "lamp" ];then
apache_vhost_add
elif [ "$stack" == "lnamp" ];then
lnamp_vhost_add
else
echo "stack variable not found,exit."
exit 1
fi
}
vhost_del(){
if [ "$stack" == "lnmp" ];then
nginx_vhost_del
elif [ "$stack" == "lamp" ];then
apache_vhost_del
elif [ "$stack" == "lnamp" ];then
lnamp_vhost_del
else
echo "stack variable not found,exit."
exit 1
fi
}
vhost_list(){
if [ "$stack" == "lnmp" ];then
nginx_vhost_list
elif [ "$stack" == "lamp" ];then
apache_vhost_list
elif [ "$stack" == "lnamp" ];then
lnamp_vhost_list
else
echo "stack variable not found,exit."
exit 1
fi
}
lnamp_vhost_list(){
sed -n -r -e 's/ServerAlias\s+(.*)/\1/p' -e 's/DocumentRoot\s+(.*)/\1/p' ${apache_location}/conf/vhost/*.conf | awk 'BEGIN{printf ("%-50s %-50s\n%-50s %-50s\n","server_name","root","-----------","----")}{printf("%-50s",$0);getline;printf $0"\n" }'
}
lnamp_vhost_del(){
read -p "input server_name of vhost you'll delete(ie.www.centos.bz): " domain
#删除nginx配置
if vhost_is_exist "$domain";then
rm -f ${nginx_location}/conf/vhost/$domain.conf
echo "complete deleted the server_name ${domain} of vhost."
echo "reloading the nginx config file..."
if ${nginx_location}/sbin/nginx -t;then
${nginx_location}/sbin/nginx -s reload
echo "reload success."
else
echo "reload failed.config file had an error,please fix it."
exit 1
fi
else
echo "vhost $domain not found,failed to delete."
exit 1
fi
#删除apache配置
if ! apache_vhost_is_exist "$domain";then
echo "vhost $domain not found"
exit 1
else
rm -f ${apache_location}/conf/vhost/$domain.conf
echo "complete deleted the server_name ${domain} of vhost."
#重载配置
echo "reloading the apache config file..."
if ${apache_location}/bin/apachectl -t;then
/etc/init.d/httpd restart
echo "reload success."
else
echo "reload failed.config file had an error,please fix it."
exit 1
fi
fi
}
lnamp_vhost_add(){
set_apache_allow_syntax
#输入域名
while true; do
read -p "input server names(ie.www.centos.bz centos.bz): " server_names
for i in $server_names;do
if vhost_is_exist $i;then
echo "vhost $i is exist,please reinput server_names."
break
fi
break 2
done
done
#设置默认网站目录
default_root="/home/${server_names%% *}"
#输入网站目录
read -p "input website root(default:$default_root): " website_root
website_root=${website_root:=$default_root}
#创建目录
mkdir -p ${website_root}/ /home/wwwlog/${server_names%% *}
chown -R www ${website_root}
#写入nginx配置
cat > ${nginx_location}/conf/vhost/${server_names%% *}.conf << EOF
server {
server_name ${server_names};
listen 80;
index index.php index.html index.htm;
root ${website_root};
location / {
try_files $uri $uri/index.html @apache;
}
location @apache {
internal;
proxy_pass http://127.0.0.1:88;
include proxy.conf;
}
location ~ .*\.(php|php5)?$ {
proxy_pass http://127.0.0.1:88;
include proxy.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}
location ~ .*\.(js|css)?$ {
expires 12h;
}
access_log /home/wwwlog/${server_names%% *}/access_nginx.log access;
error_log /home/wwwlog/${server_names%% *}/error_nginx.log error;
}
EOF
#写入apache配置
cat > ${apache_location}/conf/vhost/${server_names%% *}.conf << EOF
<VirtualHost 127.0.0.1:88>
ServerName ${server_names%% *}
ServerAlias ${server_names}
DocumentRoot ${website_root}
DirectoryIndex index.php index.html index.htm
<Directory ${website_root}>
Options +Includes -Indexes
AllowOverride All
Order Deny,Allow
${allow_from_all}
php_admin_value open_basedir ${website_root}:/tmp:/proc
</Directory>
ErrorLog /home/wwwlog/${server_names%% *}/error_apache.log
TransferLog /home/wwwlog/${server_names%% *}/access_apache.log
</VirtualHost>
EOF
#重载配置
echo "reloading the apache config file..."
if ${apache_location}/bin/apachectl -t;then
/etc/init.d/httpd restart
echo "reload success."
else
echo "reload failed.config file had an error,please fix it."
exit 1
fi
echo "reloading the nginx config file..."
if ${nginx_location}/sbin/nginx -t;then
${nginx_location}/sbin/nginx -s reload
echo "reload success."
else
echo "reload failed.config file had an error,please fix it."
exit 1
fi
echo "congratulations.vhost ${server_names%% *} had created."
echo "website root is ${website_root}/."
}
nginx_vhost(){
local action=$1
case $action in
add ) nginx_vhost_add;;
list ) nginx_vhost_list;;
del ) nginx_vhost_del;;
*) echo "action $action not found";exit 1;;
esac
}
php_support_without_pathinfo(){
php_support_code="location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
fastcgi_param PHP_VALUE open_basedir=\$document_root:/tmp/:/proc/;
include fastcgi_params;
}"
}
php_support_with_pathinfo(){
php_support_code="location ~ \.php($|/){
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
set \$path_info \"\";
set \$real_script_name \$fastcgi_script_name;
if (\$fastcgi_script_name ~ \"^(.+?\.php)(/.+)$\") {
set \$real_script_name \$1;
set \$path_info \$2;
}
fastcgi_param SCRIPT_FILENAME \$document_root\$real_script_name;
fastcgi_param SCRIPT_NAME \$real_script_name;
fastcgi_param PATH_INFO \$path_info;
fastcgi_param PHP_VALUE open_basedir=\$document_root:/tmp/:/proc/;
}"
}
enable_php(){
yes_or_no "enable PATH_INFO support" "php_support_with_pathinfo" "php_support_without_pathinfo"
}
nginx_vhost_add(){
#输入域名
while true; do
read -p "input server names(ie.www.centos.bz centos.bz): " server_names
for i in $server_names;do
if vhost_is_exist $i;then
echo "vhost $i is exist,please reinput server_names."
break
fi
break 2
done
done
#设置默认网站目录
default_root="/home/${server_names%% *}"
#输入网站目录
read -p "input website root(default:$default_root): " website_root
website_root=${website_root:=$default_root}
#是否添加重写规则
yes_or_no "add nginx rewrite rule" "select_rewrite_rule" "rewrite_rule=''"
#是否支持php
yes_or_no "enable php support" "enable_php" "php_support_code=''"
cat > ${nginx_location}/conf/vhost/${server_names%% *}.conf << EOF
server {
server_name ${server_names};
listen 80;
index index.php index.html index.htm;
root ${website_root};
${rewrite_rule}
${php_support_code}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}
location ~ .*\.(js|css)?$ {
expires 12h;
}
access_log /home/wwwlog/${server_names%% *}/access.log access;
error_log /home/wwwlog/${server_names%% *}/error.log error;
}
EOF
echo "congratulations.vhost ${server_names%% *} had created."
echo "website root is ${website_root}/."
#创建目录
mkdir -p /home/wwwlog/${server_names%% *} ${website_root}
chown -R www ${website_root}
#重载配置
echo "reloading the nginx config file..."
if ${nginx_location}/sbin/nginx -t;then
${nginx_location}/sbin/nginx -s reload
echo "reload success."
else
echo "reload failed.config file had an error,please fix it."
exit 1
fi
}
nginx_vhost_list(){
sed -n -r -e 's/server_name\s+(.*);/\1/p' -e 's/root\s+(.*);/\1/p' ${nginx_location}/conf/vhost/*.conf | awk 'BEGIN{printf ("%-50s %-50s\n%-50s %-50s\n","server_name","root","-----------","----")}{printf("%-50s",$0);getline;printf $0"\n" }'
}
nginx_vhost_del(){
read -p "input server_name of vhost you'll delete(ie.www.centos.bz): " domain
if vhost_is_exist "$domain";then
rm -f ${nginx_location}/conf/vhost/$domain.conf
echo "complete deleted the server_name ${domain} of vhost."
echo "reloading the nginx config file..."
if ${nginx_location}/sbin/nginx -t;then
${nginx_location}/sbin/nginx -s reload
echo "reload success."
else
echo "reload failed.config file had an error,please fix it."
exit 1
fi
else
echo "vhost $domain not found,failed to delete."
exit 1
fi
}
apache_vhost(){
local action=$1
case $action in
add ) apache_vhost_add;;
list ) apache_vhost_list;;
del ) apache_vhost_del;;
*) echo "action $action not found";exit 1;;
esac
}
set_apache_allow_syntax(){
if [[ $apache_location == "" ]]; then
while true; do
read -p "sorry,can not figure out the apache location,please input(default:/usr/local/apache): " apache_location
apache_location=${apache_location:=/usr/local/apache}
apache_location=`filter_location "$apache_location"`
#判断版本
if ${apache_location}/bin/httpd -v | grep -q "Apache/2.4"; then
allow_from_all="Require all granted"
break
elif ${apache_location}/bin/httpd -v | grep -q "Apache/2.2"; then
allow_from_all="Allow from All"
break
else
echo "can not get apache version,may be the "
fi
done
else
#判断版本
if ${apache_location}/bin/httpd -v | grep -q "Apache/2.4"; then
allow_from_all="Require all granted"
elif ${apache_location}/bin/httpd -v | grep -q "Apache/2.2"; then
allow_from_all="Allow from All"
else
while true; do
read -p "sorry,can not figure out the apache location,please input(default:/usr/local/apache): " apache_location
apache_location=${apache_location:=/usr/local/apache}
apache_location=`filter_location "$apache_location"`
#判断版本
if ${apache_location}/bin/httpd -v | grep -q "Apache/2.4"; then
allow_from_all="Require all granted"
break
elif ${apache_location}/bin/httpd -v | grep -q "Apache/2.2"; then
allow_from_all="Allow from All"
break
else
echo "can not get apache version,may be the "
fi
done
fi
fi
}
apache_vhost_add(){
set_apache_allow_syntax
#输入域名
while true; do
read -p "input server names(ie.www.centos.bz centos.bz): " server_names
for i in $server_names;do
if apache_vhost_is_exist $i;then
echo "vhost $i is exist,please reinput server_names."
break
fi
break 2
done
done
#设置默认网站目录
default_root="/home/${server_names%% *}"
#输入网站目录
read -p "input website root(default:$default_root): " website_root
website_root=${website_root:=$default_root}
#开始写入配置文件
cat > ${apache_location}/conf/vhost/${server_names%% *}.conf << EOF
<VirtualHost *:80>
ServerName ${server_names%% *}
ServerAlias ${server_names}
DocumentRoot ${website_root}
DirectoryIndex index.php index.html index.htm
<Directory ${website_root}>
Options +Includes -Indexes
AllowOverride All
Order Deny,Allow
${allow_from_all}
php_admin_value open_basedir ${website_root}:/tmp:/proc
</Directory>
ErrorLog /home/wwwlog/${server_names%% *}/error.log
TransferLog /home/wwwlog/${server_names%% *}/access.log
</VirtualHost>
EOF
echo "congratulations.vhost ${server_names%% *} had created."
echo "website root is ${website_root}/."
#创建目录
mkdir -p /home/wwwlog/${server_names%% *} ${website_root}
chown -R www ${website_root}
#重载配置
echo "reloading the apache config file..."
if ${apache_location}/bin/apachectl -t;then
/etc/init.d/httpd restart
echo "reload success."
else
echo "reload failed.config file had an error,please fix it."
exit 1
fi
}
apache_vhost_list(){
sed -n -r -e 's/ServerAlias\s+(.*)/\1/p' -e 's/DocumentRoot\s+(.*)/\1/p' ${apache_location}/conf/vhost/*.conf | awk 'BEGIN{printf ("%-50s %-50s\n%-50s %-50s\n","server_name","root","-----------","----")}{printf("%-50s",$0);getline;printf $0"\n" }'
}
apache_vhost_del(){
read -p "input server_name of vhost you'll delete(ie.www.centos.bz): " domain
if ! apache_vhost_is_exist "$domain";then
echo "vhost $domain not found"
exit 1
else
rm -f ${apache_location}/conf/vhost/$domain.conf
echo "complete deleted the server_name ${domain} of vhost."
#重载配置
echo "reloading the apache config file..."
if ${apache_location}/bin/apachectl -t;then
/etc/init.d/httpd restart
echo "reload success."
else
echo "reload failed.config file had an error,please fix it."
exit 1
fi
fi
}
#判断root密码是否正确
check_root_passwd(){
while true
do
read -p "please input your mysql root password: " root_password
echo "show databases" | ${mysql_location}/bin/mysql -uroot -p${root_password} > /tmp/mysql_err 2>&1
if [ $? != 0 ];then
grep -q "1045" /tmp/mysql_err && echo "your root password is not correct"
else
break
fi
done
}
mysql_manger(){
local action=$1
case $action in
add ) mysql_add;;
mod ) mysql_user_mod;;
del ) mysql_del;;
reset ) mysql_reset;;
*) echo "action $action not found";exit 1
esac
}
mysql_add_db(){
read -p "please input the database name: " dbname
echo "create database ${dbname};" | ${mysql_location}/bin/mysql -uroot -p${root_password} > /dev/null 2>&1 && echo "successfully create database ${dbname}" || echo "create database ${dbname} failed."
}
mysql_add_user(){
read -p "please input the user name: " user
read -p "please input the user password: " passwd
read -p "input the database you'll grant privileges on to this user,input \"*\" means grant all databases.(default:all databases.): " grantdb
grantdb=${grantdb:=*}
read -p "input the client you'll allow access to this user,input \"%\" means allow all client.(default:localhost 127.0.0.1): " grantclient
grantclient=${grantclient:="localhost 127.0.0.1"}
for client in $grantclient; do
echo "GRANT ALL PRIVILEGES ON ${grantdb}.* TO '${user}'@'$client' IDENTIFIED BY '$passwd'" | ${mysql_location}/bin/mysql -uroot -p${root_password} > /dev/null 2>&1
done
echo "flush privileges;" | ${mysql_location}/bin/mysql -uroot -p${root_password} > /dev/null 2>&1
echo "successfully add user ${user}"
}
mysql_add(){
check_root_passwd
#是否添加数据库
yes_or_no "add a database" "mysql_add_db"
#是否添加用户
yes_or_no "add a user" "mysql_add_user"
}
mysql_del_db(){
read -p "please input the database name: " $db
echo "drop database $db;" | ${mysql_location}/bin/mysql -uroot -p${root_password} > /dev/null 2>&1
echo "successfully delete database $db."
}
mysql_del_user(){
read -p "please input the user name: " user
echo "use mysql;delete from user where User='$user' " | ${mysql_location}/bin/mysql -uroot -p${root_password} > /dev/null 2>&1
echo "successfully delete user $user."
}
mysql_user_mod(){
check_root_passwd
read -p "please input the user: " user
read -p "please input a new password: " passwd
echo "use mysql;update user set password=PASSWORD('$passwd') where User='$user';flush privileges;" | ${mysql_location}/bin/mysql -uroot -p${root_password} > /dev/null 2>&1
echo "successfully modify user $user password."
}
mysql_del(){
check_root_passwd
yes_or_no "delete a database" "mysql_del_db"
yes_or_no "delete a user" "mysql_del_user"
}
mysql_reset(){
read -p "please input a new password for root user: " password
/etc/init.d/mysqld stop 2>&1 >/dev/null
if [ "$mysql_location" == "" ];then
read -p "mysql location not found,input mysql location(ie./usr/local/mysql): " mysql_location
fi
${mysql_location}/bin/mysqld_safe --defaults-file=${mysql_location}/etc/my.cnf --skip-grant-tables 2>&1 >/dev/null &
echo "wait for 8 seconds..."
sleep 8 && ${mysql_location}/bin/mysql -u root -e "use mysql;update user set password=PASSWORD(\"${password}\") where User='root';flush privileges;"
/etc/init.d/mysqld restart 2>&1 >/dev/null
echo "show databases;" | ${mysql_location}/bin/mysql -uroot -p${password} > /dev/null 2>&1 && echo "successfully reset your mysql root password" || echo "Sorry,failed to reset your root password."
}
ftp_user(){
if [[ "$pureftpd_location" == "" ]]; then
echo "pureftpd not found,please install pureftpd first."
exit 1
fi
local action=$1
case $action in
add ) ftp_user_add;;
list ) ftp_user_list;;
del ) ftp_user_del;;
mod ) ftp_user_mod;;
*) echo "action $action not found";exit 1;;
esac
}
ftp_user_add(){
if [[ $user_manager_pureftpd == true ]]; then
echo "you had installed pure-ftpd with mysql.you should add ftp user with user manager panel."
exit 1
else
read -p "input ftp user name: " ftp_username
read -p "input ftp user $ftp_username Home Directory: " ftp_home
while true;do
read -p "input system user name(ie. www): " sys_username
user_id=`id $sys_username | sed -r 's/uid=([0-9]+).*/\1/'`
if [[ "$user_id" == "" ]]; then
echo "user $sys_username not found,please input an exsit system user."
continue
fi
if [[ "$user_id" == "0" ]]; then
echo "the system user $sys_username has root privilege,please input a non root privilege user."
continue
fi
break
done
${pureftpd_location}/bin/pure-pw useradd $ftp_username -u $sys_username -d $ftp_home
${pureftpd_location}/bin/pure-pw mkdb
echo "successfully add ftp user $ftp_username."
fi
}
ftp_user_list(){
printf "FTPUser\t\tRoot Directory\n"
${pureftpd_location}/bin/pure-pw list
}
ftp_user_del(){
read -p "(Please input the ftpuser you'll delete):" ftpuser
${pureftpd_location}/bin/pure-pw userdel $ftpuser
${pureftpd_location}/bin/pure-pw mkdb
echo "successfully delete ftpuser $ftpuser"
}
ftp_user_mod(){
read -p "(Please input the ftpuser you'll modify): " ftpuser
echo "1. modify ftpuser $ftpuser password"
echo "2. modify ftpuser $ftpuser home directory"
echo "3. modify ftpuser $ftpuser system user name"
while true; do
read -p "please input a number: " ftp_mod
case $ftp_mod in
1 ) ${pureftpd_location}/bin/pure-pw passwd $ftpuser;echo "change ftp user $ftpuser password successfully.";break;;
2 ) read -p "please enter ftpuser $ftpuser new home directory: " ftp_home;${pureftpd_location}/bin/pure-pw usermod $ftpuser -d $ftp_home;break;;
3 ) read -p "please enter ftpuser $ftpuser system user name: " sys_username;${pureftpd_location}/bin/pure-pw usermod $ftpuser -u $sys_username;break;;
* ) echo "input error.";;
esac
done
${pureftpd_location}/bin/pure-pw mkdb
}
#检查vhost是否存在
vhost_is_exist(){
local domain=$1
local conf_file="${nginx_location}/conf/vhost/$1.conf"
if [ -f "$conf_file" ];then
return 0
else
return 1
fi
}
#检查apahcevhost是否存在
apache_vhost_is_exist(){
local domain=$1
local conf_file="${apache_location}/conf/vhost/$1.conf"
if [ -f "$conf_file" ];then
return 0
else
return 1
fi
}
#大写转换成小写
upcase_to_lowcase(){
words=$1
echo $words | tr '[A-Z]' '[a-z]'
}
#nginx重写规则选择
select_rewrite_rule(){
local rewrite_rules=( "include rewrite/wordpress.conf;" "include rewrite/DEDECMS.conf;" "include rewrite/Discuz_7.conf;" "include rewrite/Discuz_X.conf;" "include rewrite/ecshop.conf;" "include rewrite/phpcms.conf;" "include rewrite/PHPWind.conf;" "include rewrite/shopex.conf;" "include rewrite/Typecho.conf;" )
echo "available nginx rewrite rules:"
echo -e "1. Custom\n2. WordPress\n3. DEDECMS\n4. Discuz_7\n5. Discuz_X\n6. ECshop\n7. PHPCMS\n8. PHPWind\n9. Shopex\n10. Typecho"
while true; do
read -p "please input a number: " rule
case "$rule" in
1|2|3|4|5|6|7|8|9|10) break;;
*) echo "input error.";;
esac
done
if [[ "$rule" == "1" ]];then
while true;do
read -p "please input your rewrite rule name: " rule_name
if [[ -f ${nginx_location}/conf/rewrite/${rule_name}.conf ]];then
echo "${rule_name}.conf file exists,please reinput"
else
touch ${nginx_location}/conf/rewrite/${rule_name}.conf
echo "file ${nginx_location}/conf/rewrite/${rule_name}.conf have created,please input your rewrite rule to this file."
rewrite_rule="include rewrite/${rule_name}.conf;"
break
fi
done
else
rewrite_rule=${rewrite_rules[$rule-2]}
fi
}
#程序从这里开始
rootness
if [ $# != 2 ];then
echo "Usage: ez program_name action"
exit 1
fi
#引入各软件安装路径
if [[ -s /etc/ezhttp_info_do_not_del ]]; then
. /etc/ezhttp_info_do_not_del
else
echo "error,file /etc/ezhttp_info_do_not_del not found,ez command can not be executed."
exit 1
fi
#接收脚本传参
proname=$1
action=$2
case $proname in
vhost ) vhost $action;;
nginx ) echo "ez nginx $2 is not available,please use ez vhost $2";;
apache ) echo "ez apache $2 is not available,please use ez vhost $2";;
ftp ) ftp_user $action;;
mysql ) mysql_manger $action;;
*) echo "program_name $proname not found.";exit 1;;
esac