Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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."

share|improve this question

marked as duplicate by jokerdino, John S Gruber, Mitch, RolandiXor, hbdgaf Aug 23 '12 at 16:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
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

1 Answer 1

up vote 2 down vote accepted

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]
task
script
  myscript=`mktemp /tmp/killme.sh.XXXXXX`
  chmod 0750 /tmp/killme.sh
  cat > $myscript <<EOF
#!/bin/sh
# script is sent key pressed
cat > /tmp/keypresses.txt
kill -USR1 $$
EOF
  key=""
  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"
  timeleft=10
  while [ $timeleft -gt 0 ] ; do
    plymouth display-message --text="you have $timeleft seconds to press A,B,C, or D..."
    timeleft=(($timeleft-1))
  done
  plymouth display-message --text="Timed out..."
end script
share|improve this answer

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