2013-05-19 17:43:14 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2013-06-08 17:05:08 +02:00
|
|
|
## This script will toggle HDMI Audio (and set video properly). To do this
|
|
|
|
## automatically when the cable is plugged, add the following udev rule (Linux
|
|
|
|
## only):
|
|
|
|
##
|
2013-05-19 17:43:14 +02:00
|
|
|
## $ cat /etc/udev/rules.d/hdmi.rules
|
|
|
|
## SUBSYSTEM=="drm", ACTION=="change", RUN+="/bin/sh /usr/local/bin/hdmi-switch"
|
2013-06-08 17:05:08 +02:00
|
|
|
##
|
|
|
|
## To get audio working on radeon, you may need to boot with the following
|
|
|
|
## kernel paremeter:
|
|
|
|
##
|
|
|
|
## radeon.audio=1
|
2013-05-19 17:43:14 +02:00
|
|
|
|
2013-05-21 21:57:54 +02:00
|
|
|
if [ $(id -u) -ne 0 ]; then
|
|
|
|
echo "You must be root to run this script."
|
|
|
|
exit
|
|
|
|
fi
|
2013-05-19 17:43:14 +02:00
|
|
|
|
|
|
|
HDMI_STATUS="$(cat /sys/class/drm/card0-HDMI-A-1/status)"
|
|
|
|
ALSACONF="/etc/asound.conf"
|
|
|
|
|
|
|
|
HDMICARD="$(aplay -l | awk '/HDMI/ {sub(/:/,"",$2); sub(/:/,"",$7); printf "card " $2 "\ndevice " $7 "\n"}')"
|
|
|
|
|
|
|
|
[ -z "$HDMI_STATUS" ] && exit
|
|
|
|
|
2013-05-21 21:57:54 +02:00
|
|
|
udevadm settle --quiet --timeout=16
|
|
|
|
|
2013-05-19 17:43:14 +02:00
|
|
|
## Video
|
|
|
|
for i in $(xrandr | awk '/^[[:alnum:]-]+ connected/ {print $1}'); do
|
|
|
|
xrandr --output "$i" --auto
|
|
|
|
done
|
|
|
|
|
|
|
|
## Sound
|
|
|
|
if [ "$HDMI_STATUS" = "connected" ]; then
|
|
|
|
echo "pcm.!default {
|
|
|
|
type hw
|
|
|
|
$HDMICARD
|
|
|
|
}" > "$ALSACONF"
|
|
|
|
|
2013-05-21 21:57:54 +02:00
|
|
|
chmod 644 "${ALSACONF}"
|
2013-05-19 17:43:14 +02:00
|
|
|
else
|
2013-05-21 21:57:54 +02:00
|
|
|
rm -f "$ALSACONF"
|
2013-05-19 17:43:14 +02:00
|
|
|
fi
|
|
|
|
|