override fun install()

in src/aws/install-aws-cli/src.main.kts [238:288]


    override fun install(version: String) {
        val installDir = getInstallDir(version).also { File(it).mkdirs() }
        val isInstalled =
            ProcessUtils.runProcess(
                listOf("aws", "--version"),
                File(installDir),
                ProcessUtils.RunOptions(isSilent = true),
            )?.exitCode == 0
        if (isInstalled) {
            val isNotTeamCityTool = File(installDir).listFiles()?.isEmpty() ?: true
            if (isNotTeamCityTool) {
                println(
                    "AWS CLI is already installed on this agent, but not as a TeamCity tool. On Windows only one version " +
                            "of AWS CLI can be installed at the time, skipping installation..."
                )
                exitProcess(0)
            }
        }

        val url = "https://awscli.amazonaws.com/AWSCLIV2-$version.msi"
        val temp = prepareTempDir()

        println("Downloading AWS CLI from $url to ${temp.absolutePath}")
        val msi = downloadFile(url, temp)
        val logFile = "${temp.absolutePath}\\aws-cli-${version}-install-log.txt"
        ProcessUtils.runProcess(
            listOf(
                "msiexec.exe", "/i", "\"${msi.absolutePath}\"", "AWSCLIV2=\"$installDir\"", "/quiet", "/norestart",
                "/l*v", "\"$logFile\""
            ), temp
        ).let {
            if (it?.exitCode != 0) {
                moveMsiExecLogsToBuildLog(logFile)
                System.err.println(
                    """
                    Installation failed with exit code ${it?.exitCode}.
                    Ensure that the agent does not have AWS CLI installed in a different location and that
                    it has the necessary administrative permissions to install third party software
                    """.trimIndent()
                )
                exitProcess(it?.exitCode ?: 1)
            }
        }
        updateEnvPath(version)
        cleanUpAndLogSuccess(temp, version)
        File(logFile).let {
            if (it.exists()) {
                FileUtils.delete(it)
            }
        }
    }