#!/usr/bin/env bash # Run a PowerShell script (passed as $1 text, or a file with -f) on win10 through server-access, # encoded as -EncodedCommand so quoting never crosses the relay. Output is UTF-8; progress noise off. # AGENT_ACCESS_HOME = directory of the vault client (default ~/.local/share/server-access-client); # AGENT_ACCESS_CONFIG = identity URL/file. set -euo pipefail CLIENT="${AGENT_ACCESS_HOME:-$HOME/.local/share/server-access-client}/agent-access.py" CFG="${AGENT_ACCESS_CONFIG:-https://nas.tail9531b.ts.net:8443/identity/agent.json}" TIMEOUT="${WIN10_TIMEOUT:-120}" if [ "${1:-}" = "-f" ]; then SCRIPT="$(cat "$2")"; else SCRIPT="$1"; fi SCRIPT="[Console]::OutputEncoding=[Text.Encoding]::UTF8 \$ErrorActionPreference='Continue' \$ProgressPreference='SilentlyContinue' $SCRIPT" B64="$(printf '%s' "$SCRIPT" | iconv -f UTF-8 -t UTF-16LE | base64 -w0)" if [ "${#B64}" -gt 7600 ]; then echo "encoded command too long (${#B64} > 7600)" >&2; exit 2; fi exec python3 -I "$CLIENT" --config "$CFG" run --target win10 --timeout "$TIMEOUT" -- \ powershell.exe -NoProfile -NonInteractive -EncodedCommand "$B64" 2> >(grep -v -E '^#< CLIXML|^&2)