From 13f13161c24bbeca739faad301b8e06633d72a11 Mon Sep 17 00:00:00 2001 From: hayao Date: Sat, 18 Apr 2020 11:57:45 +0900 Subject: [PATCH] [update] : Enhanced user creation at rebuild. --- channels/share/airootfs/root/customize_airootfs.sh | 87 ++++++++++++---------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/channels/share/airootfs/root/customize_airootfs.sh b/channels/share/airootfs/root/customize_airootfs.sh index 3434d41a..effcf14c 100755 --- a/channels/share/airootfs/root/customize_airootfs.sh +++ b/channels/share/airootfs/root/customize_airootfs.sh @@ -93,54 +93,63 @@ fi sed -i s/%OS_NAME%/"${os_name}"/g /etc/skel/Desktop/calamares.desktop -# If rebuild is enabled, do not create users. -# This is described in detail on ArchWiki. -if [[ ${rebuild} = false ]]; then - # Creating a root user. - # usermod -s /usr/bin/zsh root +# Creating a root user. +# usermod -s /usr/bin/zsh root +function user_check () { +if [[ $(getent passwd $1 > /dev/null ; printf $?) = 0 ]]; then + if [[ -z $1 ]]; then + echo -n "false" + fi + echo -n "true" +else + echo -n "false" +fi +} +if [[ $(user_check root) = false ]]; then usermod -s "${usershell}" root cp -aT /etc/skel/ /root/ chmod 700 /root - LC_ALL=C xdg-user-dirs-update - LANG=C xdg-user-dirs-update - echo -e "${password}\n${password}" | passwd root - - # Allow sudo group to run sudo - sed -i 's/^#\s*\(%sudo\s\+ALL=(ALL)\s\+ALL\)/\1/' /etc/sudoers - - # Create alter user. - # create_user - function create_user () { - local _password - local _username - - _username=${1} - _password=${2} - - set +u - if [[ -z "${_username}" ]]; then - echo "User name is not specified." >&2 - return 1 - fi - if [[ -z "${_password}" ]]; then - echo "No password has been specified." >&2 - return 1 - fi - set -u - + LC_ALL=C LANG=C xdg-user-dirs-update +fi +echo -e "${password}\n${password}" | passwd root + +# Allow sudo group to run sudo +sed -i 's/^#\s*\(%sudo\s\+ALL=(ALL)\s\+ALL\)/\1/' /etc/sudoers + +# Create a user. +# create_user +function create_user () { + local _password + local _username + + _username=${1} + _password=${2} + + set +u + if [[ -z "${_username}" ]]; then + echo "User name is not specified." >&2 + return 1 + fi + if [[ -z "${_password}" ]]; then + echo "No password has been specified." >&2 + return 1 + fi + set -u + + if [[ $(user_check ${_username}) = false ]]; then useradd -m -s ${usershell} ${_username} groupadd sudo usermod -U -g ${_username} -G sudo ${_username} cp -aT /etc/skel/ /home/${_username}/ - chmod 700 -R /home/${_username} - chown ${_username}:${_username} -R /home/${_username} - echo -e "${_password}\n${_password}" | passwd ${_username} - set -u - } + fi + chmod 700 -R /home/${_username} + chown ${_username}:${_username} -R /home/${_username} + echo -e "${_password}\n${_password}" | passwd ${_username} + set -u +} - create_user "${username}" "${password}" -fi +create_user "${username}" "${password}" # Set up auto login -- 2.11.0