Compare commits

...

35 Commits

Author SHA1 Message Date
f24c8edda1
fix: 删除错误的安装逻辑 2024-04-21 13:03:45 +08:00
1256fe7564
style: 优化全自动安装 完成安装后的输出 2024-04-21 12:54:08 +08:00
4ccf9f70e3
feat: 添加基础组件 apt-transport-https 2024-04-21 12:53:23 +08:00
5d4b3cdd6c
fix: 全自动安装 在设置数据库部分的代码错误 2024-04-21 12:52:45 +08:00
acf1704349
feat: 全自动安装 配置数据库部分 2024-04-21 11:24:25 +08:00
2e1b528888
feat: 全自动安装 跳过图床安装程序 2024-04-21 11:24:25 +08:00
f972a70616
style: 删除一个空行 2024-04-21 11:24:25 +08:00
dc460555db
feat: 全自动安装 安装数据库部分 2024-04-21 11:23:52 +08:00
d1b407a67e
feat: 全自动安装 提示部分 2024-02-19 18:16:14 +08:00
7b44f53f74
fix: URL 拼接错误 2024-02-02 12:10:18 +08:00
7e8cbda6b0
fix: 数据库信息生成选择不同导致的信息复杂度不同 2024-01-22 21:47:05 +08:00
1215d6adec
feat: 自动设置数据库,并将相关内容输出打印 2024-01-22 17:21:38 +08:00
7b2ad0cb34
style: 调整获取数据库信息的顺序 2024-01-22 16:17:43 +08:00
08eb20f386
style: 优化无法判断系统信息的返回 2024-01-22 16:16:02 +08:00
5846b40226
feat: 提供手动强制安装的选项 2024-01-22 16:14:34 +08:00
081d6f9ac8
feat: 添加clear清理terminal信息 2024-01-22 15:36:35 +08:00
2977bf00ec
docs: 添加RHEL系的数据库版本说明 2024-01-19 13:02:12 +08:00
07c7a18483
feat: 数据库部分添加提示 2024-01-19 13:01:16 +08:00
517be22954
fix: RHEL系使用大版本号以避免可能的404 2024-01-19 12:55:36 +08:00
ce4aec4a9e
fix: 添加设置网站时的RHEL系写法 2024-01-19 12:53:18 +08:00
fa80d50690
feat: 添加Sury, Remi, MariaDB 的中国镜像并启用 2024-01-19 12:51:59 +08:00
a055ec8943
docs: 更新README的描述 2024-01-19 12:49:39 +08:00
2d6feebcf5
fix: 修复高版本Debian导入低版本软件源的错误 2024-01-19 12:49:39 +08:00
aeece3ed6b
style: 删除多余空行 2024-01-18 21:56:47 +08:00
061e09a7d6
fix: RHEL系PHP模组安装与环境配置 2024-01-18 17:47:47 +08:00
521ec6ea0b
fix: RHEL系的apache模组启用与加载 2024-01-18 17:40:35 +08:00
d8fb28c930
feat: 安装MariaDB部分,新增RHEL系安装方式 2024-01-18 17:31:12 +08:00
5cd510b655
feat: 安装Apache部分,优化Ubuntu上的安装方式、新增RHEL系安装方式 2024-01-18 17:29:05 +08:00
f092c4ab98
feat: 优化基础安装组建以支持RHEL系 2024-01-18 17:08:06 +08:00
34c1e8f36c
feat: 安装PHP部分,优化Ubuntu上的安装方式、新增RHEL系安装方式 2024-01-18 17:06:54 +08:00
84784720a9
fix: 完善对系统版本的判断 2024-01-18 16:44:52 +08:00
10a42edd46
modify: 使用PRETTY_NAME代替ID作为返回值 2024-01-18 16:42:59 +08:00
578edcaca1
fix: 完善基础组件内容 2024-01-18 16:33:21 +08:00
28657ce8e2
feat: 添加对操作系统的判断 2024-01-18 16:29:10 +08:00
ad64dc29f8
style: 优化安装命令 2024-01-18 16:09:56 +08:00
2 changed files with 186 additions and 55 deletions

View File

