【问题标题】:Unable to read from user in rpm install script无法在 rpm 安装脚本中从用户读取
【发布时间】:2015-08-17 12:57:59
【问题描述】:

我创建了 RPM 包,其中包含如下所示的 shell 脚本代码。当我在 RedHat OS 中安装它时,它没有接受用户输入并不断循环。如果我手动运行相同的文件,它工作正常。如果有人知道,请告诉我。

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

提前致谢

【问题讨论】:

    标签: linux bash shell redhat rpmbuild


    【解决方案1】:

    你不能这样做是故意的; RPM 不应提示用户输入,因此,RPM 在运行钩子脚本之前会关闭标准输入。

    但是,如果您想更加努力(您不应该这样做!),请打开 /dev/tty 以查找附加到您的控制 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
    

    当软件需要信息才能工作时,最佳做法是要求将信息带外写入配置文件。

    【讨论】:

      【解决方案2】:

      我只是在 RPM 安装脚本上查找了有关处理用户输入的详细信息,我能找到的最广泛的共识是您不应该尝试获取用户输入。

      典型的理由是从图形 UI 安装 RPM,如 here 所述。

      另外,我发现这个相关的问题也出现了“否”的答案:https://superuser.com/questions/408852/is-it-possible-to-get-users-input-during-installation-of-rpm

      【讨论】:

      • “否”是不正确的,在技术学究的意义上。这是最好的答案,因为人们应该找到一种更好的方法来配置他们正在安装的软件,但这并不能准确回答以“是否可能”开头的问题。
      猜你喜欢
      • 1970-01-01
      • 2020-03-28
      • 2012-12-15
      • 2019-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-04
      • 1970-01-01
      相关资源
      最近更新 更多