Skip to content

Commit

Permalink
Adding lwr-default-user
Browse files Browse the repository at this point in the history
  • Loading branch information
marigostra committed Jul 9, 2022
1 parent a2c4bd4 commit 5a21d0e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions ubuntu/22.04/dist/opt/luwrain-utils/lwr-default-user
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"

0 comments on commit 5a21d0e

Please sign in to comment.