|
4 | 4 | # ============================================================================ |
5 | 5 | # Renames the default desktop user (e.g. hyperi) to a new username, updates: |
6 | 6 | # - Linux user account (username, group, home directory) |
| 7 | +# - Absolute symlinks in home directory (uv, gext, Claude, etc.) |
7 | 8 | # - Passwordless sudo configuration |
8 | 9 | # - GNOME keyring (reset so PAM auto-unlocks with new password) |
9 | 10 | # - GNOME Remote Desktop (RDP) credentials |
@@ -179,13 +180,31 @@ sleep 2 |
179 | 180 |
|
180 | 181 | # Rename user account and move home directory |
181 | 182 | 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" |
183 | 186 | echo "User renamed" |
184 | 187 |
|
185 | 188 | # Rename primary group |
186 | 189 | groupmod -n "$NEW_USER" "$DEFAULT_USER" 2>/dev/null || true |
187 | 190 | echo "Group renamed" |
188 | 191 |
|
| 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 | +
|
189 | 208 | # Set new password |
190 | 209 | printf '%s:%s\n' "$NEW_USER" "$NEW_PASS" | chpasswd |
191 | 210 | echo "Password set" |
|
0 commit comments