Kodi keeps crashing when it is started without connected displays. Sometimes I want to startup my kodi setup for some other reasen and start using kodi later.... then kodi was already closed with some crash log file... :(
This script works arround by waiting to start kodi until some hdmi port is connected (modify the grep query to adapt to some other port name).
#!/bin/bash
# Some programs have issues when run without connected display. E.g. Kodi likes to crash when started without any display connected on my system.
# This script starts after some hdmi port is connected.
# Depends on xrandr.
WARNINGTIMEOUTINSECONDS=840
TIMEOUTINSECONDS=900
POLLINGDURATIONINSECONDS=5
LOGFILE="$HOME/waitTillHdmiConnected.log"
#set start conditions
SECONDS=0
triggerTimeoutActions(){
echo "Shuting down" | tee -a "$LOGFILE"
echo $(date && echo "shutting realy down") | tee -a "$LOGFILE"
# e.g. shutdown the system
#sudo shutdown +1 | tee -a "$LOGFILE"
exit
}
triggerHdmiConnectedActions(){
# e.g. set some overscan hack
#xrandr --output HDMI-3 --transform 1.05,0,-34,0,1.05,-20,0,0,1
# e.g. start kodi
#kodi &
exit
}
echo $(date && echo "Start polling") | tee -a "$LOGFILE"
while [ 1 ]
do
if xrandr 2> /dev/null | grep -q 'HDMI-[0-9] connected'; then
echo "HDMI connected" | tee -a "$LOGFILE"
triggerHdmiConnectedActions
else
echo "HDMI not connected waiting $POLLINGDURATIONINSECONDS seconds" | tee -a "$LOGFILE"
duration=$SECONDS
#calc if timeout ocured -> shutdown
echo "$(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed since first poll." | tee -a "$LOGFILE"
if [ "$duration" -gt "$WARNINGTIMEOUTINSECONDS" ]; then
echo "Warning: HDMI connection timout is about to occure!" | tee -a "$LOGFILE"
if [ "$duration" -gt "$TIMEOUTINSECONDS" ]; then
triggerTimeoutActions
fi
fi
sleep $POLLINGDURATIONINSECONDS
fi
done
Kommentare