-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-mac.sh
More file actions
executable file
·104 lines (94 loc) · 5.36 KB
/
Copy pathrun-mac.sh
File metadata and controls
executable file
·104 lines (94 loc) · 5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env bash
# Identity-graph recognition test runner — macOS.
#
# Usage:
# ./run-mac.sh # interactive
# ./run-mac.sh --dry-run # print, launch nothing
# TESTER=tuan MACHINE=mac-mini ./run-mac.sh
# CHAIN_WAIT=45 ./run-mac.sh # slower machine/network → wait longer per combo
set -u
# ── Config ────────────────────────────────────────────────────────────────────
CHAIN_HOSTS="stage.oiopdf.com,stage.oiosend.com,stage.oiolink.com" # order the chain visits
FIRST_HOST="${CHAIN_HOSTS%%,*}" # first host = entry point
PARAM="idt_test_id"
CHAIN_WAIT="${CHAIN_WAIT:-36}" # seconds to let the 3-site chain finish before the next combo
WARMUP="${WARMUP:-8}" # one-time boot wait per browser (cold start)
OS="macos"
DRY=0; [ "${1:-}" = "--dry-run" ] && DRY=1
# label|App name|binary path|private flag
BROWSERS=(
"chrome|Google Chrome|/Applications/Google Chrome.app/Contents/MacOS/Google Chrome|--incognito"
"edge|Microsoft Edge|/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge|--inprivate"
"brave|Brave Browser|/Applications/Brave Browser.app/Contents/MacOS/Brave Browser|--incognito"
"opera|Opera|/Applications/Opera.app/Contents/MacOS/Opera|--private"
"vivaldi|Vivaldi|/Applications/Vivaldi.app/Contents/MacOS/Vivaldi|--incognito"
"firefox|Firefox|/Applications/Firefox.app/Contents/MacOS/firefox|-private-window"
)
urlencode() { local s="$1" o="" c i; for ((i=0;i<${#s};i++)); do c="${s:i:1}"; case "$c" in [a-zA-Z0-9.~_-]) o+="$c";; *) o+=$(printf '%%%02X' "'$c");; esac; done; printf '%s' "$o"; }
chain_url() { # $1=identifier -> URL for the first host carrying the chain
local enc; enc=$(urlencode "$1")
printf 'https://%s/?%s=%s&idt_chain=%s&idt_step=0' "$FIRST_HOST" "$PARAM" "$enc" "$(urlencode "$CHAIN_HOSTS")"
}
# ── Inputs ──────────────────────────────────────────────────────────────────────
TESTER="${TESTER:-}"; MACHINE="${MACHINE:-}"
if [ -z "$TESTER" ]; then read -r -p "Tên tester (vd: tuan): " TESTER; fi
if [ -z "$MACHINE" ]; then
DEF=$(scutil --get ComputerName 2>/dev/null || hostname); DEF=$(echo "$DEF" | tr ' ' '-')
read -r -p "Tên máy [$DEF]: " MACHINE; MACHINE="${MACHINE:-$DEF}"
fi
[ -z "$TESTER" ] && { echo "Thiếu tên tester."; exit 1; }
# ── Detect installed browsers ────────────────────────────────────────────────────
echo "== Quét trình duyệt trên máy =="
FOUND=(); for row in "${BROWSERS[@]}"; do
IFS='|' read -r label app bin flag <<< "$row"
if [ -x "$bin" ]; then echo " ✓ $label ($app)"; FOUND+=("$row"); fi
done
[ -x "/Applications/Safari.app/Contents/MacOS/Safari" ] && { echo " ✓ safari (Safari)"; SAFARI=1; } || SAFARI=0
[ ${#FOUND[@]} -eq 0 ] && [ "$SAFARI" = 0 ] && { echo "Không tìm thấy trình duyệt nào."; exit 1; }
echo
run_combo() { # $1=label $2=app $3=bin $4=incflag $5=mode(default|annon)
local label="$1" app="$2" bin="$3" incflag="$4" mode="$5"
local id="${TESTER} - ${mode} - ${label} - ${OS} - ${MACHINE}"
local url; url=$(chain_url "$id")
echo " → $label / $mode (mở 1 tab, tự đi qua 3 site)"
if [ "$DRY" = 1 ]; then
if [ "$mode" = "annon" ]; then echo " [dry] \"$bin\" $incflag \"$url\" (+ open -a để foreground)"; else echo " [dry] open -a \"$app\" \"$url\""; fi
return
fi
if [ "$mode" = "annon" ]; then
"$bin" $incflag "$url" >/dev/null 2>&1 &
sleep 1
open -a "$app" >/dev/null 2>&1 # kéo cửa sổ private/incognito lên FOREGROUND (tránh throttle cửa sổ nền)
else
open -a "$app" "$url" >/dev/null 2>&1
fi
sleep "$CHAIN_WAIT"
}
echo "== Bắt đầu (mỗi combo mở 1 tab; trang tự đi qua 3 site) =="
for row in "${FOUND[@]}"; do
IFS='|' read -r label app bin flag <<< "$row"
if [ "$DRY" = 0 ]; then echo " (khoi dong ${label}...)"; open -a "$app" >/dev/null 2>&1; sleep "$WARMUP"; fi
run_combo "$label" "$app" "$bin" "$flag" default
run_combo "$label" "$app" "$bin" "$flag" annon
done
# Safari: default via `open`; private via AppleScript (Automation permission) — optional.
if [ "$SAFARI" = 1 ]; then
[ "$DRY" = 0 ] && { echo " (khởi động safari…)"; open -a Safari >/dev/null 2>&1; sleep "$WARMUP"; }
url_def=$(chain_url "${TESTER} - default - safari - ${OS} - ${MACHINE}")
echo " → safari / default (mở 1 tab, tự đi qua 3 site)"
[ "$DRY" = 1 ] && echo " [dry] open -a Safari \"$url_def\"" || { open -a Safari "$url_def"; sleep "$CHAIN_WAIT"; }
url_pri=$(chain_url "${TESTER} - annon - safari - ${OS} - ${MACHINE}")
echo " → safari / private (AppleScript — cần quyền Automation lần đầu)"
if [ "$DRY" = 1 ]; then echo " [dry] osascript Safari private -> $url_pri"; else
osascript >/dev/null 2>&1 <<OSA
tell application "Safari" to activate
tell application "System Events" to tell process "Safari"
keystroke "n" using {shift down, command down}
end tell
delay 1
tell application "Safari" to set URL of front document to "$url_pri"
OSA
sleep "$CHAIN_WAIT"
fi
fi
echo "== Xong. Đóng các cửa sổ khi hoàn tất. =="