#!/bin/bash
######系統配合
#下載ISO檔
# https://ftp.ubuntu-tw.org/ubuntu-releases/26.04.1/ 安裝
######鄭亮星 jls@mail.jls.idv.tw , jls550225@gmail.com , jls@acfs.tw
##安裝 phpBB3 網路論壇網站系統
ETH0=$(ls /proc/net/dev_snmp6 |awk '{ print $1 }' |sed -n '1p')
IP=$(ifconfig $ETH0 |grep 'inet ' |awk '{print $2}')
HOSTNAME=$(/bin/hostname)
DOMAINNAME=$(/bin/hostname -d)
DATE=$(date "+%Y%m%d%H")
sync
. /root/setup.txt
clear
read -p "請輸入 phpBB 網路論壇網站系統的資料庫名稱 :" phpBB
mysqladmin -uroot -p$Mysqlpasswd create $phpBB;
clear
## 英文版
# https://download.phpbb.com/pub/release/3.3/3.3.17/phpBB-3.3.17.zip
## 繁體中文模組
# https://www.phpbb.com/customise/db/translation/mandarin_chinese_traditional_script
tar zxvf phpbb.tgz -C /var/www
chown -R www-data:www-data /var/www/phpbb
chmod -R 755 /var/www/phpbb
chmod 777 /var/www/phpbb/phpbb/cache
cp -arf /etc/bind/$DOMAINNAME /etc/bind/$DOMAINNAME-$DATE
cat >> /etc/bind/$DOMAINNAME << EOF
phpbb IN A $IP
EOF
cp -arf /etc/apache2/sites-available/http_80.conf /etc/apache2/sites-available/http_80.conf-$DATE
cat >> /etc/apache2/sites-available/http_80.conf << EOF
#------------------------------------------------------------------------------------------------------------------------
ServerAdmin root@$DOMAINNAME
DocumentRoot /var/www/phpbb
ServerName phpbb.$DOMAINNAME
DirectoryIndex index.html index.php index.htm index.php3
#
#### From the Apache version 2.4.10 and above, use the SetHandler to run PHP as a fastCGI process server
# SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
#
# CBandSpeed 40960 200 200
# CBandRemoteSpeed 40960kb/s 100 100
# CBandLimit 10000Mb
# CBandPeriod 4W
# CBandScoreboard /var/log/scoreboard/phpbb.$DOMAINNAME
# CBandScoreFlushPeriod /var/log/scoreboard/phpbb.$DOMAINNAME
# CBandExceededURL http://$DOMAINNAME/cband_error.html
EOF
cp -arf /etc/apache2/sites-available/https_443.conf /etc/apache2/sites-available/https_443.conf-$DATE
cat >> /etc/apache2/sites-available/https_443.conf << EOF
#------------------------------------------------------------------------------------------------------------------------
ServerAdmin root@$DOMAINNAME
DocumentRoot /var/www/phpbb
ServerName phpbb.$DOMAINNAME
DirectoryIndex index.html index.php index.htm index.php3
#
#### From the Apache version 2.4.10 and above, use the SetHandler to run PHP as a fastCGI process server
# SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
#
# CBandSpeed 40960 200 200
# CBandRemoteSpeed 40960kb/s 100 100
# CBandLimit 10000Mb
# CBandPeriod 4W
# CBandScoreboard /var/log/scoreboard/phpbb.$DOMAINNAME
# CBandScoreFlushPeriod /var/log/scoreboard/phpbb.$DOMAINNAME
# CBandExceededURL https://$DOMAINNAME/cband_error.html
EOF
systemctl restart named.service
systemctl restart apache2.service
clear
echo "請開啟瀏覽器,在網址列輸入 http://phpbb.$DOMAINNAME 來完成網路論壇系統設定。"