mirror of
https://github.com/whyour/qinglong.git
synced 2026-10-17 07:20:51 +08:00
fix: synchronize runtime locales and harden online updates
Translate UI, scheduler, validation, preload and maintenance messages dynamically, and propagate locale changes between workers. Harden update checks, downloads and terminal states, verify Debian pnpm, and ignore generated test artifacts.
This commit is contained in:
+1
-1
@@ -236,7 +236,7 @@ find_cron_api() {
|
||||
|
||||
update_auth_config() {
|
||||
local body="$1"
|
||||
local tip="$2"
|
||||
local tip=$(t "$2")
|
||||
local currentTimeStamp=$(date +%s)
|
||||
local api=$(ql_api_request \
|
||||
"http://localhost:${ql_port}/open/system/auth/reset?t=$currentTimeStamp" \
|
||||
|
||||
@@ -108,4 +108,42 @@ declare -gA LANG_MESSAGES=(
|
||||
['暂不支持此系统部署 %s']='Unsupported system for deployment: %s'
|
||||
# update.sh
|
||||
['命令输入错误...\n']='Invalid command...\n'
|
||||
['%s 删除任务%s']='%s removed tasks%s'
|
||||
['%s 新增任务']='%s added tasks'
|
||||
['新增任务通知']='New task notification'
|
||||
['失效']='obsolete'
|
||||
['新']='new'
|
||||
['%s 命令使用方法:']='Usage: %s'
|
||||
['更新并重启青龙']='Update and restart QingLong'
|
||||
['运行自定义脚本']='Run custom scripts'
|
||||
['更新单个脚本文件']='Update a script'
|
||||
['更新单个仓库的脚本']='Update scripts from a repository'
|
||||
['删除旧日志']='Delete old logs'
|
||||
['启动tg-bot']='Start tg-bot'
|
||||
['检测青龙环境并修复']='Check and repair the QingLong environment'
|
||||
['查看青龙运行日志']='View QingLong service logs'
|
||||
['重置登录错误次数']='Reset failed login attempts'
|
||||
['禁用两步登录']='Disable two-factor login'
|
||||
['修改登录密码']='Change login password'
|
||||
['修改登录用户名']='Change login username'
|
||||
['禁用两步验证']='Disable two-factor authentication'
|
||||
['重置密码']='Reset password'
|
||||
['重置用户名']='Reset username'
|
||||
[', 任务状态更新失败(%s)']=', task status update failed (%s)'
|
||||
[', 状态更新失败(%s)']=', status update failed (%s)'
|
||||
['<未识别出活动名称>']='<Unrecognized task name>'
|
||||
['task命令运行本程序自动添加进crontab的脚本,需要输入脚本的绝对路径或去掉 “%s/” 目录后的相对路径(定时任务中请写作相对路径),用法为:']='task runs scripts registered in crontab. Use an absolute path or a path relative to %s/ (use relative paths in scheduled tasks). Usage:'
|
||||
['1.%s <file_name> # 依次执行,如果设置了随机延迟,将随机延迟一定秒数']='1.%s <file_name> # Run sequentially, with the configured random delay'
|
||||
['2.%s <file_name> now # 依次执行,无论是否设置了随机延迟,均立即运行,前台会输出日志,同时记录在日志文件中']='2.%s <file_name> now # Run immediately, displaying and saving logs'
|
||||
['3.%s <file_name> conc <环境变量名称> <账号编号,空格分隔>(可选的) # 并发执行,无论是否设置了随机延迟,均立即运行,前台不产生日志,直接记录在日志文件中,且可指定账号执行']='3.%s <file_name> conc <variable> [account-numbers...] # Run selected accounts concurrently, saving logs'
|
||||
['4.%s <file_name> desi <环境变量名称> <账号编号,空格分隔> # 指定账号执行,无论是否设置了随机延迟,均立即运行']='4.%s <file_name> desi <variable> <account-numbers...> # Run selected accounts immediately'
|
||||
['\n当前有以下脚本可以运行:']='\nAvailable scripts:'
|
||||
['\n暂无脚本可以执行']='\nNo scripts available'
|
||||
['🚀 1. 检测配置文件...']='🚀 1. Checking configuration...'
|
||||
['🔄 2. 启动 nginx...']='🔄 2. Starting nginx...'
|
||||
['⚙️ 3. 启动 pm2 服务...']='⚙️ 3. Starting pm2 services...'
|
||||
['🤖 4. 启动 bot...']='🤖 4. Starting bot...'
|
||||
['🛠️ 5. 执行自定义脚本...']='🛠️ 5. Running custom scripts...'
|
||||
['🎉 启动成功!']='🎉 Started successfully!'
|
||||
['\n## 执行结束... %s 耗时 %s 秒']='\n## Execution finished... %s elapsed %s seconds'
|
||||
)
|
||||
|
||||
+8
-8
@@ -45,7 +45,7 @@ gen_array_scripts() {
|
||||
let i++
|
||||
array_scripts[i]=$file
|
||||
array_scripts_name[i]=$(grep -- "new Env" "$file" | awk -F '[(]' '{print $2}' | awk -F '[)]' '{print $1}' | sed 's:.*\('\''\|"\)\([^"'\'']*\)\('\''\|"\).*:\2:' | sed 's:"::g' | sed "s:'::g" | head -1)
|
||||
[[ -z ${array_scripts_name[i]} ]] && array_scripts_name[i]="<未识别出活动名称>"
|
||||
[[ -z ${array_scripts_name[i]} ]] && array_scripts_name[i]="$(t '<未识别出活动名称>')"
|
||||
fi
|
||||
done
|
||||
cd "$dir_current" || return $?
|
||||
@@ -54,18 +54,18 @@ gen_array_scripts() {
|
||||
## 使用说明
|
||||
usage() {
|
||||
gen_array_scripts
|
||||
echo -e "task命令运行本程序自动添加进crontab的脚本,需要输入脚本的绝对路径或去掉 “$dir_scripts/” 目录后的相对路径(定时任务中请写作相对路径),用法为:"
|
||||
echo -e "1.$cmd_task <file_name> # 依次执行,如果设置了随机延迟,将随机延迟一定秒数"
|
||||
echo -e "2.$cmd_task <file_name> now # 依次执行,无论是否设置了随机延迟,均立即运行,前台会输出日志,同时记录在日志文件中"
|
||||
echo -e "3.$cmd_task <file_name> conc <环境变量名称> <账号编号,空格分隔>(可选的) # 并发执行,无论是否设置了随机延迟,均立即运行,前台不产生日志,直接记录在日志文件中,且可指定账号执行"
|
||||
echo -e "4.$cmd_task <file_name> desi <环境变量名称> <账号编号,空格分隔> # 指定账号执行,无论是否设置了随机延迟,均立即运行"
|
||||
t 'task命令运行本程序自动添加进crontab的脚本,需要输入脚本的绝对路径或去掉 “%s/” 目录后的相对路径(定时任务中请写作相对路径),用法为:' "$dir_scripts"
|
||||
t '1.%s <file_name> # 依次执行,如果设置了随机延迟,将随机延迟一定秒数' "$cmd_task"
|
||||
t '2.%s <file_name> now # 依次执行,无论是否设置了随机延迟,均立即运行,前台会输出日志,同时记录在日志文件中' "$cmd_task"
|
||||
t '3.%s <file_name> conc <环境变量名称> <账号编号,空格分隔>(可选的) # 并发执行,无论是否设置了随机延迟,均立即运行,前台不产生日志,直接记录在日志文件中,且可指定账号执行' "$cmd_task"
|
||||
t '4.%s <file_name> desi <环境变量名称> <账号编号,空格分隔> # 指定账号执行,无论是否设置了随机延迟,均立即运行' "$cmd_task"
|
||||
if [[ ${#array_scripts[*]} -gt 0 ]]; then
|
||||
echo -e "\n当前有以下脚本可以运行:"
|
||||
t '\n当前有以下脚本可以运行:'
|
||||
for ((i = 0; i < ${#array_scripts[*]}; i++)); do
|
||||
echo -e "$(($i + 1)). ${array_scripts_name[i]}:${array_scripts[i]}"
|
||||
done
|
||||
else
|
||||
echo -e "\n暂无脚本可以执行"
|
||||
t '\n暂无脚本可以执行'
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ function run() {
|
||||
].filter(Boolean);
|
||||
|
||||
if (task_before) {
|
||||
console.log('执行前置命令\n');
|
||||
console.log(process.env.QL_LANG === 'en' ? 'Executing before command\n' : '执行前置命令\n');
|
||||
}
|
||||
|
||||
const res = execSync(commands.join(' && '), {
|
||||
@@ -122,7 +122,7 @@ function run() {
|
||||
console.log(output);
|
||||
}
|
||||
if (task_before) {
|
||||
console.log('执行前置命令结束\n');
|
||||
console.log(process.env.QL_LANG === 'en' ? 'Before command finished\n' : '执行前置命令结束\n');
|
||||
}
|
||||
} catch (error) {
|
||||
if (!error.message.includes('spawnSync /bin/bash E2BIG')) {
|
||||
@@ -131,7 +131,7 @@ function run() {
|
||||
// environment variable is too large
|
||||
}
|
||||
if (task_before) {
|
||||
console.log('执行前置命令结束\n');
|
||||
console.log(process.env.QL_LANG === 'en' ? 'Before command finished\n' : '执行前置命令结束\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ def run():
|
||||
if task_before:
|
||||
escaped_task_before = task_before.replace('"', '\\"').replace("$", "\\$")
|
||||
commands.append(f"eval '{escaped_task_before}'")
|
||||
print("执行前置命令\n")
|
||||
print("Executing before command\n" if os.environ.get("QL_LANG") == "en" else "执行前置命令\n")
|
||||
|
||||
commands.append(f"echo -e '{split_str}'")
|
||||
|
||||
@@ -88,12 +88,12 @@ def run():
|
||||
if len(output) > 0:
|
||||
print(output)
|
||||
if task_before:
|
||||
print("执行前置命令结束\n")
|
||||
print("Before command finished\n" if os.environ.get("QL_LANG") == "en" else "执行前置命令结束\n")
|
||||
|
||||
except subprocess.CalledProcessError as error:
|
||||
print(f"\ue926 run task before error: {error}")
|
||||
if task_before:
|
||||
print("执行前置命令结束\n")
|
||||
print("Before command finished\n" if os.environ.get("QL_LANG") == "en" else "执行前置命令结束\n")
|
||||
except OSError as error:
|
||||
error_message = str(error)
|
||||
if "Argument list too long" not in error_message:
|
||||
@@ -101,11 +101,11 @@ def run():
|
||||
# else:
|
||||
# environment variable is too large
|
||||
if task_before:
|
||||
print("执行前置命令结束\n")
|
||||
print("Before command finished\n" if os.environ.get("QL_LANG") == "en" else "执行前置命令结束\n")
|
||||
except Exception as error:
|
||||
print(f"\ue926 run task before error: {error}")
|
||||
if task_before:
|
||||
print("执行前置命令结束\n")
|
||||
print("Before command finished\n" if os.environ.get("QL_LANG") == "en" else "执行前置命令结束\n")
|
||||
|
||||
import task_before
|
||||
|
||||
|
||||
+2
-2
@@ -395,7 +395,7 @@ handle_task_start() {
|
||||
if [[ $ID ]]; then
|
||||
local error=$(update_cron "\"$ID\"" "0" "$$" "$log_path" "$begin_timestamp")
|
||||
if [[ $error ]]; then
|
||||
error_message=", 任务状态更新失败(${error})"
|
||||
error_message=$(t ', 任务状态更新失败(%s)' "$error")
|
||||
fi
|
||||
fi
|
||||
t '## 开始执行... %s\n' "${begin_time}${error_message}"
|
||||
@@ -437,7 +437,7 @@ handle_task_end() {
|
||||
if [[ $ID ]]; then
|
||||
local error=$(update_cron "\"$ID\"" "1" "$$" "$log_path" "$begin_timestamp" "$diff_time" "$exit_code")
|
||||
if [[ $error ]]; then
|
||||
error_message=", 状态更新失败(${error})"
|
||||
error_message=$(t ', 状态更新失败(%s)' "$error")
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
@@ -46,28 +46,28 @@ log_with_style() {
|
||||
printf "\n[%s] [%7s] %s\n" "${timestamp}" "${level}" "${message}"
|
||||
}
|
||||
|
||||
log_with_style "INFO" "🚀 1. 检测配置文件..."
|
||||
import_config "$@"
|
||||
log_with_style "INFO" "$(t '🚀 1. 检测配置文件...')"
|
||||
make_dir /etc/nginx/conf.d
|
||||
make_dir /run/nginx
|
||||
fix_config
|
||||
|
||||
pm2 l &>/dev/null
|
||||
|
||||
log_with_style "INFO" "🔄 2. 启动 nginx..."
|
||||
log_with_style "INFO" "$(t '🔄 2. 启动 nginx...')"
|
||||
nginx -s reload 2>/dev/null || nginx -c /etc/nginx/nginx.conf
|
||||
|
||||
log_with_style "INFO" "⚙️ 3. 启动 pm2 服务..."
|
||||
log_with_style "INFO" "$(t '⚙️ 3. 启动 pm2 服务...')"
|
||||
reload_pm2
|
||||
|
||||
if [[ $command != "reload" ]]; then
|
||||
if [[ $AutoStartBot == true ]]; then
|
||||
log_with_style "INFO" "🤖 4. 启动 bot..."
|
||||
log_with_style "INFO" "$(t '🤖 4. 启动 bot...')"
|
||||
nohup ql bot >"$dir_log/bot.log" 2>&1 &
|
||||
fi
|
||||
|
||||
if [[ $EnableExtraShell == true ]]; then
|
||||
log_with_style "INFO" "🛠️ 5. 执行自定义脚本..."
|
||||
log_with_style "INFO" "$(t '🛠️ 5. 执行自定义脚本...')"
|
||||
nohup ql extra >"$dir_log/extra.log" 2>&1 &
|
||||
fi
|
||||
|
||||
@@ -75,4 +75,4 @@ if [[ $command != "reload" ]]; then
|
||||
pm2 save
|
||||
fi
|
||||
|
||||
log_with_style "SUCCESS" "🎉 启动成功!"
|
||||
log_with_style "SUCCESS" "$(t '🎉 启动成功!')"
|
||||
|
||||
@@ -8,6 +8,16 @@ set -x
|
||||
startup_message() {
|
||||
local format="$1"
|
||||
shift
|
||||
if [[ ${QL_LANG:-zh} == en ]]; then
|
||||
case "$format" in
|
||||
'未找到 qinglong 模块,请先执行 npm i -g @whyour/qinglong 安装') format='Module not found. Run: npm i -g @whyour/qinglong' ;;
|
||||
'请先手动设置 export QL_DIR=%s,环境变量,并手动添加到系统环境变量,然后再次执行命令 qinglong 启动服务') format='Set export QL_DIR=%s in your system environment, then run qinglong to start the service' ;;
|
||||
'QL_DIR 必须为绝对路径,例如 /ql') format='QL_DIR must be an absolute path, e.g. /ql' ;;
|
||||
'请先手动设置数据存储目录 export QL_DATA_DIR 环境变量,目录必须以斜杠开头的绝对路径,并且以 /data 结尾,例如 /ql/data 并手动添加到系统环境变量') format='Set QL_DATA_DIR to an absolute path ending in /data, e.g. /ql/data, in your system environment' ;;
|
||||
'QL_DATA_DIR 必须为以 /data 结尾的绝对路径,例如 /ql/data,如果有历史数据,请新建 data 目录,把历史数据放到 data 目录中') format='QL_DATA_DIR must be an absolute path ending in /data, e.g. /ql/data. Move existing data into that directory' ;;
|
||||
'暂不支持此系统部署 %s') format='Unsupported system for deployment: %s' ;;
|
||||
esac
|
||||
fi
|
||||
printf -- "$format\n" "$@" >&2
|
||||
}
|
||||
|
||||
|
||||
+23
-19
@@ -31,7 +31,7 @@ diff_cron() {
|
||||
## 输出是否有新的或失效的定时任务,$1:新的或失效的任务清单文件路径,$2:新/失效
|
||||
output_list_add_drop() {
|
||||
local list=$1
|
||||
local type=$2
|
||||
local type=$(t "$2")
|
||||
if [[ -s $list ]]; then
|
||||
t '检测到有%s的定时任务:' "$type"
|
||||
cat $list
|
||||
@@ -67,7 +67,7 @@ del_cron() {
|
||||
done
|
||||
if [[ $ids ]]; then
|
||||
result=$(del_cron_api "$ids")
|
||||
notify_api "$path 删除任务${result}" "$detail"
|
||||
notify_api "$(t '%s 删除任务%s' "$path" "$result")" "$detail"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ add_cron() {
|
||||
fi
|
||||
fi
|
||||
done
|
||||
notify_api "$path 新增任务" "$detail"
|
||||
notify_api "$(t '%s 新增任务' "$path")" "$detail"
|
||||
}
|
||||
|
||||
## 更新仓库
|
||||
@@ -199,7 +199,7 @@ update_raw() {
|
||||
cron_line=${cron_line//$'\r'/}
|
||||
result=$(add_cron_api "$cron_line" "${cmd_task} ${filename}" "$cron_name" "$SUB_ID")
|
||||
echo -e "$result\n"
|
||||
notify_api "新增任务通知" "\n$result"
|
||||
notify_api "$(t '新增任务通知')" "\n$result"
|
||||
# update_cron_api "$cron_line:$cmd_task $filename:$cron_name:$cron_id"
|
||||
fi
|
||||
else
|
||||
@@ -276,19 +276,19 @@ show_service_logs() {
|
||||
|
||||
## 脚本用法
|
||||
usage() {
|
||||
t "$cmd_update 命令使用方法:"
|
||||
echo -e "1. $cmd_update update # 更新并重启青龙"
|
||||
echo -e "2. $cmd_update extra # 运行自定义脚本"
|
||||
echo -e "3. $cmd_update raw <fileurl> # 更新单个脚本文件"
|
||||
echo -e "4. $cmd_update repo <repourl> <path> <blacklist> <dependence> <branch> <extensions> # 更新单个仓库的脚本"
|
||||
echo -e "5. $cmd_update rmlog <days> # 删除旧日志"
|
||||
echo -e "6. $cmd_update bot # 启动tg-bot"
|
||||
echo -e "7. $cmd_update check # 检测青龙环境并修复"
|
||||
echo -e "8. $cmd_update log [--lines <n>] [--nostream] # 查看青龙运行日志"
|
||||
echo -e "9. $cmd_update resetlet # 重置登录错误次数"
|
||||
echo -e "10. $cmd_update resettfa # 禁用两步登录"
|
||||
echo -e "11. $cmd_update resetpwd # 修改登录密码"
|
||||
echo -e "12. $cmd_update resetname # 修改登录用户名"
|
||||
t '%s 命令使用方法:' "$cmd_update"
|
||||
echo -e "1. $cmd_update update # $(t '更新并重启青龙')"
|
||||
echo -e "2. $cmd_update extra # $(t '运行自定义脚本')"
|
||||
echo -e "3. $cmd_update raw <fileurl> # $(t '更新单个脚本文件')"
|
||||
echo -e "4. $cmd_update repo <repourl> <path> <blacklist> <dependence> <branch> <extensions> # $(t '更新单个仓库的脚本')"
|
||||
echo -e "5. $cmd_update rmlog <days> # $(t '删除旧日志')"
|
||||
echo -e "6. $cmd_update bot # $(t '启动tg-bot')"
|
||||
echo -e "7. $cmd_update check # $(t '检测青龙环境并修复')"
|
||||
echo -e "8. $cmd_update log [--lines <n>] [--nostream] # $(t '查看青龙运行日志')"
|
||||
echo -e "9. $cmd_update resetlet # $(t '重置登录错误次数')"
|
||||
echo -e "10. $cmd_update resettfa # $(t '禁用两步登录')"
|
||||
echo -e "11. $cmd_update resetpwd # $(t '修改登录密码')"
|
||||
echo -e "12. $cmd_update resetname # $(t '修改登录用户名')"
|
||||
}
|
||||
|
||||
reload_qinglong() {
|
||||
@@ -504,7 +504,9 @@ main() {
|
||||
local begin_time=$(format_time "$time_format" "$time")
|
||||
|
||||
if [[ "$p1" != "repo" ]] && [[ "$p1" != "raw" ]]; then
|
||||
eval echo -e "\#\# 开始执行... $begin_time\\\n" $cmd
|
||||
local start_message
|
||||
printf -v start_message '%q' "$(t '## 开始执行... %s\n' "$begin_time")"
|
||||
eval "printf '%s\n' $start_message $cmd"
|
||||
fi
|
||||
|
||||
[[ $ID ]] && update_cron "\"$ID\"" "0" "$$" "$log_path" "$begin_timestamp"
|
||||
@@ -577,7 +579,9 @@ main() {
|
||||
[[ $ID ]] && update_cron "\"$ID\"" "1" "$$" "$log_path" "$begin_timestamp" "$diff_time"
|
||||
|
||||
if [[ "$p1" != "repo" ]] && [[ "$p1" != "raw" ]]; then
|
||||
eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒 " $cmd
|
||||
local end_message
|
||||
printf -v end_message '%q' "$(t '\n## 执行结束... %s 耗时 %s 秒' "$end_time" "$diff_time") "
|
||||
eval "printf '%s\n' $end_message $cmd"
|
||||
fi
|
||||
return "$command_status"
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,6 +3,6 @@ const upgrade = require('../cli/src/internal/maintenance/upgradeArtifacts.cjs');
|
||||
module.exports = upgrade;
|
||||
if (require.main === module)
|
||||
upgrade.main().catch((error) => {
|
||||
console.error(`更新失败: ${error.message}`);
|
||||
console.error(upgrade.upgradeMessage('更新失败: %s', process.env, error.message));
|
||||
process.exitCode = 1;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user