Possible Duplicate:
Upstart script: Detect shift key down at boot

I want to add a question during boot. The user is supposed to make keyboard inputs and depending on those inputs, there is an if inside the script.

"Do you want X or Y?"

"Or simply wait 10 seconds to default to X."

  • Not sure I agree with that, as that is specifically "how to detect shift" – SpamapS Aug 6 '12 at 20:06
  • The question itself allowed more general solutions, although shift key was desired, and no answer was shift key only. Covers the same ground. – John S Gruber Aug 20 '12 at 2:36

Its a bit tricky, but you can use plymouth to converse with the user while the system is coming up. This will only work if your job blocks the startup, because once runlevel 2 is reached and plymouth is terminated, you won't be able to interact anymore.

Basically you want to execute 'plymouth ask-question' or 'plymouth watch-keystroke' and the user will be prompted. So if you want to wait 10 seconds for the user, you'd have an upstart job like this (this is quite theoretical and untested!):

start on starting rc RUNLEVEL=[2345]
  myscript=`mktemp /tmp/killme.sh.XXXXXX`
  chmod 0750 /tmp/killme.sh
  cat > $myscript <<EOF
# script is sent key pressed
cat > /tmp/keypresses.txt
kill -USR1 $$
  handle_usr1() {
    key=`cat /tmp/keypresses.txt`
    plymouth display-message --text="you pressed $key"
    exit 0
  trap handle_usr1 USR1
  plymouth watch-keystroke --command=$myscript --keys="ABCD"
  while [ $timeleft -gt 0 ] ; do
    plymouth display-message --text="you have $timeleft seconds to press A,B,C, or D..."
  plymouth display-message --text="Timed out..."
end script
|improve this answer|||||

Not the answer you're looking for? Browse other questions tagged or ask your own question.