From a077e4d15d982010496157efe48da6ba86e7a6d7 Mon Sep 17 00:00:00 2001 From: CodeChenL <2540735020@qq.com> Date: Wed, 17 Jul 2024 18:07:44 +0800 Subject: [PATCH 1/3] fix: add --all options for available_targets check --- src/usr/lib/rsetup/tui/system/system.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/lib/rsetup/tui/system/system.sh b/src/usr/lib/rsetup/tui/system/system.sh index ddf93e6c..5637fe55 100644 --- a/src/usr/lib/rsetup/tui/system/system.sh +++ b/src/usr/lib/rsetup/tui/system/system.sh @@ -171,7 +171,7 @@ __system_set_target(){ for i in "${available_targets[@]}" do - if [[ -z "$(systemctl list-units --no-legend "$i")" ]] + if [[ -z "$(systemctl list-units --all --no-legend "$i")" ]] then continue elif [[ "$i" == "$current_target" ]] From 1f4f106325e317f58ccacb59227ee6b2b65ad5cc Mon Sep 17 00:00:00 2001 From: CodeChenL <2540735020@qq.com> Date: Wed, 17 Jul 2024 18:09:13 +0800 Subject: [PATCH 2/3] feat: cli: add some autologin functions --- src/usr/lib/rsetup/cli/system.sh | 139 +++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) diff --git a/src/usr/lib/rsetup/cli/system.sh b/src/usr/lib/rsetup/cli/system.sh index 88c6a205..a15bb49b 100644 --- a/src/usr/lib/rsetup/cli/system.sh +++ b/src/usr/lib/rsetup/cli/system.sh @@ -177,3 +177,142 @@ set_led_netdev() { echo "1" > "$node/rx" done } + +set_getty_autologin() { + local user="$1" switch="$2" service="$3" + local config_dir="/etc/systemd/system/$service.d" + + if [[ "$switch" == "ON" ]]; then + mkdir -p "$config_dir" + local cmd + if grep -q "serial" <<< "$service"; then + cmd="-/sbin/agetty -o '-p -f -- \\\\u' --autologin $user --noclear --keep-baud 1500000,115200,57600,38400,9600 %I \$TERM" + else + cmd="-/sbin/agetty -o '-p -f -- \\\\u' --autologin $user --noclear %I \$TERM" + fi + cat << EOF | tee "$config_dir/50-rsetup-autologin.conf" >/dev/null +# Auto generated by rsetup +# DO NOT MODIFY! +[Service] +ExecStart= +ExecStart=$cmd +EOF + else + rm -f "$config_dir/50-rsetup-autologin.conf" + fi + + systemctl daemon-reload +} + +set_sddm_autologin() { + local user="$1" switch="$2" + local config_dir="/etc/sddm.conf.d" + + if [[ "$switch" == "ON" ]]; then + mkdir -p "$config_dir" + cat << EOF | tee "$config_dir/50-rsetup-autologin.conf" >/dev/null +# Auto generated by rsetup +# DO NOT MODIFY! +[Autologin] +User=$user +Session=plasma +EOF + else + rm -f "$config_dir/50-rsetup-autologin.conf" + fi +} + +set_gdm_autologin() { + local user="$1" switch="$2" + local config_dir="/etc/gdm3/" + + if [[ "$switch" == "ON" ]]; then + mkdir -p "$config_dir" + sed -i '/^# Rsetup/,/# Rsetup$/d' $config_dir/daemon.conf + cat << EOF | tee -a $config_dir/daemon.conf >/dev/null +# Rsetup +# Auto generated by rsetup +# DO NOT MODIFY! +[daemon] +AutomaticLogin=$user +AutomaticLoginEnable=true +# Rsetup +EOF + else + sed -i '/^# Rsetup/,/# Rsetup$/d' $config_dir/daemon.conf + fi +} + +set_lightdm_autologin() { + local user="$1" switch="$2" + local config_dir="/etc/lightdm/lightdm.conf.d/" + + if [[ "$switch" == "ON" ]]; then + mkdir -p "$config_dir" + cat << EOF | tee -a $config_dir/50-rsetup-autologin.conf >/dev/null +# Auto generated by rsetup +# DO NOT MODIFY! +[Seat:*] +autologin-user=$user +autologin-user-timeout=0 +EOF + else + rm -f "$config_dir/50-rsetup-autologin.conf" + fi +} + +get_autologin_status() { + local service="$1" + + case "$service" in + *getty@*.service) + if grep -q -e "--autologin" <(grep -v '^#' "/etc/systemd/system/$service.d/50-rsetup-autologin.conf") + then + echo "ON" + else + echo "OFF" + fi + ;; + sddm.service) + if grep -q -e "[Autologin]" -e "User=" -e "Session=plasma" <(grep -v '^#' "/etc/sddm.conf.d/50-rsetup-autologin.conf") + then + echo "ON" + else + echo "OFF" + fi + ;; + gdm.service) + if grep -q -e "AutomaticLogin=" -e "AutomaticLoginEnable=true" <(grep -v '^#' "/etc/gdm3/daemon.conf") + then + echo "ON" + else + echo "OFF" + fi + ;; + lightdm.service) + if grep -q -e "[Seat:*]" -e "autologin-user=" -e "autologin-user-timeout=0" <(grep -v '^#' "/etc/lightdm/lightdm.conf.d/50-rsetup-autologin.conf") + then + echo "ON" + else + echo "OFF" + fi + ;; + esac +} + +set_autologin_status() { + local user="$1" service="$2" switch="$3" + + case "$service" in + *getty@*.service) + set_getty_autologin "$user" "$switch" "$service" + ;; + sddm.service|gdm.service|lightdm.service) + "set_${service/.service}_autologin" "$user" "$switch" + ;; + *) + echo "Invalid options: $service" >&2 + return 1 + ;; + esac +} From 9e66f320f67a60744ca979af468d4c4844d3b260 Mon Sep 17 00:00:00 2001 From: CodeChenL <2540735020@qq.com> Date: Wed, 17 Jul 2024 18:11:21 +0800 Subject: [PATCH 3/3] feat: user: supports autologin for more session types --- src/usr/lib/rsetup/tui/user/user.sh | 44 +++++++++++------------------ 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/src/usr/lib/rsetup/tui/user/user.sh b/src/usr/lib/rsetup/tui/user/user.sh index 206a1536..d63a7d64 100644 --- a/src/usr/lib/rsetup/tui/user/user.sh +++ b/src/usr/lib/rsetup/tui/user/user.sh @@ -50,43 +50,33 @@ Hostname has been set to $(hostname)." } __user_enable_auto_login (){ - local username selected_tty_device parameter + local username service username="$(logname)" checklist_init - for i in /etc/systemd/system/getty.target.wants/*tty*.service - do - checklist_add "$(basename "$i")" "OFF" - done - if ! checklist_show "Please select the interface(s) you want to enable auto login:" || checklist_is_selection_empty + while read -r; do + service="$(awk '{print $1}' <<< "$REPLY")" + checklist_add "$service" "$(get_autologin_status "$service")" + done < <(systemctl list-units --state running --no-legend -- "*getty@*.service" sddm.service gdm.service lightdm.service) + if ! checklist_show "Please select the service(s) you want to enable auto login:" || checklist_is_selection_empty then return fi - if ! yesno "After auto login is enabled, your current password will be deleted, and you can only login SSH with public key. -Are you sure to continue?" - then - return - fi + while read -r; do + service="$(awk '{print $1}' <<< "$REPLY")" + set_autologin_status "$username" "$service" "OFF" + done < <(systemctl list-units --state running --no-legend -- "*getty@*.service" sddm.service gdm.service lightdm.service) - for selected_tty_shrinked_index in "${RTUI_CHECKLIST_STATE_NEW[@]}" + for i in "${RTUI_CHECKLIST_STATE_NEW[@]}" do - selected_tty_real_index=$((3*${selected_tty_shrinked_index//\"}+1)) - selected_tty_device=${RTUI_CHECKLIST[${selected_tty_real_index}]} - SYSTEMD_OVERRIDE=/etc/systemd/system/getty.target.wants/$selected_tty_device.d - mkdir -p "$SYSTEMD_OVERRIDE" - cat << EOF > "$SYSTEMD_OVERRIDE/override.conf" -[Service] -ExecStart= -EOF - parameter="$(grep "ExecStart" "/etc/systemd/system/getty.target.wants/$selected_tty_device" | cut -d ' ' -f2-)" - AUTOLOGIN="ExecStart=-/sbin/agetty --autologin $username $parameter" - echo "$AUTOLOGIN" >> "$SYSTEMD_OVERRIDE/override.conf" + i="${i//\"}" + j=$((3 * i + 1)) + service="${RTUI_CHECKLIST[$j]}" + set_autologin_status "$username" "$service" "ON" done - if passwd --delete "$username" >/dev/null - then - msgbox "Configuration succeeded" - fi + + msgbox "Auto login settings has been updated." } __user() {