LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   on SlackBuild scripting (http://www.linuxquestions.org/questions/slackware-14/on-slackbuild-scripting-942700/)

tramni1980 05-01-2012 05:41 AM

on SlackBuild scripting
 
Hello,
I am writing a SlackBuild script for an application. The odd thing is that the configure script of the application at some point prompts the user to enter a number from the terminal
and then goes on. Until one enters a number, it just hangs and waits. My question is, is there a way to provide the number (the answer) to the configure call in the SlackBuild script itself, so that it doesn't prompt and the package building runs smoothly?

Any suggestions will be appreciated.

BlackRider 05-01-2012 05:53 AM

Of course you can.

The method you should use depends in the quality of the random number you need.

For cryptographic software, you want the best randomness you can get. You can surely obtain it by the clever use of openssl's "rand" and some scripting abilities.

If you don't need crypto-geek randomness, the Bash shell has a built in function to generate numbers between 0 and 32767. There is plenty of information about the $RANDOM function in search engines.

Please, tell us what software are you dealing with so we can decide upon facts.

tramni1980 05-01-2012 06:11 AM

Quote:

Originally Posted by BlackRider (Post 4667461)
Of course you can.

The method you should use depends in the quality of the random number you need.

For cryptographic software, you want the best randomness you can get. You can surely obtain it by the clever use of openssl's "rand" and some scripting abilities.

If you don't need crypto-geek randomness, the Bash shell has a built in function to generate numbers between 0 and 32767. There is plenty of information about the $RANDOM function in search engines.

Please, tell us what software are you dealing with so we can decide upon facts.

Oh, no it has nothing to do with random numbers, actually it is a fixed number (25) that I must type from the console during the configure. Can I
provide that number in the script, so that no prompt comes? This number gives the architecture that the sources will be configured for, and in my case 25 means Linux 64 bit with gfortran and gcc.

BlackRider 05-01-2012 06:46 AM

If the configure script accepts the number as an option (i.e: you could use "./configure --number=25") or variable (i.e: you could use "NUMBER=25 ./configure"), then it is as easy as setting the variable from the start of the SlackBuild script. If you are using the classical template, you should find something like this somewhere:

Code:

# Automatically determine the architecture we're building on:
if [ -z "$ARCH" ]; then
  case "$( uname -m )" in
    i?86) ARCH=i486 ;;
    arm*) ARCH=arm ;;
    # Unless $ARCH is already set, use uname -m for all other archs:
      *) ARCH=$( uname -m ) ;;
  esac
fi

You can modify this so it looks like:

Code:

# Automatically determine the architecture we're building on:
if [ -z "$ARCH" ]; then
  case "$( uname -m )" in
    i?86) ARCH=i486 && NUMBER=whatever1;;
    arm*) ARCH=arm && NUMBER=whatever2;;
    # Unless $ARCH is already set, use uname -m for all other archs:
      *) ARCH=$( uname -m ) && NUMBER=whatever3;;
  esac
fi

When running configure, you would just pass it the NUMBER variable by the means accepted by the script. It would look like this, where the "number" option is the option that parses your 25:

Code:

./configure \
  --prefix=/usr \
  --libdir=/usr/lib${LIBDIRSUFFIX} \
  --sysconfdir=/etc \
  --localstatedir=/var \
  --mandir=/usr/man \
  --docdir=/usr/doc/$PRGNAM-$VERSION \
  --build=$ARCH-slackware-linux \
  --number=$NUMBER

Other tweaks may be needed, but I hope you get the idea.

If the configure script does not accept the number as an input, and supports only interactive prompting, then you are supposed to patch the ./configure script so it behaves like explained above. You can do this by having the ./configure script accept non-interactive modes or by making it figure the number by itself.

catkin 05-01-2012 06:50 AM

Edit pkgname.SlackBuild's running of the configure command, something like echo 25 | ./configure ...

If that works you could implement it to use a variable value instead of 25 and set that variable before running pkgname.SlackBuild.

bosth 05-01-2012 08:15 AM

Two ideas:
1) check to see if the install script that you are running has a help flag which might tell you a way to pass this number as an argument or an environment variable. For example, ./configure -h could tell you that calling ./configure --arch=25 is equivalent to providing the number during the script.

2) Patch the script so that instead of asking it just uses 25. Many SlackBuilds patch the source code or the Makefiles to fix problems, and in this case it shouldn't be too hard to remove the prompt and assign 25 to the variable in question.

larryhaja 05-01-2012 08:42 AM

Quote:

Originally Posted by catkin (Post 4667503)
Edit pkgname.SlackBuild's running of the configure command, something like echo 25 | ./configure ...

This is how I have dealt with this issue in the past. It allows the slackbuild to continue uninterrupted.

tramni1980 05-01-2012 09:18 AM

Quote:

Originally Posted by catkin (Post 4667503)
Edit pkgname.SlackBuild's running of the configure command, something like echo 25 | ./configure ...

If that works you could implement it to use a variable value instead of 25 and set that variable before running pkgname.SlackBuild.

Thank you very much for your reply, it worked like a charm.
The configure script does not allow a parameter for this option, and the prompt actually comes from a perl script, so hacking it would not be easy for me.
But the echo-pipe thing worked perfectly, many thanks!


All times are GMT -5. The time now is 03:24 PM.