I'm trying to get a startup script requiring user input running before gdm starts (the script should allow me to choose from a list of xorg.conf's the one I'd like to use for the current session).

Already tried creating a pregdm.conf in /etc/init, containing:

start on filesystem
stop on runlevels [06]
#  ...
console output

script
  # script that uses read to gather user input and replaces xorg.conf with the selected one
end script

and changing start on in /etc/init/gdm.conf to:

start on (filesystem
          and started dbus
          and started pregdm
          and (drm-device-added card0 PRIMARY_DEVICE_FOR_DISPLAY=1
               or stopped udevtrigger))

Echos are displayed in console but I can't make it wait for user input: gdm is started straight away.

Any pointers?

Thanks a lot

link|improve this question
feedback

2 Answers

Upstart isn't intended for interactive use.

It's likely that the standard input for your script is redirected away from you. You could try using a different file descriptor.

#!/bin/bash
exec 3<&0
read -u 3 -p "Choose one: " input
exec 3<&-

Here's a complete demo script that shows input coming from a file and from the user:

#!/bin/bash
exec 3<&0
while read -r line
do
    read -r -p "$line " -u 3 input
    echo "$line/$input"
done < inputfile

If you're using a shell that doesn't have the -u option for read:

read input <&3
link|improve this answer
I almost forgot about this. Thanks a lot for the pointers (and demo) about input/output redirection, didn't know about it. As far I've understood messing with upstart isn't a good solution for my problem: do you have any idea how to implement a simple interactive startup menu? – Utaal Mar 20 '11 at 16:26
@Utaal: I don't know. Have you looked at doing something through grub? – Dennis Williamson Mar 20 '11 at 19:39
feedback

I think you should do something like this:

  [ -x /usr/bin/plymouth ] && /usr/bin/plymouth --hide-splash
  while : ; do
      echo -n $"XXX $1 (Y)es/(N)o? [Y] "
      read answer
      if strstr $"yY" "$answer" || [ "$answer" = "" ] ; then
         ...
  [ -x /usr/bin/plymouth ] && /usr/bin/plymouth --show-splash
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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