[Console]::OutputEncoding = [Text.Encoding]::UTF8 $ErrorActionPreference = "Stop" Set-ExecutionPolicy -Scope Process Bypass -Force Import-Module Posh-SSH $sec = ConvertTo-SecureString "0" -AsPlainText -Force $cred = New-Object PSCredential("tonycao", $sec) $s = New-SSHSession -ComputerName 192.168.58.7 -Credential $cred -AcceptKey -ConnectionTimeout 15 if (-not $s) { throw "SSH connect failed" } $src = "C:\Users\tonycao\work\light\enet-validator\src\tests.rs" $b64 = [Convert]::ToBase64String([IO.File]::ReadAllBytes($src)) $chunkSize = 6000 $chunks = [Math]::Ceiling($b64.Length / $chunkSize) $r = Invoke-SSHCommand -SSHSession $s -Command "rm -f /tmp/up.b64 && touch /tmp/up.b64" for ($i = 0; $i -lt $chunks; $i++) { $part = $b64.Substring($i * $chunkSize, [Math]::Min($chunkSize, $b64.Length - $i * $chunkSize)) $r = Invoke-SSHCommand -SSHSession $s -Command "echo '$part' >> /tmp/up.b64" } $r = Invoke-SSHCommand -SSHSession $s -Command "base64 -d /tmp/up.b64 > ~/enet-validator/src/tests.rs && md5sum ~/enet-validator/src/tests.rs" $localMd5 = (Get-FileHash $src -Algorithm MD5).Hash.ToLower() $remoteMd5 = ($r.Output -join "").Split(" ")[0] Write-Host ("tests.rs sync: {0} ({1})" -f $(if ($localMd5 -eq $remoteMd5) { "OK" } else { "MISMATCH!" }), $localMd5) Write-Host "--- build on .7 ---" $r = Invoke-SSHCommand -SSHSession $s -Command "cd ~/enet-validator && ~/.cargo/bin/cargo build --release 2>&1 | tail -2" -TimeOut 300 Write-Host ($r.Output -join "`n") Write-Host "--- restart butler ---" $r = Invoke-SSHCommand -SSHSession $s -Command "bash ~/run_butler.sh device 2>&1 | tail -3; sleep 2; pgrep -af 'enet-validator device' | head -2" Write-Host ($r.Output -join "`n") Remove-SSHSession $s | Out-Null