mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 22:36:06 +08:00
修改 ql update 逻辑
This commit is contained in:
parent
5a2caeb66b
commit
683482e067
|
@ -4,8 +4,6 @@ dir_shell=/ql/shell
|
||||||
. $dir_shell/share.sh
|
. $dir_shell/share.sh
|
||||||
link_shell
|
link_shell
|
||||||
|
|
||||||
export isFirstStartServer=true
|
|
||||||
|
|
||||||
echo -e "======================1. 检测配置文件========================\n"
|
echo -e "======================1. 检测配置文件========================\n"
|
||||||
make_dir /etc/nginx/conf.d
|
make_dir /etc/nginx/conf.d
|
||||||
make_dir /run/nginx
|
make_dir /run/nginx
|
||||||
|
@ -25,7 +23,10 @@ if [[ "$is_equal_registry" == "" ]]; then
|
||||||
cd && pnpm config set registry $NpmMirror
|
cd && pnpm config set registry $NpmMirror
|
||||||
pnpm install -g
|
pnpm install -g
|
||||||
fi
|
fi
|
||||||
update_depend
|
if [[ ! -s $dir_scripts/package.json ]] || [[ $(diff $dir_sample/package.json $dir_scripts/package.json) ]]; then
|
||||||
|
cp -f $dir_sample/package.json $dir_scripts/package.json
|
||||||
|
npm_install_2 $dir_scripts
|
||||||
|
fi
|
||||||
echo
|
echo
|
||||||
|
|
||||||
echo -e "======================3. 启动nginx========================\n"
|
echo -e "======================3. 启动nginx========================\n"
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
## 目录
|
## 目录
|
||||||
dir_root=$QL_DIR
|
dir_root=$QL_DIR
|
||||||
|
dir_tmp=$dir_root/.tmp
|
||||||
dir_data=$dir_root/data
|
dir_data=$dir_root/data
|
||||||
dir_shell=$dir_root/shell
|
dir_shell=$dir_root/shell
|
||||||
dir_sample=$dir_root/sample
|
dir_sample=$dir_root/sample
|
||||||
|
@ -175,6 +176,7 @@ define_cmd() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fix_config() {
|
fix_config() {
|
||||||
|
make_dir $dir_tmp
|
||||||
make_dir $dir_static
|
make_dir $dir_static
|
||||||
make_dir $dir_data
|
make_dir $dir_data
|
||||||
make_dir $dir_config
|
make_dir $dir_config
|
||||||
|
@ -263,6 +265,7 @@ npm_install_sub() {
|
||||||
else
|
else
|
||||||
pnpm install --loglevel error --production
|
pnpm install --loglevel error --production
|
||||||
fi
|
fi
|
||||||
|
exit_status=$?
|
||||||
}
|
}
|
||||||
|
|
||||||
npm_install_2() {
|
npm_install_2() {
|
||||||
|
@ -283,90 +286,22 @@ diff_and_copy() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
update_depend() {
|
|
||||||
local dir_current=$(pwd)
|
|
||||||
|
|
||||||
if [[ ! -s $dir_scripts/package.json ]] || [[ $(diff $dir_sample/package.json $dir_scripts/package.json) ]]; then
|
|
||||||
cp -f $dir_sample/package.json $dir_scripts/package.json
|
|
||||||
npm_install_2 $dir_scripts
|
|
||||||
fi
|
|
||||||
|
|
||||||
cd $dir_current
|
|
||||||
}
|
|
||||||
|
|
||||||
git_clone_scripts() {
|
git_clone_scripts() {
|
||||||
local url="$1"
|
local url="$1"
|
||||||
local dir="$2"
|
local dir="$2"
|
||||||
local branch="$3"
|
local branch="$3"
|
||||||
local proxy="$4"
|
local proxy="$4"
|
||||||
[[ $branch ]] && local part_cmd="-b $branch "
|
[[ $branch ]] && local part_cmd="-b $branch "
|
||||||
echo -e "开始拉取 $url 到 $dir\n"
|
echo -e "开始拉取仓库 ${uniq_path} 到 $dir\n"
|
||||||
|
|
||||||
set_proxy "$proxy"
|
set_proxy "$proxy"
|
||||||
|
|
||||||
git clone --depth=1 $part_cmd $url $dir
|
git clone --depth=1 $part_cmd $url $dir
|
||||||
exit_status=$?
|
exit_status=$?
|
||||||
|
|
||||||
reset_branch "$branch" "$dir"
|
|
||||||
|
|
||||||
unset_proxy
|
unset_proxy
|
||||||
}
|
}
|
||||||
|
|
||||||
git_pull_scripts() {
|
|
||||||
local dir_current=$(pwd)
|
|
||||||
local dir_work="$1"
|
|
||||||
local branch="$2"
|
|
||||||
local proxy="$3"
|
|
||||||
cd $dir_work
|
|
||||||
echo -e "开始更新仓库:$dir_work"
|
|
||||||
set_proxy "$proxy"
|
|
||||||
|
|
||||||
if [[ ! $branch ]]; then
|
|
||||||
branch=$(cd $dir_work && git remote show origin | grep 'HEAD branch' | cut -d' ' -f5)
|
|
||||||
fi
|
|
||||||
|
|
||||||
local pre_commit_id=$(git rev-parse --short HEAD)
|
|
||||||
reset_branch "$branch" "$dir_work"
|
|
||||||
|
|
||||||
git fetch --depth 1 origin $branch
|
|
||||||
exit_status=$?
|
|
||||||
|
|
||||||
reset_branch "$branch" "$dir_work"
|
|
||||||
local cur_commit_id=$(git rev-parse --short HEAD)
|
|
||||||
if [[ $cur_commit_id != $pre_commit_id ]]; then
|
|
||||||
exit_status=0
|
|
||||||
fi
|
|
||||||
|
|
||||||
unset_proxy
|
|
||||||
cd $dir_current
|
|
||||||
}
|
|
||||||
|
|
||||||
reset_romote_url() {
|
|
||||||
local dir_current=$(pwd)
|
|
||||||
local dir_work=$1
|
|
||||||
local url=$2
|
|
||||||
local branch="$3"
|
|
||||||
|
|
||||||
cd $dir_work
|
|
||||||
if [[ -d "$dir_work/.git" ]]; then
|
|
||||||
[[ -f ".git/index.lock" ]] && rm -f .git/index.lock >/dev/null
|
|
||||||
git remote set-url origin $url &>/dev/null
|
|
||||||
else
|
|
||||||
git init
|
|
||||||
git remote add origin $url &>/dev/null
|
|
||||||
fi
|
|
||||||
|
|
||||||
cd $dir_current
|
|
||||||
}
|
|
||||||
|
|
||||||
reset_branch() {
|
|
||||||
local branch="$1"
|
|
||||||
local part_cmd="origin/${branch}"
|
|
||||||
git remote set-branches origin $branch
|
|
||||||
git reset --hard $part_cmd &>/dev/null
|
|
||||||
git checkout -b $branch $part_cmd &>/dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
random_range() {
|
random_range() {
|
||||||
local beg=$1
|
local beg=$1
|
||||||
local end=$2
|
local end=$2
|
||||||
|
@ -378,6 +313,7 @@ reload_pm2() {
|
||||||
# 代理会影响 grpc 服务
|
# 代理会影响 grpc 服务
|
||||||
unset_proxy
|
unset_proxy
|
||||||
pm2 flush &>/dev/null
|
pm2 flush &>/dev/null
|
||||||
|
pm2 kill &>/dev/null
|
||||||
pm2 startOrGracefulReload $file_ecosystem_js
|
pm2 startOrGracefulReload $file_ecosystem_js
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -231,59 +231,74 @@ usage() {
|
||||||
|
|
||||||
## 更新qinglong
|
## 更新qinglong
|
||||||
update_qinglong() {
|
update_qinglong() {
|
||||||
|
rm -rf "${dir_tmp}/*"
|
||||||
local mirror="gitee"
|
local mirror="gitee"
|
||||||
|
local downloadQLUrl="https://gitee.com/whyour/qinglong/repository/archive"
|
||||||
|
local downloadStaticUrl="https://gitee.com/whyour/qinglong-static/repository/archive"
|
||||||
local githubStatus=$(curl -s -m 2 -IL "https://google.com" | grep 200)
|
local githubStatus=$(curl -s -m 2 -IL "https://google.com" | grep 200)
|
||||||
if [[ ! -z $githubStatus ]]; then
|
if [[ ! -z $githubStatus ]]; then
|
||||||
mirror="github"
|
mirror="github"
|
||||||
|
downloadQLUrl="https://github.com/whyour/qinglong/archive/refs/heads"
|
||||||
|
downloadStaticUrl="https://github.com/whyour/qinglong-static/archive/refs/heads"
|
||||||
fi
|
fi
|
||||||
echo -e "使用 ${mirror} 源更新...\n"
|
echo -e "使用 ${mirror} 源更新...\n"
|
||||||
export isFirstStartServer=false
|
|
||||||
|
|
||||||
local primary_branch="master"
|
local primary_branch="master"
|
||||||
if [[ "${QL_BRANCH}" == "develop" ]]; then
|
if [[ "${QL_BRANCH}" == "develop" ]]; then
|
||||||
primary_branch="develop"
|
primary_branch="develop"
|
||||||
fi
|
fi
|
||||||
[[ -f $dir_root/package.json ]] && ql_depend_old=$(cat $dir_root/package.json)
|
|
||||||
reset_romote_url ${dir_root} "https://${mirror}.com/whyour/qinglong.git" ${primary_branch}
|
wget -cqO "${dir_tmp}/ql.zip" "${downloadQLUrl}/${primary_branch}.zip"
|
||||||
git_pull_scripts $dir_root ${primary_branch}
|
exit_status=$?
|
||||||
|
|
||||||
if [[ $exit_status -eq 0 ]]; then
|
if [[ $exit_status -eq 0 ]]; then
|
||||||
echo -e "\n更新青龙源文件成功...\n"
|
echo -e "\n更新青龙源文件成功...\n"
|
||||||
cp -f $file_config_sample $dir_config/config.sample.sh
|
unzip -oq "${dir_tmp}/ql.zip"
|
||||||
update_depend
|
|
||||||
|
update_qinglong_static
|
||||||
[[ -f $dir_root/package.json ]] && ql_depend_new=$(cat $dir_root/package.json)
|
|
||||||
[[ "$ql_depend_old" != "$ql_depend_new" ]] && npm_install_2 $dir_root
|
|
||||||
|
|
||||||
update_qinglong_static "$1" "$primary_branch"
|
|
||||||
else
|
else
|
||||||
echo -e "\n更新青龙源文件失败,请检查网络...\n"
|
echo -e "\n更新青龙源文件失败,请检查网络...\n"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
update_qinglong_static() {
|
update_qinglong_static() {
|
||||||
local no_restart="$1"
|
wget -cqO "${dir_tmp}/static.zip" "${downloadStaticUrl}/${primary_branch}.zip"
|
||||||
local primary_branch="$2"
|
exit_status=$?
|
||||||
local url="https://${mirror}.com/whyour/qinglong-static.git"
|
|
||||||
rm -rf ${ql_static_repo} &>/dev/null
|
|
||||||
git_clone_scripts ${url} ${ql_static_repo} ${primary_branch}
|
|
||||||
|
|
||||||
if [[ $exit_status -eq 0 ]]; then
|
if [[ $exit_status -eq 0 ]]; then
|
||||||
echo -e "\n更新青龙静态资源成功...\n"
|
echo -e "\n更新青龙静态资源成功...\n"
|
||||||
|
unzip -oq "${dir_tmp}/static.zip"
|
||||||
|
|
||||||
rm -rf $dir_static/*
|
check_update_dep
|
||||||
cp -rf $ql_static_repo/* $dir_static
|
|
||||||
if [[ $no_restart != "no-restart" ]]; then
|
|
||||||
nginx -s reload 2>/dev/null || nginx -c /etc/nginx/nginx.conf
|
|
||||||
echo -e "重启面板中..."
|
|
||||||
sleep 3
|
|
||||||
reload_pm2
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
echo -e "\n更新青龙静态资源失败,请检查网络...\n"
|
echo -e "\n更新青龙静态资源失败,请检查网络...\n"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_update_dep() {
|
||||||
|
echo -e "\n开始检测依赖...\n"
|
||||||
|
if [[ $(diff $dir_sample/package.json $dir_scripts/package.json) ]]; then
|
||||||
|
cp -f $dir_sample/package.json $dir_scripts/package.json
|
||||||
|
npm_install_2 $dir_scripts
|
||||||
|
fi
|
||||||
|
if [[ $(diff $dir_root/package.json ${dir_tmp}/qinglong-${primary_branch}/package.json) ]]; then
|
||||||
|
npm_install_2 "${dir_tmp}/qinglong-${primary_branch}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $exit_status -eq 0 ]]; then
|
||||||
|
echo -e "\n依赖检测安装成功...\n"
|
||||||
|
|
||||||
|
cp -rf ${dir_tmp}/qinglong-${primary_branch}/* ${dir_root}
|
||||||
|
rm -rf $dir_static/*
|
||||||
|
cp -rf ${dir_tmp}/qinglong-static-${primary_branch}/* ${dir_static}
|
||||||
|
cp -f $file_config_sample $dir_config/config.sample.sh
|
||||||
|
|
||||||
|
reload_pm2
|
||||||
|
else
|
||||||
|
echo -e "\n依赖检测安装失败,请检查网络...\n"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
## 对比脚本
|
## 对比脚本
|
||||||
diff_scripts() {
|
diff_scripts() {
|
||||||
local dir_current=$(pwd)
|
local dir_current=$(pwd)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user