dotfiles files and stuff
1#!/usr/bin/env bash
2
3# this script was pulled from somewhere on the nix forums and was used to try
4# to correct whatever issue was messing up OS updates on macbook
5
6((NEW_NIX_FIRST_BUILD_UID=301))
7
8id_available(){
9 dscl . list /Users UniqueID | grep -E '\b'$1'\b' >/dev/null
10}
11
12change_nixbld_names_and_ids(){
13 local name uid next_id
14 ((next_id=NEW_NIX_FIRST_BUILD_UID))
15 echo "Attempting to migrate nixbld users."
16 echo "Each user should change from nixbld# to _nixbld#"
17 echo "and their IDs relocated to $next_id+"
18 while read -r name uid; do
19 echo " Checking $name (uid: $uid)"
20 # iterate for a clean ID
21 while id_available "$next_id"; do
22 ((next_id++))
23 if ((next_id >= 400)); then
24 echo "We've hit UID 400 without placing all of your users :("
25 echo "You should use the commands in this script as a starting"
26 echo "point to review your UID-space and manually move the"
27 echo "remaining users (or delete them, if you don't need them)."
28 exit 1
29 fi
30 done
31
32 if [[ $name == _* ]]; then
33 echo " It looks like $name has already been renamed--skipping."
34 else
35 # first 3 are cleanup, it's OK if they aren't here
36 sudo dscl . delete /Users/$name dsAttrTypeNative:_writers_passwd &>/dev/null || true
37 sudo dscl . change /Users/$name NFSHomeDirectory "/private/var/empty 1" "/var/empty" &>/dev/null || true
38 # remove existing user from group
39 sudo dseditgroup -o edit -t user -d $name nixbld || true
40 sudo dscl . change /Users/$name UniqueID $uid $next_id
41 sudo dscl . change /Users/$name RecordName $name _$name
42 # add renamed user to group
43 sudo dseditgroup -o edit -t user -a _$name nixbld
44 echo " $name migrated to _$name (uid: $next_id)"
45 fi
46 done < <(dscl . list /Users UniqueID | grep nixbld | sort -n -k2)
47}
48
49change_nixbld_names_and_ids