param( [ValidateSet('', 'codex', 'claude', 'opencode')] [string]$App = 'codex', [string]$Model = '' ) $ErrorActionPreference = 'Stop' $gmTempDirectory = $null $gmCorePath = $null $gmExitCode = 1 try { if (-not (Get-Command node -ErrorAction SilentlyContinue)) { throw 'Node.js 22 or newer is required: https://nodejs.org/' } $gmNodeVersion = & node -p 'process.versions.node' if ($LASTEXITCODE -ne 0 -or [int]$gmNodeVersion.Split('.')[0] -lt 22) { throw 'Update Node.js to 22 or newer: https://nodejs.org/' } if (-not $App) { throw 'Choose an application: -App codex, -App claude or -App opencode.' } $gmTempDirectory = Join-Path ([IO.Path]::GetTempPath()) ('gmshop-install-' + [guid]::NewGuid().ToString('N')) $null = New-Item -ItemType Directory -Path $gmTempDirectory if ($env:OS -eq 'Windows_NT') { $gmIdentity = [Security.Principal.WindowsIdentity]::GetCurrent().User $gmAcl = New-Object Security.AccessControl.DirectorySecurity $gmAcl.SetAccessRuleProtection($true, $false) $gmRule = New-Object Security.AccessControl.FileSystemAccessRule($gmIdentity, 'FullControl', 'ContainerInherit,ObjectInherit', 'None', 'Allow') $gmAcl.AddAccessRule($gmRule) Set-Acl -LiteralPath $gmTempDirectory -AclObject $gmAcl } else { & chmod 700 $gmTempDirectory if ($LASTEXITCODE -ne 0) { throw 'Unable to protect the temporary directory.' } } [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 $gmCorePath = Join-Path $gmTempDirectory 'configure.mjs' Invoke-WebRequest -Uri 'https://download.sosihuy.ru/configure.mjs' -OutFile $gmCorePath -UseBasicParsing -MaximumRedirection 0 -TimeoutSec 60 $gmArguments = @($gmCorePath, '--app', $App) if ($Model) { $gmArguments += @('--model', $Model) } & node @gmArguments $gmExitCode = $LASTEXITCODE } catch { [Console]::Error.WriteLine('GMshopPW installer: ' + $_.Exception.Message) } finally { if ($gmCorePath -and (Test-Path -LiteralPath $gmCorePath)) { Remove-Item -LiteralPath $gmCorePath -Force } if ($gmTempDirectory -and (Test-Path -LiteralPath $gmTempDirectory)) { Remove-Item -LiteralPath $gmTempDirectory -Force } } if ($gmExitCode -ne 0) { throw "GMshopPW configuration failed (exit $gmExitCode)." }