为什么TERM = xterm必须设置为我的脚本远程执行时正确工作?

我试图自动安装Debian服务器(debian 6.0 squeeze 64bit)。

部分安装需要安装Sun JRE软件包。

这个软件包有一个许可协议,必须被接受。 我有一个脚本,它使用以下几行来接受和安装JRE:

echo "sun-java6-bin shared/accepted-sun-dlj-v1-1 boolean true" | debconf-set-selections apt-get install -y sun-java6-jre 

这在本地执行脚本时工作正常。 但是,我需要使用ssh命令远程执行脚本,例如:

 ssh -i keyFile root@hostname './myScript' 

这不起作用。

尤其是在apt-get install -y sun-java6-jre上失败。 看起来,尽pipe我把许可协议设定为可接受的,但是当以这种方式远程运行时,它被忽略了。

尽pipe将该值设置为true ,但在运行此命令时仍然会提示手动接受协议:

 ssh -i keyFile root@hostname 'apt-get install -y sun-java6-jre' 

我怀疑这是与运行正确的terminal会话时照顾的环境有关,但不知道下一步要尝试修复它。

编辑0 :我通过ssh远程执行并通过本地terminal会话执行时比较了env的输出。 输出之间的唯一区别是本地terminal会话具有附加值TERM=xterm

编辑1 :在调用我的脚本时设置TERM环境variables,像这样ssh -i keyFile root@hostname 'export TERM=xterm; ./myScript' ssh -i keyFile root@hostname 'export TERM=xterm; ./myScript'产生正确的行为,但这只是答案的一半,因为我不知道为什么需要设置它。 对于能够最好地解释为什么的人的一个被接受的答案!

(我已经修改了问题标题,从“ 远程脚本安装的Sun / Oracle JRE ”到“ 为什么TERM = xterm必须被设置为我的脚本在远程执行时正确工作? ”,因为这是一个更准确的问题)

sun- preinst -jre软件包包含preinst脚本,通过/usr/share/debconf/confmodule (也被称为“shell脚本”界面,用于debconf前端)提示许可协议。 debconf的实现很难遵循,但我猜测db_input()的实现会检查TERM环境variables,并尝试为不同的terminal实现不同的许可协议提示。 请参阅http://www.fifi.org/doc/debconf-doc/tutorial.html上的debconf教程。 这个想法是,如果最终用户视力受损,preconf脚本将正常工作,debconf前端最终可能会使用盲文显示。

据我所知,您不应该将脚本输出传递到交互式debconf前端。 它意味着供人类消费,随时可能改变(根据环境variables,月相等)。 你可能想google的debconf frontend noninteractive

这不是布尔值,select

你可以validationdebconf数据库的内容:

 root@workstation:~# debconf-show sun-java6-jre * shared/accepted-sun-dlj-v1-1: true sun-java6-jre/stopthread: true sun-java6-jre/jcepolicy: shared/error-sun-dlj-v1-1: * shared/present-sun-dlj-v1-1: root@workstation:~# 

正如你在我的机器上看到的,它已经设置为true,因为我在安装时手动接受了它。 如果我再次安装sun-java6-jre,它不会提示我接受许可证。

让我们把它设置为false:

 root@workstation:~# echo sun-java6-jre shared/accepted-sun-dlj-v1-1 select false | /usr/bin/debconf-set-selections 

现在我们来检查一下:

 root@workstation:~# debconf-show sun-java6-jre * shared/accepted-sun-dlj-v1-1: false sun-java6-jre/stopthread: true sun-java6-jre/jcepolicy: shared/error-sun-dlj-v1-1: * shared/present-sun-dlj-v1-1: root@workstation:~# 

所以请尝试:

 ssh -i keyFile root@hostname "echo sun-java6-jre shared/accepted-sun-dlj-v1-1 select true | /usr/bin/debconf-set-selections && apt-get install -y sun-java6-jre" 

使用debconf-show命令进行故障排除。

我怀疑你什么时候说

这在本地执行脚本时工作正常。

这是因为你在某个时候手动安装了sun-java6-jre。

由于这里的问题已经改变了另一个答案。

