feat: 添加驱动管理器 - Web界面安装打印机驱动
新增功能: - 独立的Web服务(端口632)用于管理打印机驱动 - 支持上传安装多种驱动格式:.deb, .ppd, .tar.gz, .zip, .rpm, .sh - 自动识别文件类型并执行对应安装命令 - 中文Web界面,风格与CUPS保持一致 - 基本认证保护,随机生成管理密码 - 查看已安装驱动列表 安装脚本更新: - 新增"是否安装驱动管理器"选项 - 自动配置systemd服务开机自启 - 安装完成后显示驱动管理器地址和密码 - 卸载时自动清理驱动管理器 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
22
cups-driver-manager/cups-driver-manager.service
Normal file
22
cups-driver-manager/cups-driver-manager.service
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=CUPS Printer Driver Manager
|
||||||
|
Documentation=https://gitee.com/yu-yon/S905L3A
|
||||||
|
After=network.target cups.service
|
||||||
|
Wants=cups.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=root
|
||||||
|
WorkingDirectory=/opt/cups-driver-manager
|
||||||
|
ExecStart=/usr/bin/python3 /opt/cups-driver-manager/driver_manager.py --port 632
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=5
|
||||||
|
Environment=DRIVER_MANAGER_PASSWORD=admin
|
||||||
|
|
||||||
|
# 安全设置
|
||||||
|
NoNewPrivileges=false
|
||||||
|
ProtectSystem=false
|
||||||
|
ProtectHome=false
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
1023
cups-driver-manager/driver_manager.py
Normal file
1023
cups-driver-manager/driver_manager.py
Normal file
File diff suppressed because it is too large
Load Diff
127
setup_cups.sh
127
setup_cups.sh
@@ -713,6 +713,100 @@ install_chinese_templates() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 安装驱动管理器(Web界面安装驱动)
|
||||||
|
install_driver_manager() {
|
||||||
|
info "安装 CUPS 驱动管理器..."
|
||||||
|
|
||||||
|
# 安装依赖
|
||||||
|
apt install -y python3 python3-pip python3-flask 2>/dev/null || {
|
||||||
|
# 如果系统包不可用,使用 pip 安装
|
||||||
|
apt install -y python3 python3-pip
|
||||||
|
pip3 install flask 2>/dev/null || pip3 install flask --break-system-packages 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
# 创建安装目录
|
||||||
|
local install_dir="/opt/cups-driver-manager"
|
||||||
|
mkdir -p "$install_dir"
|
||||||
|
|
||||||
|
# 复制文件
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "$0")" 2>/dev/null && pwd)" || SCRIPT_DIR=""
|
||||||
|
|
||||||
|
if [ -n "$SCRIPT_DIR" ] && [ -f "$SCRIPT_DIR/cups-driver-manager/driver_manager.py" ]; then
|
||||||
|
# 从本地复制
|
||||||
|
cp -f "$SCRIPT_DIR/cups-driver-manager/driver_manager.py" "$install_dir/"
|
||||||
|
cp -f "$SCRIPT_DIR/cups-driver-manager/cups-driver-manager.service" /etc/systemd/system/ 2>/dev/null || true
|
||||||
|
info "从本地复制驱动管理器文件"
|
||||||
|
else
|
||||||
|
# 从 Gitee 下载
|
||||||
|
info "从 Gitee 下载驱动管理器..."
|
||||||
|
local tmp_dir=$(mktemp -d)
|
||||||
|
local zip_url="https://gitee.com/yu-yon/S905L3A/repository/archive/master.zip"
|
||||||
|
|
||||||
|
if wget -q --show-progress -O "$tmp_dir/repo.zip" "$zip_url" 2>/dev/null || \
|
||||||
|
curl -sL -o "$tmp_dir/repo.zip" "$zip_url" 2>/dev/null; then
|
||||||
|
cd "$tmp_dir"
|
||||||
|
unzip -q repo.zip 2>/dev/null
|
||||||
|
|
||||||
|
local dm_dir=$(find . -type d -name "cups-driver-manager" 2>/dev/null | head -1)
|
||||||
|
if [ -n "$dm_dir" ] && [ -d "$dm_dir" ]; then
|
||||||
|
cp -f "$dm_dir/driver_manager.py" "$install_dir/"
|
||||||
|
cp -f "$dm_dir/cups-driver-manager.service" /etc/systemd/system/ 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
cd - > /dev/null
|
||||||
|
rm -rf "$tmp_dir"
|
||||||
|
else
|
||||||
|
warn "驱动管理器下载失败,跳过安装"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 设置权限
|
||||||
|
chmod +x "$install_dir/driver_manager.py"
|
||||||
|
|
||||||
|
# 生成随机密码
|
||||||
|
local admin_pass=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 8)
|
||||||
|
|
||||||
|
# 更新 systemd 服务文件中的密码
|
||||||
|
if [ -f /etc/systemd/system/cups-driver-manager.service ]; then
|
||||||
|
sed -i "s/DRIVER_MANAGER_PASSWORD=admin/DRIVER_MANAGER_PASSWORD=$admin_pass/" /etc/systemd/system/cups-driver-manager.service
|
||||||
|
else
|
||||||
|
# 手动创建服务文件
|
||||||
|
cat > /etc/systemd/system/cups-driver-manager.service << EOF
|
||||||
|
[Unit]
|
||||||
|
Description=CUPS Printer Driver Manager
|
||||||
|
After=network.target cups.service
|
||||||
|
Wants=cups.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=root
|
||||||
|
WorkingDirectory=$install_dir
|
||||||
|
ExecStart=/usr/bin/python3 $install_dir/driver_manager.py --port 632
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=5
|
||||||
|
Environment=DRIVER_MANAGER_PASSWORD=$admin_pass
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 启动服务
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl enable cups-driver-manager
|
||||||
|
systemctl restart cups-driver-manager
|
||||||
|
|
||||||
|
# 保存密码到文件
|
||||||
|
echo "$admin_pass" > "$install_dir/.password"
|
||||||
|
chmod 600 "$install_dir/.password"
|
||||||
|
|
||||||
|
success "驱动管理器安装完成"
|
||||||
|
info "驱动管理器密码: $admin_pass"
|
||||||
|
|
||||||
|
# 导出变量供后续使用
|
||||||
|
DRIVER_MANAGER_PASSWORD="$admin_pass"
|
||||||
|
}
|
||||||
|
|
||||||
# 安装虚拟PDF打印机(用于测试连接)
|
# 安装虚拟PDF打印机(用于测试连接)
|
||||||
install_pdf_printer() {
|
install_pdf_printer() {
|
||||||
info "安装虚拟 PDF 打印机..."
|
info "安装虚拟 PDF 打印机..."
|
||||||
@@ -892,6 +986,15 @@ main() {
|
|||||||
config_static_ip=${config_static_ip:-Y}
|
config_static_ip=${config_static_ip:-Y}
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
# 询问是否安装驱动管理器
|
||||||
|
echo -e "${YELLOW}是否安装驱动管理器(Web界面安装打印机驱动)?${NC}"
|
||||||
|
echo " 推荐:选择 Y,可通过网页上传安装 .deb/.ppd/.tar.gz 等驱动"
|
||||||
|
echo " 端口: 632"
|
||||||
|
echo ""
|
||||||
|
read -p "安装驱动管理器? [Y/n]: " install_dm < /dev/tty
|
||||||
|
install_dm=${install_dm:-Y}
|
||||||
|
echo ""
|
||||||
|
|
||||||
# 确认安装
|
# 确认安装
|
||||||
echo -e "${YELLOW}即将执行以下操作:${NC}"
|
echo -e "${YELLOW}即将执行以下操作:${NC}"
|
||||||
local step=1
|
local step=1
|
||||||
@@ -913,6 +1016,10 @@ main() {
|
|||||||
((step++))
|
((step++))
|
||||||
echo " $step. 将当前用户添加到 lpadmin 组"
|
echo " $step. 将当前用户添加到 lpadmin 组"
|
||||||
((step++))
|
((step++))
|
||||||
|
if [[ "$install_dm" =~ ^[Yy]$ ]]; then
|
||||||
|
echo " $step. 安装驱动管理器 (端口 632)"
|
||||||
|
((step++))
|
||||||
|
fi
|
||||||
echo " $step. 启动并设置开机自启"
|
echo " $step. 启动并设置开机自启"
|
||||||
echo ""
|
echo ""
|
||||||
read -p "是否继续? [Y/n]: " confirm < /dev/tty
|
read -p "是否继续? [Y/n]: " confirm < /dev/tty
|
||||||
@@ -990,7 +1097,12 @@ main() {
|
|||||||
fi
|
fi
|
||||||
success "用户组配置完成"
|
success "用户组配置完成"
|
||||||
|
|
||||||
# 6. 启动服务
|
# 6. 安装驱动管理器(如果选择)
|
||||||
|
if [[ "$install_dm" =~ ^[Yy]$ ]]; then
|
||||||
|
install_driver_manager
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 7. 启动服务
|
||||||
info "启动 CUPS 服务..."
|
info "启动 CUPS 服务..."
|
||||||
systemctl restart cups
|
systemctl restart cups
|
||||||
systemctl enable cups
|
systemctl enable cups
|
||||||
@@ -1018,6 +1130,13 @@ main() {
|
|||||||
echo -e " ${BLUE}用户名:${NC} root"
|
echo -e " ${BLUE}用户名:${NC} root"
|
||||||
echo -e " ${BLUE}密码:${NC} 你的 SSH 密码"
|
echo -e " ${BLUE}密码:${NC} 你的 SSH 密码"
|
||||||
echo ""
|
echo ""
|
||||||
|
# 检查是否安装了驱动管理器
|
||||||
|
if systemctl is-active cups-driver-manager >/dev/null 2>&1; then
|
||||||
|
local dm_pass=$(cat /opt/cups-driver-manager/.password 2>/dev/null || echo "admin")
|
||||||
|
echo -e " ${GREEN}[驱动管理器]${NC} http://${LOCAL_IP}:632"
|
||||||
|
echo -e " ${GREEN} ${NC} 用户名: admin 密码: ${dm_pass}"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
# 检查是否安装了PDF打印机
|
# 检查是否安装了PDF打印机
|
||||||
if lpstat -p PDF 2>/dev/null | grep -q "PDF"; then
|
if lpstat -p PDF 2>/dev/null | grep -q "PDF"; then
|
||||||
echo -e " ${GREEN}[PDF打印机]${NC} 已安装虚拟 PDF 打印机用于测试"
|
echo -e " ${GREEN}[PDF打印机]${NC} 已安装虚拟 PDF 打印机用于测试"
|
||||||
@@ -1068,6 +1187,7 @@ uninstall() {
|
|||||||
echo " - Avahi 服务 (AirPrint)"
|
echo " - Avahi 服务 (AirPrint)"
|
||||||
echo " - CUPS-PDF 虚拟打印机"
|
echo " - CUPS-PDF 虚拟打印机"
|
||||||
echo " - 中文界面模板"
|
echo " - 中文界面模板"
|
||||||
|
echo " - 驱动管理器"
|
||||||
echo " - 所有打印任务和配置"
|
echo " - 所有打印任务和配置"
|
||||||
echo ""
|
echo ""
|
||||||
read -p "确定要卸载吗? [y/N]: " confirm < /dev/tty
|
read -p "确定要卸载吗? [y/N]: " confirm < /dev/tty
|
||||||
@@ -1085,8 +1205,10 @@ uninstall() {
|
|||||||
info "停止服务..."
|
info "停止服务..."
|
||||||
systemctl stop cups 2>/dev/null || true
|
systemctl stop cups 2>/dev/null || true
|
||||||
systemctl stop avahi-daemon 2>/dev/null || true
|
systemctl stop avahi-daemon 2>/dev/null || true
|
||||||
|
systemctl stop cups-driver-manager 2>/dev/null || true
|
||||||
systemctl disable cups 2>/dev/null || true
|
systemctl disable cups 2>/dev/null || true
|
||||||
systemctl disable avahi-daemon 2>/dev/null || true
|
systemctl disable avahi-daemon 2>/dev/null || true
|
||||||
|
systemctl disable cups-driver-manager 2>/dev/null || true
|
||||||
|
|
||||||
# 卸载软件包
|
# 卸载软件包
|
||||||
info "卸载软件包..."
|
info "卸载软件包..."
|
||||||
@@ -1103,6 +1225,9 @@ uninstall() {
|
|||||||
rm -rf /usr/share/cups/templates-zh_CN
|
rm -rf /usr/share/cups/templates-zh_CN
|
||||||
rm -rf /usr/share/cups/templates-zh
|
rm -rf /usr/share/cups/templates-zh
|
||||||
rm -rf /usr/share/cups/templates-en-backup
|
rm -rf /usr/share/cups/templates-en-backup
|
||||||
|
rm -rf /opt/cups-driver-manager
|
||||||
|
rm -f /etc/systemd/system/cups-driver-manager.service
|
||||||
|
systemctl daemon-reload 2>/dev/null || true
|
||||||
|
|
||||||
# 清理依赖
|
# 清理依赖
|
||||||
info "清理依赖..."
|
info "清理依赖..."
|
||||||
|
|||||||
Reference in New Issue
Block a user