how to pass variables from bash script .sh to Initialization Actions?

Comments

5 comments

  • Avatar
    michiel

    You can use the program_stdout installer variable to store the output of <runProgram>

            <runProgram>
                <program>sh</program>
                <programArguments>${build_project_directory}/dmi_info_linux.sh</programArguments>
             </runProgram>

           <setInstallerVariable name="your_var" value="${progam_stdout}"/>

     

  • Avatar
    Paula

    How about if there are two or more output from the .sh file?

  • Avatar
    BitRock support

    Could you give more details regarding your requirements? The standard output - what is shown in the terminal when executing the command - is stored in the `progam_stdout` variable.

  • Avatar
    Paula

    This is what is inside the dmi_info_linux.sh file:

    #!/bin/bash

    TERMINAL=`dmidecode | grep -m1 "Product Name" | awk '{print $3}'`
    echo $TERMINAL

    TERMINAL_CLASS=${TERMINAL:0:4}
    echo $TERMINAL_CLASS

    TERMINAL_MODEL=${TERMINAL:5:2}
    echo $TERMINAL_MODEL

    MOTHERBOARD=`dmidecode | sort -r | grep -m1 "Product Name" | awk '{print $3}'`
    echo $MOTHERBOARD

    I wanted to get the output of the echoed variables to be used as a variable in Installbuilder. How should I do it using ${progam_stdout}" ?

  • Avatar
    michiel

    You could loop through the output using <forEach>


    <setInstallerVariable name="counter" value="0"/>

    <runProgram program="${build_project_directory}/linux.sh"/>
    <foreach variables="line" values="${program_stdout}">
    <actionList>
    <setInstallerVariable name="variable-${counter}" value="${line}"/>
    <mathExpression>
    <text>${counter}+1</text>
    <variable>counter</variable>
    </mathExpression>
    </actionList>
    </foreach>

    <showInfo text="${variable-2}"/>

     

Please sign in to leave a comment.