fix: 修复curl|bash方式运行时中文模板无法安装的问题
- 新增 install_chinese_templates 函数 - 优先使用本地模板文件 - 本地不存在时自动从 Gitee 下载67个模板文件 - 显示下载进度 解决其他服务器使用脚本后界面仍为英文的问题 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
123
setup_cups.sh
123
setup_cups.sh
@@ -626,6 +626,119 @@ install_drivers() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 安装中文界面模板
|
||||||
|
install_chinese_templates() {
|
||||||
|
info "安装 CUPS 中文界面模板..."
|
||||||
|
|
||||||
|
local templates_dir="/usr/share/cups/templates-zh_CN"
|
||||||
|
local gitee_base="https://gitee.com/yu-yon/S905L3A/raw/master/cups-templates-zh_CN"
|
||||||
|
|
||||||
|
# 模板文件列表
|
||||||
|
local templates=(
|
||||||
|
"add-class.tmpl"
|
||||||
|
"add-printer.tmpl"
|
||||||
|
"add-rss-subscription.tmpl"
|
||||||
|
"admin.tmpl"
|
||||||
|
"choose-device.tmpl"
|
||||||
|
"choose-make.tmpl"
|
||||||
|
"choose-model.tmpl"
|
||||||
|
"choose-serial.tmpl"
|
||||||
|
"choose-uri.tmpl"
|
||||||
|
"class-added.tmpl"
|
||||||
|
"class-confirm.tmpl"
|
||||||
|
"class-deleted.tmpl"
|
||||||
|
"class-jobs-header.tmpl"
|
||||||
|
"class-modified.tmpl"
|
||||||
|
"class.tmpl"
|
||||||
|
"classes-header.tmpl"
|
||||||
|
"classes.tmpl"
|
||||||
|
"command.tmpl"
|
||||||
|
"edit-config.tmpl"
|
||||||
|
"error-op.tmpl"
|
||||||
|
"error.tmpl"
|
||||||
|
"header.tmpl"
|
||||||
|
"help-header.tmpl"
|
||||||
|
"help-printable.tmpl"
|
||||||
|
"help-trailer.tmpl"
|
||||||
|
"job-cancel.tmpl"
|
||||||
|
"job-hold.tmpl"
|
||||||
|
"job-move.tmpl"
|
||||||
|
"job-moved.tmpl"
|
||||||
|
"job-release.tmpl"
|
||||||
|
"job-restart.tmpl"
|
||||||
|
"jobs-header.tmpl"
|
||||||
|
"jobs.tmpl"
|
||||||
|
"list-available-printers.tmpl"
|
||||||
|
"modify-class.tmpl"
|
||||||
|
"modify-printer.tmpl"
|
||||||
|
"norestart.tmpl"
|
||||||
|
"option-boolean.tmpl"
|
||||||
|
"option-conflict.tmpl"
|
||||||
|
"option-header.tmpl"
|
||||||
|
"option-pickmany.tmpl"
|
||||||
|
"option-pickone.tmpl"
|
||||||
|
"option-trailer.tmpl"
|
||||||
|
"pager.tmpl"
|
||||||
|
"printer-accept.tmpl"
|
||||||
|
"printer-added.tmpl"
|
||||||
|
"printer-confirm.tmpl"
|
||||||
|
"printer-default.tmpl"
|
||||||
|
"printer-deleted.tmpl"
|
||||||
|
"printer-jobs-header.tmpl"
|
||||||
|
"printer-modified.tmpl"
|
||||||
|
"printer-reject.tmpl"
|
||||||
|
"printer-start.tmpl"
|
||||||
|
"printer-stop.tmpl"
|
||||||
|
"printer.tmpl"
|
||||||
|
"printers-header.tmpl"
|
||||||
|
"printers.tmpl"
|
||||||
|
"restart.tmpl"
|
||||||
|
"samba-export.tmpl"
|
||||||
|
"samba-exported.tmpl"
|
||||||
|
"search.tmpl"
|
||||||
|
"set-printer-options-header.tmpl"
|
||||||
|
"set-printer-options-trailer.tmpl"
|
||||||
|
"subscription-added.tmpl"
|
||||||
|
"subscription-canceled.tmpl"
|
||||||
|
"test-page.tmpl"
|
||||||
|
"trailer.tmpl"
|
||||||
|
"users.tmpl"
|
||||||
|
)
|
||||||
|
|
||||||
|
# 先检查本地是否有模板目录
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "$0")" 2>/dev/null && pwd)" || SCRIPT_DIR=""
|
||||||
|
|
||||||
|
if [ -n "$SCRIPT_DIR" ] && [ -d "$SCRIPT_DIR/cups-templates-zh_CN" ]; then
|
||||||
|
# 本地有模板文件,直接复制
|
||||||
|
info "从本地复制中文模板..."
|
||||||
|
mkdir -p "$templates_dir"
|
||||||
|
cp -f "$SCRIPT_DIR/cups-templates-zh_CN/"*.tmpl "$templates_dir/"
|
||||||
|
success "中文界面模板安装完成(本地)"
|
||||||
|
else
|
||||||
|
# 从 Gitee 下载模板
|
||||||
|
info "从 Gitee 下载中文模板..."
|
||||||
|
mkdir -p "$templates_dir"
|
||||||
|
|
||||||
|
local success_count=0
|
||||||
|
local total=${#templates[@]}
|
||||||
|
|
||||||
|
for tmpl in "${templates[@]}"; do
|
||||||
|
if wget -q -O "$templates_dir/$tmpl" "$gitee_base/$tmpl" 2>/dev/null; then
|
||||||
|
((success_count++))
|
||||||
|
fi
|
||||||
|
# 显示进度
|
||||||
|
echo -ne "\r 下载进度: $success_count/$total"
|
||||||
|
done
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
if [ $success_count -gt 0 ]; then
|
||||||
|
success "中文界面模板安装完成(已下载 $success_count/$total 个文件)"
|
||||||
|
else
|
||||||
|
warn "中文模板下载失败,界面将显示英文"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# 安装虚拟PDF打印机(用于测试连接)
|
# 安装虚拟PDF打印机(用于测试连接)
|
||||||
install_pdf_printer() {
|
install_pdf_printer() {
|
||||||
info "安装虚拟 PDF 打印机..."
|
info "安装虚拟 PDF 打印机..."
|
||||||
@@ -870,15 +983,7 @@ main() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# 安装中文 Web 界面模板
|
# 安装中文 Web 界面模板
|
||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
install_chinese_templates
|
||||||
if [ -d "$SCRIPT_DIR/cups-templates-zh_CN" ]; then
|
|
||||||
info "安装 CUPS 中文界面模板..."
|
|
||||||
mkdir -p /usr/share/cups/templates-zh_CN
|
|
||||||
cp -f "$SCRIPT_DIR/cups-templates-zh_CN/"*.tmpl /usr/share/cups/templates-zh_CN/
|
|
||||||
success "中文界面模板安装完成"
|
|
||||||
else
|
|
||||||
warn "未找到中文模板目录 (cups-templates-zh_CN),跳过界面汉化"
|
|
||||||
fi
|
|
||||||
success "中文语言包安装完成"
|
success "中文语言包安装完成"
|
||||||
|
|
||||||
# 3. 安装驱动
|
# 3. 安装驱动
|
||||||
|
|||||||
Reference in New Issue
Block a user