dpkg-preconfigure hangs when a password is passed to sudo from the stdin

Asked by Leon Nardella on 2009-02-05

Please, have a look at http://paste.ubuntu.com/114087

I'm trying to build a script that will automatize my post-installation procedures after a fresh Ubuntu installation.
The majority of the commands within that script need root priviledges to be run, hence the need to uso sudo.
Given that I want it to be as automatic as possible, I needed a way to pass my password to sudo only once, when I run the script.

To do that, I could only came up with something that seems like a hack:
'sudo' accepts '-S' as a flag indicating it should read the password from the stdin.
Within the script, the I use 'echo $1 | sudo -S command', which takes the first parameter when I run my script and passes it to sudo

It essentially works as I need, but the script hangs when trying to install the Sun Java JDK.
It shows a dialog where I should accept the Sun license, but the terminal becomes useless, and nothing works. I usually get a grey screen if I try to run the script again after that.

If you make a custom a script, with the following contents: http://paste.ubuntu.com/114167 you will be able to reproduce this issue.

Now... I actually want to know if that is a bug that I should file and/or whether there's a better approach to do what I am trying to do.

Thanks in advance.

Question information

English Edit question
Ubuntu debconf Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
Best TJ (tj) said : #1

Call the script using sudo instead. e.g. "sudo post-install.sh"

Alter your script and remove all the commands that are prefixed with "sudo" since they are no longer required (the script is running as root and all sub-processes will likewise).

For commands in the script that need to run as a regular user (e.g. wget downloading to a user directory), you can use su -c "$COMMAND" $USER

You could maybe pass the $USER on the command line too, so you'd do:

sudo post-install.sh username

and in the script, at the start:


TJ (tj) said : #2

Ooops, slight clarification!

"Alter your script and remove all the commands that are prefixed with "sudo" since they are no longer required"

Should read:

"Alter your script and remove the "sudo" prefix to commands since it is no longer required"

Leon Nardella (leon.nardella) said : #3

Thanks for your hastiness, TJ.

It seems at some point during my tests I assumed sudo'ing the whole script wouldn't work.
I'm testing the hopefully-fixed script right now and then, if all goes well, I'll mark this solved.

Leon Nardella (leon.nardella) said : #4

Yep.. It solved the problem.
Seems like I kind of over-engineered my script. ;)


Leon Nardella (leon.nardella) said : #5

Thanks TJ, that solved my question.