Skip to content

Commit 0d14135

Browse files
author
Derek
committed
fix: rewrite broken symlinks after home directory rename
find all symlinks under new home that reference old path and rewrite. Catches uv, gext, Claude, keyrings, and any future tools automatically.
1 parent 6b4c622 commit 0d14135

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

ansible/roles/developer/files/rename-user

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# ============================================================================
55
# Renames the default desktop user (e.g. hyperi) to a new username, updates:
66
# - Linux user account (username, group, home directory)
7+
# - Absolute symlinks in home directory (uv, gext, Claude, etc.)
78
# - Passwordless sudo configuration
89
# - GNOME keyring (reset so PAM auto-unlocks with new password)
910
# - GNOME Remote Desktop (RDP) credentials
@@ -179,13 +180,31 @@ sleep 2
179180
180181
# Rename user account and move home directory
181182
echo "Renaming user..."
182-
usermod -l "$NEW_USER" -d "/home/$NEW_USER" -m "$DEFAULT_USER"
183+
OLD_HOME="/home/${DEFAULT_USER}"
184+
NEW_HOME="/home/${NEW_USER}"
185+
usermod -l "$NEW_USER" -d "$NEW_HOME" -m "$DEFAULT_USER"
183186
echo "User renamed"
184187
185188
# Rename primary group
186189
groupmod -n "$NEW_USER" "$DEFAULT_USER" 2>/dev/null || true
187190
echo "Group renamed"
188191
192+
# Fix symlinks that still reference the old home directory
193+
# usermod -m moves the directory but doesn't rewrite absolute symlinks
194+
# inside it. Tools like uv, gext, Claude, etc. create absolute symlinks
195+
# pointing to /home/<olduser>/... which break after the move.
196+
echo "Fixing symlinks referencing old home path..."
197+
FIXED_LINKS=0
198+
while IFS= read -r -d '' link; do
199+
target=$(readlink "$link")
200+
new_target="${target/#${OLD_HOME}/${NEW_HOME}}"
201+
if [[ "$new_target" != "$target" ]]; then
202+
ln -sfn "$new_target" "$link"
203+
(( FIXED_LINKS++ ))
204+
fi
205+
done < <(find "$NEW_HOME" -type l -print0 2>/dev/null)
206+
echo "Fixed ${FIXED_LINKS} symlinks"
207+
189208
# Set new password
190209
printf '%s:%s\n' "$NEW_USER" "$NEW_PASS" | chpasswd
191210
echo "Password set"

0 commit comments

Comments
 (0)