mirror of
https://gitlab.archlinux.org/tpowa/archboot.git
synced 2024-09-19 19:40:37 +02:00
add basic usermanagement
This commit is contained in:
parent
ca632aa712
commit
f8b5c55256
2 changed files with 69 additions and 10 deletions
|
@ -162,22 +162,22 @@ _configure_system() {
|
|||
_DEFAULT=""
|
||||
fi
|
||||
#shellcheck disable=SC2086
|
||||
_dialog --title " System Configuration " --no-cancel ${_DEFAULT} --menu "" 19 60 13 \
|
||||
"/etc/hostname" "System Hostname" \
|
||||
_dialog --title " System Configuration " --no-cancel ${_DEFAULT} --menu "" 20 60 14 \
|
||||
"Basic User Configuration" "User Management" \
|
||||
"/etc/vconsole.conf" "Virtual Console" \
|
||||
"/etc/locale.conf" "Locale Setting" \
|
||||
"/etc/locale.gen" "Glibc Locales" \
|
||||
"/etc/fstab" "Filesystem Mountpoints" \
|
||||
"/etc/mkinitcpio.conf" "Initramfs Config" \
|
||||
"/etc/modprobe.d/modprobe.conf" "Kernel Modules" \
|
||||
"/etc/hostname" "System Hostname" \
|
||||
"/etc/resolv.conf" "DNS Servers" \
|
||||
"/etc/hosts" "Network Hosts" \
|
||||
"/etc/locale.gen" "Glibc Locales" \
|
||||
"/etc/pacman.d/mirrorlist" "Pacman Mirrors" \
|
||||
"/etc/pacman.conf" "Pacman Config" \
|
||||
"Root-Password" "Set Root Password" \
|
||||
"Return" "Return To Main Menu" 2>"${_ANSWER}" || break
|
||||
"Back to Main Menu" "Return" 2>"${_ANSWER}" || break
|
||||
_FILE="$(cat "${_ANSWER}")"
|
||||
if [[ "${_FILE}" = "Return" || -z "${_FILE}" ]]; then
|
||||
if [[ "${_FILE}" = "Back to Main Menu" || -z "${_FILE}" ]]; then
|
||||
_S_CONFIG=1
|
||||
break
|
||||
elif [[ "${_FILE}" = "/etc/mkinitcpio.conf" ]]; then
|
||||
|
@ -186,7 +186,8 @@ _configure_system() {
|
|||
_auto_set_locale
|
||||
${_EDITOR} "${_DESTDIR}""${_FILE}"
|
||||
_run_locale_gen
|
||||
elif [[ "${_FILE}" = "Root-Password" ]]; then
|
||||
elif [[ "${_FILE}" = "Basic User Configuration" ]]; then
|
||||
_user_management
|
||||
_set_password
|
||||
else
|
||||
${_EDITOR} "${_DESTDIR}""${_FILE}"
|
||||
|
|
|
@ -71,11 +71,11 @@ _set_password() {
|
|||
_PASS2=""
|
||||
while [[ -z "${_PASSWORD}" ]]; do
|
||||
while [[ -z "${_PASS}" ]]; do
|
||||
_dialog --title " New Root Password " --insecure --passwordbox "" 7 50 2>"${_ANSWER}" || return 1
|
||||
_dialog --title " New ${1} Password " --insecure --passwordbox "" 7 50 2>"${_ANSWER}" || return 1
|
||||
_PASS=$(cat "${_ANSWER}")
|
||||
done
|
||||
while [[ -z "${_PASS2}" ]]; do
|
||||
_dialog --title " Retype Root Password " --insecure --passwordbox "" 7 50 2>"${_ANSWER}" || return 1
|
||||
_dialog --title " Retype ${1} Password " --insecure --passwordbox "" 7 50 2>"${_ANSWER}" || return 1
|
||||
_PASS2=$(cat "${_ANSWER}")
|
||||
done
|
||||
if [[ "${_PASS}" == "${_PASS2}" ]]; then
|
||||
|
@ -91,7 +91,65 @@ _set_password() {
|
|||
_PASS2=""
|
||||
fi
|
||||
done
|
||||
chroot "${_DESTDIR}" passwd root < /tmp/.password &>"${_NO_LOG}"
|
||||
chroot "${_DESTDIR}" passwd ${2} < /tmp/.password &>"${_NO_LOG}"
|
||||
rm /tmp/.password
|
||||
}
|
||||
|
||||
_user_management() {
|
||||
_dialog --title " User Management " --no-cancel ${_DEFAULT} --menu "" 14 40 8 \
|
||||
"1" "Set Root Password" \
|
||||
"2" "Set Default Shell" \
|
||||
"3" "Add User" \
|
||||
"4" "Back to System Configuration" 2>"${_ANSWER}" || break
|
||||
_FILE="$(cat "${_ANSWER}")"
|
||||
if [[ "${_FILE}" = "1" ]]; then
|
||||
_set_password Root root
|
||||
elif [[ "${_FILE}" = "2" ]]; then
|
||||
_dialog --title " Default Shell " --no-cancel --menu "" 8 45 2 \
|
||||
"BASH" "Standard Shell" \
|
||||
"ZSH" "More features for experts" 2>"${_ANSWER}" || return 1
|
||||
case $(cat "${_ANSWER}") in
|
||||
"BASH") _SHELL="bash"
|
||||
if ! [[ -f "${_DESTDIR}/usr/share/bash-completion/completions/arch" ]]; then
|
||||
_PACKAGES="bash-completion"
|
||||
_run_pacman | _dialog --title " Logging to ${_VC} | ${_LOG} " --gauge "Installing package(s):\n${_PACKAGES}..." 7 75 0
|
||||
_pacman_error
|
||||
fi
|
||||
;;
|
||||
"ZSH") _SHELL="zsh"
|
||||
if ! [[ -f "${_DESTDIR}/usr/bin/zsh" ]]; then
|
||||
_PACKAGES="grml-zsh-config"
|
||||
_run_pacman | _dialog --title " Logging to ${_VC} | ${_LOG} " --gauge "Installing package(s):\n${_PACKAGES}..." 7 75 0
|
||||
_pacman_error
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
if chroot "${_DESTDIR}" chsh -l | grep -q "/usr/bin/${_SHELL}"; then
|
||||
# change root shell
|
||||
chroot "${_DESTDIR}" chsh -s "/usr/bin/${_SHELL}" root
|
||||
# change default shell
|
||||
sed -i -e "s#^SHELL=.*#SHELL=/usr/bin/${_SHELL}#g" "${_DESTDIR}"/etc/default/useradd
|
||||
fi
|
||||
elif [[ "${_FILE}" = "3" ]]; then
|
||||
_USER=""
|
||||
while [[ -z "${_USER}" ]]; do
|
||||
_dialog --title " Setup User " --no-cancel --inputbox "Enter Username" 8 65 "" 2>"${_ANSWER}" || return 1
|
||||
_USER=$(cat "${_ANSWER}")
|
||||
if grep -q "^${_USER}:" ${_DESTDIR}/etc/passwd; then
|
||||
_dialog --title " ERROR " --no-mouse --infobox "Username already exists! Choose an other one." 3 65
|
||||
sleep 3
|
||||
_USER=""
|
||||
fi
|
||||
done
|
||||
_FN=""
|
||||
while [[ -z "${_FN}" ]]; do
|
||||
_dialog --title " Setup ${_USER} " --no-cancel --inputbox "Enter a comment eg. your Full Name" 8 65 "" 2>"${_ANSWER}" || return 1
|
||||
_FN=$(cat "${_ANSWER}")
|
||||
done
|
||||
chroot "${_DESTDIR}" useradd -c "${_FN}" -m "${_USER}"
|
||||
_set_password User ${_USER}
|
||||
elif [[ "${_FILE}" = "4" ]]; then
|
||||
break
|
||||
fi
|
||||
}
|
||||
# vim: set ft=sh ts=4 sw=4 et:
|
||||
|
|
Loading…
Reference in a new issue