Files
chromebox_10th_audio_driver/scripts/restore-ubuntu-audio-baseline.sh
2026-04-06 21:59:41 +08:00

81 lines
3.0 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 将系统尽量恢复到某次 capture-ubuntu-audio-baseline 采集时的「安装 deb 前」文件状态。
# 典型purge kaisa-hdmi-pipewire-fix → reinstall alsa-ucm-conf → 可选解压备份 tar。
# 用法:./scripts/restore-ubuntu-audio-baseline.sh [基线目录]
# 若不传参数,使用 audio_topology/baseline-stash/ 下最近修改的子目录。
# 需要sudoapt、解压到 /);建议在桌面会话下执行以便重启 PipeWire。
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
resolve_stash() {
if [[ -n "${1:-}" ]]; then
realpath "$1"
return
fi
local latest
latest="$(ls -td "${REPO_ROOT}/audio_topology/baseline-stash"/*/ 2>/dev/null | head -1 || true)"
if [[ -z "$latest" ]]; then
echo "未找到基线目录。请先运行: ${REPO_ROOT}/scripts/capture-ubuntu-audio-baseline.sh" >&2
exit 1
fi
realpath "${latest%/}"
}
STASH="$(resolve_stash "${1:-}")"
if [[ ! -f "$STASH/manifest.txt" ]]; then
echo "不是有效基线目录(缺少 manifest.txt: $STASH" >&2
exit 1
fi
echo "========== 使用基线: $STASH =========="
echo "manifest 创建于:"
head -5 "$STASH/manifest.txt"
echo ""
if ! command -v sudo &>/dev/null; then
echo "需要 sudo 以执行 apt。" >&2
exit 1
fi
if dpkg -s kaisa-hdmi-pipewire-fix &>/dev/null; then
echo ">>> apt purge kaisa-hdmi-pipewire-fix"
sudo apt purge -y kaisa-hdmi-pipewire-fix
else
echo "(未安装 kaisa-hdmi-pipewire-fix跳过 purge)"
fi
echo ">>> apt install --reinstall alsa-ucm-conf"
sudo apt install --reinstall -y alsa-ucm-conf
if [[ -f "$STASH/system-overlay.tar.gz" ]]; then
echo ">>> 解压 system-overlay.tar.gz -> /(覆盖 vendor sof-rt5682.conf与 reinstall 通常等价)"
sudo tar -xzf "$STASH/system-overlay.tar.gz" -C /
else
echo "(无 system-overlay.tar.gz仅依赖 alsa-ucm-conf reinstall)"
fi
if [[ -f "$STASH/user-wireplumber-conf.tar.gz" ]]; then
echo ">>> 解压 user-wireplumber-conf.tar.gz -> ${HOME}/.config/wireplumber/wireplumber.conf.d/"
mkdir -p "${HOME}/.config/wireplumber/wireplumber.conf.d"
tar -xzf "$STASH/user-wireplumber-conf.tar.gz" -C "${HOME}/.config/wireplumber/wireplumber.conf.d"
echo "已恢复用户 WirePlumber 片段。"
else
echo "(无 user-wireplumber-conf.tar.gz跳过用户配置)"
fi
if systemctl --user is-system-running &>/dev/null; then
echo ">>> systemctl --user restart wireplumber pipewire pipewire-pulse"
systemctl --user restart wireplumber pipewire pipewire-pulse 2>/dev/null || {
echo "user 会话重启 pipewire 失败,请手动重登或重启)" >&2
}
else
echo "(无可用 user systemd 会话,请登录图形界面后执行: systemctl --user restart wireplumber pipewire pipewire-pulse"
fi
echo ""
echo "========== 恢复步骤已完成 =========="
echo "若曾启用登录自动 restoreuser systemd恢复前可先禁用 kaisa-hdmi-iec958-pipewire 单元(见 OPERATION §4.3 / §4.5)。"
echo "建议核对: pactl list cards | head -40 ; aplay -l"