8

Is it possible to get input from a user during an rpm installation?
I have a script that works by itself (taking input from a user and doing actions) but when run as part of the post install of an rpm (i.e. added in the %post section of an rpm spec) then it does not work.

Should it be possible? This is the part:

%post

import()  
{  
echo "Do you want to import file?"   
select INPUT in "Y" "N"; do  
        case $INPUT in  
                Y ) echo "You selected to import file";break;;  
                N ) echo "Exiting";exit 0;break;;  
        esac  
done   

read -p "Please file path: " FILE  
if [ -d "$FILE" ]; then  
      cp $FILE/myFile /opt/tmp/   
      echo "Done!"  
else  
   echo "No File Path."  
   done=0  
   while [ $done = 0 ]  
   do   
        echo  "Do you want to abort"  
        select INPUT in "Y" "N";  
        do  
                case $INPUT in  
                        Y )   
                                echo "Aborting"   
                                done=1  
                                break  
                                        ;;  
                        N )  
                                 echo "You selected to import"  
                                # break  
                                 #;;  
                                 read -p "Please provide the directory : " FILE  
                                 if [ -d "$FILE" ]; then  
                                        cp $FILE/myFile /opt/tmp  
                                        echo "Done"   
                                        done=1  
                                else  
                                        echo "Aborting."  
                                fi  
                                break  
                                ;;  
                esac  
           done  
   done  

fi
}    

import
exit 0  

During installation it directly jumps to the aborting inside the second case statement.
Why? What am I doing wrong here?

4 Answers 4

4

No, you cannot have interactive postinstall scripts in RPMs. This is deliberate.

Many times RPMs are installed on an unattended system. If the install were to hang until someone came along, it could be stuck there for ages.

2
  • You mean it is not technically possible?
    – Jim
    Apr 5, 2012 at 11:58
  • I know this is old as dirt but it's not strictly speaking a bad idea as long as your application was the end-product (as opposed to base OS or something) and the rpm consistently and always prompts for input during installation. I disagree with putting it in a spec script (it should probably be a post-install activation/configuration command or something) but it's not wrong. Installing software always requires you have some notion of what you're installing. If you know it requires input then you can just work that into your automated process.
    – Bratchley
    Jul 14, 2016 at 20:24
4

It's a very bad idea, but it's possible.

if ! exec </dev/tty; then
  : "deal with the case where you simply can't read from the user here"
  exit
fi

# ...the read command will work here.
1
  • Thanks @Charles. Your suggestion seems to lead to a promising (albeit abad idea) solution. I'll discuss with the higher-ups a more sane solution...
    – boardrider
    Jan 6, 2016 at 16:41
1

As @Charles Duffy posted answer, we can do this with /dev/tty functionality of Linux. Also we can use read to Read a line from the standard input.

Below example is for interactive rpm -

If you want to take user input like [Y/n] -

echo "Do you want to install <some package> [Y/n] "
if exec </dev/tty; then
    read input;
fi

# use input here or below

Some cent os users may want to create a yum repo from this interactive rpm.

Below example is for interactive rpm with yum -

If you want to take user input like [Y/n] -

echo "Do you want to install <some package> [Y/n] " >/dev/tty
if exec </dev/tty; then
    read input;
fi

# use input here or below

Make sure in above script echo ends with >/dev/tty i.e. print this message on different terminal on which user will enter the input.

Hope it Helps.

0

Technically, it IS possible, at least for some commands. In one of my RPMs I have mount command in post-install scripts that mounts a password-protected Windows share:

mount -t cifs //1.2.3.4/share /var/www/html -o username=user

and I get the following output during RPM install:

Password:

then user has to type the password before installation continues.

1
  • ...because, for security reasons, password prompts go straight to the TTY, as my answer describes. Oct 12, 2015 at 14:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .