Fix for #53

+ Switch to kernel 4.19 or higher (handle HDMI)
+ Add script that watches pactl events for switching sound output
parent 2983a887
#!/bin/bash
echo "$(date)" > /var/log/end_session.log
kill -9 $(ps aux | grep "pactl_watch\|pactl.*subscribe" | awk '{print $2}')
#!/bin/bash
cat <<EOF > /etc/modprobe.d/alsa-base.conf
options snd-hda-intel model=generic
EOF
echo "Pour prise en compte de la configuration de son, un redémarrage peut être nécessaire"
kmajor=$(uname -r | cut -d '.' -f 1)
kminor=$(uname -r | cut -d '.' -f 2)
echo $kver
if (( $(echo "$kmajor <= 4" | bc -l) )) && (( $(echo "$kminor < 19" | bc -l) ))
then
rm /etc/modprobe.d/alsa-base.conf
echo "deb http://deb.debian.org/debian stretch-backports main" \
> /etc/apt/sources.list.d/backports.list
apt-get update
pkg=$(apt-cache search "linux-image-4.19.*[0-9]-amd64" | \
sort -n | grep -v "amd64-.*" | tail -n 1 | awk '{print $1}')
apt-get install -y $pkg
echo "Pour prise en compte de la configuration de son, un redémarrage peut être nécessaire"
else
echo "kernel $kmajor.$kminor >= to 4.19, doing nothing"
fi
sed -i -e 's@^#\(session-cleanup-script=\)@\1/opt/primtux-eole/end_session.sh@' /etc/lightdm/lightdm.conf
#!/bin/bash
# from https://askubuntu.com/questions/458194/switching-to-hdmi-audio-when-hdmi-is-plugged-into-a-laptop-14-04
# Get rights to access display
user=$(who | grep -v "root" | head -n 1 | cut -d ' ' -f 1)
if [ ! -z "$user" ]
then
id=$(id -u $user)
export DISPLAY=:0
export XAUTHORITY="/home/$user/.Xauthority"
fi
pulsecmd(){
cmd=$1
shift
if [ $cmd == "pactl" ]
then
cmd="$cmd --server unix:/run/user/$id/pulse/native"
fi
# set -x
if [ "$(whoami)" != "root" ]
then
$cmd $@
else
sudo -u $user XDG_RUNTIME_DIR="/run/user/$id/" $cmd $@
fi
# set +x
}
HDMI_STATUS=`grep "^connected$" /sys/class/drm/card0/*HDMI*/status`
HEADPHONE_STATUS=`pulsecmd pacmd list-sinks | grep "headphones.*available: yes"`
INPUTS=$(pulsecmd pacmd list-sink-inputs | grep index | awk '{print $2}')
# Compute output name
echo $INPUTS
if [ ! -z $HDMI_STATUS ] && [ -z "$HEADPHONE_STATUS" ]
then
name="hdmi"
plusname=".monitor"
type="output"
else
name="analog"
type="input"
fi
name="$name-stereo"
echo "name $name"
card=`pulsecmd pacmd list-cards | grep device.bus_path | head -n 1 | awk '{print $3}' \
| sed -e 's/"//g' -e 's/:/_/g' `
echo "card $card"
output="alsa_output.$card.$name"
echo "out $output"
io=`pulsecmd pacmd list-cards | grep "output:$name.*input:" | awk '{print $1}' \
| head -n 1 | sed 's/:$//' `
if [ -z "$io" ]
then
# Io does not support input mode
io=`pulsecmd pacmd list-cards | grep "output:$name" | awk '{print $1}' \
| head -n 1 | sed 's/:$//' `
fi
echo "io $io"
# Iterate over all cardes
for i in $(seq 0 $(($(pulsecmd pacmd list-cards | grep index |wc -l)-1)))
do
# Set profile or turn card off
pulsecmd pactl set-card-profile $i $io
if [ $? -ne 0 ]
then
pulsecmd pactl set-card-profile $i off
else
pulsecmd pactl set-default-sink $output
pulsecmd pactl set-source-mute alsa_$type.$card.$name$plusname 1
fi
done
# Move all sources to the right sink
for i in $INPUTS
do
pulsecmd pacmd move-sink-input $i $output
done
#!/bin/bash
DIR=$(realpath $(dirname $0))
user=$(who | grep -v "root" | head -n 1 | cut -d ' ' -f 1)
if [ ! -z "$user" ]
then
id=$(id -u $user)
export DISPLAY=:0
export XAUTHORITY="/home/$user/.Xauthority"
fi
pacmd(){
# set -x
cmd="pactl --server unix:/run/user/$id/pulse/native $@"
if [ "$(whoami)" != "root" ]
then
$cmd
else
sudo -u $user XDG_RUNTIME_DIR="/run/user/$id/" $cmd
fi
# set +x
}
date=$(date +%Y%m%d%H%M%S)
pacmd subscribe | while read line
do
ndate=$(date +%Y%m%d%H%M%S)
if [ $ndate != $date ]
then
$DIR/hdmi_sound_toggle.sh
fi
date=$ndate
done
......@@ -24,6 +24,8 @@ then
export XAUTHORITY="/home/$user/.Xauthority"
fi
DIR=$(realpath $(dirname $0))
# show max between two res
max_res(){
[ -z "$2" ] && echo $1 && return
......
......@@ -5,6 +5,10 @@ SCOPE2=CE1-CE2
SCOPE3=CM1-CM2
SHARE_DIR="/home/shares/$USER"
# unmute sound
pactl set-sink-mute 0 0
/opt/primtux-eole/pactl_watch.sh &
while ! /bin/ping -c 2 ecole-dc; do sleep 10; done;
for d in 01-cp 02-ce1-ce2 03-cm1-cm2
......@@ -66,6 +70,3 @@ case "$USER" in
echo file://$DOCUMENTS/CONFIDENTIEL_PROFESSEURS CONFIDENTIEL_PROFESSEURS >> $HOME/.config/gtk-3.0/bookmarks
;;
esac
# unmute sound
pactl set-sink-mute 0 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment