-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2c4bd4
commit 5a21d0e
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash -e | ||
# Copyright 2022 Michael Pozhidaev <[email protected]> | ||
# Changes the default user in the installed system | ||
|
||
THIS="${0##*/}" | ||
|
||
[ -z "$1" ] && echo "ERROR: THIS: No partition" >&2 && exit 1 | ||
[ -z "$2" ] && echo "ERROR: THIS: No new user name" >&2 && exit 1 | ||
|
||
PART="$1" | ||
NEW_USER="$2" | ||
|
||
exit_handler() | ||
{ | ||
local rc=$? | ||
trap - EXIT | ||
cd / | ||
umount $PART &> /dev/null ||: | ||
exit $rc | ||
} | ||
trap exit_handler EXIT HUP INT QUIT PIPE TERM | ||
|
||
mount $PART /mnt | ||
chroot /mnt usermod -l "$NEW_USER" luwrain | ||
chroot /mnt usermod -d "/home/$NEW_USER" "$NEW_USER" | ||
mv /mnt/home/luwrain "/mnt/home/$NEW_USER" | ||
echo "$NEW_USER" > /mnt/etc/luwrain/default-user | ||
cd /mnt/etc/sudoers.d | ||
sed -i -e s/luwrain/"$NEW_USER"/ luwrain | ||
mv luwrain "$NEW_USER" | ||
cd / | ||
echo "Default system user has been successfully changed to $NEW_USER" |