mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-13 07:59:20 +00:00
Finished update & install scripts
This commit is contained in:
86
download.sh
86
download.sh
@@ -1,86 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
db_dir="./database"
|
||||
version_file="$db_dir/version.json"
|
||||
|
||||
# 检查 jq 是否已安装
|
||||
if ! command -v jq >/dev/null 2>&1; then
|
||||
|
||||
# Ubuntu/Debian
|
||||
if command -v apt-get >/dev/null 2>&1; then
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y jq
|
||||
|
||||
# CentOS/RHEL
|
||||
elif command -v yum >/dev/null 2>&1; then
|
||||
sudo yum install -y epel-release
|
||||
sudo yum install -y jq
|
||||
|
||||
# Fedora
|
||||
elif command -v dnf >/dev/null 2>&1; then
|
||||
sudo dnf install -y jq
|
||||
|
||||
# Arch Linux
|
||||
elif command -v pacman >/dev/null 2>&1; then
|
||||
sudo pacman -S jq
|
||||
|
||||
# openSUSE
|
||||
elif command -v zypper >/dev/null 2>&1; then
|
||||
sudo zypper install -y jq
|
||||
|
||||
else
|
||||
echo -e "\e[31mUnable to install jq, unsupported Linux distro\e[0m"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# 如果版本文件不存在,创建一个空的
|
||||
if [ ! -f "$version_file" ]; then
|
||||
echo '{"GeoLite2":"0.0","IP2Location":"0.0","qqwry":"0.0"}' >"$version_file"
|
||||
fi
|
||||
|
||||
# 读取本地版本信息
|
||||
geo_lite_local=$(jq -r .GeoLite2 $version_file)
|
||||
ip2location_local=$(jq -r .IP2Location $version_file)
|
||||
qqwry_local=$(jq -r .qqwry $version_file)
|
||||
|
||||
# 获取线上的最新版本
|
||||
geo_lite_remote=$(curl -s https://api.github.com/repos/PrxyHunter/GeoLite2/releases/latest | grep tag_name | cut -d\" -f4)
|
||||
ip2location_remote=$(curl -s https://api.github.com/repos/renfei/ip2location/releases/latest | grep tag_name | cut -d\" -f4)
|
||||
qqwry_remote=$(curl -s https://api.github.com/repos/metowolf/qqwry.dat/releases/latest | grep tag_name | cut -d\" -f4)
|
||||
|
||||
echo -e "\e[1;47;34mGeoLite2 Version Info: 【本地版本】$geo_lite_local | 【最新版本】$geo_lite_remote\e[0m"
|
||||
echo -e "\e[1;47;34mIP2Location Version Info: 【本地版本】$ip2location_local | 【最新版本】$ip2location_remote\e[0m"
|
||||
echo -e "\e[1;47;34mQQwry Version Info: 【本地版本】$qqwry_local | 【最新版本】$qqwry_remote\e[0m"
|
||||
|
||||
# 如果线上版本大于本地版本,则执行下载更新
|
||||
if [ "$geo_lite_remote" != "$geo_lite_local" ]; then
|
||||
# 下载GeoLite2的代码
|
||||
echo "Updating GeoLite2 to $geo_lite_remote"
|
||||
# Download the latest release of GeoLite2-City.mmdb from PrxyHunter/GeoLite2
|
||||
url=$(curl -s https://api.github.com/repos/PrxyHunter/GeoLite2/releases/latest | grep "browser_download_url.*Country.mmdb" | cut -d : -f 2,3 | tr -d \")
|
||||
if ! curl -L -S $url -o $db_dir/GeoLite2-City.mmdb; then
|
||||
echo -e "\e[31mFailed to download GeoLite2\e[0m"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$ip2location_remote" != "$ip2location_local" ]; then
|
||||
# 下载IP2Location的代码
|
||||
echo "Updating IP2Location to $ip2location_remote"
|
||||
# Download the latest release of IP2LOCATION-LITE-DB11.IPV6.BIN from renfei/ip2location
|
||||
url=$(curl -s https://api.github.com/repos/renfei/ip2location/releases/latest | grep "browser_download_url.*IP2LOCATION-LITE-DB11.IPV6.BIN" | cut -d : -f 2,3 | tr -d \")
|
||||
if ! curl -L -S $url -o $db_dir/IP2LOCATION-LITE-DB11.IPV6.BIN; then
|
||||
echo -e "\e[31mFailed to download IP2Location\e[0m"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$qqwry_remote" != "$qqwry_local" ]; then
|
||||
# 下载qqwry的代码
|
||||
echo "Updating qqwry to $qqwry_remote"
|
||||
if ! curl -L -S https://cdn.jsdelivr.net/npm/qqwry.ipdb/qqwry.ipdb -o $db_dir/qqwry.ipdb; then
|
||||
echo -e "\e[31mFailed to download qqwry\e[0m"
|
||||
fi
|
||||
fi
|
||||
|
||||
# 更新版本文件
|
||||
echo "{\"GeoLite2\":\"$geo_lite_remote\",\"IP2Location\":\"$ip2location_remote\",\"qqwry\":\"$qqwry_remote\"}" >"$version_file"
|
||||
191
install.sh
191
install.sh
@@ -1,170 +1,45 @@
|
||||
#!/bin/bash
|
||||
|
||||
#安装依赖
|
||||
install_dependencies() {
|
||||
#判断系统
|
||||
if [[ -f /etc/debian_version ]]; then
|
||||
PM=apt-get
|
||||
elif [[ -f /etc/redhat-release ]]; then
|
||||
PM=yum
|
||||
elif [[ -f /etc/SuSE-release ]]; then
|
||||
PM=zypper
|
||||
elif [[ -f /etc/arch-release ]]; then
|
||||
PM=pacman
|
||||
elif [[ -f /etc/alpine-release ]]; then
|
||||
PM=apk
|
||||
else
|
||||
echo "不支持的Linux发行版。"
|
||||
exit 1
|
||||
fi
|
||||
# 引入依赖脚本
|
||||
source ./scripts/lib.sh
|
||||
|
||||
if which supervisorctl >/dev/null; then
|
||||
echo -e "\e[32mSupervisor installed! | Supervisor 已完成!\e[0m"
|
||||
else
|
||||
echo -e "\e[31mSupervisor did not installed! | Supervisor 未安装!\e[0m"
|
||||
# Install Supervisor
|
||||
case $PM in
|
||||
apt-get)
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y supervisor
|
||||
;;
|
||||
yum)
|
||||
sudo yum install -y epel-release
|
||||
sudo yum install -y supervisor
|
||||
;;
|
||||
zypper)
|
||||
sudo zypper install -y supervisor
|
||||
;;
|
||||
apk)
|
||||
sudo apk add supervisor
|
||||
;;
|
||||
pacman)
|
||||
sudo pacman -S supervisor
|
||||
;;
|
||||
esac
|
||||
# 信号处理
|
||||
trap 'rm -f .env; exit' SIGINT SIGTSTP SIGTERM
|
||||
|
||||
#激活
|
||||
case $PM in
|
||||
yum)
|
||||
sudo service supervisord start
|
||||
sudo chkconfig supervisord on
|
||||
;;
|
||||
*)
|
||||
sudo systemctl start supervisor.service
|
||||
sudo systemctl enable supervisor.service
|
||||
;;
|
||||
esac
|
||||
echo -e "\e[32mSupervisor installation completed! | Supervisor 安装完成!\e[0m"
|
||||
fi
|
||||
}
|
||||
# 清理不需要的文件
|
||||
clean_files
|
||||
|
||||
#清理不需要的文件
|
||||
clean_files() {
|
||||
if [ -f .user.ini ]; then
|
||||
chattr -i .user.ini
|
||||
fi
|
||||
rm -rf .htaccess 404.html index.html .user.ini
|
||||
}
|
||||
# 安装依赖
|
||||
echo -e "\e[34m========= Checking server environment... | 检查服务器环境... =========\e[0m"
|
||||
install_dependencies
|
||||
|
||||
check_available() {
|
||||
tools=$1
|
||||
available=$(command -v $tools >/dev/null 2>&1)
|
||||
|
||||
if $available; then
|
||||
echo -e "\e[32m$tools Installed! | $tools 已安装!\e[0m"
|
||||
|
||||
case $tools in
|
||||
redis-cli)
|
||||
redis-cli ping
|
||||
;;
|
||||
php)
|
||||
php -v
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo -e "\e[31m$tools did not installed! | $tools 未安装!\e[0m"
|
||||
fi
|
||||
}
|
||||
|
||||
#检查环境
|
||||
check_env() {
|
||||
echo "========= Checking for Software dependency | 检查依赖软件是否安装/运行 ========="
|
||||
# 需要检查的软件数组
|
||||
check_list=(redis-cli php)
|
||||
|
||||
for item in "${check_list[@]}"; do
|
||||
check_available "$item"
|
||||
done
|
||||
|
||||
if which nginx >/dev/null || which httpd >/dev/null; then
|
||||
echo -e "\e[32mNginx/Apache Installed! | Nginx 或 Apache 已安装!\e[0m"
|
||||
if which nginx >/dev/null; then
|
||||
nginx -v
|
||||
else
|
||||
httpd -v
|
||||
fi
|
||||
else
|
||||
echo -e "\e[31mNginx/Apache did not installed! | Nginx 或 Apache 未安装!\e[0m"
|
||||
fi
|
||||
}
|
||||
#检查composer是否安装
|
||||
check_composer() {
|
||||
if [ ! -f "/usr/bin/composer" ]; then
|
||||
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
|
||||
else
|
||||
if [[ $(composer -n --version --no-ansi | cut -d" " -f3) < 2.2.0 ]]; then
|
||||
composer self-update
|
||||
fi
|
||||
fi
|
||||
}
|
||||
# 检查环境
|
||||
echo -e "\e[34m========= Checking the panel environment... | 检查面板运行环境... =========\e[0m"
|
||||
check_env
|
||||
|
||||
# 设置权限
|
||||
set_permissions() {
|
||||
if [ ! -d "/home/www" ]; then
|
||||
mkdir -p /home/www
|
||||
chown www:www /home/www
|
||||
fi
|
||||
chown -R www:www ./
|
||||
chmod -R 755 ./
|
||||
chmod -R 777 storage/
|
||||
}
|
||||
|
||||
set_schedule() {
|
||||
cmd="php $PWD/artisan schedule:run >> /dev/null 2>&1"
|
||||
cronjob="* * * * * $cmd"
|
||||
(
|
||||
crontab -u www -l | grep -v -F "$cmd"
|
||||
echo "$cronjob"
|
||||
) | crontab -u www -
|
||||
}
|
||||
|
||||
set_horizon() {
|
||||
if [ ! -f /etc/supervisor/conf.d/horizon.conf ]; then
|
||||
echo "
|
||||
[program:horizon]
|
||||
process_name=%(program_name)s
|
||||
command=php $PWD/artisan horizon
|
||||
autostart=true
|
||||
autorestart=true
|
||||
user=www
|
||||
redirect_stderr=true
|
||||
stdout_logfile=$PWD/storage/logs/horizon.log
|
||||
stopwaitsecs=3600" >>/etc/supervisor/conf.d/horizon.conf
|
||||
|
||||
sudo supervisorctl reread
|
||||
sudo supervisorctl update
|
||||
sudo supervisorctl start horizon
|
||||
fi
|
||||
}
|
||||
|
||||
clean_files
|
||||
install_dependencies
|
||||
check_env
|
||||
check_composer
|
||||
composer install
|
||||
php artisan panel:install
|
||||
echo -e "\e[34m========= Setting Folder Permissions... | 设置文件夹权限... =========\e[0m"
|
||||
set_permissions
|
||||
|
||||
# 检查Composer
|
||||
echo -e "\e[34m========= Checking Composer... | 检查Composer... =========\e[0m"
|
||||
check_composer
|
||||
|
||||
# 执行Composer安装
|
||||
echo -e "\e[34m========= Installing packages via Composer... | 通过Composer安装程序包... =========\e[0m"
|
||||
yes | composer install
|
||||
|
||||
# 执行Panel安装
|
||||
php artisan panel:install
|
||||
|
||||
# 设置定时任务
|
||||
echo -e "\e[34m========= Enabling Panel schedule tasks... | 开启面板定时任务... =========\e[0m"
|
||||
set_schedule
|
||||
|
||||
# 设置Horizon
|
||||
echo -e "\e[34m========= Setting Horizon daemon... | 设置Horizon守护程序... =========\e[0m"
|
||||
set_horizon
|
||||
echo -e "\e[32mGoing to Download some IP database files... | 将下载一些IP数据附件文件...\e[0m"
|
||||
|
||||
# 下载IP数据库文件
|
||||
echo -e "\e[34m========= Downloading IP database files... | 下载IP数据库文件... =========\e[0m"
|
||||
cd scripts/ && bash download_dbs.sh && cd ../
|
||||
|
||||
@@ -1,38 +1,31 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 设置文件目录和版本文件
|
||||
FILE_DIR="../database"
|
||||
VERSION_FILE="$FILE_DIR/version.json"
|
||||
|
||||
# 引入下载工具函数
|
||||
source ./download_utils.sh
|
||||
|
||||
# 检查 jq 是否已安装
|
||||
# 检查并安装依赖软件包
|
||||
check_and_install jq
|
||||
|
||||
# 数据库信息
|
||||
geo_lite_version=$(get_tag "PrxyHunter/GeoLite2")
|
||||
geo_lite_url="https://github.com/PrxyHunter/GeoLite2/releases/download/$geo_lite_version/GeoLite2-City.mmdb"
|
||||
|
||||
ip2location_version=$(get_tag "renfei/ip2location")
|
||||
ip2location_url="https://github.com/renfei/ip2location/releases/download/$ip2location_version/IP2LOCATION-LITE-DB11.IPV6.BIN"
|
||||
|
||||
qqwry_version=$(get_tag "metowolf/qqwry.dat")
|
||||
qqwry_url="https://cdn.jsdelivr.net/npm/qqwry.ipdb/qqwry.ipdb"
|
||||
|
||||
# 定义数据库信息
|
||||
declare -Ag docs
|
||||
|
||||
# 设置数据库信息
|
||||
docs[geo_lite_name]="GeoLite2-City.mmdb"
|
||||
docs[geo_lite_version]="$geo_lite_version"
|
||||
docs[geo_lite_url]="$geo_lite_url"
|
||||
docs[geo_lite_version]=$(get_tag "PrxyHunter/GeoLite2")
|
||||
docs[geo_lite_url]="https://github.com/PrxyHunter/GeoLite2/releases/download/${docs[geo_lite_version]}/GeoLite2-City.mmdb"
|
||||
|
||||
docs[ip2location_name]="IP2LOCATION-LITE-DB11.IPV6.BIN"
|
||||
docs[ip2location_version]="$ip2location_version"
|
||||
docs[ip2location_url]="$ip2location_url"
|
||||
docs[ip2location_version]=$(get_tag "renfei/ip2location")
|
||||
docs[ip2location_url]="https://github.com/renfei/ip2location/releases/download/${docs[ip2location_version]}/IP2LOCATION-LITE-DB11.IPV6.BIN"
|
||||
|
||||
docs[qqwry_name]="qqwry.ipdb"
|
||||
docs[qqwry_version]="$qqwry_version"
|
||||
docs[qqwry_url]="$qqwry_url"
|
||||
docs[qqwry_version]=$(get_tag "metowolf/qqwry.dat")
|
||||
docs[qqwry_url]="https://cdn.jsdelivr.net/npm/qqwry.ipdb/qqwry.ipdb"
|
||||
|
||||
# 主逻辑
|
||||
# 处理文件下载
|
||||
process_files
|
||||
echo "Update completed!"
|
||||
|
||||
exit 0
|
||||
echo -e "\e[32mUpdate completed!\e[0m"
|
||||
@@ -1,79 +1,82 @@
|
||||
#!/bin/bash
|
||||
# 信号处理
|
||||
trap 'rm -rf /tmp; exit 130' SIGINT SIGTSTP SIGTERM
|
||||
|
||||
function check_and_install() {
|
||||
pkg=$1
|
||||
if ! command -v ${pkg} >/dev/null 2>&1; then
|
||||
# 检查并安装软件包
|
||||
check_and_install() {
|
||||
local pkg=$1
|
||||
|
||||
# Ubuntu/Debian
|
||||
if ! command -v "$pkg" >/dev/null 2>&1; then
|
||||
if command -v apt-get >/dev/null 2>&1; then
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ${pkg}
|
||||
|
||||
# CentOS/RHEL
|
||||
sudo apt-get install -y "$pkg"
|
||||
elif command -v yum >/dev/null 2>&1; then
|
||||
sudo yum install -y epel-release
|
||||
sudo yum install -y ${pkg}
|
||||
|
||||
# Fedora
|
||||
sudo yum install -y "$pkg"
|
||||
elif command -v dnf >/dev/null 2>&1; then
|
||||
sudo dnf install -y ${pkg}
|
||||
|
||||
# Arch Linux
|
||||
sudo dnf install -y "$pkg"
|
||||
elif command -v pacman >/dev/null 2>&1; then
|
||||
sudo pacman -S ${pkg}
|
||||
|
||||
# openSUSE
|
||||
sudo pacman -S "$pkg"
|
||||
elif command -v zypper >/dev/null 2>&1; then
|
||||
sudo zypper install -y ${pkg}
|
||||
|
||||
sudo zypper install -y "$pkg"
|
||||
else
|
||||
echo -e "\e[31mUnable to install ${pkg}, unsupported Linux distro\e[0m"
|
||||
echo -e "\e[31m无法安装 $pkg,不支持的 Linux 发行版\e[0m"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# 获取 GitHub 仓库的最新标签
|
||||
get_tag() {
|
||||
curl -fsSL "https://api.github.com/repos/$1/releases/latest" | jq -r '.tag_name'
|
||||
local repo=$1
|
||||
curl -fsSL "https://api.github.com/repos/$repo/releases/latest" | jq -r '.tag_name'
|
||||
}
|
||||
|
||||
# 定义下载函数
|
||||
download_file() {
|
||||
name=$1
|
||||
version=$2
|
||||
url=$3
|
||||
local_version=$(jq -r ".[\"$name\"]" <$VERSION_FILE)
|
||||
local name=$1
|
||||
local version=$2
|
||||
local url=$3
|
||||
local tmp_file="/tmp/$name.tmp"
|
||||
local local_version=$(jq -r ".[\"$name\"]" <"$VERSION_FILE" 2>/dev/null || echo "0.0.0")
|
||||
|
||||
echo -e "\e[1;47;34m$name Version Info: 【本地版本】$local_version | 【最新版本】$version\e[0m"
|
||||
echo -e "\e[1;47;34m$name 版本信息:【本地版本】$local_version | 【最新版本】$version\e[0m"
|
||||
|
||||
if [ "$version" != "$local_version" ]; then
|
||||
echo "Updating $name to $version"
|
||||
echo -e "\e[37m正在更新 $name 到版本 $version\e[0m"
|
||||
|
||||
# 下载
|
||||
if ! curl -L -o "$FILE_DIR/$name" "$url"; then
|
||||
echo -e "\e[31mFailed to download $name\e[0m"
|
||||
# 下载文件
|
||||
if ! curl -I -L -m 10 "$url" >/dev/null 2>&1; then
|
||||
echo -e "\e[31mURL $url 不存在\e[0m"
|
||||
return 2
|
||||
fi
|
||||
if ! curl -L -m 60 -o "$tmp_file" "$url"; then
|
||||
echo -e "\e[31m下载 $name 失败\e[0m"
|
||||
rm -f "$tmp_file"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# 下载成功,重命名文件
|
||||
mv "$tmp_file" "$FILE_DIR/$name"
|
||||
echo -e "\e[32m成功更新 $name 到版本 $version\e[0m"
|
||||
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# 处理文件下载
|
||||
process_files() {
|
||||
json="{"
|
||||
local json="{}"
|
||||
for doc in "${!docs[@]}"; do
|
||||
if [[ $doc == *_name ]]; then
|
||||
name=${docs[$doc]}
|
||||
version=${docs[${doc/_name/_version}]}
|
||||
url=${docs[${doc/_name/_url}]}
|
||||
local name=${docs[$doc]}
|
||||
local version=${docs[${doc/_name/_version}]}
|
||||
local url=${docs[${doc/_name/_url}]}
|
||||
|
||||
download_file "$name" "$version" "$url"
|
||||
json+="\"$name\":\"$version\","
|
||||
json=$(jq -r --arg name "$name" --arg version "$version" '.[$name]=$version' <<<"$json")
|
||||
fi
|
||||
done
|
||||
json="${json%,}}"
|
||||
|
||||
echo "$json" >$VERSION_FILE
|
||||
echo "$json" >"$VERSION_FILE"
|
||||
}
|
||||
|
||||
157
scripts/lib.sh
Normal file
157
scripts/lib.sh
Normal file
@@ -0,0 +1,157 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 安装依赖
|
||||
install_dependencies() {
|
||||
# 判断系统
|
||||
if [[ -f /etc/debian_version ]]; then
|
||||
PM=apt-get
|
||||
elif [[ -f /etc/redhat-release ]]; then
|
||||
PM=yum
|
||||
elif [[ -f /etc/SuSE-release ]]; then
|
||||
PM=zypper
|
||||
elif [[ -f /etc/arch-release ]]; then
|
||||
PM=pacman
|
||||
elif [[ -f /etc/alpine-release ]]; then
|
||||
PM=apk
|
||||
else
|
||||
echo -e "\e[31m不支持的Linux发行版。\e[0m"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if command -v supervisorctl >/dev/null; then
|
||||
echo -e "\e[32mSupervisor installed! | Supervisor 已完成!\e[0m"
|
||||
else
|
||||
echo -e "\e[31mSupervisor did not installed! | Supervisor 未安装!\e[0m"
|
||||
# 安装 Supervisor
|
||||
case $PM in
|
||||
apt-get)
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y supervisor
|
||||
;;
|
||||
yum)
|
||||
sudo yum install -y epel-release
|
||||
sudo yum install -y supervisor
|
||||
;;
|
||||
zypper)
|
||||
sudo zypper install -y supervisor
|
||||
;;
|
||||
apk)
|
||||
sudo apk add supervisor
|
||||
;;
|
||||
pacman)
|
||||
sudo pacman -S supervisor
|
||||
;;
|
||||
esac
|
||||
|
||||
# 激活
|
||||
case $PM in
|
||||
yum)
|
||||
sudo service supervisord start
|
||||
sudo chkconfig supervisord on
|
||||
;;
|
||||
*)
|
||||
sudo systemctl start supervisor.service
|
||||
sudo systemctl enable supervisor.service
|
||||
;;
|
||||
esac
|
||||
echo -e "\e[32mSupervisor installation completed! | Supervisor 安装完成!\e[0m"
|
||||
fi
|
||||
}
|
||||
|
||||
# 清理不需要的文件
|
||||
clean_files() {
|
||||
rm -rf .htaccess 404.html index.html
|
||||
if [ -f .user.ini ]; then
|
||||
chattr -i .user.ini
|
||||
rm -f .user.ini
|
||||
fi
|
||||
}
|
||||
|
||||
# 检查软件是否安装
|
||||
check_available() {
|
||||
tools=$1
|
||||
if command -v $tools >/dev/null 2>&1; then
|
||||
echo -e "\e[32m$tools Installed! | $tools 已安装!\e[0m"
|
||||
else
|
||||
echo -e "\e[31m$tools did not installed! | $tools 未安装!\e[0m"
|
||||
fi
|
||||
}
|
||||
|
||||
# 检查环境
|
||||
check_env() {
|
||||
check_available php
|
||||
check_available php-fpm
|
||||
check_available nginx
|
||||
check_available mysql
|
||||
check_available redis-cli
|
||||
}
|
||||
|
||||
# 检查composer是否安装
|
||||
check_composer() {
|
||||
if [ ! -f "/usr/bin/composer" ]; then
|
||||
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
|
||||
else
|
||||
if [[ $(composer -n --version --no-ansi 2>/dev/null | cut -d" " -f3) < 2.2.0 ]]; then
|
||||
composer self-update
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# 设置权限
|
||||
set_permissions() {
|
||||
if [ ! -d "/home/www" ]; then
|
||||
mkdir -p /home/www
|
||||
chown www:www /home/www
|
||||
fi
|
||||
chown -R www:www ./
|
||||
chmod -R 755 ./
|
||||
chmod -R 777 storage/
|
||||
}
|
||||
|
||||
# 设置定时任务
|
||||
set_schedule() {
|
||||
cmd="php $PWD/artisan schedule:run >> /dev/null 2>&1"
|
||||
cronjob="* * * * * $cmd"
|
||||
|
||||
if (crontab -u www -l | grep -q -F "$cmd"); then
|
||||
echo -e "\e[36m定时任务已存在,无需重复设置。\e[0m"
|
||||
else
|
||||
(
|
||||
crontab -u www -l
|
||||
echo "$cronjob"
|
||||
) | crontab -u www -
|
||||
echo -e "\e[32m定时任务设置完成!\e[0m"
|
||||
fi
|
||||
}
|
||||
|
||||
# 设置Horizon
|
||||
set_horizon() {
|
||||
if [ ! -f /etc/supervisor/conf.d/horizon.conf ]; then
|
||||
cat <<EOF | sudo tee -a /etc/supervisor/conf.d/horizon.conf >/dev/null
|
||||
[program:horizon]
|
||||
process_name=%(program_name)s
|
||||
command=php $PWD/artisan horizon
|
||||
autostart=true
|
||||
autorestart=true
|
||||
user=www
|
||||
redirect_stderr=true
|
||||
stdout_logfile=$PWD/storage/logs/horizon.log
|
||||
stopwaitsecs=3600
|
||||
EOF
|
||||
sudo supervisorctl restart horizon
|
||||
echo -e "\e[32mHorizon configuration completed! | Horizon 配置完成!\e[0m"
|
||||
else
|
||||
echo -e "\e[36mHorizon already configured! | Horizon 已配置!\e[0m"
|
||||
fi
|
||||
}
|
||||
|
||||
# 更新旧的队列设置
|
||||
update_old_queue() {
|
||||
if crontab -l | grep -q "queue.sh"; then
|
||||
crontab_content=$(crontab -l | grep -v "queue.sh")
|
||||
echo "$crontab_content" | crontab -
|
||||
echo -e "\e[32mOld queue.sh cron job removed! | 旧的 queue.sh 定时任务已移除!\e[0m"
|
||||
fi
|
||||
|
||||
set_horizon
|
||||
}
|
||||
45
update.sh
45
update.sh
@@ -1,30 +1,35 @@
|
||||
#!/bin/bash
|
||||
|
||||
#检查composer是否安装
|
||||
check_composer() {
|
||||
if [ ! -f "/usr/bin/composer" ]; then
|
||||
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
|
||||
else
|
||||
if [[ $(composer -n --version --no-ansi | cut -d" " -f3) < 2.2.0 ]]; then
|
||||
composer self-update
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# 设置权限
|
||||
set_permissions() {
|
||||
chown -R www:www ./
|
||||
chmod -R 755 ./
|
||||
chmod -R 777 storage/
|
||||
}
|
||||
# 引入依赖脚本
|
||||
source ./scripts/lib.sh
|
||||
|
||||
# 更新代码
|
||||
echo -e "\e[34m========= Checking server environment... | 检查服务器环境... =========\e[0m"
|
||||
git fetch -f
|
||||
git reset -q --hard origin/master
|
||||
git pull -q
|
||||
git pull
|
||||
|
||||
# 检查Composer
|
||||
echo -e "\e[34m========= Checking Composer... | 检查Composer... =========\e[0m"
|
||||
check_composer
|
||||
|
||||
# 清理优化缓存
|
||||
echo -e "\e[34m========= Cleaning panel cache... | 清理面板缓存... =========\e[0m"
|
||||
php artisan optimize:clear
|
||||
composer update
|
||||
|
||||
# 执行Composer更新
|
||||
echo -e "\e[34m========= Updating packages via Composer... | 通过Composer更新程序包... =========\e[0m"
|
||||
yes | composer update
|
||||
|
||||
# 执行Panel更新
|
||||
php artisan panel:update
|
||||
|
||||
# 设置权限
|
||||
set_permissions
|
||||
echo -e "\e[32mCheck For newest IP database files | 检测IP数据附件文件最新版本\e[0m"
|
||||
|
||||
# 更新旧的队列设置
|
||||
update_old_queue
|
||||
|
||||
# 检查最新的IP数据库文件
|
||||
echo -e "\e[34m========= Updating IP database files... | 更新本地IP数据库文件... =========\e[0m"
|
||||
cd scripts/ && bash download_dbs.sh && cd ../
|
||||
Reference in New Issue
Block a user