def run_inno_installer()

in assets/scripts/SilentInstaller.py [0:0]


def run_inno_installer(options):
    ''' Runs the installer.exe, and checks for the exit code. Return the installer version. '''

    inno_setup_exit_codes = {
        1: 'Inno Setup: Setup failed to initialize.',
        2: 'Inno Setup: The user clicked Cancel in the wizard before the actual installation started, or chose "No" on the opening "This will install..." message box.',
        3: 'Inno Setup: A fatal error occurred while preparing to move to the next installation phase (for example, from displaying the pre-installation wizard pages to the actual installation process). This should never happen except under the most unusual of circumstances, such as running out of memory or Windows resources.',
        4: 'Inno Setup: A fatal error occurred during the actual installation process.',
        5: 'Inno Setup: The user clicked Cancel during the actual installation process, or chose Abort at an Abort-Retry-Ignore box.',
        6: 'Inno Setup: The Setup process was forcefully terminated by the debugger',
        7: 'Inno Setup: The Preparing to Install stage determined that Setup cannot proceed with installation.',
        8: 'Inno Setup: The Preparing to Install stage determined that Setup cannot proceed with installation, and that the system needs to be restarted in order to correct the problem.'
    }
    inno_log_file = tempfile.NamedTemporaryFile(prefix='TableauServerInstaller_', suffix='.log', delete=False);
    inno_log_file_full_path = inno_log_file.name
    inno_log_file.close()

    # the installer will write its version to this file so that we know the full path to the installed binaries
    version_file = tempfile.NamedTemporaryFile(prefix='TableauServerInstallerVersion_', suffix='.txt', delete=False);
    version_file_full_path = version_file.name
    version_file.close()

    inno_installer_args = [
        '/VERYSILENT',          # No progress GUI, message boxes still possible
        '/SUPPRESSMSGBOXES',    # No message boxes. Only has an effect when combined with '/SILENT' or '/VERYSILENT'.
        '/ACCEPTEULA',
        '/LOG=' + inno_log_file_full_path,
        '/DIR=' + options.installDir,
        '/DATADIR=' + options.dataDir,
        '/CONTROLLERPORT=' + options.controllerPort,
        '/VERSIONFILE=' + version_file_full_path
    ]

    if options.coordinationserviceClientPort is not None:
        inno_installer_args.append('/COORDINATIONSERVICECLIENTPORT=' + options.coordinationserviceClientPort)

    if options.coordinationservicePeerPort is not None:
        inno_installer_args.append('/COORDINATIONSERVICEPEERPORT=' + options.coordinationservicePeerPort)

    if options.coordinationserviceLeaderPort is not None:
        inno_installer_args.append('/COORDINATIONSERVICELEADERPORT=' + options.coordinationserviceLeaderPort)

    if options.licenseserviceVendorDaemonPort is not None:
        inno_installer_args.append('/LICENSESERVICEVENDORDAEMONPORT=' + options.licenseserviceVendorDaemonPort)

    if options.agentFileTransferPort is not None:
        inno_installer_args.append('/AGENTFILETRANSFERPORT=' + options.agentFileTransferPort)

    if options.portRangeMin is not None:
        inno_installer_args.append('/PORTRANGEMIN=' + options.portRangeMin)

    if options.portRangeMax is not None:
        inno_installer_args.append('/PORTRANGEMAX=' + options.portRangeMax)

    if options.portRemappingEnabled is not None:
        inno_installer_args.append('/PORTREMAPPINGENABLED=' + options.portRemappingEnabled)

    try:
        run_command(options.installer, inno_installer_args, show_args=True)

        # The installer will setup two environment variables: TABLEAU_SERVER_DATA_DIR and TABLEAU_SERVER_INSTALL_DIR.
        # However, this shell session will not be able to pick them up unless the shell is restarted.
        # Here we update the current shell with those environment variables.
        os.environ["TABLEAU_SERVER_DATA_DIR"] = options.dataDir if isinstance(options.dataDir, str) else options.dataDir.encode('utf-8')
        os.environ["TABLEAU_SERVER_INSTALL_DIR"] = options.installDir if isinstance(options.installDir, str) else options.installDir.encode('utf-8')

        with open(version_file_full_path) as version_file:
            # read the version of the installer we just run
            return version_file.read().strip()

    except ExitCodeError as ex:
        if(ex.exit_code >= 1 and ex.exit_code <= 8):
            print_error(inno_setup_exit_codes[ex.exit_code])
        else:
            print_error('Unknown exit code from the Inno Setup installer: %d' % ex.exit_code)

        # print the last 5 lines from the Inno Setup log
        print_error_lines(inno_log_file_full_path)