jdunson
Posts: 10
Joined: Thu Dec 18, 2014 8:17 pm

Run startup script only if no HDMI?

Thu Dec 18, 2014 8:53 pm

What I would like to do is set up Raspbian so that it does the following:
* If a HDMI monitor (of whatever size or type) is plugged in, boot completely normally.
* If no HDMI monitor is plugged in, boot normally at first, but instead of simply waiting for a user to log in, run a specific script.

The initial use case will be a card / OS set up such that it boots and functions normally when attached to a screen (and presumably keyboard); but if booted with no screen, runs a script that calls a python program that displays an unattended holiday light show on the (presumed) attached Unicorn HAT.

Optionally, I'd like to be able to detect the presence of specific HATs, and run a different script based on whether certain ones are installed; and optionally shut down cleanly if neither a HDMI monitor nor any supported "kiosk" HATs are detected. Another interesting variant might include detection of a keyboard, to set up a third boot state: with-monitor-without-keyboard going into a slideshow, for instance.

I'm generally familiar with Linux and shell scripting, but I'm not clear on how to read the state of the Raspberry Pi monitor detection from a shell script, or where the best place for "do this last" / kiosk style scripts are in the Raspbian boot hierarchy.

For the optional / expansion idea, while I've skimmed some of the HAT info and understand that they have an ID EEPROM, it's not clear what the "stock" method of querying from user-land (shell script, python program, etc.) whether a HAT is present at all, and if so which one is attached.

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Run startup script only if no HDMI?

Thu Dec 18, 2014 9:31 pm

Play around with the tvservice tool , it should be able to
do what you want.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

DirkS
Posts: 10347
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Run startup script only if no HDMI?

Thu Dec 18, 2014 11:20 pm

I have played around with this code in /etc/rc.local:

Code: Select all

echo "is it HDMI or DVI?" > /home/pi/tft.log
/usr/bin/tvservice -s >> /home/pi/tft.log
if (/usr/bin/tvservice -s | /bin/egrep 'HDMI|DVI') ; then
    echo "HDMI / DVI screen" >> /home/pi/tft.log
else
    echo "No HDMI / DVI; run script" >> /home/pi/tft.log
    /full/path/to/your/script   # replace this with full path to script
fi
Addit *before* the line 'exit 0'.
The stuff sent to /home/pi/tft.log is just meant for debugging.
The script is run as root.

Gr
Dirk.

john.t
Posts: 28
Joined: Fri Sep 23, 2016 10:56 am

Re: Run startup script only if no HDMI?

Mon Apr 03, 2017 7:03 pm

Do i have to make my own tft.log to make this work?
thnx
john

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Run startup script only if no HDMI?

Mon Apr 03, 2017 8:03 pm

The file should be automatically created on first run.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

Return to “Raspberry Pi OS”