登录
cat > fix_apt_sssd_xdg.sh <<'EOF' #!/usr/bin/env bash set -euo pipefail log() { echo -e "\n[+] $*\n"; } die() { echo -e "\n[!] $*\n" >&2; exit 1; } # 必须用 root 跑 if [ "${EUID:-$(id -u)}" -ne 0 ]; then die "请用 sudo 运行:sudo bash fix_apt_sssd_xdg.sh" fi log "Step 0: 检查是否有 hold 的包(如有请先手动处理)" HOLD="$(apt-mark showhold || true)" if echo "$HOLD" | grep -Eq '^(sssd|python3-sss|sssd-ad|sssd-common|sssd-ipa|sssd-krb5|sssd-ldap|sssd-proxy)$'; then echo "$HOLD" die "检测到 sssd 相关包被 hold(锁定)。请先执行:sudo apt-mark unhold <包名>,再重跑本脚本。" fi log "Step 1: 更新软件包索引" apt-get update log "Step 2: 读取可用版本(Candidate)" cand_sssd="$(apt-cache policy sssd | awk '/Candidate:/{print $2}')" cand_p3sss="$(apt-cache policy python3-sss | awk '/Candidate:/{print $2}')" echo "Candidate sssd: $cand_sssd" echo "Candidate python3-sss: $cand_p3sss" if [ -z "${cand_sssd:-}" ] || [ "$cand_sssd" = "(none)" ]; then die "你的软件源里找不到 sssd 的 Candidate 版本(Candidate=(none))。请先修复 /etc/apt/sources.list 后再试。" fi # 统一按 2.9.4-1.1ubuntu6.2 或 6.3 来处理(你截图里就是这两种) target="" if echo "$cand_sssd" | grep -q "2.9.4-1.1ubuntu6.3"; then target="2.9.4-1.1ubuntu6.3" elif echo "$cand_sssd" | grep -q "2.9.4-1.1ubuntu6.2"; then target="2.9.4-1.1ubuntu6.2" else # 兜底:如果不是这两种,就直接按 Candidate 不固定版本安装全家桶 target="AUTO" fi log "Step 3: 修复 sssd 全家桶版本一致性" pkgs=(sssd python3-sss sssd-ad sssd-common sssd-ipa sssd-krb5 sssd-ldap sssd-proxy) if [ "$target" = "AUTO" ]; then log "未匹配到 ubuntu6.2/6.3,改为按 Candidate 直接安装/升级(不固定版本)" apt-get install -y "${pkgs[@]}" else log "目标版本:$target(强制把 sssd 全家桶拉齐到同一版本)" apt-get install -y --allow-downgrades \ "sssd=$target" \ "python3-sss=$target" \ "sssd-ad=$target" \ "sssd-common=$target" \ "sssd-ipa=$target" \ "sssd-krb5=$target" \ "sssd-ldap=$target" \ "sssd-proxy=$target" fi log "Step 4: 修复破损依赖并完成未配置包" apt --fix-broken install -y dpkg --configure -a log "Step 5: (可选但建议)如果 xdg-dbus-proxy.list 存在,清理 NUL 与空行" LIST="/var/lib/dpkg/info/xdg-dbus-proxy.list" if [ -f "$LIST" ]; then cp -a "$LIST" "${LIST}.bak.$(date +%s)" || true tr -d '\000' < "$LIST" | sed '/^$/d' > "${LIST}.fixed" mv "${LIST}.fixed" "$LIST" fi log "Step 6: 重装 xdg-dbus-proxy,并再次收尾" apt-get install --reinstall -y xdg-dbus-proxy apt --fix-broken install -y dpkg --configure -a log "完成:建议查看当前版本状态" dpkg -l | awk 'NR==1 || $2 ~ /^(sssd|python3-sss|sssd-ad|sssd-common|sssd-ipa|sssd-krb5|sssd-ldap|sssd-proxy|xdg-dbus-proxy)$/' EOF