forked from centos-bz/ezhttp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc
More file actions
746 lines (688 loc) · 21.7 KB
/
func
File metadata and controls
746 lines (688 loc) · 21.7 KB
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
#监控编译安装中是否有错误,有错误就停止安装,并把错误写入到文件/root/ezhttp_errors.log
error_detect(){
local command=$1
local cur_soft=`pwd | awk -F'/' '{print $NF}'`
${command}
if [ $? != 0 ];then
distro=`cat /etc/issue`
version=`cat /proc/version`
architecture=`uname -m`
cat >>/root/ezhttp_errors.log<<EOF
ezhttp errors:
distributions:$distro
architecture:$architecture
version:$version
Nginx: ${nginx}
Apache: ${apache}
MySQL Server: $mysql
PHP Version: $php
Other Software: ${other_soft_install[@]}
issue:failed to install $cur_soft
EOF
echo "#########################################################"
echo "failed to install $cur_soft."
echo "please visit website http://www.centos.bz/ezhttp/"
echo "and submit /root/ezhttp_errors.log ask for help."
echo "#########################################################"
exit 1
fi
}
#保证是在根用户下运行
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
}
#禁止selinux,因为在selinux下会出现很多意想不到的问题
disable_selinux(){
if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config; then
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
fi
}
#大写转换成小写
upcase_to_lowcase(){
words=$1
echo $words | tr '[A-Z]' '[a-z]'
}
#多核并行编译
parallel_make(){
local para=$1
cpunum=`cat /proc/cpuinfo |grep 'processor'|wc -l`
if [ $cpunum == 1 ];then
[ "$para" == "" ] && make || make "$para"
else
[ "$para" == "" ] && make -j$cpunum || make -j$cpunum "$para"
fi
}
#开机启动
boot_start(){
if [ "`check_sys_version`" == "debian" ];then
update-rc.d -f $1 defaults
elif [ "`check_sys_version`" == "centos" ];then
chkconfig --add $1
chkconfig $1 on
fi
}
#关闭开机启动
boot_stop(){
if [ "`check_sys_version`" == "debian" ];then
update-rc.d -f $1 remove
elif [ "`check_sys_version`" == "centos" ];then
chkconfig $1 off
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
}
#检查压缩包完善性
check_integrity(){
local filename=$1
local url1=$2
local url2=$3
local code=0
if echo $filename | grep -q -E "(tar\.gz|tgz)$";then
gzip -t ${cur_dir}/soft/$filename
local code=$?
elif echo $filename | grep -q -E "tar\.bz2$";then
bzip2 -t ${cur_dir}/soft/$filename
local code=$?
fi
if [ "$code" != 0 ];then
echo "the file $filename is incomplete.redownload now..."
rm -f ${cur_dir}/soft/${filename}
download_file "$url1" "$url2" "$filename"
else
echo "the file $filename is complete."
fi
}
#下载软件
download_file(){
local url1=$1
local url2=$2
local filename=$3
if [ -s "${cur_dir}/soft/${filename}" ];then
#check_md5 "$filename"
echo "${filename} is existed.check the file integrity."
check_integrity "${filename}" "$url1" "$url2"
else
[ ! -d "${cur_dir}/soft" ] && mkdir -p ${cur_dir}/soft
cd ${cur_dir}/soft
choose_url_download "$url1" "$url2" "$filename"
fi
}
#判断64位系统
is_64bit(){
if [ `getconf WORD_BIT` = '32' ] && [ `getconf LONG_BIT` = '64' ] ; then
return 0
else
return 1
fi
}
#选择最优下载url
choose_url_download()
{
local url1=$1
local url2=$2
local filename=$3
echo "testing other url download speed..."
speed1=`curl -m 5 -L -s -w '%{speed_download}' "$url1" -o /dev/null`
echo "other url download speed is $speed1"
echo "testing Official url download speed..."
speed2=`curl -m 5 -L -s -w '%{speed_download}' "$url2" -o /dev/null`
echo "Official url download speed is $speed2"
speed1=${speed1%%.*}
speed2=${speed2%%.*}
if [ $speed1 -gt $speed2 ];then
url=$url1
else
url=$url2
fi
echo "use the url $url to download $filename.."
sleep 1
#开始下载
wget -c --tries=3 ${url} -O $filename
[ $? != 0 ] && echo "fail to download $filename,exited." && exit 1
#check_md5 "$filename"
}
#检查软件md5
check_md5(){
local filename=$1
cd ${cur_dir}/soft
grep "$filename" ${cur_dir}/conf/md5.txt | sed 's/\r//g' | md5sum -c -
[ $? != 0 ] && echo "$filename md5 check failed,may be the file is modified or incompleted,please redownload it, exited." && exit 1
}
#判断命令是否存在
check_command_exist(){
local command=$1
if ! which $command > /dev/null;then
echo "$command not found,please install it."
exit 1
fi
}
#yes or no询问
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
}
#安装编译工具
install_tool(){
if cat /etc/issue | grep -q -E -i "ubuntu|debian";then
apt-get -y update
apt-get -y install gcc g++ make wget perl curl
elif cat /etc/issue | grep -q -E -i "centos|read hat|redhat";then
yum -y install gcc gcc-c++ make wget perl curl
elif cat /proc/version | grep -q -E -i "ubuntu|debian";then
apt-get -y update
apt-get -y install gcc g++ make wget perl curl
elif cat /proc/version | grep -q -E -i "centos|read hat|redhat";then
yum -y install gcc gcc-c++ make wget perl curl
fi
check_command_exist "gcc"
check_command_exist "g++"
check_command_exist "make"
check_command_exist "wget"
check_command_exist "perl"
}
#判断系统版本
check_sys_version(){
if cat /etc/issue | grep -q -E -i "ubuntu|debian";then
echo "debian"
elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat";then
echo "centos"
elif cat /proc/version | grep -q -E -i "ubuntu|debian";then
echo "debian"
elif cat /proc/version | grep -q -E -i "centos|red hat|redhat";then
echo "centos"
fi
}
#支持包管理工具安装依赖的系统
package_support(){
if cat /etc/issue | grep -q -E -i "ubuntu|debian";then
echo "1"
elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat";then
echo "1"
elif cat /proc/version | grep -q -E -i "ubuntu|debian";then
echo "1"
elif cat /proc/version | grep -q -E -i "centos|red hat|redhat";then
echo "1"
fi
}
#安装cmake
install_cmake(){
download_file "${cmake_other_link}" "${cmake_official_link}" "${cmake_filename}.tar.gz"
cd $cur_dir/soft/
tar xzvf ${cmake_filename}.tar.gz
cd ${cmake_filename}
make clean
error_detect "./configure --prefix=${depends_prefix}/${cmake_filename}"
error_detect "parallel_make"
error_detect "make install"
add_to_env "${depends_prefix}/${cmake_filename}"
}
#安装ncurses
install_ncurses(){
if [ "$mysql" == "${mysql5_1_filename}" ];then
download_file "${ncurses_other_link2}" "${ncurses_official_link2}" "${ncurses_filename2}.tar.gz"
cd $cur_dir/soft/
tar xzvf ${ncurses_filename2}.tar.gz
cd ${ncurses_filename2}
make clean
error_detect "./configure --prefix=${depends_prefix}/${ncurses_filename2} --with-shared"
error_detect "parallel_make"
error_detect "make install"
add_to_env "${depends_prefix}/${ncurses_filename2}"
else
download_file "${ncurses_other_link}" "${ncurses_official_link}" "${ncurses_filename}.tar.gz"
cd $cur_dir/soft/
tar xzvf ${ncurses_filename}.tar.gz
cd ${ncurses_filename}
make clean
error_detect "./configure --prefix=${depends_prefix}/${ncurses_filename} --with-shared"
error_detect "parallel_make"
error_detect "make install"
add_to_env "${depends_prefix}/${ncurses_filename}"
fi
}
#安装bison
install_bison(){
download_file "${bison_other_link}" "${bison_official_link}" "${bison_filename}.tar.gz"
cd $cur_dir/soft/
tar xzvf ${bison_filename}.tar.gz
cd ${bison_filename}
make clean
error_detect "./configure --prefix=${depends_prefix}/${bison_filename}"
error_detect "parallel_make"
error_detect "make install"
add_to_env "${depends_prefix}/${bison_filename}"
}
#安装patch
install_patch(){
download_file "${patch_other_link}" "${patch_official_link}" "${patch_filename}.tar.gz"
cd $cur_dir/soft/
tar xzvf ${patch_filename}.tar.gz
cd ${patch_filename}
make clean
error_detect "./configure --prefix=${depends_prefix}/${patch_filename}"
error_detect "parallel_make"
error_detect "make install"
add_to_env "${depends_prefix}/${patch_filename}"
}
#安装libiconv
install_libiconv(){
download_file "${libiconv_other_link}" "${libiconv_official_link}" "${libiconv_filename}.tar.gz"
cd $cur_dir/soft/
tar xzvf ${libiconv_filename}.tar.gz
cd ${libiconv_filename}
make clean
./configure --prefix=/usr
#修复ubuntu 13.04 错误:‘gets’未声明(不在函数内)
if grep -q -i "Ubuntu 13.04" /etc/issue;then
parallel_make
sed -i 's/_GL_WARN_ON_USE (gets.*/\/\/&/' srclib/stdio.h
parallel_make
else
parallel_make
fi
make install
}
#安装autoconf
install_autoconf(){
download_file "${autoconf_other_link}" "${autoconf_official_link}" "${autoconf_filename}.tar.gz"
cd $cur_dir/soft/
tar xzvf ${autoconf_filename}.tar.gz
cd ${autoconf_filename}
make clean
error_detect "./configure --prefix=${depends_prefix}/${autoconf_filename}"
error_detect "parallel_make"
error_detect "make install"
add_to_env "${depends_prefix}/${autoconf_filename}"
}
#安装libxml2
install_libxml2(){
download_file "${libxml2_other_link}" "${libxml2_official_link}" "${libxml2_filename}.tar.gz"
cd $cur_dir/soft/
tar xzvf ${libxml2_filename}.tar.gz
cd ${libxml2_filename}
make clean
error_detect "./configure --prefix=${depends_prefix}/${libxml2_filename}"
error_detect "parallel_make"
error_detect "make install"
add_to_env "${depends_prefix}/${libxml2_filename}"
create_lib64_dir "${depends_prefix}/${libxml2_filename}"
}
#安装openssl
install_openssl(){
download_file "${openssl_other_link}" "${openssl_official_link}" "${openssl_filename}.tar.gz"
cd $cur_dir/soft/
tar xzvf ${openssl_filename}.tar.gz
cd ${openssl_filename}
make clean
error_detect "./config --prefix=${depends_prefix}/${openssl_filename} shared threads"
#并行编译可能会出错
error_detect "make"
error_detect "make install"
add_to_env "${depends_prefix}/${openssl_filename}"
create_lib64_dir "${depends_prefix}/${openssl_filename}"
}
#安装zlib
install_zlib(){
download_file "${zlib_other_link}" "${zlib_official_link}" "${zlib_filename}.tar.gz"
cd $cur_dir/soft/
tar xzvf ${zlib_filename}.tar.gz
cd ${zlib_filename}
make clean
error_detect "./configure --prefix=${depends_prefix}/${zlib_filename}"
error_detect "parallel_make"
error_detect "make install"
add_to_env "${depends_prefix}/${zlib_filename}"
create_lib64_dir "${depends_prefix}/${zlib_filename}"
}
#安装libcurl
install_curl(){
download_file "${libcurl_other_link}" "${libcurl_official_link}" "${libcurl_filename}.tar.gz"
cd $cur_dir/soft/
tar xzvf ${libcurl_filename}.tar.gz
cd ${libcurl_filename}
make clean
error_detect "./configure --prefix=${depends_prefix}/${libcurl_filename} --with-ssl=${depends_prefix}/${openssl_filename}"
error_detect "parallel_make"
error_detect "make install"
add_to_env "${depends_prefix}/${libcurl_filename}"
create_lib64_dir "${depends_prefix}/${libcurl_filename}"
}
#安装pcre
install_pcre(){
download_file "${pcre_other_link}" "${pcre_official_link}" "${pcre_filename}.tar.gz"
cd $cur_dir/soft/
tar xzvf ${pcre_filename}.tar.gz
cd ${pcre_filename}
make clean
error_detect "./configure --prefix=${depends_prefix}/${pcre_filename}"
error_detect "parallel_make"
error_detect "make install"
add_to_env "${depends_prefix}/${pcre_filename}"
create_lib64_dir "${depends_prefix}/${pcre_filename}"
}
#安装libtool
install_libtool(){
download_file "${libtool_other_link}" "${libtool_official_link}" "${libtool_filename}.tar.gz"
cd $cur_dir/soft/
tar xzvf ${libtool_filename}.tar.gz
cd ${libtool_filename}
make clean
error_detect "./configure --prefix=${depends_prefix}/${libtool_filename} --enable-ltdl-install"
error_detect "parallel_make"
error_detect "make install"
add_to_env "${depends_prefix}/${libtool_filename}"
create_lib64_dir "${depends_prefix}/${libtool_filename}"
}
#安装libjpeg
install_libjpeg(){
download_file "${libjpeg_other_link}" "${libjpeg_official_link}" "${libjpeg_filename}.tar.gz"
cd $cur_dir/soft/
tar xzvf ${libjpeg_filename}.tar.gz
cd ${libjpeg_filename}
make clean
\cp ${depends_prefix}/${libtool_filename}/share/libtool/config/config.sub ./
\cp ${depends_prefix}/${libtool_filename}/share/libtool/config/config.guess ./
error_detect "./configure --prefix=${depends_prefix}/${libjpeg_filename} --enable-shared --enable-static"
mkdir -p ${depends_prefix}/${libjpeg_filename}/include/ ${depends_prefix}/${libjpeg_filename}/lib/ ${depends_prefix}/${libjpeg_filename}/bin/ ${depends_prefix}/${libjpeg_filename}/man/man1/
error_detect "parallel_make"
error_detect "make install"
add_to_env "${depends_prefix}/${libjpeg_filename}"
create_lib64_dir "${depends_prefix}/${libjpeg_filename}"
}
#安装libpng
install_libpng(){
download_file "${libpng_other_link}" "${libpng_official_link}" "${libpng_filename}.tar.gz"
cd $cur_dir/soft/
tar xzvf ${libpng_filename}.tar.gz
cd ${libpng_filename}
make clean
export LDFLAGS="-L${depends_prefix}/${zlib_filename}/lib"
export CPPFLAGS="-I${depends_prefix}/${zlib_filename}/include"
error_detect "./configure --prefix=${depends_prefix}/${libpng_filename}"
error_detect "parallel_make"
error_detect "make install"
unset LDFLAGS CPPFLAGS
add_to_env "${depends_prefix}/${libpng_filename}"
create_lib64_dir "${depends_prefix}/${libpng_filename}"
}
#安装mhash
install_mhash(){
download_file "${mhash_other_link}" "${mhash_official_link}" "${mhash_filename}.tar.gz"
cd $cur_dir/soft/
tar xzvf ${mhash_filename}.tar.gz
cd ${mhash_filename}
make clean
error_detect "./configure --prefix=${depends_prefix}/${mhash_filename}"
error_detect "parallel_make"
error_detect "make install"
add_to_env "${depends_prefix}/${mhash_filename}"
create_lib64_dir "${depends_prefix}/${mhash_filename}"
}
#安装freetype
install_freetype(){
download_file "${freetype_other_link}" "${freetype_official_link}" "${freetype_filename}.tar.gz"
cd $cur_dir/soft/
tar xzvf ${freetype_filename}.tar.gz
cd ${freetype_filename}
make clean
error_detect "./configure --prefix=${depends_prefix}/${freetype_filename}"
error_detect "parallel_make"
error_detect "make install"
add_to_env "${depends_prefix}/${freetype_filename}"
create_lib64_dir "${depends_prefix}/${freetype_filename}"
}
#安装libmcrypt
install_libmcrypt(){
download_file "${libmcrypt_other_link}" "${libmcrypt_official_link}" "${libmcrypt_filename}.tar.gz"
cd $cur_dir/soft/
tar xzvf ${libmcrypt_filename}.tar.gz
cd ${libmcrypt_filename}
make clean
error_detect "./configure --prefix=${depends_prefix}/${libmcrypt_filename}"
error_detect "parallel_make"
error_detect "make install"
add_to_env "${depends_prefix}/${libmcrypt_filename}"
create_lib64_dir "${depends_prefix}/${libmcrypt_filename}"
}
#安装m4
install_m4(){
download_file "${m4_other_link}" "${m4_official_link}" "${m4_filename}.tar.gz"
cd $cur_dir/soft/
tar xzvf ${m4_filename}.tar.gz
cd ${m4_filename}
make clean
error_detect "./configure --prefix=${depends_prefix}/${m4_filename}"
error_detect "parallel_make"
error_detect "make install"
add_to_env "${depends_prefix}/${m4_filename}"
}
#安装ImageMagick
install_ImageMagick(){
download_file "${ImageMagick_other_link}" "${ImageMagick_official_link}" "${ImageMagick_filename}.tar.gz"
cd $cur_dir/soft/
tar xzvf ${ImageMagick_filename}.tar.gz
cd ${ImageMagick_filename}
error_detect "./configure --prefix=${depends_prefix}/${ImageMagick_filename}"
error_detect "parallel_make"
error_detect "make install"
#修复php-ImageMagick找不到MagickWand.h的问题
cd ${depends_prefix}/${ImageMagick_filename}/include
ln -s ImageMagick-6 ImageMagick
add_to_env "${depends_prefix}/${ImageMagick_filename}"
}
#安装pkgconfig
install_pkgconfig(){
download_file "${pkgconfig_other_link}" "${pkgconfig_official_link}" "${pkgconfig_filename}.tar.gz"
cd $cur_dir/soft/
tar xzvf ${pkgconfig_filename}.tar.gz
cd ${pkgconfig_filename}
error_detect "./configure --prefix=${depends_prefix}/${pkgconfig_filename}"
error_detect "parallel_make"
error_detect "make install"
add_to_env "${depends_prefix}/${pkgconfig_filename}"
}
#添加必要的环境变量
add_to_env(){
local location=$1
cd ${location} && [ ! -d lib ] && [ -d lib64 ] && ln -s lib64 lib
[ -d "${location}/lib" ] && export LD_LIBRARY_PATH=${location}/lib:$LD_LIBRARY_PATH
[ -d "${location}/bin" ] && export PATH=${location}/bin:$PATH
}
#测试元素是否在数组里
if_in_array(){
local element=$1
local array=$2
for i in $array
do
if [ "$i" == "$element" ];then
return 0
fi
done
return 1
}
#判断php版本
check_php_version(){
local location=$1
$location/bin/php -v | grep -q -i -E "php[ ]+5\.2" && echo "5.2"
$location/bin/php -v | grep -q -i -E "php[ ]+5\.3" && echo "5.3"
$location/bin/php -v | grep -q -i -E "php[ ]+5\.4" && echo "5.4"
}
#安装libevent
install_libevent(){
download_file "${libevent_other_link}" "${libevent_official_link}" "${libevent_filename}.tar.gz"
cd $cur_dir/soft/
tar xzvf ${libevent_filename}.tar.gz
cd ${libevent_filename}
make clean
error_detect "./configure --prefix=${depends_prefix}/${libevent_filename}"
error_detect "parallel_make"
error_detect "make install"
add_to_env "${depends_prefix}/${libevent_filename}"
}
#检测是否安装,存在就不安装了
check_installed(){
local command=$1
local location=$2
if [ -d "$location" ];then
echo "$location found,skip the installation."
add_to_env "$location"
else
${command}
fi
}
#检测是否安装,带确认对话
check_installed_ask(){
local command=$1
local location=$2
if [ -d "$location" ];then
#发现路径存在,是否删除安装
yes_or_no "directory $location found,may be the software had installed,remove it and reinstall it" "rm -rf $location && ${command}" "echo 'do not reinstall this software.' "
else
${command}
fi
}
#获取版本号
VersionGet(){
grep -oE "[0-9.]+" /etc/issue
}
#判断centos版本
CentOSVerCheck(){
local code=$1
local version="`VersionGet`"
local main_ver=${version%.*}
if [ $main_ver == $code ];then
return 0
else
return 1
fi
}
#安装php依赖
install_php_depends(){
#安装libiconv
if [ ! -f "/usr/lib/libiconv.so" ] && [ ! -f "/usr/lib64/libiconv.so" ];then
install_libiconv
fi
#安装依赖
if [ "`check_sys_version`" == "debian" ];then
apt-get -y install m4 autoconf libcurl4-gnutls-dev autoconf2.13 libxml2-dev openssl zlib1g-dev libpcre3-dev libtool libjpeg-dev libpng12-dev libfreetype6-dev libmhash-dev libmcrypt-dev libssl-dev
create_lib_link "libjpeg.so"
create_lib_link "libpng.so"
create_lib_link "libltdl.so"
create_lib_link "libmcrypt.so"
create_lib_link "libiconv.so"
create_lib_link "libiconv.so.2"
elif [ "`check_sys_version`" == "centos" ];then
yum -y install m4 autoconf libxml2-devel openssl openssl-devel zlib-devel curl-devel pcre-devel libtool-libs libtool-ltdl-devel libjpeg-devel libpng-devel freetype-devel mhash-devel libmcrypt-devel
create_lib_link "libjpeg.so"
create_lib_link "libpng.so"
create_lib_link "libltdl.so"
create_lib_link "libmcrypt.so"
create_lib_link "libiconv.so"
create_lib_link "libiconv.so.2"
#解决centos 6 libmcrypt和libmhash不在在的问题
if CentOSVerCheck 6;then
if is_64bit; then
rpm -i $cur_dir/conf/libmcrypt-2.5.7-1.2.el6.rf.x86_64.rpm
rpm -i $cur_dir/conf/libmcrypt-devel-2.5.7-1.2.el6.rf.x86_64.rpm
rpm -i $cur_dir/conf/mhash-0.9.9.9-3.el6.x86_64.rpm
rpm -i $cur_dir/conf/mhash-devel-0.9.9.9-3.el6.x86_64.rpm
else
rpm -i $cur_dir/conf/libmcrypt-2.5.7-1.2.el6.rf.i686.rpm
rpm -i $cur_dir/conf/libmcrypt-devel-2.5.7-1.2.el6.rf.i686.rpm
rpm -i $cur_dir/conf/mhash-0.9.9.9-3.el6.i686.rpm
rpm -i $cur_dir/conf/mhash-devel-0.9.9.9-3.el6.i686.rpm
fi
fi
else
check_installed "install_m4" "${depends_prefix}/${m4_filename}"
check_installed "install_autoconf" "${depends_prefix}/${autoconf_filename}"
check_installed "install_libxml2" "${depends_prefix}/${libxml2_filename}"
check_installed "install_openssl" "${depends_prefix}/${openssl_filename}"
check_installed "install_zlib " "${depends_prefix}/${zlib_filename}"
check_installed "install_curl" "${depends_prefix}/${libcurl_filename}"
check_installed "install_pcre" "${depends_prefix}/${pcre_filename}"
check_installed "install_libtool" "${depends_prefix}/${libtool_filename}"
check_installed "install_libjpeg" "${depends_prefix}/${libjpeg_filename}"
check_installed "install_libpng" "${depends_prefix}/${libpng_filename}"
check_installed "install_freetype" "${depends_prefix}/${freetype_filename}"
check_installed "install_mhash " "${depends_prefix}/${mhash_filename}"
check_installed "install_libmcrypt" "${depends_prefix}/${libmcrypt_filename}"
fi
}
#在/usr/lib创建库文件的链接
create_lib_link(){
local lib=$1
if [ ! -s "/usr/lib64/$lib" ] && [ ! -s "/usr/lib/$lib" ];then
libdir=$(find /usr -name "$lib" | awk 'NR==1{print}')
if [ "$libdir" != "" ];then
if is_64bit;then
mkdir /usr/lib64
ln -s $libdir /usr/lib64/$lib
ln -s $libdir /usr/lib/$lib
else
ln -s $libdir /usr/lib/$lib
fi
fi
fi
if is_64bit;then
mkdir /usr/lib64
[ ! -s "/usr/lib64/$lib" ] && [ -s "/usr/lib/$lib" ] && ln -s /usr/lib/${lib} /usr/lib64/${lib}
[ ! -s "/usr/lib/$lib" ] && [ -s "/usr/lib64/$lib" ] && ln -s /usr/lib64/${lib} /usr/lib/${lib}
fi
}
#在64位时需要创建lib64目录
create_lib64_dir(){
local dir=$1
if is_64bit;then
if [ -s "$dir/lib/" ] && [ ! -s "$dir/lib64/" ];then
cd $dir
ln -s lib lib64
fi
fi
}
#显示菜单
display_menu(){
local soft=$1
local prompt="which ${soft} you'd install: "
eval arr=(\${${soft}_arr[@]})
while true
do
echo -e "#################### ${soft} setting ####################\n\n"
for ((i=1;i<=${#arr[@]};i++ )); do echo -e "$i) ${arr[$i-1]}"; done
echo
read -p "${prompt}" $soft
if [ "${arr[$soft-1]}" == "" ];then
prompt="input errors,please input a number: "
else
eval $soft=${arr[$soft-1]}
eval echo "your selection: \$$soft"
break
fi
done
}