Files
win-remote-toolkit/scripts/ssh/activate-windows.sh
2026-04-24 17:44:02 +08:00

28 lines
917 B
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -euo pipefail
HOST="${HOST:-192.168.88.108}"
USER_NAME="${USER_NAME:-Admin}"
PASS="${PASS:-P@ssw0rd!}"
HERE="$(cd "$(dirname "$0")" && pwd)"
SCRIPT="$HERE/../powershell/activate-windows.ps1"
LOG_DIR="$HERE/../../logs"
STAMP="$(date +%Y%m%d-%H%M%S)"
LOG="$LOG_DIR/activate-windows-${HOST}-${STAMP}.log"
mkdir -p "$LOG_DIR"
SSH_OPTS=(-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=10)
echo "[*] 上傳 Windows 啟用腳本到 $USER_NAME@$HOST"
sshpass -p "$PASS" scp "${SSH_OPTS[@]}" "$SCRIPT" \
"$USER_NAME@$HOST:C:/Users/$USER_NAME/activate-windows.ps1" >/dev/null
echo "[*] 執行 Windows 啟用程序log -> $LOG"
sshpass -p "$PASS" ssh "${SSH_OPTS[@]}" "$USER_NAME@$HOST" \
"powershell -NoProfile -ExecutionPolicy Bypass -File C:/Users/$USER_NAME/activate-windows.ps1" \
2>&1 | tee "$LOG"
echo ""
echo "[*] 完成。紀錄已儲存: $LOG"