#!/usr/bin/env bash
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (C) 2026 Shea's Tech, LLC — Learn Linux for Work
# https://mac.learnlinuxforwork.com
#
# uninstall-cs8409-driver.sh — Linux-on-Mac baseline: built-in speakers.
#
# Removes the third-party speaker driver installed by install-cs8409-driver.sh
# and restores the stock kernel module. Run with sudo, then reboot.
#
# Original work of Shea's Tech, LLC. It contains no code from the driver
# project: it runs that project's own removal option. Credits are printed at the end.

set -euo pipefail

DEST="/opt/snd_hda_macbookpro"

[ "$(id -u)" -eq 0 ] || { echo "error: run this with sudo: sudo $0" >&2; exit 1; }
[ -x "$DEST/install.cirrus.driver.sh" ] || { echo "error: $DEST not found: nothing to uninstall" >&2; exit 1; }

( cd "$DEST" && ./install.cirrus.driver.sh -r )

echo
echo "Driver removed and the stock module restored. Reboot:  sudo reboot"
echo "To also delete the driver source folder afterwards:    sudo rm -r $DEST"

cat <<'CREDITS'

Credits
  Speaker driver: snd_hda_macbookpro by davidjo and contributors, GPL-2.0.
  https://github.com/davidjo/snd_hda_macbookpro
  This script is original Learn Linux for Work work; it contains no code from
  that project.
CREDITS
