-
Notifications
You must be signed in to change notification settings - Fork 186
/
mac_change_id.sh
49 lines (39 loc) · 1.31 KB
/
mac_change_id.sh
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
#!/bin/bash
# 配置文件路径
STORAGE_FILE="$HOME/Library/Application Support/Cursor/User/globalStorage/storage.json"
# 生成随机 ID
generate_random_id() {
openssl rand -hex 32
}
# 生成随机 UUID
generate_random_uuid() {
uuidgen | tr '[:upper:]' '[:lower:]'
}
# 生成新的 IDs
NEW_MACHINE_ID=${1:-$(generate_random_id)}
NEW_MAC_MACHINE_ID=$(generate_random_id)
NEW_DEV_DEVICE_ID=$(generate_random_uuid)
# 创建备份
backup_file() {
if [ -f "$STORAGE_FILE" ]; then
cp "$STORAGE_FILE" "${STORAGE_FILE}.backup_$(date +%Y%m%d_%H%M%S)"
echo "已创建备份文件"
fi
}
# 确保目录存在
mkdir -p "$(dirname "$STORAGE_FILE")"
# 创建备份
backup_file
# 如果文件不存在,创建新的 JSON
if [ ! -f "$STORAGE_FILE" ]; then
echo "{}" > "$STORAGE_FILE"
fi
# 更新所有遥测 ID
tmp=$(mktemp)
perl -i -pe 's/"telemetry\.machineId":\s*"[^"]*"/"telemetry.machineId": "'$NEW_MACHINE_ID'"/' "$STORAGE_FILE"
perl -i -pe 's/"telemetry\.macMachineId":\s*"[^"]*"/"telemetry.macMachineId": "'$NEW_MAC_MACHINE_ID'"/' "$STORAGE_FILE"
perl -i -pe 's/"telemetry\.devDeviceId":\s*"[^"]*"/"telemetry.devDeviceId": "'$NEW_DEV_DEVICE_ID'"/' "$STORAGE_FILE"
echo "已成功修改 ID:"
echo "machineId: $NEW_MACHINE_ID"
echo "macMachineId: $NEW_MAC_MACHINE_ID"
echo "devDeviceId: $NEW_DEV_DEVICE_ID"