Apache/Nginx/php/MySQL/pgsql/gitlab/java(已有环境不可安装)

    1. #!/bin/bash
    2. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
    3. export PATH
    4. LANG=en_US.UTF-8
    5. cd ~
    6. setup_path="/www"
    7. python_bin=$setup_path/server/panel/pyenv/bin/python
    8. cpu_cpunt=$(cat /proc/cpuinfo|grep processor|wc -l)
    9. if [ "$1" ];then
    10. IDC_CODE=$1
    11. fi
    12. GetSysInfo(){
    13. if [ -s "/etc/redhat-release" ];then
    14. SYS_VERSION=$(cat /etc/redhat-release)
    15. elif [ -s "/etc/issue" ]; then
    16. SYS_VERSION=$(cat /etc/issue)
    17. fi
    18. SYS_INFO=$(uname -a)
    19. SYS_BIT=$(getconf LONG_BIT)
    20. MEM_TOTAL=$(free -m|grep Mem|awk '{print $2}')
    21. CPU_INFO=$(getconf _NPROCESSORS_ONLN)
    22. echo -e ${SYS_VERSION}
    23. echo -e Bit:${SYS_BIT} Mem:${MEM_TOTAL}M Core:${CPU_INFO}
    24. echo -e ${SYS_INFO}
    25. echo -e "请截图以上报错信息发帖至论坛www.bt.cn/bbs求助"
    26. }
    27. Red_Error(){
    28. echo '=================================================';
    29. printf '\033[1;31;40m%b\033[0m\n' "$1";
    30. GetSysInfo
    31. exit 1;
    32. }
    33. is64bit=$(getconf LONG_BIT)
    34. if [ "${is64bit}" != '64' ];then
    35. Red_Error "抱歉, 当前面板版本不支持32位系统, 请使用64位系统或安装宝塔5.9!";
    36. fi
    37. Lock_Clear(){
    38. if [ -f "/etc/bt_crack.pl" ];then
    39. chattr -R -ia /www
    40. chattr -ia /etc/init.d/bt
    41. \cp -rpa /www/backup/panel/vhost/* /www/server/panel/vhost/
    42. mv /www/server/panel/BTPanel/__init__.bak /www/server/panel/BTPanel/__init__.py
    43. rm -f /etc/bt_crack.pl
    44. fi
    45. }
    46. Install_Check(){
    47. while [ "$yes" != 'yes' ] && [ "$yes" != 'n' ]
    48. do
    49. echo -e "----------------------------------------------------"
    50. echo -e "已有Web环境,安装宝塔可能影响现有站点"
    51. echo -e "Web service is alreday installed,Can't install panel"
    52. echo -e "----------------------------------------------------"
    53. read -p "输入yes强制安装/Enter yes to force installation (yes/n): " yes;
    54. done
    55. if [ "$yes" == 'n' ];then
    56. exit;
    57. fi
    58. }
    59. System_Check(){
    60. for serviceS in nginx httpd mysqld
    61. do
    62. if [ -f "/etc/init.d/${serviceS}" ]; then
    63. if [ "${serviceS}" = "httpd" ]; then
    64. serviceCheck=$(cat /etc/init.d/${serviceS}|grep /www/server/apache)
    65. elif [ "${serviceS}" = "mysqld" ]; then
    66. serviceCheck=$(cat /etc/init.d/${serviceS}|grep /www/server/mysql)
    67. else
    68. serviceCheck=$(cat /etc/init.d/${serviceS}|grep /www/server/${serviceS})
    69. fi
    70. [ -z "${serviceCheck}" ] && Install_Check
    71. fi
    72. done
    73. }
    74. Get_Pack_Manager(){
    75. if [ -f "/usr/bin/yum" ] && [ -d "/etc/yum.repos.d" ]; then
    76. PM="yum"
    77. elif [ -f "/usr/bin/apt-get" ] && [ -f "/usr/bin/dpkg" ]; then
    78. PM="apt-get"
    79. fi
    80. }
    81. Auto_Swap()
    82. {
    83. swap=$(free |grep Swap|awk '{print $2}')
    84. if [ "${swap}" -gt 1 ];then
    85. echo "Swap total sizse: $swap";
    86. return;
    87. fi
    88. if [ ! -d /www ];then
    89. mkdir /www
    90. fi
    91. swapFile="/www/swap"
    92. dd if=/dev/zero of=$swapFile bs=1M count=1025
    93. mkswap -f $swapFile
    94. swapon $swapFile
    95. echo "$swapFile swap swap defaults 0 0" >> /etc/fstab
    96. swap=`free |grep Swap|awk '{print $2}'`
    97. if [ $swap -gt 1 ];then
    98. echo "Swap total sizse: $swap";
    99. return;
    100. fi
    101. sed -i "/\/www\/swap/d" /etc/fstab
    102. rm -f $swapFile
    103. }
    104. Service_Add(){
    105. if [ "${PM}" == "yum" ] || [ "${PM}" == "dnf" ]; then
    106. chkconfig --add bt
    107. chkconfig --level 2345 bt on
    108. elif [ "${PM}" == "apt-get" ]; then
    109. update-rc.d bt defaults
    110. fi
    111. }
    112. get_node_url(){
    113. if [ ! -f /bin/curl ];then
    114. if [ "${PM}" = "yum" ]; then
    115. yum install curl -y
    116. elif [ "${PM}" = "apt-get" ]; then
    117. apt-get install curl -y
    118. fi
    119. fi
    120. echo '---------------------------------------------';
    121. echo "Selected download node...";
    122. nodes=(http://dg2.bt.cn http://dg1.bt.cn http://180.101.160.68:5880 http://103.224.251.67 http://45.76.53.20 http://120.206.184.160 http://113.107.111.78 http://128.1.164.196);
    123. tmp_file1=/dev/shm/net_test1.pl
    124. tmp_file2=/dev/shm/net_test2.pl
    125. [ -f "${tmp_file1}" ] && rm -f ${tmp_file1}
    126. [ -f "${tmp_file2}" ] && rm -f ${tmp_file2}
    127. touch $tmp_file1
    128. touch $tmp_file2
    129. for node in ${nodes[@]};
    130. do
    131. NODE_CHECK=$(curl --connect-timeout 3 -m 3 2>/dev/null -w "%{http_code} %{time_total}" ${node}/net_test|xargs)
    132. RES=$(echo ${NODE_CHECK}|awk '{print $1}')
    133. NODE_STATUS=$(echo ${NODE_CHECK}|awk '{print $2}')
    134. TIME_TOTAL=$(echo ${NODE_CHECK}|awk '{print $3 * 1000 - 500 }'|cut -d '.' -f 1)
    135. if [ "${NODE_STATUS}" == "200" ];then
    136. if [ $TIME_TOTAL -lt 100 ];then
    137. if [ $RES -ge 1500 ];then
    138. echo "$RES $node" >> $tmp_file1
    139. fi
    140. else
    141. if [ $RES -ge 1500 ];then
    142. echo "$TIME_TOTAL $node" >> $tmp_file2
    143. fi
    144. fi
    145. i=$(($i+1))
    146. if [ $TIME_TOTAL -lt 100 ];then
    147. if [ $RES -ge 3000 ];then
    148. break;
    149. fi
    150. fi
    151. fi
    152. done
    153. NODE_URL=$(cat $tmp_file1|sort -r -g -t " " -k 1|head -n 1|awk '{print $2}')
    154. if [ -z "$NODE_URL" ];then
    155. NODE_URL=$(cat $tmp_file2|sort -g -t " " -k 1|head -n 1|awk '{print $2}')
    156. if [ -z "$NODE_URL" ];then
    157. NODE_URL='http://download.bt.cn';
    158. fi
    159. fi
    160. rm -f $tmp_file1
    161. rm -f $tmp_file2
    162. download_Url=$NODE_URL
    163. echo "Download node: $download_Url";
    164. echo '---------------------------------------------';
    165. }
    166. Remove_Package(){
    167. local PackageNmae=$1
    168. if [ "${PM}" == "yum" ];then
    169. isPackage=$(rpm -q ${PackageNmae}|grep "not installed")
    170. if [ -z "${isPackage}" ];then
    171. yum remove ${PackageNmae} -y
    172. fi
    173. elif [ "${PM}" == "apt-get" ];then
    174. isPackage=$(dpkg -l|grep ${PackageNmae})
    175. if [ "${PackageNmae}" ];then
    176. apt-get remove ${PackageNmae} -y
    177. fi
    178. fi
    179. }
    180. Install_RPM_Pack(){
    181. yumPath=/etc/yum.conf
    182. Centos8Check=$(cat /etc/redhat-release | grep ' 8.' | grep -iE 'centos|Red Hat')
    183. isExc=$(cat $yumPath|grep httpd)
    184. if [ "$isExc" = "" ];then
    185. echo "exclude=httpd nginx php mysql mairadb python-psutil python2-psutil" >> $yumPath
    186. fi
    187. yumBaseUrl=$(cat /etc/yum.repos.d/CentOS-Base.repo|grep baseurl=http|cut -d '=' -f 2|cut -d '$' -f 1|head -n 1)
    188. [ "${yumBaseUrl}" ] && checkYumRepo=$(curl --connect-timeout 5 --head -s -o /dev/null -w %{http_code} ${yumBaseUrl})
    189. if [ "${checkYumRepo}" != "200" ];then
    190. curl -Ss --connect-timeout 3 -m 60 http://download.bt.cn/install/yumRepo_select.sh|bash
    191. fi
    192. #尝试同步时间(从bt.cn)
    193. echo 'Synchronizing system time...'
    194. getBtTime=$(curl -sS --connect-timeout 3 -m 60 http://www.bt.cn/api/index/get_time)
    195. if [ "${getBtTime}" ];then
    196. date -s "$(date -d @$getBtTime +"%Y-%m-%d %H:%M:%S")"
    197. fi
    198. if [ -z "${Centos8Check}" ]; then
    199. yum install ntp -y
    200. rm -rf /etc/localtime
    201. ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
    202. #尝试同步国际时间(从ntp服务器)
    203. ntpdate 0.asia.pool.ntp.org
    204. setenforce 0
    205. fi
    206. startTime=`date +%s`
    207. sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
    208. #yum remove -y python-requests python3-requests python-greenlet python3-greenlet
    209. 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"
    210. yum install -y ${yumPacks}
    211. for yumPack in ${yumPacks}
    212. do
    213. rpmPack=$(rpm -q ${yumPack})
    214. packCheck=$(echo ${rpmPack}|grep not)
    215. if [ "${packCheck}" ]; then
    216. yum install ${yumPack} -y
    217. fi
    218. done
    219. if [ -f "/usr/bin/dnf" ]; then
    220. dnf install -y redhat-rpm-config
    221. fi
    222. yum install epel-release -y
    223. }
    224. Install_Deb_Pack(){
    225. ln -sf bash /bin/sh
    226. apt-get update -y
    227. apt-get install ruby -y
    228. apt-get install lsb-release -y
    229. #apt-get install ntp ntpdate -y
    230. #/etc/init.d/ntp stop
    231. #update-rc.d ntp remove
    232. #cat >>~/.profile<<EOF
    233. #TZ='Asia/Shanghai'; export TZ
    234. #EOF
    235. #rm -rf /etc/localtime
    236. #cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
    237. #echo 'Synchronizing system time...'
    238. #ntpdate 0.asia.pool.ntp.org
    239. #apt-get upgrade -y
    240. for pace in wget curl libcurl4-openssl-dev gcc make zip unzip openssl libssl-dev gcc libxml2 libxml2-dev libxslt 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;
    241. do apt-get -y install $pace --force-yes; done
    242. if [ ! -d '/etc/letsencrypt' ];then
    243. mkdir -p /etc/letsencryp
    244. mkdir -p /var/spool/cron
    245. if [ ! -f '/var/spool/cron/crontabs/root' ];then
    246. echo '' > /var/spool/cron/crontabs/root
    247. chmod 600 /var/spool/cron/crontabs/root
    248. fi
    249. fi
    250. }
    251. Install_Bt(){
    252. panelPort="8888"
    253. if [ -f ${setup_path}/server/panel/data/port.pl ];then
    254. panelPort=$(cat ${setup_path}/server/panel/data/port.pl)
    255. fi
    256. mkdir -p ${setup_path}/server/panel/logs
    257. mkdir -p ${setup_path}/server/panel/vhost/apache
    258. mkdir -p ${setup_path}/server/panel/vhost/nginx
    259. mkdir -p ${setup_path}/server/panel/vhost/rewrite
    260. mkdir -p ${setup_path}/server/panel/install
    261. mkdir -p /www/server
    262. mkdir -p /www/wwwroot
    263. mkdir -p /www/wwwlogs
    264. mkdir -p /www/backup/database
    265. mkdir -p /www/backup/site
    266. if [ ! -f "/usr/bin/unzip" ]; then
    267. if [ "${PM}" = "yum" ]; then
    268. yum install unzip -y
    269. elif [ "${PM}" = "apt-get" ]; then
    270. apt-get install unzip -y
    271. fi
    272. fi
    273. if [ -f "/etc/init.d/bt" ]; then
    274. /etc/init.d/bt stop
    275. sleep 1
    276. fi
    277. wget -O panel.zip ${download_Url}/install/src/panel6.zip -T 10
    278. wget -O /etc/init.d/bt ${download_Url}/install/src/bt6.init -T 10
    279. wget -O /www/server/panel/install/public.sh ${download_Url}/install/public.sh -T 10
    280. if [ -f "${setup_path}/server/panel/data/default.db" ];then
    281. if [ -d "/${setup_path}/server/panel/old_data" ];then
    282. rm -rf ${setup_path}/server/panel/old_data
    283. fi
    284. mkdir -p ${setup_path}/server/panel/old_data
    285. d_format=$(date +"%Y%m%d_%H%M%S")
    286. \cp -arf ${setup_path}/server/panel/data/default.db ${setup_path}/server/panel/data/default_backup_${d_format}.db
    287. mv -f ${setup_path}/server/panel/data/default.db ${setup_path}/server/panel/old_data/default.db
    288. mv -f ${setup_path}/server/panel/data/system.db ${setup_path}/server/panel/old_data/system.db
    289. mv -f ${setup_path}/server/panel/data/port.pl ${setup_path}/server/panel/old_data/port.pl
    290. mv -f ${setup_path}/server/panel/data/admin_path.pl ${setup_path}/server/panel/old_data/admin_path.pl
    291. fi
    292. unzip -o panel.zip -d ${setup_path}/server/ > /dev/null
    293. if [ -d "${setup_path}/server/panel/old_data" ];then
    294. mv -f ${setup_path}/server/panel/old_data/default.db ${setup_path}/server/panel/data/default.db
    295. mv -f ${setup_path}/server/panel/old_data/system.db ${setup_path}/server/panel/data/system.db
    296. mv -f ${setup_path}/server/panel/old_data/port.pl ${setup_path}/server/panel/data/port.pl
    297. mv -f ${setup_path}/server/panel/old_data/admin_path.pl ${setup_path}/server/panel/data/admin_path.pl
    298. if [ -d "/${setup_path}/server/panel/old_data" ];then
    299. rm -rf ${setup_path}/server/panel/old_data
    300. fi
    301. fi
    302. rm -f panel.zip
    303. if [ ! -f ${setup_path}/server/panel/tools.py ];then
    304. Red_Error "ERROR: Failed to download, please try install again!"
    305. fi
    306. rm -f ${setup_path}/server/panel/class/*.pyc
    307. rm -f ${setup_path}/server/panel/*.pyc
    308. chmod +x /etc/init.d/bt
    309. chmod -R 600 ${setup_path}/server/panel
    310. chmod -R +x ${setup_path}/server/panel/script
    311. ln -sf /etc/init.d/bt /usr/bin/bt
    312. echo "${panelPort}" > ${setup_path}/server/panel/data/port.pl
    313. wget -O /etc/init.d/bt ${download_Url}/install/src/bt7.init -T 10
    314. wget -O /www/server/panel/init.sh ${download_Url}/install/src/bt7.init -T 10
    315. }
    316. Install_Python_Lib(){
    317. curl -Ss --connect-timeout 3 -m 60 $download_Url/install/pip_select.sh|bash
    318. pyenv_path="/www/server/panel"
    319. if [ -f $pyenv_path/pyenv/bin/python ];then
    320. chmod -R 700 $pyenv_path/pyenv/bin
    321. is_package=$($python_bin -m psutil 2>&1|grep package)
    322. if [ "$is_package" = "" ];then
    323. wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip.txt -T 5
    324. $pyenv_path/pyenv/bin/pip install -U pip
    325. $pyenv_path/pyenv/bin/pip install -U setuptools
    326. $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt
    327. fi
    328. source $pyenv_path/pyenv/bin/activate
    329. return
    330. fi
    331. py_version="3.7.8"
    332. mkdir -p $pyenv_path
    333. os_type='el'
    334. os_version='7'
    335. is_export_openssl=0
    336. Get_Versions
    337. Centos6_Openssl
    338. Other_Openssl
    339. echo "OS: $os_type - $os_version"
    340. is_aarch64=$(uname -a|grep aarch64)
    341. if [ "$is_aarch64" != "" ];then
    342. os_version="aarch64"
    343. fi
    344. if [ "${os_version}" != "" ];then
    345. pyenv_file="/www/pyenv.tar.gz"
    346. wget -O $pyenv_file $download_Url/install/pyenv/pyenv-${os_type}${os_version}-x${is64bit}.tar.gz -T 10
    347. tmp_size=$(du -b $pyenv_file|awk '{print $1}')
    348. if [ $tmp_size -lt 703460 ];then
    349. rm -f $pyenv_file
    350. echo "ERROR: Download python env fielded."
    351. else
    352. echo "Install python env..."
    353. tar zxvf $pyenv_file -C $pyenv_path/ &> /dev/null
    354. chmod -R 700 $pyenv_path/pyenv/bin
    355. if [ ! -f $pyenv_path/pyenv/bin/python ];then
    356. rm -f $pyenv_file
    357. Red_Error "ERROR: Install python env fielded."
    358. fi
    359. rm -f $pyenv_file
    360. ln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btpip
    361. ln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btpython
    362. source $pyenv_path/pyenv/bin/activate
    363. return
    364. fi
    365. fi
    366. if [ -f /usr/local/openssl/lib/libssl.so ];then
    367. export LDFLAGS="-L/usr/local/openssl/lib"
    368. export CPPFLAGS="-I/usr/local/openssl/include"
    369. export PKG_CONFIG_PATH="/usr/local/openssl/lib/pkgconfig"
    370. echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/openssl/lib" >> /etc/profile
    371. source /etc/profile
    372. fi
    373. cd /www
    374. python_src='/www/python_src.tar.xz'
    375. python_src_path="/www/Python-${py_version}"
    376. wget -O $python_src $download_Url/src/Python-${py_version}.tar.xz -T 5
    377. tmp_size=$(du -b $python_src|awk '{print $1}')
    378. if [ $tmp_size -lt 10703460 ];then
    379. rm -f $python_src
    380. Red_Error "ERROR: Download python source code fielded."
    381. fi
    382. tar xvf $python_src
    383. rm -f $python_src
    384. cd $python_src_path
    385. ./configure --prefix=$pyenv_path/pyenv
    386. make -j$cpu_cpunt
    387. make install
    388. if [ ! -f $pyenv_path/pyenv/bin/python3.7 ];then
    389. rm -rf $python_src_path
    390. Red_Error "ERROR: Make python env fielded."
    391. fi
    392. cd ~
    393. rm -rf $python_src_path
    394. wget -O $pyenv_path/pyenv/bin/activate $download_Url/install/pyenv/activate.panel -T 5
    395. wget -O $pyenv_path/pyenv/pip.txt $download_Url/install/pyenv/pip-3.7.8.txt -T 5
    396. ln -sf $pyenv_path/pyenv/bin/pip3.7 $pyenv_path/pyenv/bin/pip
    397. ln -sf $pyenv_path/pyenv/bin/python3.7 $pyenv_path/pyenv/bin/python
    398. ln -sf $pyenv_path/pyenv/bin/pip3.7 /usr/bin/btpip
    399. ln -sf $pyenv_path/pyenv/bin/python3.7 /usr/bin/btpython
    400. chmod -R 700 $pyenv_path/pyenv/bin
    401. $pyenv_path/pyenv/bin/pip install -U pip
    402. $pyenv_path/pyenv/bin/pip install -U setuptools
    403. $pyenv_path/pyenv/bin/pip install -U wheel==0.34.2
    404. $pyenv_path/pyenv/bin/pip install -r $pyenv_path/pyenv/pip.txt
    405. source $pyenv_path/pyenv/bin/activate
    406. }
    407. Other_Openssl(){
    408. openssl_version=$(openssl version|grep -Eo '[0-9]\.[0-9]\.[0-9]')
    409. if [ "$openssl_version" = '1.0.1' ] || [ "$openssl_version" = '1.0.0' ];then
    410. opensslVersion="1.0.2r"
    411. if [ ! -f "/usr/local/openssl/lib/libssl.so" ];then
    412. cd /www
    413. openssl_src_file=/www/openssl.tar.gz
    414. wget -O $openssl_src_file ${download_Url}/src/openssl-${opensslVersion}.tar.gz
    415. tmp_size=$(du -b $openssl_src_file|awk '{print $1}')
    416. if [ $tmp_size -lt 703460 ];then
    417. rm -f $openssl_src_file
    418. Red_Error "ERROR: Download openssl-1.0.2 source code fielded."
    419. fi
    420. tar -zxf $openssl_src_file
    421. rm -f $openssl_src_file
    422. cd openssl-${opensslVersion}
    423. #zlib-dynamic shared
    424. ./config --openssldir=/usr/local/openssl zlib-dynamic shared
    425. make -j${cpuCore}
    426. make install
    427. echo "/usr/local/openssl/lib" > /etc/ld.so.conf.d/zopenssl.conf
    428. ldconfig
    429. cd ..
    430. rm -rf openssl-${opensslVersion}
    431. is_export_openssl=1
    432. cd ~
    433. fi
    434. fi
    435. }
    436. Insatll_Libressl(){
    437. openssl_version=$(openssl version|grep -Eo '[0-9]\.[0-9]\.[0-9]')
    438. if [ "$openssl_version" = '1.0.1' ] || [ "$openssl_version" = '1.0.0' ];then
    439. opensslVersion="3.0.2"
    440. cd /www
    441. openssl_src_file=/www/openssl.tar.gz
    442. wget -O $openssl_src_file ${download_Url}/install/pyenv/libressl-${opensslVersion}.tar.gz
    443. tmp_size=$(du -b $openssl_src_file|awk '{print $1}')
    444. if [ $tmp_size -lt 703460 ];then
    445. rm -f $openssl_src_file
    446. Red_Error "ERROR: Download libressl-$opensslVersion source code fielded."
    447. fi
    448. tar -zxf $openssl_src_file
    449. rm -f $openssl_src_file
    450. cd libressl-${opensslVersion}
    451. ./config –prefix=/usr/local/lib
    452. make -j${cpuCore}
    453. make install
    454. ldconfig
    455. ldconfig -v
    456. cd ..
    457. rm -rf libressl-${opensslVersion}
    458. is_export_openssl=1
    459. cd ~
    460. fi
    461. }
    462. Centos6_Openssl(){
    463. if [ "$os_type" != 'el' ];then
    464. return
    465. fi
    466. if [ "$os_version" != '6' ];then
    467. return
    468. fi
    469. echo 'Centos6 install openssl-1.0.2...'
    470. openssl_rpm_file="/www/openssl.rpm"
    471. wget -O $openssl_rpm_file $download_Url/rpm/centos6/${is64bit}/bt-openssl102.rpm -T 10
    472. tmp_size=$(du -b $openssl_rpm_file|awk '{print $1}')
    473. if [ $tmp_size -lt 102400 ];then
    474. rm -f $openssl_rpm_file
    475. Red_Error "ERROR: Download python env fielded."
    476. fi
    477. rpm -ivh $openssl_rpm_file
    478. rm -f $openssl_rpm_file
    479. is_export_openssl=1
    480. }
    481. Get_Versions(){
    482. redhat_version_file="/etc/redhat-release"
    483. deb_version_file="/etc/issue"
    484. if [ -f $redhat_version_file ];then
    485. os_type='el'
    486. is_aliyunos=$(cat $redhat_version_file|grep Aliyun)
    487. if [ "$is_aliyunos" != "" ];then
    488. return
    489. fi
    490. os_version=$(cat $redhat_version_file|grep CentOS|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]')
    491. if [ "${os_version}" = "5" ];then
    492. os_version=""
    493. fi
    494. else
    495. os_type='ubuntu'
    496. os_version=$(cat $deb_version_file|grep Ubuntu|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '^[0-9]+')
    497. if [ "${os_version}" = "" ];then
    498. os_type='debian'
    499. os_version=$(cat $deb_version_file|grep Debian|grep -Eo '([0-9]+\.)+[0-9]+'|grep -Eo '[0-9]+')
    500. if [ "${os_version}" = "" ];then
    501. os_version=$(cat $deb_version_file|grep Debian|grep -Eo '[0-9]+')
    502. fi
    503. if [ "${os_version}" = "8" ];then
    504. os_version=""
    505. fi
    506. if [ "${is64bit}" = '32' ];then
    507. os_version=""
    508. fi
    509. else
    510. if [ "$os_version" = "14" ];then
    511. os_version=""
    512. fi
    513. if [ "$os_version" = "12" ];then
    514. os_version=""
    515. fi
    516. if [ "$os_version" = "19" ];then
    517. os_version=""
    518. fi
    519. fi
    520. fi
    521. }
    522. Set_Bt_Panel(){
    523. password=$(cat /dev/urandom | head -n 16 | md5sum | head -c 8)
    524. sleep 1
    525. admin_auth="/www/server/panel/data/admin_path.pl"
    526. if [ ! -f ${admin_auth} ];then
    527. auth_path=$(cat /dev/urandom | head -n 16 | md5sum | head -c 8)
    528. echo "/${auth_path}" > ${admin_auth}
    529. fi
    530. auth_path=$(cat ${admin_auth})
    531. cd ${setup_path}/server/panel/
    532. /etc/init.d/bt start
    533. $python_bin -m py_compile tools.py
    534. $python_bin tools.py username
    535. username=$($python_bin tools.py panel ${password})
    536. cd ~
    537. echo "${password}" > ${setup_path}/server/panel/default.pl
    538. chmod 600 ${setup_path}/server/panel/default.pl
    539. sleep 3
    540. /etc/init.d/bt restart
    541. sleep 3
    542. isStart=$(ps aux |grep 'BT-Panel'|grep -v grep|awk '{print $2}')
    543. LOCAL_CURL=$(curl 127.0.0.1:8888/login 2>&1 |grep -i html)
    544. if [ -z "${isStart}" ] && [ -z "${LOCAL_CURL}" ];then
    545. /etc/init.d/bt 22
    546. Red_Error "ERROR: The BT-Panel service startup failed."
    547. fi
    548. }
    549. Set_Firewall(){
    550. sshPort=$(cat /etc/ssh/sshd_config | grep 'Port '|awk '{print $2}')
    551. if [ "${PM}" = "apt-get" ]; then
    552. apt-get install -y ufw
    553. if [ -f "/usr/sbin/ufw" ];then
    554. ufw allow 888,20,21,22,80,${panelPort},${sshPort}/tcp
    555. ufw allow 39000:40000/tcp
    556. ufw_status=`ufw status`
    557. echo y|ufw enable
    558. ufw default deny
    559. ufw reload
    560. fi
    561. else
    562. if [ -f "/etc/init.d/iptables" ];then
    563. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPT
    564. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
    565. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
    566. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
    567. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${panelPort} -j ACCEPT
    568. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${sshPort} -j ACCEPT
    569. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 39000:40000 -j ACCEPT
    570. #iptables -I INPUT -p tcp -m state --state NEW -m udp --dport 39000:40000 -j ACCEPT
    571. iptables -A INPUT -p icmp --icmp-type any -j ACCEPT
    572. iptables -A INPUT -s localhost -d localhost -j ACCEPT
    573. iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
    574. iptables -P INPUT DROP
    575. service iptables save
    576. sed -i "s#IPTABLES_MODULES=\"\"#IPTABLES_MODULES=\"ip_conntrack_netbios_ns ip_conntrack_ftp ip_nat_ftp\"#" /etc/sysconfig/iptables-config
    577. iptables_status=$(service iptables status | grep 'not running')
    578. if [ "${iptables_status}" == '' ];then
    579. service iptables restart
    580. fi
    581. else
    582. AliyunCheck=$(cat /etc/redhat-release|grep "Aliyun Linux")
    583. [ "${AliyunCheck}" ] && return
    584. yum install firewalld -y
    585. [ "${Centos8Check}" ] && yum reinstall python3-six -y
    586. systemctl enable firewalld
    587. systemctl start firewalld
    588. firewall-cmd --set-default-zone=public > /dev/null 2>&1
    589. firewall-cmd --permanent --zone=public --add-port=20/tcp > /dev/null 2>&1
    590. firewall-cmd --permanent --zone=public --add-port=21/tcp > /dev/null 2>&1
    591. firewall-cmd --permanent --zone=public --add-port=22/tcp > /dev/null 2>&1
    592. firewall-cmd --permanent --zone=public --add-port=80/tcp > /dev/null 2>&1
    593. firewall-cmd --permanent --zone=public --add-port=${panelPort}/tcp > /dev/null 2>&1
    594. firewall-cmd --permanent --zone=public --add-port=${sshPort}/tcp > /dev/null 2>&1
    595. firewall-cmd --permanent --zone=public --add-port=39000-40000/tcp > /dev/null 2>&1
    596. #firewall-cmd --permanent --zone=public --add-port=39000-40000/udp > /dev/null 2>&1
    597. firewall-cmd --reload
    598. fi
    599. fi
    600. }
    601. Get_Ip_Address(){
    602. getIpAddress=""
    603. getIpAddress=$(curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/getIpAddress)
    604. if [ -z "${getIpAddress}" ] || [ "${getIpAddress}" = "0.0.0.0" ]; then
    605. isHosts=$(cat /etc/hosts|grep 'www.bt.cn')
    606. if [ -z "${isHosts}" ];then
    607. echo "" >> /etc/hosts
    608. echo "103.224.251.67 www.bt.cn" >> /etc/hosts
    609. getIpAddress=$(curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/getIpAddress)
    610. if [ -z "${getIpAddress}" ];then
    611. sed -i "/bt.cn/d" /etc/hosts
    612. fi
    613. fi
    614. fi
    615. ipv4Check=$($python_bin -c "import re; print(re.match('^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$','${getIpAddress}'))")
    616. if [ "${ipv4Check}" == "None" ];then
    617. ipv6Address=$(echo ${getIpAddress}|tr -d "[]")
    618. ipv6Check=$($python_bin -c "import re; print(re.match('^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$','${ipv6Address}'))")
    619. if [ "${ipv6Check}" == "None" ]; then
    620. getIpAddress="SERVER_IP"
    621. else
    622. echo "True" > ${setup_path}/server/panel/data/ipv6.pl
    623. sleep 1
    624. /etc/init.d/bt restart
    625. fi
    626. fi
    627. if [ "${getIpAddress}" != "SERVER_IP" ];then
    628. echo "${getIpAddress}" > ${setup_path}/server/panel/data/iplist.txt
    629. fi
    630. 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)
    631. }
    632. Setup_Count(){
    633. curl -sS --connect-timeout 10 -m 60 https://www.bt.cn/Api/SetupCount?type=Linux\&o=$1 > /dev/null 2>&1
    634. if [ "$1" != "" ];then
    635. echo $1 > /www/server/panel/data/o.pl
    636. cd /www/server/panel
    637. $python_bin tools.py o
    638. fi
    639. echo /www > /var/bt_setupPath.conf
    640. }
    641. Install_Main(){
    642. startTime=`date +%s`
    643. Lock_Clear
    644. System_Check
    645. Get_Pack_Manager
    646. get_node_url
    647. MEM_TOTAL=$(free -g|grep Mem|awk '{print $2}')
    648. if [ "${MEM_TOTAL}" -le "1" ];then
    649. Auto_Swap
    650. fi
    651. if [ "${PM}" = "yum" ]; then
    652. Install_RPM_Pack
    653. elif [ "${PM}" = "apt-get" ]; then
    654. Install_Deb_Pack
    655. fi
    656. Install_Python_Lib
    657. Install_Bt
    658. Set_Bt_Panel
    659. Service_Add
    660. Set_Firewall
    661. Get_Ip_Address
    662. Setup_Count ${IDC_CODE}
    663. }
    664. echo "
    665. +----------------------------------------------------------------------
    666. | Bt-WebPanel FOR CentOS/Ubuntu/Debian
    667. +----------------------------------------------------------------------
    668. | Copyright © 2015-2099 BT-SOFT(http://www.bt.cn) All rights reserved.
    669. +----------------------------------------------------------------------
    670. | The WebPanel URL will be http://SERVER_IP:8888 when installed.
    671. +----------------------------------------------------------------------
    672. "
    673. while [ "$go" != 'y' ] && [ "$go" != 'n' ]
    674. do
    675. read -p "Do you want to install Bt-Panel to the $setup_path directory now?(y/n): " go;
    676. done
    677. if [ "$go" == 'n' ];then
    678. exit;
    679. fi
    680. Install_Main
    681. echo -e "=================================================================="
    682. echo -e "\033[32mCongratulations! Installed successfully!\033[0m"
    683. echo -e "=================================================================="
    684. echo "外网面板地址: http://${getIpAddress}:${panelPort}${auth_path}"
    685. echo "内网面板地址: http://${LOCAL_IP}:${panelPort}${auth_path}"
    686. echo -e "username: $username"
    687. echo -e "password: $password"
    688. echo -e "\033[33mIf you cannot access the panel,\033[0m"
    689. echo -e "\033[33mrelease the following panel port [${panelPort}] in the security group\033[0m"
    690. echo -e "\033[33m若无法访问面板,请检查防火墙/安全组是否有放行面板[${panelPort}]端口\033[0m"
    691. echo -e "=================================================================="
    692. endTime=`date +%s`
    693. ((outTime=($endTime-$startTime)/60))
    694. echo -e "Time consumed:\033[32m $outTime \033[0mMinute!"