From 21ab1ac8ab96b78a02613ddc8aa4a98689ff78df Mon Sep 17 00:00:00 2001 From: Akatsukiro Date: Mon, 15 Jan 2024 23:03:57 +0800 Subject: [PATCH] init --- README.md | 6 ++ install.sh | 183 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 189 insertions(+) create mode 100644 install.sh diff --git a/README.md b/README.md index 895ee98..4b5b91b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,8 @@ # lsky-pro-install-script 开源版 Lsky Pro 一键安装脚本 + +随便糊的。目前还不可用。 + +仅使用于纯净系统。 + +pre check 部分来自 [nezha monitor](https://github.com/naiba/nezha) 。非常好用的探针,爱 ♥ 来自瓷器。 \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..f9e6e35 --- /dev/null +++ b/install.sh @@ -0,0 +1,183 @@ +#! /bin/bash + +red='\033[0;31m' +green='\033[0;32m' +plain='\033[0m' +export PATH=$PATH:/usr/local/bin + +os_arch="" + +pre_check() { + # check root + [[ $EUID -ne 0 ]] && echo -e "${red}错误: 请使用root用户运行此脚本!${plain}" && exit 1 + + ## os_arch + if [[ $(uname -m | grep 'x86_64') != "" ]]; then + os_arch="amd64" + elif [[ $(uname -m | grep 'i386\|i686') != "" ]]; then + os_arch="386" + elif [[ $(uname -m | grep 'aarch64\|armv8b\|armv8l') != "" ]]; then + os_arch="arm64" + elif [[ $(uname -m | grep 'arm') != "" ]]; then + os_arch="arm" + fi + + echo os_arch: ${os_arch} + + ## China_IP + if [[ -z "${CN}" ]]; then + if [[ $(curl -m 10 -s https://ipapi.co/json | grep 'China') != "" ]]; then + echo "根据ip-api的数据,当前IP可能在中国" + read -e -r -p "是否选用中国镜像完成安装? [Y/n] " input + case $input in + [yY][eE][sS] | [yY]) + echo "使用中国镜像" + CN=true + ;; + + [nN][oO] | [nN]) + echo "不使用中国镜像" + ;; + *) + echo "使用中国镜像" + CN=true + ;; + esac + fi + fi + + if [[ -z "${CN}" ]]; then + # SCRIPT_RAW_URL="raw.githubusercontent.com/akastukiro/Lsky-Pro-install-script/master" + LSKYPRO_RELEASE_URL="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/') + # else + # SCRIPT_RAW_URL= + # LSKYPRO_RELEASE_URL= + # LSKY_VERSION= + fi +} + +pre_check + +install_soft() { + (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) +} + +install_base() { + 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) || + (install_soft curl wget git unzip gnupg) +} + + +install_php() { + echo -e "${green}开始安装PHP${plain}" + echo "默认安装php8.1" + # add repo + wget -O /usr/share/keyrings/php.gpg https://packages.sury.org/php/apt.gpg + 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 + apt update + apt install php8.1 php8.1-{cli,fpm,mbstring,mysql,bcmath,xml,xmlrpc,imagick,curl,gmp,imap,json,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/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 + # 关闭open_basedir + sed -i 's/;open_basedir =/open_basedir =/g' /etc/php/8.1/fpm/php.ini +} + +install_apache() { + echo -e "${green}开始安装Apache${plain}" + wget -O /usr/share/keyrings/apache2.gpg https://packages.sury.org/apache2/apt.gpg + 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 + apt update + apt install apache2 -y + a2enconf php8.1-fpm + a2enmod proxy_fcgi + a2enmod headers + a2enmod http2 + a2enmod remoteip + a2enmod ssl + a2enmod rewrite + a2enmod expires + systemctl restart apache2 + systemctl restart php8.1-fpm +} + +install_maraidb() { + echo -e "${green}开始安装MariaDB${plain}" + 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 + apt install mariadb-server -y + read -e -r -p "是否快速配置MariaDB? [Y/n] 默认 Y(es)" input + case $input in + [yY][eE][sS] | [yY]) + echo "开始快速配置MariaDB" + mysql_secure_installation + ;; + + [nN][oO] | [nN]) + echo "不快速配置MariaDB" + ;; + *) + echo "开始快速配置MariaDB" + mysql_secure_installation + ;; + esac +} + +# TODO +# 自动设置数据库,并将用户名、数据库名与密码打印出来 + +install_base +install_php +install_apache +install_maraidb + +setup_database() { + echo -e "${green}开始配置数据库${plain}" + read -e -r -p "请输入数据库用户名: " db_user + read -e -r -p "请输入数据库密码: " db_password + read -e -r -p "请输入数据库名称: " db_name + 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 "FLUSH PRIVILEGES;" +} + +setup_database + +# 下载 Lsky Pro +download_lsky() { + echo -e "${green}开始下载 Lsky Pro${plain}" + mkdir -p /var/www/lsky + cd /var/www/lsky || echo "error, can't cd" + wget -O lsky.zip https://"${LSKYPRO_RELEASE_URL}"/"${LSKY_VERSION}"/lsky-pro-"${LSKY_VERSION}".zip + unzip lsky.zip + rm -rf lsky.zip + chown -R www:www /var/www/lsky +} + +setup_apache() { + echo -e "${green}开始配置 Apache${plain}" + read -e -r -p "请输入域名: " domain + cat > /etc/apache2/sites-available/lsky.conf < + ServerName ${domain} + DocumentRoot /var/www/lsky/public + + AllowOverride All + Require all granted + + ErrorLog \${APACHE_LOG_DIR}/lsky_error.log + CustomLog \${APACHE_LOG_DIR}/lsky_access.log combined + +EOF + a2ensite lsky.conf + systemctl restart apache2 +} + +download_lsky +setup_apache + +echo -e "${green}安装完成${plain}" +echo -e "${green}请访问 http://${domain} 完成后续配置 ${plain}" \ No newline at end of file