[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Unattended package install.



> 
> I tried it and it seemed to die in the middle of the generation of
> it's script.  It might have something to do with my script hanging at
> the end though.

Just run the interactive bits through the expect script.  i.e.:

  /usr/doc/expect5.24/examples/autoexpect -f inewsinn.exp  \
      dpkg -i `find . -name "inewsinn_*.deb"`

and fill in the blanks.  Once done, have a look at the new script.  Each 
prompt should have been turned into an ``expect'' statement, but there will be 
a lot of stuff you don't need, and you need to make the script capable of 
surviving variable prompts.

So in the case of inewsinn (I just chose that beccause I don't use it, so 
don't mind purging it),  the middle section of the autoexpect output looks 
like this:

...
expect -exact "Selecting previously deselected package inewsinn.\r
(Reading database ... 47380 files and directories currently installed.)\r
Unpacking inewsinn (from .../news/inewsinn_1.7.2-2.deb) ...\r
Setting up inewsinn (1.7.2-2) ...\r
\r
** INN inews (news client) configuration\r
\r
If you are installing \"inews\" as part of a complete INN installation,\r
you should _not_ configure \"inews\" now. Inews will be configured as\r
a part of INN after the INN installation.\r
\r
Configure inews now? \[Y/n\] "
send -- "y\r"
expect -exact "y\r
\r
Please enter the `return mail name' of your system.  This is the hostname\r
portion of the address to be shown on outgoing news (not mail) messages.\r
\r
Return mail name \[palm.hands.com\]: "
send -- "hands.com\r"
expect -exact "hands.com\r
\r
Name of your local organisation, for the Organization: header line ?\r
Setting NEWSORG or ORGANIZATION in the user's environment overrides this.\r
\r
Organization \[A poorly-maintained Debian GNU/Linux InterNetNews site\]: "
send -- "Philip Hands Computing Ltd.\r"
...

which should be tidied up by removing all but the last line of each expect 
string, and making some of them into regular expressions.  The result is an 
expect script that looks like this:

---- inewsinn.exp ----
#!/usr/bin/expect -f
#

set timeout -1
spawn dpkg -i /mirror/Debian/hamm/hamm/binary-i386/news/inewsinn_1.7.2-2.deb
match_max 100000
expect -exact "Configure inews now? \[Y/n\] "
send -- "y\r"
expect -re "Return mail name .*\]: "
send -- "hands.com\r"
expect -re "Organization .*\]: "
send -- "Philip Hands Computing Ltd.\r"
expect -re "News server .*\]: "
send -- "news.hands.com\r"
expect -exact "Are these settings correct \[Y/n\] "
send -- "y\r"
expect eof
----------------------

Once you've done that, you just call the whatever.exp script in your firewall 
script to install that package.

Assuming that works, you could actually write the whole script in expect, by 
tacking the spawn, expect eof, bits together.

Alternatively (I should have thought of this earlier) there is a perl module 
called Comm.pl that gives you similar functionality.  This is probably better, 
since debian systems have perl by default.

See:  ftp://ftp.demon.co.uk/pub/mirrors/perl/CPAN/authors/id/ERICA/Comm.pl-1.8.tar.gz

It looks like there is also an alternative perl implementation called
Expect.pm, available on CPAN.

If you use one of these, you could write your whole script in perl, and not 
need to install expect,tcl etc.

Cheers, Phil.



--
To UNSUBSCRIBE, email to debian-devel-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org


Reply to: