Skip to content

Commit

Permalink
feat: Enhance Linux ID modifier with advanced file modification checks
Browse files Browse the repository at this point in the history
- Improved random ID generation to ensure single-line output
- Added chattr attribute removal for immutable files before modification
- Enhanced file modification reliability by handling read-only file attributes
- Implemented pre-modification checks to prevent potential configuration errors
  • Loading branch information
yuaotian committed Feb 19, 2025
1 parent e8e37b3 commit 644d663
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions scripts/run/cursor_linux_id_modifier.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ backup_config() {

# 生成随机 ID
generate_random_id() {
# 生成32字节(64个十六进制字符)的随机数
head -c 32 /dev/urandom | xxd -p
# 生成32字节(64个十六进制字符)的随机数,并确保一行输出
head -c 32 /dev/urandom | xxd -p -c 32
}

# 生成随机 UUID
Expand All @@ -176,6 +176,15 @@ modify_or_add_config() {
return 1
fi

# 检查并移除chattr只读属性(如果存在)
if lsattr "$file" 2>/dev/null | grep -q '^....i'; then
log_debug "移除文件不可变属性..."
sudo chattr -i "$file" || {
log_error "无法移除文件不可变属性"
return 1
}
fi

# 确保文件可写
chmod 644 "$file" || {
log_error "无法修改文件权限: $file"
Expand Down

0 comments on commit 644d663

Please sign in to comment.