mirror of
https://github.com/LnL7/nix-darwin.git
synced 2024-12-14 11:57:34 +00:00
users: prevent deleting the user calling darwin-rebuild
`sysadminctl -deleteUser` will only prevent you from deleting the current user if it's not the last admin and not the last secure token user, otherwise it will happily oblige.
This commit is contained in:
parent
d99f9ae9fd
commit
467a0d3d0c
1 changed files with 18 additions and 2 deletions
|
@ -149,6 +149,15 @@ in
|
|||
echo "setting up users..." >&2
|
||||
|
||||
deleteUser() {
|
||||
# TODO: add `darwin.primaryUser` as well
|
||||
if [[ "$1" == "$SUDO_USER" ]]; then
|
||||
printf >&2 '\e[1;31merror: refusing to delete the user calling `darwin-rebuild` (%s), aborting activation\e[0m\n', "$1"
|
||||
exit 1
|
||||
elif [[ "$1" == "root" ]]; then
|
||||
printf >&2 '\e[1;31merror: refusing to delete `root`, aborting activation\e[0m\n', "$1"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
fullDiskAccess=false
|
||||
|
||||
if cat /Library/Preferences/com.apple.TimeMachine.plist > /dev/null 2>&1; then
|
||||
|
@ -191,8 +200,15 @@ in
|
|||
${optionalString cfg.forceRecreate ''
|
||||
u=$(id -u ${name} 2> /dev/null) || true
|
||||
if [[ "$u" -eq ${toString v.uid} ]]; then
|
||||
echo "deleting user ${v.name}..." >&2
|
||||
deleteUser ${name}
|
||||
# TODO: add `darwin.primaryUser` as well
|
||||
if [[ ${name} == "$SUDO_USER" ]]; then
|
||||
printf >&2 '[1;31mwarning: not going to recreate the user calling `darwin-rebuild` (%s), skipping...[0m\n' "$SUDO_USER"
|
||||
elif [[ ${name} == "root" ]]; then
|
||||
printf >&2 '[1;31mwarning: not going to recreate root, skipping...[0m\n'
|
||||
else
|
||||
printf >&2 'deleting user ${v.name}...\n'
|
||||
deleteUser ${name}
|
||||
fi
|
||||
else
|
||||
echo "[1;31mwarning: existing user '${v.name}' has unexpected uid $u, skipping...[0m" >&2
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue