简体   繁体   中英

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. 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.

Is there any way to execute interactive script by InstallAnywhere in console mode?

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.

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$ .
  3. Add the Console Action "Get User Input" to read the last name. Assign the result to $LAST_NAME$ .
  4. Add the Console Action "Get User Input" to read the phone number. Assign the result to $PHONE_NUMBER$ .
  5. Add the "Jump To Target" Action with a NEXT Jump Action of "Get User Info" (#1, above). Add rules to validate these three variables such that a TRUE result will execute the jump to "Get User Info". In other words, a BAD first name or BAD last name or BAD phone number should evaluate to 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. 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. (word of caution: use the full variable name form ${MY_VARIABLE_NAME} to help IA distinguish your variables from its own variables).

A Unix/Linux version might look like this:

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

The Windows version is similar:

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.

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$ is the default variable where the process' exit code is stored by "Execute Script/Batch file" Actions.

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.

Two parting thoughts:

First, this same technique could be used with a GUI installer, too. In fact, mixing GUI and console input actions in the same project extends your installer to both graphical and console target platforms. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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