Unable to read from user in rpm install script

£可爱£侵袭症+ 提交于 2021-02-05 09:24:08

问题


I've Created RPM Package which contains shell script code which shown below. When I'm installing it in RedHat OS, It is not taking user input and continuously looping. If I run the same file manually it's working fine. If Anybody Knows Please let me know.

set +e 

IpAddress='0' 
condition=1    

while [[ $condition -ne 0 ]] 
do
    echo ' '   
    echo "PLEASE PROVIDE APPLIANCE IP" 
    read IpAddress   
    if valid_ip $IpAddress;   
    then
       condition=0   
    else
    echo $IpAddress  " IS INVALID IP PLEASE PROVIDE A VALID IP: " 
    echo ' '
    condition=1   
    f`enter code here`i 
done

condition=1 
while [[ $condition -ne 0 ]] 
do   
     echo "PLEASE PROVIDE APPLIANCE LOGIN PASSWORD"   
     read uiPassword   
     echo "The Password u entered is "$uiPassword   
     echo "Press Yes/No:"   
     read choice  
     choice=`echo $choice | tr '[:upper:]' '[:lower:]'`   
    case "$choice" in   
     yes|Yes ) condition=0;;   
     no|No ) echo "no";;   
     * ) echo "invalid";; 
    esac 
done

set -e

Thanks in Advance


回答1:


It's intentional that you can't; RPMs shouldn't prompt for user input, and for that reason, RPM closes stdin before running hook scripts.

However, if you want to try harder (which you shouldn't!), then open /dev/tty to find the process attached to your controlling TTY:

if exec </dev/tty; then
  read IpAddress || {
    : "deal with the case where attempting to read from the user failed here"
  }
  # ...and use the information read here...
else
  : "deal with the case where you simply can't read from the user here"
fi

Best practice when software needs information before it can work is to require that information to be written to a configuration file out-of-band.




回答2:


I just looked for details on handling user input on RPM installation scripts and the widest consensus I can find is that you should not try to get user input.

Typical rationale is the case of installing RPMs from a graphical UI, as described here.

Also, I found this related question where the "no" answer also appears: https://superuser.com/questions/408852/is-it-possible-to-get-users-input-during-installation-of-rpm



来源:https://stackoverflow.com/questions/30618014/unable-to-read-from-user-in-rpm-install-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!