#Requires -Version 5.1 <# .SYNOPSIS Удалённый sudo на SAC-сервере без интерактивного ввода. Пароль: Password из ssh-setup/local/kalinamall-sac.conf #> [CmdletBinding()] param( [string]$HostAlias = 'sac.kalinamall.ru', [Parameter(Mandatory = $true)] [string]$RemoteCommand, [string]$PasswordFile = (Join-Path $HOME 'Projects\Answer.and.other.shit\scripts\ssh-setup\local\kalinamall-sac.conf') ) Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' function Read-ConfigFile { param([string]$Path) $data = @{} if (-not (Test-Path -LiteralPath $Path)) { throw "Config not found: $Path" } Get-Content -LiteralPath $Path | ForEach-Object { if ($_ -match '^([^#=]+)=(.*)$') { $data[$Matches[1].Trim()] = $Matches[2].Trim() } } return $data } $cfg = Read-ConfigFile -Path $PasswordFile $password = $cfg['Password'] if (-not $password) { throw "Password not found in $PasswordFile" } $inner = $RemoteCommand.Replace("'", "'\\''") $remote = "sudo -S -p '' bash -lc '$inner'" $password | & ssh -o BatchMode=yes -o ConnectTimeout=15 $HostAlias $remote