简体   繁体   English

在linux中自动安装二进制文件

[英]Automate installation of binary in linux

I have a Bourne-Again shell script text executable named engine.bin that I want to install. 我有一个名为engine.bin的Bourne-Again shell脚本文本可执行文件,我想安装它。

If I install the executable manually ./engine.bin I get a screen with the EULA I have to accept (by pushing space), then accept it by writing yes and then enter the installation path by typing /usr/local/engine . 如果我手动安装可执行文件./engine.bin我得到一个我必须接受的EULA屏幕(通过推送空间),然后通过编写yes接受它,然后键入/usr/local/engine输入安装路径。

Now I want to do the installation automatically through provisioning scripts without manual interaction . 现在我想通过配置脚本自动完成安装, 无需手动交互 Is there a way to do this? 有没有办法做到这一点? I do not know if the installer accepts any parameters, unfortunately the thing is undocumented. 我不知道安装程序是否接受任何参数,遗憾的是这件事没有记录。

Based on the suggestion of bill-agee and jgr208 I wrote the following which is working for me: 根据bill-agee和jgr208的建议,我写了以下哪些内容对我有用:

#!/usr/bin/expect -f
set timeout -1
spawn /tmp/engine.bin
expect {
   -gl "*Press SPACE or PAGE DOWN key to continue, U or PAGE UP key to scroll back*" { send -- " "; exp_continue }
   -gl "*yes/no*"
}
send -- "yes\r" 
expect -gl "*press ENTER to accept the default*"
send -- "/tmp/tce\r"
expect eof

If the executable allows you to spam input at it without waiting for each separate prompt to appear, you might be able to accomplish this with bash. 如果可执行文件允许您在其上输入垃圾邮件而不等待每个单独的提示出现,您可以使用bash完成此操作。

For example, this script will run program_that_takes_several_lines_of_input.py and send it four lines of input - three with text and one blank line: 例如,此脚本将运行program_that_takes_several_lines_of_input.py并向其发送四行输入 - 三行包含文本和一行空行:

#!/bin/bash -eux

./program_that_takes_several_lines_of_input.py <<EOD
first line
one enter keypress later

yet another line of input after the empty line above
EOD

If you need to stop and wait for each prompt to appear, the cram Python package may be a good fit for this scenario - I find it useful for tasks like this where you only need to send a few lines of input, but each line of input is different. 如果你需要停下来等待每个提示出现,那么cram Python包可能非常适合这种情况 - 我觉得它对于这样的任务非常有用,你只需要输入几行输入,但每一行都是输入是不同的。

See: 看到:

https://bitheap.org/cram/ https://bitheap.org/cram/

https://pypi.python.org/pypi/cram https://pypi.python.org/pypi/cram

Expect would also work, but I find that I reach working solutions a bit faster when using cram than with Expect. 期望也会有效,但我发现使用cram比使用Expect更快地达到工作解决方案。

pexpect is a great choice as well! pexpect也是一个很好的选择! See: 看到:

https://pexpect.readthedocs.org/en/stable/ https://pexpect.readthedocs.org/en/stable/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM