测试版本库,随便折腾。
陈炜
2024-12-23 c52062234bdaf9d463d8d583c1984a227c2c974d
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
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
LANG=en_US.UTF-8
 
if [ $(whoami) != "root" ];then
    echo "请使用root权限执行宝塔安装命令!"
    exit 1;
fi
 
is64bit=$(getconf LONG_BIT)
if [ "${is64bit}" != '64' ];then
    Red_Error "抱歉, 当前面板版本不支持32位系统, 请使用64位系统或安装宝塔5.9!";
fi
 
cd ~
setup_path="/www"
python_bin=$setup_path/server/panel/pyenv/bin/python
cpu_cpunt=$(cat /proc/cpuinfo|grep processor|wc -l)
 
if [ "$1" ];then
    IDC_CODE=$1
fi
 
GetSysInfo(){
    if [ -s "/etc/redhat-release" ];then
        SYS_VERSION=$(cat /etc/redhat-release)
    elif [ -s "/etc/issue" ]; then
        SYS_VERSION=$(cat /etc/issue)
    fi
    SYS_INFO=$(uname -a)
    SYS_BIT=$(getconf LONG_BIT)
    MEM_TOTAL=$(free -m|grep Mem|awk '{print $2}')
    CPU_INFO=$(getconf _NPROCESSORS_ONLN)
 
    echo -e ${SYS_VERSION}
    echo -e Bit:${SYS_BIT} Mem:${MEM_TOTAL}M Core:${CPU_INFO}
    echo -e ${SYS_INFO}
    echo -e "请截图以上报错信息发帖至论坛v7.hostcli.com/bbs求助"
}
Red_Error(){
    echo '=================================================';
    printf '\033[1;31;40m%b\033[0m\n' "$1";
    GetSysInfo
    exit 1;
}
Lock_Clear(){
    if [ -f "/etc/bt_crack.pl" ];then
        chattr -R -ia /www
        chattr -ia /etc/init.d/bt
        \cp -rpa /www/backup/panel/vhost/* /www/server/panel/vhost/
        mv /www/server/panel/BTPanel/__init__.bak /www/server/panel/BTPanel/__init__.py
        rm -f /etc/bt_crack.pl
    fi
}
Install_Check(){
    if [ "${INSTALL_FORCE}" ];then
        return
    fi
    echo -e "----------------------------------------------------"
    echo -e "检查已有其他Web/mysql环境,安装宝塔可能影响现有站点及数据"
    echo -e "Web/mysql service is alreday installed,Can't install panel"
    echo -e "----------------------------------------------------"
    echo -e "已知风险/Enter yes to force installation"
    read -p "输入yes强制安装: " yes;
    if [ "$yes" != "yes" ];then
        echo -e "------------"
        echo "取消安装"
        exit;
    fi
    INSTALL_FORCE="true"
}
System_Check(){
    MYSQLD_CHECK=$(ps -ef |grep mysqld|grep -v grep|grep -v /www/server/mysql)
    PHP_CHECK=$(ps -ef|grep php-fpm|grep master|grep -v /www/server/php)
    NGINX_CHECK=$(ps -ef|grep nginx|grep master|grep -v /www/server/nginx)
    HTTPD_CHECK=$(ps -ef |grep -E 'httpd|apache'|grep -v /www/server/apache|grep -v grep)
    if [ "${PHP_CHECK}" ] || [ "${MYSQLD_CHECK}" ] || [ "${NGINX_CHECK}" ] || [ "${HTTPD_CHECK}" ];then
        Install_Check
    fi
}
Get_Pack_Manager(){
    if [ -f "/usr/bin/yum" ] && [ -d "/etc/yum.repos.d" ]; then
        PM="yum"
    elif [ -f "/usr/bin/apt-get" ] && [ -f "/usr/bin/dpkg" ]; then
        PM="apt-get"        
    fi
}
Auto_Swap()
{
    swap=$(free |grep Swap|awk '{print $2}')
    if [ "${swap}" -gt 1 ];then
        echo "Swap total sizse: $swap";
        return;
    fi
    if [ ! -d /www ];then
        mkdir /www
    fi
    swapFile="/www/swap"
    dd if=/dev/zero of=$swapFile bs=1M count=1025
    mkswap -f $swapFile
    swapon $swapFile
    echo "$swapFile    swap    swap    defaults    0 0" >> /etc/fstab
    swap=`free |grep Swap|awk '{print $2}'`
    if [ $swap -gt 1 ];then
        echo "Swap total sizse: $swap";
        return;
    fi
    
    sed -i "/\/www\/swap/d" /etc/fstab
    rm -f $swapFile
}
Service_Add(){
    if [ "${PM}" == "yum" ] || [ "${PM}" == "dnf" ]; then
        chkconfig --add bt
        chkconfig --level 2345 bt on
    elif [ "${PM}" == "apt-get" ]; then
        update-rc.d bt defaults
    fi 
}
 
get_node_url(){
    if [ ! -f /bin/curl ];then
        if [ "${PM}" = "yum" ]; then
            yum install curl -y
        elif [ "${PM}" = "apt-get" ]; then
            apt-get install curl -y
        fi
    fi
    
    echo '---------------------------------------------';
    echo "Selected download node...";   
    download_Url='http://v7.hostcli.com';
    echo "Download node: $download_Url";
    echo '---------------------------------------------';
}
Remove_Package(){
    local PackageNmae=$1
    if [ "${PM}" == "yum" ];then
        isPackage=$(rpm -q ${PackageNmae}|grep "not installed")
        if [ -z "${isPackage}" ];then
            yum remove ${PackageNmae} -y
        fi 
    elif [ "${PM}" == "apt-get" ];then
        isPackage=$(dpkg -l|grep ${PackageNmae})
        if [ "${PackageNmae}" ];then
            apt-get remove ${PackageNmae} -y
        fi
    fi
}
Install_RPM_Pack(){
    yumPath=/etc/yum.conf
    Centos8Check=$(cat /etc/redhat-release | grep ' 8.' | grep -iE 'centos|Red Hat')
    isExc=$(cat $yumPath|grep httpd)
    if [ "$isExc" = "" ];then
        echo "exclude=httpd nginx php mysql mairadb python-psutil python2-psutil" >> $yumPath
    fi
 
    #yumBaseUrl=$(cat /etc/yum.repos.d/CentOS-Base.repo|grep baseurl=http|cut -d '=' -f 2|cut -d '$' -f 1|head -n 1)
    #[ "${yumBaseUrl}" ] && checkYumRepo=$(curl --connect-timeout 5 --head -s -o /dev/null -w %{http_code} ${yumBaseUrl})   
    #if [ "${checkYumRepo}" != "200" ];then
    #   curl -Ss --connect-timeout 3 -m 60 http://download.bt.cn/install/yumRepo_select.sh|bash
    #fi
    
    #尝试同步时间(从bt.cn)
    echo 'Synchronizing system time...'
    getBtTime=$(curl -sS --connect-timeout 3 -m 60 http://v7.hostcli.com/api/index/get_time)
    if [ "${getBtTime}" ];then  
        date -s "$(date -d @$getBtTime +"%Y-%m-%d %H:%M:%S")"
    fi
 
    if [ -z "${Centos8Check}" ]; then
        yum install ntp -y
        rm -rf /etc/localtime
        ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
 
        #尝试同步国际时间(从ntp服务器)
        ntpdate 0.asia.pool.ntp.org
        setenforce 0
    fi
 
    startTime=`date +%s`
 
    sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
    #yum remove -y python-requests python3-requests python-greenlet python3-greenlet
    yumPacks="libcurl-devel wget tar gcc make zip unzip openssl openssl-devel gcc libxml2 libxml2-devel libxslt* zlib zlib-devel libjpeg-devel libpng-devel libwebp libwebp-devel freetype freetype-devel lsof pcre pcre-devel vixie-cron crontabs icu libicu-devel c-ares libffi-devel bzip2-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel"
    yum install -y ${yumPacks}
 
    for yumPack in ${yumPacks}
    do
        rpmPack=$(rpm -q ${yumPack})
        packCheck=$(echo ${rpmPack}|grep not)
        if [ "${packCheck}" ]; then
            yum install ${yumPack} -y
        fi
    done
    if [ -f "/usr/bin/dnf" ]; then
        dnf install -y redhat-rpm-config
    fi
 
    ALI_OS=$(cat /etc/redhat-release |grep "Alibaba Cloud Linux release 3")
    if [ -z "${ALI_OS}" ];then 
        yum install epel-release -y
    fi
}
Install_Deb_Pack(){
    ln -sf bash /bin/sh
    apt-get update -y
    apt-get install ruby -y
    apt-get install lsb-release -y
    #apt-get install ntp ntpdate -y
    #/etc/init.d/ntp stop
    #update-rc.d ntp remove
    #cat >>~/.profile<<EOF
    #TZ='Asia/Shanghai'; export TZ
    #EOF
    #rm -rf /etc/localtime
    #cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
    #echo 'Synchronizing system time...'
    #ntpdate 0.asia.pool.ntp.org
    #apt-get upgrade -y
    debPacks="wget curl libcurl4-openssl-dev gcc make zip unzip tar openssl libssl-dev gcc libxml2 libxml2-dev zlib1g zlib1g-dev libjpeg-dev libpng-dev lsof libpcre3 libpcre3-dev cron net-tools swig build-essential libffi-dev libbz2-dev libncurses-dev libsqlite3-dev libreadline-dev tk-dev libgdbm-dev libdb-dev libdb++-dev libpcap-dev xz-utils git";
    apt-get install -y $debPacks --force-yes
 
    for debPack in ${debPacks}
    do
        packCheck=$(dpkg -l ${debPack})
        if [ "$?" -ne "0" ] ;then
            apt-get install -y debPack
        fi
    done
 
    if [ ! -d '/etc/letsencrypt' ];then
        mkdir -p /etc/letsencryp
        mkdir -p /var/spool/cron
        if [ ! -f '/var/spool/cron/crontabs/root' ];then
            echo '' > /var/spool/cron/crontabs/root
            chmod 600 /var/spool/cron/crontabs/root
        fi  
    fi
}
Install_Bt(){
    panelPort="8888"
    if [ -f ${setup_path}/server/panel/data/port.pl ];then
        panelPort=$(cat ${setup_path}/server/panel/data/port.pl)
    fi
    mkdir -p ${setup_path}/server/panel/logs
    mkdir -p ${setup_path}/server/panel/vhost/apache
    mkdir -p ${setup_path}/server/panel/vhost/nginx
    mkdir -p ${setup_path}/server/panel/vhost/rewrite
    mkdir -p ${setup_path}/server/panel/install
    mkdir -p /www/server
    mkdir -p /www/wwwroot
    mkdir -p /www/wwwlogs
    mkdir -p /www/backup/database
    mkdir -p /www/backup/site
 
    if [ ! -f "/usr/bin/unzip" ]; then
        if [ "${PM}" = "yum" ]; then
            yum install unzip -y
        elif [ "${PM}" = "apt-get" ]; then
            apt-get install unzip -y
        fi
    fi
 
    if [ -f "/etc/init.d/bt" ]; then
        /etc/init.d/bt stop
        sleep 1
    fi
 
    wget -O panel.zip ${download_Url}/install/src/panel_new.zip -T 10
    wget -O /etc/init.d/bt ${download_Url}/install/src/bt6.init -T 10
    wget -O /www/server/panel/install/public.sh ${download_Url}/install/public.sh -T 10
 
    if [ -f "${setup_path}/server/panel/data/default.db" ];then
        if [ -d "/${setup_path}/server/panel/old_data" ];then
            rm -rf ${setup_path}/server/panel/old_data
        fi
        mkdir -p ${setup_path}/server/panel/old_data
        d_format=$(date +"%Y%m%d_%H%M%S")
        \cp -arf ${setup_path}/server/panel/data/default.db ${setup_path}/server/panel/data/default_backup_${d_format}.db
        mv -f ${setup_path}/server/panel/data/default.db ${setup_path}/server/panel/old_data/default.db
        mv -f ${setup_path}/server/panel/data/system.db ${setup_path}/server/panel/old_data/system.db
        mv -f ${setup_path}/server/panel/data/port.pl ${setup_path}/server/panel/old_data/port.pl
        mv -f ${setup_path}/server/panel/data/admin_path.pl ${setup_path}/server/panel/old_data/admin_path.pl
    fi
 
    unzip -o panel.zip -d ${setup_path}/server/ > /dev/null
 
    if [ -d "${setup_path}/server/panel/old_data" ];then
        mv -f ${setup_path}/server/panel/old_data/default.db ${setup_path}/server/panel/data/default.db
        mv -f ${setup_path}/server/panel/old_data/system.db ${setup_path}/server/panel/data/system.db
        mv -f ${setup_path}/server/panel/old_data/port.pl ${setup_path}/server/panel/data/port.pl
        mv -f ${setup_path}/server/panel/old_data/admin_path.pl ${setup_path}/server/panel/data/admin_path.pl
        if [ -d "/${setup_path}/server/panel/old_data" ];then
            rm -rf ${setup_path}/server/panel/old_data
        fi
    fi
 
    rm -f panel.zip
 
    if [ ! -f ${setup_path}/server/panel/tools.py ];then
        Red_Error "ERROR: Failed to download, please try install again!"
    fi
 
    rm -f ${setup_path}/server/panel/class/*.pyc
    rm -f ${setup_path}/server/panel/*.pyc
 
    chmod +x /etc/init.d/bt
    chmod -R 600 ${setup_path}/server/panel
    chmod -R +x ${setup_path}/server/panel/script
    ln -sf /etc/init.d/bt /usr/bin/bt
    echo "${panelPort}" > ${setup_path}/server/panel/data/port.pl
    wget -O /etc/init.d/bt ${download_Url}/install/src/bt7.init -T 10
    wget -O /www/server/panel/init.sh ${download_Url}/install/src/bt7.init -T 10
}
Install_Python_Lib(){
    curl -Ss --connect-timeout 3 -m 60 $download_Url/install/pip_select.sh|bash
    pyenv_path="/www/server/panel"
    if [ -f $pyenv_path/pyenv/bin/python ];then
        is_err=$($pyenv_path/pyenv/bin/python3.7 -V 2>&1|grep 'Could not find platform')
        if [ "$is_err" = "" ];then
            chmod -R 700 $pyenv_path/pyenv/bin
            is_package=$($python_bin -m psutil 2>&1|grep package)
            if [ "$is_package" = "" ];then
                wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip.txt -T 5
                $pyenv_path/pyenv/bin/pip install -U pip
                $pyenv_path/pyenv/bin/pip install -U setuptools
                $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt
            fi
            source $pyenv_path/pyenv/bin/activate
            return
        else
            rm -rf $pyenv_path/pyenv
        fi
    fi
    py_version="3.7.8"
    mkdir -p $pyenv_path
    os_type='el'
    os_version='7'
    is_export_openssl=0
    Get_Versions
    Centos6_Openssl
    Other_Openssl
    echo "OS: $os_type - $os_version"
    is_aarch64=$(uname -a|grep aarch64)
    if [ "$is_aarch64" != "" ];then
        os_version="aarch64"
    fi
    
    if [ -f "/www/server/panel/pymake.pl" ];then
        os_version=""
        rm -f /www/server/panel/pymake.pl
    fi  
 
    if [ "${os_version}" != "" ];then
        pyenv_file="/www/pyenv.tar.gz"
        wget -O $pyenv_file $download_Url/install/pyenv/pyenv-${os_type}${os_version}-x${is64bit}.tar.gz -T 10
        tmp_size=$(du -b $pyenv_file|awk '{print $1}')
        if [ $tmp_size -lt 703460 ];then
            rm -f $pyenv_file
            echo "ERROR: Download python env fielded."
        else
            echo "Install python env..."
            tar zxvf $pyenv_file -C $pyenv_path/ > /dev/null
            chmod -R 700 $pyenv_path/pyenv/bin
            if [ ! -f $pyenv_path/pyenv/bin/python ];then
                rm -f $pyenv_file
                Red_Error "ERROR: Install python env fielded."
            fi
            is_err=$($pyenv_path/pyenv/bin/python3.7 -V 2>&1|grep 'Could not find platform')
            if [ "$is_err" = "" ];then
                rm -f $pyenv_file
                ln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btpip
                ln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btpython
                source $pyenv_path/pyenv/bin/activate
                return
            else
                rm -f $pyenv_file
                rm -rf $pyenv_path/pyenv
            fi
        fi
        
    fi
    if [ -f /usr/local/openssl/lib/libssl.so ];then
        export LDFLAGS="-L/usr/local/openssl/lib"
        export CPPFLAGS="-I/usr/local/openssl/include"
        export PKG_CONFIG_PATH="/usr/local/openssl/lib/pkgconfig"
        echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/openssl/lib" >> /etc/profile
        source /etc/profile
    fi
    cd /www
    python_src='/www/python_src.tar.xz'
    python_src_path="/www/Python-${py_version}"
    wget -O $python_src $download_Url/src/Python-${py_version}.tar.xz -T 5
    tmp_size=$(du -b $python_src|awk '{print $1}')
    if [ $tmp_size -lt 10703460 ];then
        rm -f $python_src
        Red_Error "ERROR: Download python source code fielded."
    fi
    tar xvf $python_src
    rm -f $python_src
    cd $python_src_path
    ./configure --prefix=$pyenv_path/pyenv
    make -j$cpu_cpunt
    make install
    if [ ! -f $pyenv_path/pyenv/bin/python3.7 ];then
        rm -rf $python_src_path
        Red_Error "ERROR: Make python env fielded."
    fi
    cd ~
    rm -rf $python_src_path
    wget -O $pyenv_path/pyenv/bin/activate $download_Url/install/pyenv/activate.panel -T 5
    wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip-3.7.8.txt -T 5
    ln -sf $pyenv_path/pyenv/bin/pip3.7 $pyenv_path/pyenv/bin/pip
    ln -sf $pyenv_path/pyenv/bin/python3.7 $pyenv_path/pyenv/bin/python
    ln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btpip
    ln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btpython
    chmod -R 700 $pyenv_path/pyenv/bin
    $pyenv_path/pyenv/bin/pip install -U pip
    $pyenv_path/pyenv/bin/pip install -U setuptools
    $pyenv_path/pyenv/bin/pip install -U wheel==0.34.2 
    $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt
    source $pyenv_path/pyenv/bin/activate
}
Other_Openssl(){
    openssl_version=$(openssl version|grep -Eo '[0-9]\.[0-9]\.[0-9]')
    if [ "$openssl_version" = '1.0.1' ] || [ "$openssl_version" = '1.0.0' ];then    
        opensslVersion="1.0.2r"
        if [ ! -f "/usr/local/openssl/lib/libssl.so" ];then
            cd /www
            openssl_src_file=/www/openssl.tar.gz
            wget -O $openssl_src_file ${download_Url}/src/openssl-${opensslVersion}.tar.gz
            tmp_size=$(du -b $openssl_src_file|awk '{print $1}')
            if [ $tmp_size -lt 703460 ];then
                rm -f $openssl_src_file
                Red_Error "ERROR: Download openssl-1.0.2 source code fielded."
            fi
            tar -zxf $openssl_src_file
            rm -f $openssl_src_file
            cd openssl-${opensslVersion}
            #zlib-dynamic shared
            ./config --openssldir=/usr/local/openssl zlib-dynamic shared
            make -j${cpuCore} 
            make install
            echo  "/usr/local/openssl/lib" > /etc/ld.so.conf.d/zopenssl.conf
            ldconfig
            cd ..
            rm -rf openssl-${opensslVersion}
            is_export_openssl=1
            cd ~
        fi
    fi
}
Insatll_Libressl(){
    openssl_version=$(openssl version|grep -Eo '[0-9]\.[0-9]\.[0-9]')
    if [ "$openssl_version" = '1.0.1' ] || [ "$openssl_version" = '1.0.0' ];then    
        opensslVersion="3.0.2"
        cd /www
        openssl_src_file=/www/openssl.tar.gz
        wget -O $openssl_src_file ${download_Url}/install/pyenv/libressl-${opensslVersion}.tar.gz
        tmp_size=$(du -b $openssl_src_file|awk '{print $1}')
        if [ $tmp_size -lt 703460 ];then
            rm -f $openssl_src_file
            Red_Error "ERROR: Download libressl-$opensslVersion source code fielded."
        fi
        tar -zxf $openssl_src_file
        rm -f $openssl_src_file
        cd libressl-${opensslVersion}
        ./config –prefix=/usr/local/lib
        make -j${cpuCore}
        make install
        ldconfig
        ldconfig -v
        cd ..
        rm -rf libressl-${opensslVersion}
        is_export_openssl=1
        cd ~
    fi
}
Centos6_Openssl(){
    if [ "$os_type" != 'el' ];then
        return
    fi
    if [ "$os_version" != '6' ];then
        return
    fi
    echo 'Centos6 install openssl-1.0.2...'
    openssl_rpm_file="/www/openssl.rpm"
    wget -O $openssl_rpm_file $download_Url/rpm/centos6/${is64bit}/bt-openssl102.rpm -T 10
    tmp_size=$(du -b $openssl_rpm_file|awk '{print $1}')
    if [ $tmp_size -lt 102400 ];then
        rm -f $openssl_rpm_file
        Red_Error "ERROR: Download python env fielded."
    fi
    rpm -ivh $openssl_rpm_file
    rm -f $openssl_rpm_file
    is_export_openssl=1
}
Get_Versions(){
    redhat_version_file="/etc/redhat-release"
    deb_version_file="/etc/issue"
    if [ -f $redhat_version_file ];then
        os_type='el'
        is_aliyunos=$(cat $redhat_version_file|grep Aliyun)
        if [ "$is_aliyunos" != "" ];then
            return
        fi
        os_version=$(cat $redhat_version_file|grep CentOS|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]')
        if [ "${os_version}" = "5" ];then
            os_version=""
        fi
    else
        os_type='ubuntu'
        os_version=$(cat $deb_version_file|grep Ubuntu|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]+')
        if [ "${os_version}" = "" ];then
            os_type='debian'
            os_version=$(cat $deb_version_file|grep Debian|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '[0-9]+')
            if [ "${os_version}" = "" ];then
                os_version=$(cat $deb_version_file|grep Debian|grep -Eo '[0-9]+')
            fi
            if [ "${os_version}" = "8" ];then
                os_version=""
            fi
            if [ "${is64bit}" = '32' ];then
                os_version=""
            fi
        else
            if [ "$os_version" = "14" ];then
                os_version=""
            fi
            if [ "$os_version" = "12" ];then
                os_version=""
            fi
            if [ "$os_version" = "19" ];then
                os_version=""
            fi
 
        fi
    fi
}
Set_Bt_Panel(){
    password=$(cat /dev/urandom | head -n 16 | md5sum | head -c 8)
    sleep 1
    admin_auth="/www/server/panel/data/admin_path.pl"
    if [ ! -f ${admin_auth} ];then
        auth_path=$(cat /dev/urandom | head -n 16 | md5sum | head -c 8)
        echo "/${auth_path}" > ${admin_auth}
    fi
    auth_path=$(cat ${admin_auth})
    cd ${setup_path}/server/panel/
    /etc/init.d/bt start
    $python_bin -m py_compile tools.py
    $python_bin tools.py username
    username=$($python_bin tools.py panel ${password})
    cd ~
    echo "${password}" > ${setup_path}/server/panel/default.pl
    chmod 600 ${setup_path}/server/panel/default.pl
    sleep 3
    /etc/init.d/bt restart  
    sleep 3
    isStart=$(ps aux |grep 'BT-Panel'|grep -v grep|awk '{print $2}')
    LOCAL_CURL=$(curl 127.0.0.1:8888/login 2>&1 |grep -i html)
    if [ -z "${isStart}" ] && [ -z "${LOCAL_CURL}" ];then
        /etc/init.d/bt 22
        cd /www/server/panel/pyenv/bin
        touch t.pl
        ls -al python3.7 python
        lsattr python3.7 python
        Red_Error "ERROR: The BT-Panel service startup failed."
    fi
}
Set_Firewall(){
    sshPort=$(cat /etc/ssh/sshd_config | grep 'Port '|awk '{print $2}')
    if [ "${PM}" = "apt-get" ]; then
        apt-get install -y ufw
        if [ -f "/usr/sbin/ufw" ];then
            ufw allow 20/tcp
            ufw allow 21/tcp
            ufw allow 22/tcp
            ufw allow 80/tcp
            ufw allow 888/tcp
            ufw allow ${panelPort}/tcp
            ufw allow ${sshPort}/tcp
            ufw allow 39000:40000/tcp
            ufw_status=`ufw status`
            echo y|ufw enable
            ufw default deny
            ufw reload
        fi
    else
        if [ -f "/etc/init.d/iptables" ];then
            iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPT
            iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
            iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
            iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
            iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${panelPort} -j ACCEPT
            iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${sshPort} -j ACCEPT
            iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 39000:40000 -j ACCEPT
            #iptables -I INPUT -p tcp -m state --state NEW -m udp --dport 39000:40000 -j ACCEPT
            iptables -A INPUT -p icmp --icmp-type any -j ACCEPT
            iptables -A INPUT -s localhost -d localhost -j ACCEPT
            iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
            iptables -P INPUT DROP
            service iptables save
            sed -i "s#IPTABLES_MODULES=\"\"#IPTABLES_MODULES=\"ip_conntrack_netbios_ns ip_conntrack_ftp ip_nat_ftp\"#" /etc/sysconfig/iptables-config
            iptables_status=$(service iptables status | grep 'not running')
            if [ "${iptables_status}" == '' ];then
                service iptables restart
            fi
        else
            AliyunCheck=$(cat /etc/redhat-release|grep "Aliyun Linux")
            [ "${AliyunCheck}" ] && return
            yum install firewalld -y
            [ "${Centos8Check}" ] && yum reinstall python3-six -y
            systemctl enable firewalld
            systemctl start firewalld
            firewall-cmd --set-default-zone=public > /dev/null 2>&1
            firewall-cmd --permanent --zone=public --add-port=20/tcp > /dev/null 2>&1
            firewall-cmd --permanent --zone=public --add-port=21/tcp > /dev/null 2>&1
            firewall-cmd --permanent --zone=public --add-port=22/tcp > /dev/null 2>&1
            firewall-cmd --permanent --zone=public --add-port=80/tcp > /dev/null 2>&1
            firewall-cmd --permanent --zone=public --add-port=${panelPort}/tcp > /dev/null 2>&1
            firewall-cmd --permanent --zone=public --add-port=${sshPort}/tcp > /dev/null 2>&1
            firewall-cmd --permanent --zone=public --add-port=39000-40000/tcp > /dev/null 2>&1
            #firewall-cmd --permanent --zone=public --add-port=39000-40000/udp > /dev/null 2>&1
            firewall-cmd --reload
        fi
    fi
}
Get_Ip_Address(){
    getIpAddress=""
    getIpAddress=$(curl -sS --connect-timeout 10 -m 60 https://v7.hostcli.com/Api/getIpAddress)
    if [ -z "${getIpAddress}" ] || [ "${getIpAddress}" = "0.0.0.0" ]; then
        isHosts=$(cat /etc/hosts|grep 'v7.hostcli.com')
        if [ -z "${isHosts}" ];then
            #echo "" >> /etc/hosts
            #echo "103.224.251.67 v7.hostcli.com" >> /etc/hosts
            getIpAddress=$(curl -sS --connect-timeout 10 -m 60 https://v7.hostcli.com/Api/getIpAddress)
            if [ -z "${getIpAddress}" ];then
                sed -i "/v7.hostcli.com/d" /etc/hosts
            fi
        fi
    fi
 
    ipv4Check=$($python_bin -c "import re; print(re.match('^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$','${getIpAddress}'))")
    if [ "${ipv4Check}" == "None" ];then
        ipv6Address=$(echo ${getIpAddress}|tr -d "[]")
        ipv6Check=$($python_bin -c "import re; print(re.match('^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$','${ipv6Address}'))")
        if [ "${ipv6Check}" == "None" ]; then
            getIpAddress="SERVER_IP"
        else
            echo "True" > ${setup_path}/server/panel/data/ipv6.pl
            sleep 1
            /etc/init.d/bt restart
        fi
    fi
 
    if [ "${getIpAddress}" != "SERVER_IP" ];then
        echo "${getIpAddress}" > ${setup_path}/server/panel/data/iplist.txt
    fi
    LOCAL_IP=$(ip addr | grep -E -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -E -v "^127\.|^255\.|^0\." | head -n 1)
}
Setup_Count(){
    curl -sS --connect-timeout 10 -m 60 https://v7.hostcli.com/Api/SetupCount?type=Linux\&o=$1 > /dev/null 2>&1
    if [ "$1" != "" ];then
        echo $1 > /www/server/panel/data/o.pl
        cd /www/server/panel
        $python_bin tools.py o
    fi
    echo /www > /var/bt_setupPath.conf
}
Install_Main(){
    startTime=`date +%s`
    Lock_Clear
    System_Check
    Get_Pack_Manager
    get_node_url
 
    MEM_TOTAL=$(free -g|grep Mem|awk '{print $2}')
    if [ "${MEM_TOTAL}" -le "1" ];then
        Auto_Swap
    fi
    
    if [ "${PM}" = "yum" ]; then
        Install_RPM_Pack
    elif [ "${PM}" = "apt-get" ]; then
        Install_Deb_Pack
    fi
 
    Install_Python_Lib
    Install_Bt
    
 
    Set_Bt_Panel
    Service_Add
    Set_Firewall
 
    Get_Ip_Address
    Setup_Count ${IDC_CODE}
}
 
echo "
+----------------------------------------------------------------------
| hostcli.com FOR CentOS/Ubuntu/Debian
+----------------------------------------------------------------------
| Copyright © 2015-2099 HostCli(http://v7.hostcli.com) All rights reserved.
+----------------------------------------------------------------------
| The WebPanel URL will be http://SERVER_IP:8888 when installed.
+----------------------------------------------------------------------
"
while [ "$go" != 'y' ] && [ "$go" != 'n' ]
do
    read -p "Do you want to install Bt-Panel to the $setup_path directory now?(y/n): " go;
done
 
if [ "$go" == 'n' ];then
    exit;
fi
 
Install_Main
echo > /www/server/panel/data/bind.pl
echo -e "=================================================================="
echo -e "\033[32mCongratulations! Installed successfully!\033[0m"
echo -e "=================================================================="
echo  "外网面板地址: http://${getIpAddress}:${panelPort}${auth_path}"
echo  "内网面板地址: http://${LOCAL_IP}:${panelPort}${auth_path}"
echo -e "username: $username"
echo -e "password: $password"
echo -e "\033[33mIf you cannot access the panel,\033[0m"
echo -e "\033[33mrelease the following panel port [${panelPort}] in the security group\033[0m"
echo -e "\033[33m若无法访问面板,请检查防火墙/安全组是否有放行面板[${panelPort}]端口\033[0m"
echo -e "=================================================================="
 
endTime=`date +%s`
((outTime=($endTime-$startTime)/60))
echo -e "Time consumed:\033[32m $outTime \033[0mMinute!"