@ -18,4 +18,7 @@ curl -L https://raw.githubusercontent.com/akatsukiro/lsky-pro-install-script/mas
## 说明 ## 说明
- 拉取 [Lsky Pro](https://github.com/lsky-org/lsky-pro) 最新 Release - 拉取 [Lsky Pro](https://github.com/lsky-org/lsky-pro) 最新 Release
- 安装的环境为 LAMP( Apache2, MariaDB 10.6, PHP 8.1) - 安装的环境为 LAMP
- Apache 2
- MariaDB (Debian 12: 10.11, Debian 11: 10.6, RHEL: 10.6)
- PHP 8.1

View File

@ -2,6 +2,7 @@
red='\033[0;31m' red='\033[0;31m'
green='\033[0;32m' green='\033[0;32m'
yellow='\033[0;33m'
plain='\033[0m' plain='\033[0m'
export PATH=$PATH:/usr/local/bin export PATH=$PATH:/usr/local/bin
@ -11,6 +12,8 @@ pre_check() {
# check root # check root
[[ $EUID -ne 0 ]] && echo -e "${red}错误: 请使用root用户运行此脚本!${plain}" && exit 1 [[ $EUID -ne 0 ]] && echo -e "${red}错误: 请使用root用户运行此脚本!${plain}" && exit 1
clear
## os_arch ## os_arch
if [[ $(uname -m | grep 'x86_64') != "" ]]; then if [[ $(uname -m | grep 'x86_64') != "" ]]; then
os_arch="amd64" os_arch="amd64"
@ -24,6 +27,34 @@ pre_check() {
echo os_arch: ${os_arch} echo os_arch: ${os_arch}
# check os type and os version
if [ -f /etc/os-release ]; then
source /etc/os-release
if [[ $ID == "debian" ]]; then
systemFlag="1"
os_version=$VERSION_ID
elif [[ $ID == "ubuntu" ]]; then
systemFlag="2"
os_version=$VERSION_ID
elif [[ $ID == "centos"|| $ID == "rocky" || $ID == "alma" || $ID_LIKE == "rhel" ]]; then
systemFlag="3"
os_version=$(echo $VERSION_ID | awk -F '.' '{print $1}')
else
echo "您的操作系统为 $PRETTY_NAME ,这是不支持的操作系统"
echo -e "${red}如果您确信您的系统可以使用该脚本"
echo -e "如果您认为您的系统是Debian请输入 1"
echo -e "如果您认为您的系统是Ubuntu请输入 2"
echo -e "如果您认为您的系统是CentOS/RHEL请输入 3${plain}"
read -e -r -p "请输入您的选择: " systemFlag
echo -e "${red}请输入您的系统版本,假如您的系统为 Ubuntu 22.04 请输入 “22”无需双引号${plain}"
read -e -r -p "请输入您的系统版本: " os_version
echo -e "${red}请注意:您的系统不受脚本支持${plain}"
fi
else
echo -e "${red}无法判断系统信息,退出脚本${plain}"
exit 1
fi
## China_IP ## China_IP
if [[ -z "${CN}" ]]; then if [[ -z "${CN}" ]]; then
if [[ $(curl -m 10 -s https://ipapi.co/json | grep 'China') != "" ]]; then if [[ $(curl -m 10 -s https://ipapi.co/json | grep 'China') != "" ]]; then
@ -49,49 +80,91 @@ pre_check() {
if [[ -z "${CN}" ]]; then if [[ -z "${CN}" ]]; then
LSKYPRO_RELEASE_URL="https://github.com/lsky-org/lsky-pro/releases/download" LSKYPRO_RELEASE_URL="https://github.com/lsky-org/lsky-pro/releases/download"
LSKY_VERSION=$(curl -s "https://api.github.com/repos/lsky-org/lsky-pro/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') LSKY_VERSION=$(curl -s "https://api.github.com/repos/lsky-org/lsky-pro/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
SURY_PACKAGE_URL="https://packages.sury.org"
REMI_RPMS_URL="https://rpms.remirepo.net"
MARIADB_PACKAGE_URL="https://mirrors.xtom.com/mariadb"
else else
LSKYPRO_RELEASE_URL="https://mirror.ghproxy.com/https://github.com/lsky-org/lsky-pro/releases/download" LSKYPRO_RELEASE_URL="https://mirror.ghproxy.com/https://github.com/lsky-org/lsky-pro/releases/download"
LSKY_VERSION=$(curl -s "https://api.github.com/repos/lsky-org/lsky-pro/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') LSKY_VERSION=$(curl -s "https://api.github.com/repos/lsky-org/lsky-pro/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
SURY_PACKAGE_URL="https://mirror.nju.edu.cn/sury"
REMI_RPMS_URL="https://mirrors.aliyun.com/remi"
MARIADB_PACKAGE_URL="https://mirrors.aliyun.com/mariadb"
fi fi
} }
install_soft() { install_soft() {
(command -v apt >/dev/null 2>&1 && apt update && apt install $* -y) || (command -v apt >/dev/null 2>&1 && apt update && apt install $* -y) ||
(command -v apt-get >/dev/null 2>&1 && apt-get update && apt-get install $* -y) (command -v apt-get >/dev/null 2>&1 && apt-get update && apt-get install $* -y) ||
(command -v yum >/dev/null 2>&1 && yum install $* -y) ||
(command -v dnf >/dev/null 2>&1 && dnf makecache && dnf install $* -y)
} }
install_base() { install_base() {
echo -e "${green}开始安装基础组件${plain}" echo -e "${green}开始安装基础组件${plain}"
(command -v git >/dev/null 2>&1 && command -v curl >/dev/null 2>&1 && command -v wget >/dev/null 2>&1 && command -v unzip >/dev/null 2>&1 && command -v getenforce >/dev/null 2>&1 && command -v gnupg >/dev/null 2>&1) || (command -v git >/dev/null 2>&1 && command -v curl >/dev/null 2>&1 && command -v wget >/dev/null 2>&1 && command -v unzip >/dev/null 2>&1 && command -v getenforce >/dev/null 2>&1 && command -v gnupg >/dev/null 2>&1 && command -v lsb_release >/dev/null) ||
(install_soft curl wget git unzip gnupg) (install_soft curl wget git unzip gnupg lsb-release apt-transport-https ca-certificates)
} }
install_base install_base
pre_check pre_check
echo -e "${yellow}是否进行全自动安装?${plain}"
read -e -r -p "[Y/n]:" autoFlag
case $autoFlag in
[yY][eE][sS] | [yY])
autoFlag="1"
;;
[nN][oO] | [nN])
autoFlag="0"
;;
*)
autoFlag="1"
;;
esac
install_php() { install_php() {
echo -e "${green}开始安装PHP${plain}" echo -e "${green}开始安装PHP${plain}"
echo "默认安装php8.1" echo "默认安装php8.1"
# add repo # add repo
wget -O /usr/share/keyrings/php.gpg https://packages.sury.org/php/apt.gpg if [[ $systemFlag == "1" ]]; then
echo "deb [signed-by=/usr/share/keyrings/php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list wget -O /usr/share/keyrings/php.gpg ${SURY_PACKAGE_URL}/php/apt.gpg
apt update echo "deb [signed-by=/usr/share/keyrings/php.gpg] ${SURY_PACKAGE_URL}/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list
apt install php8.1 php8.1-{cli,fpm,mbstring,mysql,bcmath,xml,xmlrpc,imagick,curl,gmp,imap,opcache,mailparse,soap,gd,zip} -y elif [[ $systemFlag == "2" ]]; then
add-apt-repository ppa:ondrej/php
elif [[ $systemFlag == "3" ]]; then
dnf install ${REMI_RPMS_URL}/enterprise/remi-release-${os_version}.rpm -y
dnf module reset php -y
dnf module install php:remi-8.1 -y
fi
if [[ $systemFlag == "1" ]] || [[ $systemFlag == "2" ]]; then
apt update && apt install php8.1 php8.1-{cli,fpm,mbstring,mysql,bcmath,xml,xmlrpc,imagick,curl,gmp,imap,opcache,mailparse,soap,gd,zip} -y
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/php/8.1/fpm/php.ini sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/php/8.1/fpm/php.ini
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 10M/' /etc/php/8.1/fpm/php.ini sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 10M/' /etc/php/8.1/fpm/php.ini
sed -i 's/post_max_size = 8M/post_max_size = 10M/' /etc/php/8.1/fpm/php.ini sed -i 's/post_max_size = 8M/post_max_size = 10M/' /etc/php/8.1/fpm/php.ini
# 关闭open_basedir # 关闭open_basedir
sed -i 's/;open_basedir =/open_basedir =/g' /etc/php/8.1/fpm/php.ini sed -i 's/;open_basedir =/open_basedir =/g' /etc/php/8.1/fpm/php.ini
elif [[ $systemFlag == "3" ]]; then
dnf install php php-{cli,fpm,mbstring,mysqlnd,bcmath,xml,xmlrpc,imagick,curl,gmp,imap,opcache,mailparse,soap,gd,zip} -y
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/php.ini
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 10M/' /etc/php.ini
sed -i 's/post_max_size = 8M/post_max_size = 10M/' /etc/php.ini
# 关闭open_basedir
sed -i 's/;open_basedir =/open_basedir =/g' /etc/php.ini
fi
} }
install_apache() { install_apache() {
echo -e "${green}开始安装Apache${plain}" echo -e "${green}开始安装Apache${plain}"
wget -O /usr/share/keyrings/apache2.gpg https://packages.sury.org/apache2/apt.gpg if [[ $systemFlag == "1" ]]; then
echo "deb [signed-by=/usr/share/keyrings/apache2.gpg] https://packages.sury.org/apache2/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/apache2.list wget -O /usr/share/keyrings/apache2.gpg ${SURY_PACKAGE_URL}/apache2/apt.gpg
apt update echo "deb [signed-by=/usr/share/keyrings/apache2.gpg] ${SURY_PACKAGE_URL}/apache2/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/apache2.list
apt install apache2 -y elif [[ $systemFlag == "2" ]]; then
add-apt-repository ppa:ondrej/apache2
fi
if [[ $systemFlag == "1" ]] || [[ $systemFlag == "2" ]]; then
apt update && apt install apache2 -y
a2enconf php8.1-fpm a2enconf php8.1-fpm
a2enmod proxy_fcgi a2enmod proxy_fcgi
a2enmod headers a2enmod headers
@ -102,20 +175,37 @@ install_apache() {
a2enmod expires a2enmod expires
systemctl restart apache2 systemctl restart apache2
systemctl restart php8.1-fpm systemctl restart php8.1-fpm
elif [[ $systemFlag == "3" ]]; then
dnf install httpd -y
ln -s /etc/httpd/conf.d/php8.1-fpm.conf /etc/httpd/conf.modules.d/15-php8.1-fpm.conf
modules=("proxy_fcgi" "headers" "http2" "remoteip" "ssl" "rewrite" "expires")
for module in "${modules[@]}"; do
echo "LoadModule ${module}_module modules/mod_${module}.so" > /etc/httpd/conf.modules.d/10-${module}.conf
done
systemctl restart httpd
systemctl restart php-fpm.service
fi
} }
install_maraidb() { install_maraidb() {
echo -e "${green}开始安装MariaDB${plain}" echo -e "${green}开始安装MariaDB${plain}"
if [[ $systemFlag == "1" && $os_version == "11" ]] || [[ $systemFlag == "2" ]]; then
curl -sSL https://mariadb.org/mariadb_release_signing_key.asc | gpg --dearmor > /usr/share/keyrings/mariadb.gpg curl -sSL https://mariadb.org/mariadb_release_signing_key.asc | gpg --dearmor > /usr/share/keyrings/mariadb.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mariadb.gpg] https://mirror-cdn.xtom.com/mariadb/repo/10.6/debian $(lsb_release -sc) main" > /etc/apt/sources.list.d/mariadb.list echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mariadb.gpg] ${MARIADB_PACKAGE_URL}/repo/10.6/debian $(lsb_release -sc) main" > /etc/apt/sources.list.d/mariadb.list
apt install mariadb-server -y apt update && apt install mariadb-server -y
elif [[ $systemFlag == "1" && $os_version == "12" ]]; then
apt update && apt install mariadb-server -y
elif [[ $systemFlag == "3" ]]; then
dnf install ${MARIADB_PACKAGE_URL}/yum/10.6/centos/${os_version}/x86_64/mariadb-release-10.6-1.el8.noarch.rpm -y
dnf install MariaDB-server MariaDB-client -y
fi
if [[ $autoFlag == "0" ]]; then
read -e -r -p "是否快速配置MariaDB? [Y/n] 默认 Y(es)" input read -e -r -p "是否快速配置MariaDB? [Y/n] 默认 Y(es)" input
case $input in case $input in
[yY][eE][sS] | [yY]) [yY][eE][sS] | [yY])
echo "开始快速配置MariaDB" echo "开始快速配置MariaDB"
mysql_secure_installation mysql_secure_installation
;; ;;
[nN][oO] | [nN]) [nN][oO] | [nN])
echo "不快速配置MariaDB" echo "不快速配置MariaDB"
;; ;;
@ -124,10 +214,20 @@ install_maraidb() {
mysql_secure_installation mysql_secure_installation
;; ;;
esac esac
} else
PWD = "$(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
mysql_secure_installation <<EOF
# TODO y
# 自动设置数据库,并将用户名、数据库名与密码打印出来 $PWD
$PWD
y
y
y
y
EOF
fi
}
install_php install_php
install_apache install_apache
@ -135,9 +235,31 @@ install_maraidb
setup_database() { setup_database() {
echo -e "${green}开始配置数据库${plain}" echo -e "${green}开始配置数据库${plain}"
echo -e "${yellow}请无比妥善保存以下信息${plain}"
if [[ $autoFlag == "0" ]]; then
echo "自动生成数据库信息请输入1手动输入请输入2其他情况自动生成"
read -e -r -p "请输入您的选择: " dbFlag
if [[ $dbFlag == "1" ]]; then
db_user="lsky_$(openssl rand -base64 12 | tr -dc 'a-z0-9' | fold -w 8 | head -n 1)"
db_name="lsky_$(openssl rand -base64 12 | tr -dc 'a-z0-9' | fold -w 8 | head -n 1)"
db_password="$(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
elif [[ $dbFlag == "2" ]]; then
read -e -r -p "请输入数据库用户名: " db_user read -e -r -p "请输入数据库用户名: " db_user
read -e -r -p "请输入数据库密码: " db_password
read -e -r -p "请输入数据库名称: " db_name read -e -r -p "请输入数据库名称: " db_name
read -e -r -p "请输入数据库密码: " db_password
else
db_user="lsky_$(openssl rand -base64 12 | tr -dc 'a-z0-9' | fold -w 8 | head -n 1)"
db_name="lsky_$(openssl rand -base64 12 | tr -dc 'a-z0-9' | fold -w 8 | head -n 1)"
db_password="$(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
fi
else
db_user="lsky_$(openssl rand -base64 12 | tr -dc 'a-z0-9' | fold -w 8 | head -n 1)"
db_name="lsky_$(openssl rand -base64 12 | tr -dc 'a-z0-9' | fold -w 8 | head -n 1)"
db_password="$(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
fi
echo -e "${yellow}数据库用户名: ${db_user}${plain}"
echo -e "${yellow}数据库名称: ${db_name}${plain}"
echo -e "${yellow}数据库密码: ${db_password}${plain}"
mysql -e "CREATE DATABASE IF NOT EXISTS ${db_name} DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci;" mysql -e "CREATE DATABASE IF NOT EXISTS ${db_name} DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci;"
mysql -e "GRANT ALL PRIVILEGES ON ${db_name}.* TO '${db_user}'@'localhost' IDENTIFIED BY '${db_password}';" mysql -e "GRANT ALL PRIVILEGES ON ${db_name}.* TO '${db_user}'@'localhost' IDENTIFIED BY '${db_password}';"
mysql -e "FLUSH PRIVILEGES;" mysql -e "FLUSH PRIVILEGES;"
@ -150,7 +272,7 @@ download_lsky() {
echo -e "${green}开始下载 Lsky Pro${plain}" echo -e "${green}开始下载 Lsky Pro${plain}"
mkdir -p /var/www/lsky mkdir -p /var/www/lsky
cd /var/www/lsky || echo "error, can't cd" cd /var/www/lsky || echo "error, can't cd"
wget -O lsky.zip https://"${LSKYPRO_RELEASE_URL}"/"${LSKY_VERSION}"/lsky-pro-"${LSKY_VERSION}".zip wget -O lsky.zip "${LSKYPRO_RELEASE_URL}"/"${LSKY_VERSION}"/lsky-pro-"${LSKY_VERSION}".zip
unzip lsky.zip -q unzip lsky.zip -q
rm -rf lsky.zip rm -rf lsky.zip
chown -R www-data:www-data /var/www chown -R www-data:www-data /var/www
@ -176,12 +298,18 @@ setup_apache() {
</VirtualHost> </VirtualHost>
EOF EOF
if [[ $systemFlag == "1" ]] || [[ $systemFlag == "2" ]]; then
a2ensite lsky.conf a2ensite lsky.conf
systemctl restart apache2 systemctl restart apache2
elif [[ $systemFlag == "3" ]]; then
systemctl restart php-fpm.service
systemctl restart httpd
fi
} }
download_lsky download_lsky
setup_apache setup_apache
echo -e "${green}安装完成${plain}" echo -e "${green}安装完成${plain}"
echo -e "${green}请访问 http://${domain} 完成后续配置 ${plain}" echo -e "${green}请访问 http://${domain} 完成后续配置 ${plain}"