This repository has been archived on 2024-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/os/linux/arch/provision.d/00-AS_ROOT-add-user.bash

32 lines
800 B
Bash
Raw Permalink Normal View History

2023-04-13 14:04:29 -05:00
#!/usr/bin/env -S bash -i
u=daniel
ud="/home/$u"
2023-04-13 14:04:29 -05:00
if [[ "$EUID" -ne 0 ]]; then
echo "Error: This script must be run as root."
exit 1
fi
# user exists - we will assume setup has already run
2023-04-13 14:04:29 -05:00
if grep -E "^$u" /etc/passwd; then
echo "User '$u' already exists. Assuming user has been setup already."
exit 0
fi
2023-04-16 02:44:50 -05:00
# TODO: setup dotfiles repo?
# TODO: can we copy the envs from /root/.config/lytedev-env in case being setup
# from a script entirely?
2023-04-13 14:04:29 -05:00
pacman -Sy --needed --noconfirm sudo
echo '%admin ALL=(ALL) ALL' >> /etc/sudoers.d/admin-group-sudoers
groupadd admin 2>/dev/null
mkdir --parents "$ud/.home" "$ud/dl"
useradd --home-dir "$ud/.home" \
--groups "admin,users,uucp,lock" \
2023-04-16 02:44:50 -05:00
--shell "/usr/bin/fish" \
"$u"
chown --recursive "$u:$u" "$ud"
echo "Setting password for user '$u'"
passwd "$u"