autool/utils_ios/scripts/mac_setup.sh
2026-06-17 19:44:18 +08:00

65 lines
1.9 KiB
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.

#!/bin/zsh
export IOS="/Users/tpshos/yfz/code/autool/utils_ios/go_ios/bin/ios-darwin-arm64"
export UDID="00008101-0016601022C0001E"
export WDA_PORT=8100
# 存储后台进程PID
FORWARD_PID=""
TUNNEL_PID=""
WDA_PID=""
# 清理函数:停止所有进程
cleanup() {
echo "\n正在停止所有进程..."
# 停止WDA进程
if [ -n "$WDA_PID" ] && kill -0 $WDA_PID 2>/dev/null; then
echo "停止 WDA 进程 (PID: $WDA_PID)"
kill $WDA_PID 2>/dev/null
fi
# 停止端口转发进程
if [ -n "$FORWARD_PID" ] && kill -0 $FORWARD_PID 2>/dev/null; then
echo "停止端口转发进程 (PID: $FORWARD_PID)"
kill $FORWARD_PID 2>/dev/null
fi
# 停止tunnel进程
if [ -n "$TUNNEL_PID" ] && kill -0 $TUNNEL_PID 2>/dev/null; then
echo "停止 tunnel 进程 (PID: $TUNNEL_PID)"
sudo kill $TUNNEL_PID 2>/dev/null
fi
echo "所有进程已停止"
exit 0
}
# 捕获 Ctrl-C (SIGINT) 和 SIGTERM 信号
trap cleanup SIGINT SIGTERM
echo "启动服务..."
# 1. 创建tunnel - 后台运行,输出重定向到日志文件
echo "启动 tunnel..."
echo "$SUDO" | sudo -S "$IOS" tunnel start > /tmp/ios_tunnel.log 2>&1 &
TUNNEL_PID=$!
echo "Tunnel 已启动 (PID: $TUNNEL_PID, 日志: /tmp/ios_tunnel.log)"
# 2. 端口转发 - 后台运行,输出重定向到日志文件
echo "启动端口转发..."
"$IOS" forward 8100 $WDA_PORT --udid="$UDID" > /tmp/ios_forward.log 2>&1 &
FORWARD_PID=$!
echo "端口转发已启动 (PID: $FORWARD_PID, 日志: /tmp/ios_forward.log)"
# 3. 运行WDA - 前台运行
echo "启动 WDA (前台运行,按 Ctrl-C 停止所有服务)..."
cd ~/yfz/code/WebDriverAgent
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner USE_IP=127.0.0.1 USE_PORT=$WDA_PORT test-without-building -destination id="$UDID" &
WDA_PID=$!
# 等待WDA进程结束
wait $WDA_PID
# 如果WDA意外退出也清理其他进程
cleanup