#!/usr/bin/env bash # Upload a local text/binary file to win10: gzip+base64, appended in chunks through the relay, # then decoded remotely and verified by SHA-256. # usage: win10-put.sh set -euo pipefail HERE="$(cd "$(dirname "$0")" && pwd)" LOCAL="$1"; REMOTE="$2" TMP="$REMOTE.b64" SHA="$(sha256sum "$LOCAL" | cut -d' ' -f1)" B64="$(gzip -9c "$LOCAL" | base64 -w0)" CHUNK=2400 "$HERE/win10-ps.sh" "New-Item -ItemType Directory -Force -Path (Split-Path -Parent '$REMOTE') | Out-Null; Set-Content -Path '$TMP' -Value '' -NoNewline -Encoding Ascii; 'reset'" >/dev/null TOTAL=$(( (${#B64} + CHUNK - 1) / CHUNK )) for ((i=0; i<${#B64}; i+=CHUNK)); do PART="${B64:i:CHUNK}" n=$(( i / CHUNK + 1 )) "$HERE/win10-ps.sh" "Add-Content -Path '$TMP' -Value '$PART' -NoNewline -Encoding Ascii; 'chunk $n/$TOTAL'" | tail -1 done "$HERE/win10-ps.sh" "\$b=[Convert]::FromBase64String((Get-Content -Raw -Encoding Ascii '$TMP')) \$ms=New-Object IO.MemoryStream(,\$b) \$gz=New-Object IO.Compression.GZipStream(\$ms,[IO.Compression.CompressionMode]::Decompress) \$out=New-Object IO.MemoryStream; \$gz.CopyTo(\$out) [IO.File]::WriteAllBytes('$REMOTE',\$out.ToArray()) Remove-Item '$TMP' 'remote sha256 ' + (Get-FileHash '$REMOTE' -Algorithm SHA256).Hash.ToLower() 'expected $SHA'"