$ErrorActionPreference = "Stop" $Repository = if ($env:OCI_PLATFORM_REPOSITORY) { $env:OCI_PLATFORM_REPOSITORY } else { "https://github.com/mudassir-93/OCI-Always-Free-VM.git" } $InstallBranch = if ($env:OCI_PLATFORM_BRANCH) { $env:OCI_PLATFORM_BRANCH } else { "main" } $InstallDir = if ($env:OCI_PLATFORM_HOME) { $env:OCI_PLATFORM_HOME } else { Join-Path $HOME "oci-automation-platform" } $InstallDir = [System.IO.Path]::GetFullPath($InstallDir) Write-Host "OCI Automation Platform installer" Write-Host "This installs local CLI files only. It does not contact your OCI tenancy or create cloud resources." if (-not (Get-Command git -ErrorAction SilentlyContinue)) { throw "Git is required. Install Git for Windows, reopen PowerShell, and run this installer again." } $Python = $null $PythonArgs = @() $PythonCommand = Get-Command py -ErrorAction SilentlyContinue if ($PythonCommand) { foreach ($Version in @("3.12", "3.11", "3")) { & py "-$Version" --version *> $null if ($LASTEXITCODE -eq 0) { $Python = "py" $PythonArgs = @("-$Version") break } } } if (-not $Python) { $Python = "python" $PythonArgs = @() } $VersionText = & $Python @PythonArgs --version 2>&1 if ($LASTEXITCODE -ne 0) { throw "Python 3.11 or newer is required." } if ($VersionText -notmatch "Python 3\.(\d+)") { throw "Could not determine Python version: $VersionText" } if ([int]$Matches[1] -lt 11) { throw "Python 3.11 or newer is required. Found: $VersionText" } Write-Host "Using $VersionText" if (Test-Path -LiteralPath $InstallDir) { throw "Install directory already exists: $InstallDir. The installer will not overwrite or update existing files. Choose another OCI_PLATFORM_HOME or move the directory after backing it up." } $InstallDirCreated = $false try { $Parent = Split-Path -Parent $InstallDir New-Item -ItemType Directory -Force -Path $Parent | Out-Null # Reserve the destination atomically. Only remove this directory if this # installer created it and a later step fails. New-Item -ItemType Directory -Path $InstallDir -ErrorAction Stop | Out-Null $InstallDirCreated = $true git clone --depth 1 --branch $InstallBranch $Repository $InstallDir if ($LASTEXITCODE -ne 0) { throw "Git clone failed." } $VenvPath = Join-Path $InstallDir ".venv" & $Python @PythonArgs -m venv $VenvPath if ($LASTEXITCODE -ne 0) { throw "Virtual environment creation failed." } $VenvPython = Join-Path $VenvPath "Scripts\python.exe" & $VenvPython -m pip install --upgrade pip if ($LASTEXITCODE -ne 0) { throw "pip upgrade failed." } & $VenvPython -m pip install -e $InstallDir if ($LASTEXITCODE -ne 0) { throw "CLI installation failed." } $Cli = Join-Path $VenvPath "Scripts\oci-platform.exe" & $Cli setup if ($LASTEXITCODE -ne 0) { throw "Initial local configuration setup failed." } } catch { if ($InstallDirCreated -and (Test-Path -LiteralPath $InstallDir)) { Remove-Item -LiteralPath $InstallDir -Recurse -Force -ErrorAction SilentlyContinue Write-Warning "Installation failed. Removed the incomplete installation directory: $InstallDir" } throw } Write-Host "" Write-Host "Installation complete: $InstallDir" Write-Host "Next steps:" Write-Host " 1. Run: $Cli configure" Write-Host " 2. Run: $Cli doctor" Write-Host " 3. Run: $Cli vm audit" Write-Host "VM creation remains disabled. The installer never enables it."