Skip to content

Commit 2cfd7e6

Browse files
committed
Add auto-update disabling feature to Cursor ID modifier scripts
- Implemented `disable_auto_update()` function for Linux, macOS, and Windows scripts - Added interactive prompt to allow users to disable Cursor's automatic updates - Included comprehensive manual guide for users if automatic disabling fails - Enhanced error handling and validation for update disabling process - Provided clear instructions and fallback methods across different platforms
1 parent 09a95b9 commit 2cfd7e6

File tree

3 files changed

+242
-21
lines changed

3 files changed

+242
-21
lines changed

scripts/run/cursor_linux_id_modifier.sh

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,87 @@ show_follow_info() {
243243
echo
244244
}
245245

246+
# 修改 disable_auto_update 函数,在失败处理时添加手动教程
247+
disable_auto_update() {
248+
echo
249+
log_warn "是否要禁用 Cursor 自动更新功能?"
250+
echo "0) 否 - 保持默认设置 (按回车键)"
251+
echo "1) 是 - 禁用自动更新"
252+
read -r choice
253+
254+
if [ "$choice" = "1" ]; then
255+
echo
256+
log_info "正在处理自动更新..."
257+
local updater_path="$HOME/.config/cursor-updater"
258+
259+
# 定义手动设置教程
260+
show_manual_guide() {
261+
echo
262+
log_warn "自动设置失败,请尝试手动操作:"
263+
echo -e "${YELLOW}手动禁用更新步骤:${NC}"
264+
echo "1. 打开终端"
265+
echo "2. 复制粘贴以下命令:"
266+
echo -e "${BLUE}rm -rf \"$updater_path\" && touch \"$updater_path\" && chmod 444 \"$updater_path\"${NC}"
267+
echo
268+
echo -e "${YELLOW}如果上述命令提示权限不足,请使用 sudo:${NC}"
269+
echo -e "${BLUE}sudo rm -rf \"$updater_path\" && sudo touch \"$updater_path\" && sudo chmod 444 \"$updater_path\"${NC}"
270+
echo
271+
echo -e "${YELLOW}如果要添加额外保护(推荐),请执行:${NC}"
272+
echo -e "${BLUE}sudo chattr +i \"$updater_path\"${NC}"
273+
echo
274+
echo -e "${YELLOW}验证方法:${NC}"
275+
echo "1. 运行命令:ls -l \"$updater_path\""
276+
echo "2. 确认文件权限为 r--r--r--"
277+
echo "3. 运行命令:lsattr \"$updater_path\""
278+
echo "4. 确认有 'i' 属性(如果执行了 chattr 命令)"
279+
echo
280+
log_warn "完成后请重启 Cursor"
281+
}
282+
283+
if [ -d "$updater_path" ]; then
284+
rm -rf "$updater_path" 2>/dev/null || {
285+
log_error "删除 cursor-updater 目录失败"
286+
show_manual_guide
287+
return 1
288+
}
289+
log_info "成功删除 cursor-updater 目录"
290+
fi
291+
292+
touch "$updater_path" 2>/dev/null || {
293+
log_error "创建阻止文件失败"
294+
show_manual_guide
295+
return 1
296+
}
297+
298+
chmod 444 "$updater_path" 2>/dev/null && \
299+
chown "$CURRENT_USER:$CURRENT_USER" "$updater_path" 2>/dev/null || {
300+
log_error "设置文件权限失败"
301+
show_manual_guide
302+
return 1
303+
}
304+
305+
# 尝试设置不可修改属性
306+
if command -v chattr &> /dev/null; then
307+
chattr +i "$updater_path" 2>/dev/null || {
308+
log_warn "chattr 设置失败"
309+
show_manual_guide
310+
return 1
311+
}
312+
fi
313+
314+
# 验证设置是否成功
315+
if [ ! -f "$updater_path" ] || [ -w "$updater_path" ]; then
316+
log_error "验证失败:文件权限设置可能未生效"
317+
show_manual_guide
318+
return 1
319+
}
320+
321+
log_info "成功禁用自动更新"
322+
else
323+
log_info "保持默认设置,不进行更改"
324+
fi
325+
}
326+
246327
# 主函数
247328
main() {
248329
clear
@@ -273,7 +354,8 @@ main() {
273354
show_follow_info
274355
show_file_tree
275356
log_info "请重启 Cursor 以应用新的配置"
276-
echo
357+
358+
disable_auto_update
277359
}
278360

279361
# 执行主函数

scripts/run/cursor_mac_id_modifier.sh

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,77 @@ main() {
246246
show_file_tree
247247
show_follow_info
248248
log_info "请重启 Cursor 以应用新的配置"
249-
echo
249+
250+
# 询问是否要禁用自动更新
251+
disable_auto_update
250252
}
251253

252254
# 执行主函数
253255
main
256+
257+
# 询问是否要禁用自动更新
258+
disable_auto_update() {
259+
echo
260+
log_warn "是否要禁用 Cursor 自动更新功能?"
261+
echo "0) 否 - 保持默认设置 (按回车键)"
262+
echo "1) 是 - 禁用自动更新"
263+
read -r choice
264+
265+
if [ "$choice" = "1" ]; then
266+
echo
267+
log_info "正在处理自动更新..."
268+
local updater_path="$HOME/Library/Application Support/cursor-updater"
269+
270+
# 定义手动设置教程
271+
show_manual_guide() {
272+
echo
273+
log_warn "自动设置失败,请尝试手动操作:"
274+
echo -e "${YELLOW}手动禁用更新步骤:${NC}"
275+
echo "1. 打开终端(Terminal)"
276+
echo "2. 复制粘贴以下命令:"
277+
echo -e "${BLUE}rm -rf \"$updater_path\" && touch \"$updater_path\" && chmod 444 \"$updater_path\"${NC}"
278+
echo
279+
echo -e "${YELLOW}如果上述命令提示权限不足,请使用 sudo:${NC}"
280+
echo -e "${BLUE}sudo rm -rf \"$updater_path\" && sudo touch \"$updater_path\" && sudo chmod 444 \"$updater_path\"${NC}"
281+
echo
282+
echo -e "${YELLOW}验证方法:${NC}"
283+
echo "1. 运行命令:ls -l \"$updater_path\""
284+
echo "2. 确认文件权限为 r--r--r--"
285+
echo
286+
log_warn "完成后请重启 Cursor"
287+
}
288+
289+
if [ -d "$updater_path" ]; then
290+
rm -rf "$updater_path" 2>/dev/null || {
291+
log_error "删除 cursor-updater 目录失败"
292+
show_manual_guide
293+
return 1
294+
}
295+
log_info "成功删除 cursor-updater 目录"
296+
fi
297+
298+
touch "$updater_path" 2>/dev/null || {
299+
log_error "创建阻止文件失败"
300+
show_manual_guide
301+
return 1
302+
}
303+
304+
chmod 444 "$updater_path" 2>/dev/null && \
305+
chown "$CURRENT_USER" "$updater_path" 2>/dev/null || {
306+
log_error "设置文件权限失败"
307+
show_manual_guide
308+
return 1
309+
}
310+
311+
# 验证设置是否成功
312+
if [ ! -f "$updater_path" ] || [ -w "$updater_path" ]; then
313+
log_error "验证失败:文件权限设置可能未生效"
314+
show_manual_guide
315+
return 1
316+
}
317+
318+
log_info "成功禁用自动更新"
319+
else
320+
log_info "保持默认设置,不进行更改"
321+
fi
322+
}

