简体   繁体   English

控制台模式下InstallAnywhere的交互式Shell脚本

[英]interactive shell script from InstallAnywhere in console mode

I use InstallAnywhere in console mode in Linux for installation and want to run some interactive shell script after finishing the installation. 我在Linux的控制台模式下使用InstallAnywhere进行安装,并希望在完成安装后运行一些交互式Shell脚本。 By "interactive" I mean that the script should ask some questions and receive user input. “交互式”是指脚本应提出一些问题并接受用户输入。

I tried to run it with "Execute target file" action, but the script prints nothing to the console (it surely executed because prints debug information to output file). 我尝试使用“执行目标文件”操作来运行它,但是脚本未将任何内容打印到控制台(由于将调试信息打印到输出文件,因此该脚本确实执行了)。 I also tried to bring the script to foreground using "fg %1" (it was the last command in InstallAnywhere), but it did not work too. 我还尝试使用“ fg%1”(这是InstallAnywhere中的最后一个命令)将脚本放到前台,但是它也无法正常工作。

Is there any way to execute interactive script by InstallAnywhere in console mode? 有什么方法可以通过InstallAnywhere在控制台模式下执行交互式脚本吗?

Rather than using a shell script for user interaction, leverage IA to collect the answers you need, stuff them into IA variables, then use those variables in one or more "Execute Script/Batch file" Actions to do the post-install work. 与其使用Shell脚本进行用户交互,不如利用IA收集所需的答案,将其填充到IA变量中,然后在一个或多个“ Execute Script / Batch file”操作中使用这些变量来完成安装后的工作。

Say you want to collect a first name, last name and phone then write those to a file in your installation directory (contrived, I know, but hopefully demonstrative). 假设您要收集名字,姓氏和电话,然后将其写入安装目录中的文件中(我知道,是有希望的,但希望能得到示范)。

  1. Add a Jump Label and name it something like "Get User Info" 添加跳转标签,并将其命名为“获取用户信息”
  2. Add the Console Action "Get User Input" to read the first name. 添加控制台操作“获取用户输入”以读取名字。 Assign the result to $FIRST_NAME$ . 将结果分配给$FIRST_NAME$
  3. Add the Console Action "Get User Input" to read the last name. 添加控制台操作“获取用户输入”以读取姓氏。 Assign the result to $LAST_NAME$ . 将结果分配给$LAST_NAME$
  4. Add the Console Action "Get User Input" to read the phone number. 添加控制台操作“获取用户输入”以读取电话号码。 Assign the result to $PHONE_NUMBER$ . 将结果分配给$PHONE_NUMBER$
  5. Add the "Jump To Target" Action with a NEXT Jump Action of "Get User Info" (#1, above). 添加“跳转到目标”操作和“获取用户信息”(上面的#1)的下一个跳转操作。 Add rules to validate these three variables such that a TRUE result will execute the jump to "Get User Info". 添加规则以验证这三个变量,以使结果为TRUE将执行跳转到“获取用户信息”的操作。 In other words, a BAD first name or BAD last name or BAD phone number should evaluate to TRUE . 换句话说,BAD名或BAD姓或BAD电话号码应评估为TRUE This will send the user back to the "Get User Info" Target Label. 这会将用户发送回“获取用户信息”目标标签。 Three valid values should evaluate to false, thereby NOT executing the jump. 三个有效值应评估为false,从而不执行跳转。 I know. 我知道。 It's weird. 有点奇怪。
  6. Finally, add as many "Execute Script/Batch file" Actions as needed to for each target installation platform. 最后,为每个目标安装平台添加所需数量的“执行脚本/批处理文件”操作。 For each of these actions, add a rule that limits execution of that Action to a specific platform. 对于这些操作中的每一个,添加一条规则,以限制该操作在特定平台上的执行。 For the Unix/Linux actions, be sure to check the checkbox "Do not substitute unknown variables" or IA will substitute YOUR script variables with blanks. 对于Unix / Linux操作,请确保选中“不要替换未知变量”复选框,否则IA将用空格替换您的脚本变量。 (word of caution: use the full variable name form ${MY_VARIABLE_NAME} to help IA distinguish your variables from its own variables). (警告:使用完整的变量名格式${MY_VARIABLE_NAME}可以帮助IA区分您的变量和它自己的变量)。

A Unix/Linux version might look like this: Unix / Linux版本可能如下所示:

#!/bin/sh
echo <<EOF
Name: $FIRST_NAME$ $LAST_NAME$
Phone: $PHONE_NUMBER$
EOF > $USER_INSTALL_FOLDER$$/$userName.txt

The Windows version is similar: Windows版本类似于:

echo "Name: $FIRST_NAME$ $LAST_NAME$" > $USER_INSTALL_FOLDER$$/$userName.txt
echo "Phone: $PHONE_NUMBER$" >> $USER_INSTALL_FOLDER$$/$userName.txt

Note the use of $/$ which IA converts to the appropriate path separator for the current platform. 请注意$/$的使用,IA会将其转换为当前平台的适当路径分隔符。

After the "Execute Script/Batch file" Actions you can add steps to evaluate the success of the Script/Batch file. 在“执行脚本/批处理文件”操作之后,您可以添加步骤以评估脚本/批处理文件的成功。 Add rules on "Jump To Target" Actions to evaluate the value of $EXECUTE_EXITCODE$ . 在“跳转到目标”操作上添加规则,以评估$EXECUTE_EXITCODE$的值。 $EXECUTE_EXITCODE$ is the default variable where the process' exit code is stored by "Execute Script/Batch file" Actions. $EXECUTE_EXITCODE$是默认变量,通过“执行脚本/批处理文件”操作在其中存储进程的退出代码。

Real-life installation scripts could be more complex than this. 实际的安装脚本可能比这更复杂。 You could collect any number of variables and use them in any number of post-installation script(s). 您可以收集任意数量的变量,并在任意数量的安装后脚本中使用它们。 These scripts then focus on doing the work, not on talking to the user. 这些脚本然后专注于完成工作,而不是与用户交谈。 That should be IA's job. 那应该是IA的工作。

Two parting thoughts: 两个分开的想法:

First, this same technique could be used with a GUI installer, too. 首先,同样的技术也可以与GUI安装程序一起使用。 In fact, mixing GUI and console input actions in the same project extends your installer to both graphical and console target platforms. 实际上,在同一项目中混合使用GUI和控制台输入操作会将您的安装程序扩展到图形和控制台目标平台。 The Post-Install scripts remain the same regardless of how you collect the input. 无论您如何收集输入,安装后脚本均保持不变。

Finally, you should ask your questions (if possible) during Pre-Install. 最后,您应该在预安装过程中提出您的问题(如果可能)。 That way the user can decide to bail on the installation if they can't or won't answer the questions. 这样,用户可以决定是否能够回答或不回答问题。 Asking the questions during post-installation could leave the installation hanging, or force the user to roll back, if they are unwilling or unable to provide the information you need. 如果不愿意或无法提供所需的信息,则在安装后提出问题可能会使安装挂起,或者迫使用户回退。

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

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