#!/bin/bash

# A script to patch HD audio config to enable headset jack functionality on
# kernel versions < v6.0 (before commit be561ffad708f0cee18aee4231f80ffafaf7a419

# Location of the snd-hda-intel patch file
PATCH="/lib/firmware/hda-init.fw"
# Location of the module config file
MODCONFIG="/etc/modprobe.d/audio-jack.conf"

if [ "$EUID" -ne 0 ]
  then echo "This script needs to be executed as root."
  exit
fi

echo "
[codec]
0x10ec0256 0x15584041 0

[model]
headset-mode-no-hp-mic

[pincfg]
0x19 0x03a11120
" > $PATCH

echo "
options snd_hda_intel patch=$(echo $PATCH | awk -F'/' '{print $(NF)}')
" > $MODCONFIG

echo "Done. Reboot to apply changes."