scripts/run/cursor_win_id_modifier.ps1

Lines changed: 89 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -306,41 +306,111 @@ Write-Host ""
306306
Write-Host "$YELLOW[询问]$NC 是否要禁用 Cursor 自动更新功能?"
307307
Write-Host "0) 否 - 保持默认设置 (按回车键)"
308308
Write-Host "1) 是 - 禁用自动更新"
309-
$choice = Read-Host "请输入选项 (1)"
309+
$choice = Read-Host "请输入选项 (0)"
310310

311311
if ($choice -eq "1") {
312312
Write-Host ""
313313
Write-Host "$GREEN[信息]$NC 正在处理自动更新..."
314314
$updaterPath = "$env:LOCALAPPDATA\cursor-updater"
315315

316-
if (Test-Path $updaterPath) {
316+
# 定义手动设置教程
317+
function Show-ManualGuide {
318+
Write-Host ""
319+
Write-Host "$YELLOW[警告]$NC 自动设置失败,请尝试手动操作:"
320+
Write-Host "$YELLOW手动禁用更新步骤$NC"
321+
Write-Host "1. 以管理员身份打开 PowerShell"
322+
Write-Host "2. 复制粘贴以下命令:"
323+
Write-Host "$BLUE命令1 - 删除现有目录(如果存在):$NC"
324+
Write-Host "Remove-Item -Path `"$updaterPath`" -Force -Recurse -ErrorAction SilentlyContinue"
325+
Write-Host ""
326+
Write-Host "$BLUE命令2 - 创建阻止文件:$NC"
327+
Write-Host "New-Item -Path `"$updaterPath`" -ItemType File -Force | Out-Null"
328+
Write-Host ""
329+
Write-Host "$BLUE命令3 - 设置只读属性:$NC"
330+
Write-Host "Set-ItemProperty -Path `"$updaterPath`" -Name IsReadOnly -Value `$true"
331+
Write-Host ""
332+
Write-Host "$BLUE命令4 - 设置权限(可选):$NC"
333+
Write-Host "icacls `"$updaterPath`" /inheritance:r /grant:r `"`$($env:USERNAME):(R)`""
334+
Write-Host ""
335+
Write-Host "$YELLOW验证方法$NC"
336+
Write-Host "1. 运行命令:Get-ItemProperty `"$updaterPath`""
337+
Write-Host "2. 确认 IsReadOnly 属性为 True"
338+
Write-Host "3. 运行命令:icacls `"$updaterPath`""
339+
Write-Host "4. 确认只有读取权限"
340+
Write-Host ""
341+
Write-Host "$YELLOW[提示]$NC 完成后请重启 Cursor"
342+
}
343+
344+
try {
345+
# 删除现有目录
346+
if (Test-Path $updaterPath) {
347+
try {
348+
Remove-Item -Path $updaterPath -Force -Recurse -ErrorAction Stop
349+
Write-Host "$GREEN[信息]$NC 成功删除 cursor-updater 目录"
350+
}
351+
catch {
352+
Write-Host "$RED[错误]$NC 删除 cursor-updater 目录失败"
353+
Show-ManualGuide
354+
return
355+
}
356+
}
357+
358+
# 创建阻止文件
317359
try {
318-
# 强制删除目录
319-
Remove-Item -Path $updaterPath -Force -Recurse -ErrorAction Stop
320-
Write-Host "$GREEN[信息]$NC 成功删除 cursor-updater 目录"
321-
322-
# 创建同名文件
323-
New-Item -Path $updaterPath -ItemType File -Force | Out-Null
360+
New-Item -Path $updaterPath -ItemType File -Force -ErrorAction Stop | Out-Null
324361
Write-Host "$GREEN[信息]$NC 成功创建阻止文件"
325362
}
326363
catch {
327-
Write-Host "$RED[错误]$NC 处理 cursor-updater 时出错: $_"
364+
Write-Host "$RED[错误]$NC 创建阻止文件失败"
365+
Show-ManualGuide
366+
return
367+
}
368+
369+
# 设置文件权限
370+
try {
371+
# 设置只读属性
372+
Set-ItemProperty -Path $updaterPath -Name IsReadOnly -Value $true -ErrorAction Stop
373+
374+
# 使用 icacls 设置权限
375+
$result = Start-Process "icacls.exe" -ArgumentList "`"$updaterPath`" /inheritance:r /grant:r `"$($env:USERNAME):(R)`"" -Wait -NoNewWindow -PassThru
376+
if ($result.ExitCode -ne 0) {
377+
throw "icacls 命令失败"
378+
}
379+
380+
Write-Host "$GREEN[信息]$NC 成功设置文件权限"
328381
}
382+
catch {
383+
Write-Host "$RED[错误]$NC 设置文件权限失败"
384+
Show-ManualGuide
385+
return
386+
}
387+
388+
# 验证设置
389+
try {
390+
$fileInfo = Get-ItemProperty $updaterPath
391+
if (-not $fileInfo.IsReadOnly) {
392+
Write-Host "$RED[错误]$NC 验证失败:文件权限设置可能未生效"
393+
Show-ManualGuide
394+
return
395+
}
396+
}
397+
catch {
398+
Write-Host "$RED[错误]$NC 验证设置失败"
399+
Show-ManualGuide
400+
return
401+
}
402+
403+
Write-Host "$GREEN[信息]$NC 成功禁用自动更新"
329404
}
330-
else {
331-
# 直接创建阻止文件
332-
New-Item -Path $updaterPath -ItemType File -Force | Out-Null
333-
Write-Host "$GREEN[信息]$NC 成功创建阻止文件"
405+
catch {
406+
Write-Host "$RED[错误]$NC 发生未知错误: $_"
407+
Show-ManualGuide
334408
}
335409
}
336-
elseif ($choice -ne "") {
337-
Write-Host "$YELLOW[信息]$NC 保持默认设置,不进行更改"
338-
}
339410
else {
340-
Write-Host "$YELLOW[信息]$NC 保持默认设置,不进行更改"
411+
Write-Host "$GREEN[信息]$NC 保持默认设置,不进行更改"
341412
}
342413

343-
344-
414+
Write-Host ""
345415
Read-Host "按回车键退出"
346416
exit 0

0 commit comments

Comments
 (0)