Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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.

share|improve this answer
    
You mean it is not technically possible? – Jim Apr 5 '12 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 at 20:24

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.
share|improve this answer
    
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 at 16:41

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.

share|improve this answer
    
...because, for security reasons, password prompts go straight to the TTY, as my answer describes. – Charles Duffy Oct 12 '15 at 14:27

You must log in to answer this question.

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