TERMvariables作为sun-java5-jre preinst脚本的一部分进行检查(请参阅此处 )。 在这个脚本里面,使用/ usr / share / debconf / confmodule和deconf数据库进行交互,并检查数据库中的许可证是否已经被接受。 如果没有,它会调用debconf方法向您颁发许可证。 Debconf将以适合您的环境的方式呈现它。 这是TERM进来的地方。如果你没有TERM,它应该故障转移到其他方法

所以这里是一个例子,在debconf中许可证设置为false(不被接受)

 Preparing to replace sun-java6-jre 6.26-1~lffl~oneiric~ppa (using .../sun-java6-jre_6.26-1~lffl~oneiric~ppa_all.deb) ... debconf: Unable to initialise frontend: Dialog debconf: (TERM is not set so the dialogue frontend is not usable.) debconf: falling back to frontend: Readline debconf: Unable to initialise frontend: Readline debconf: (This frontend requires a controlling tty.) debconf: falling back to frontend: Teletype Configuring sun-java6-jre ------------------------- Operating System Distributor License for Java v1.1 (DLJ) Operating System Distributor License for Java version 1.1 (DLJ) SUN MICROSYSTEMS, INC. ("SUN") IS WILLING TO LICENSE THE JAVA PLATFORM STANDARD EDITION DEVELOPER KIT ("JDK" - THE "SOFTWARE") TO YOU ONLY UPON THE CONDITION THAT YOU ACCEPT ALL OF THE TERMS CONTAINED IN THIS LICENSE AGREEMENT (THE "AGREEMENT"). PLEASE READ THE AGREEMENT CAREFULLY. BY INSTALLING, USING, OR DISTRIBUTING THIS SOFTWARE, YOU ACCEPT ALL OF THE TERMS OF THE AGREEMENT. ...................................... CUT ................................. DLJ v1.1 27APR2006ANS In order to install this package, you must accept the license terms, the "Operating System Distributor License for Java" (DLJ), v1.1. Not accepting will cancel the installation. Do you accept the DLJ license terms? yes 

这是许可证已被批准的一个例子(在deconf中设置为true)

  root@workstation:/home/andrey/buildarea# ssh root@localhost "echo 'sun-java6-bin shared/accepted-sun-dlj-v1-1 boolean true' | debconf-set-selections && aptitude -y reinstall sun-java6-jre" root@localhost's password: Reading package lists... Building dependency tree... Reading state information... Reading extended state information... Initialising package states... Writing extended state information... The following packages will be REINSTALLED: sun-java6-jre 0 packages upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 168 not upgraded. Need to get 0 B/6,381 kB of archives. After unpacking 0 B will be used. Writing extended state information... debconf: Unable to initialise frontend: Dialog debconf: (TERM is not set so the dialogue frontend is not usable.) debconf: falling back to frontend: Readline debconf: Unable to initialise frontend: Readline debconf: (This frontend requires a controlling tty.) debconf: falling back to frontend: Teletype dpkg-preconfigure: Unable to re-open stdin: (Reading database ... 161723 files and directories currently installed.) Preparing to replace sun-java6-jre 6.26-1~lffl~oneiric~ppa (using .../sun-java6-jre_6.26-1~lffl~oneiric~ppa_all.deb) ... debconf: Unable to initialise frontend: Dialog debconf: (TERM is not set so the dialogue frontend is not usable.) debconf: falling back to frontend: Readline debconf: Unable to initialise frontend: Readline debconf: (This frontend requires a controlling tty.) debconf: falling back to frontend: Teletype sun-dlj-v1-1 license has already been accepted Unpacking replacement sun-java6-jre ... Processing triggers for shared-mime-info ... Setting up sun-java6-jre (6.26-1~lffl~oneiric~ppa) ... Reading package lists... Building dependency tree... Reading state information... Reading extended state information... Initialising package states... Writing extended state information... root@workstation:/home/andrey/buildarea# 

安装过程中是否收到相同的“debconf”消息? 你可以通过SSH 在这里看到我的实验并成功安装了sun-java6-jre注意:运行ssh root @ localhost“env”时,我看不到TERMvariables。

如果你想看看deb包在做什么之前,在安装后,donwload .deb文件:

 aptitude download sun-java6-jre 

提取.deb

 ar x sun-java6-jre......deb 

提取control.tar.gz并查看preinstal和其他文件。 data.tar.gz是包的内容。

这可能不会直接回答你的问题,但希望会有所帮助。