| 1 | #!/usr/bin/env bash |
| 2 | # Publish the release exe to %LOCALAPPDATA%\Programs\ms-teams-linux\update\. The running app swaps itself. |
| 3 | # Usage: scripts/deploy-windows.sh [exe, default the teams.exe scripts/build-windows.sh wrote] |
| 4 | set -euo pipefail |
| 5 | targetDirectory="${CARGO_TARGET_DIR:-${XDG_CACHE_HOME:-$HOME/.cache}/rusty-teams/target}" |
| 6 | sourceExe="$(realpath "${1:-$targetDirectory/x86_64-pc-windows-msvc/release/teams.exe}")" |
| 7 | installRoot="${TEAMS_INSTALL_DIR:-}" |
| 8 | if [ -z "$installRoot" ]; then |
| 9 | localAppData="$(PATH="$PATH:/mnt/c/Windows/System32" cmd.exe /c 'echo %LOCALAPPDATA%' 2>/dev/null | tr -d '\r')" |
| 10 | installRoot="$(wslpath "$localAppData")/Programs/ms-teams-linux" |
| 11 | fi |
| 12 | version="$(grep -aoE 'teams-build:[0-9a-f]+-[0-9]{8}T[0-9]{6}Z' "$sourceExe" | head -n1 | cut -d: -f2)" |
| 13 | [ -n "$version" ] || { echo "no build version found in $sourceExe" >&2; exit 1; } |
| 14 | |
| 15 | updateDirectory="$installRoot/update" |
| 16 | mkdir -p "$updateDirectory" |
| 17 | cp "$sourceExe" "$updateDirectory/teams.exe.partial" |
| 18 | mv -f "$updateDirectory/teams.exe.partial" "$updateDirectory/teams.exe" |
| 19 | sourcePdb="${sourceExe%.exe}.pdb" |
| 20 | if [ -f "$sourcePdb" ]; then |
| 21 | cp "$sourcePdb" "$updateDirectory/teams.pdb.partial" |
| 22 | mv -f "$updateDirectory/teams.pdb.partial" "$updateDirectory/teams.pdb" |
| 23 | fi |
| 24 | printf '%s\n' "$version" > "$updateDirectory/version.txt.partial" |
| 25 | mv -f "$updateDirectory/version.txt.partial" "$updateDirectory/version.txt" |
| 26 | echo "deployed $version to $updateDirectory" |