Skip to content

Commit 02b0c38

Browse files
committed
feat: user: supports autologin for more session types
1 parent 352cd0d commit 02b0c38

1 file changed

Lines changed: 17 additions & 27 deletions

File tree

src/usr/lib/rsetup/tui/user/user.sh

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,43 +50,33 @@ Hostname has been set to $(hostname)."
5050
}
5151

5252
__user_enable_auto_login (){
53-
local username selected_tty_device parameter
53+
local username service
5454
username="$(logname)"
5555

5656
checklist_init
57-
for i in /etc/systemd/system/getty.target.wants/*tty*.service
58-
do
59-
checklist_add "$(basename "$i")" "OFF"
60-
done
61-
if ! checklist_show "Please select the interface(s) you want to enable auto login:" || checklist_is_selection_empty
57+
while read -r; do
58+
service="$(awk '{print $1}' <<< "$REPLY")"
59+
checklist_add "$service" "$(get_autologin_status "$service")"
60+
done < <(systemctl list-units --state running --no-legend -- "*getty@*.service" sddm.service gdm.service lightdm.service)
61+
if ! checklist_show "Please select the service(s) you want to enable auto login:" || checklist_is_selection_empty
6262
then
6363
return
6464
fi
6565

66-
if ! yesno "After auto login is enabled, your current password will be deleted, and you can only login SSH with public key.
67-
Are you sure to continue?"
68-
then
69-
return
70-
fi
66+
while read -r; do
67+
service="$(awk '{print $1}' <<< "$REPLY")"
68+
set_autologin_status "$username" "$service" "OFF"
69+
done < <(systemctl list-units --state running --no-legend -- "*getty@*.service" sddm.service gdm.service lightdm.service)
7170

72-
for selected_tty_shrinked_index in "${RTUI_CHECKLIST_STATE_NEW[@]}"
71+
for i in "${RTUI_CHECKLIST_STATE_NEW[@]}"
7372
do
74-
selected_tty_real_index=$((3*${selected_tty_shrinked_index//\"}+1))
75-
selected_tty_device=${RTUI_CHECKLIST[${selected_tty_real_index}]}
76-
SYSTEMD_OVERRIDE=/etc/systemd/system/getty.target.wants/$selected_tty_device.d
77-
mkdir -p "$SYSTEMD_OVERRIDE"
78-
cat << EOF > "$SYSTEMD_OVERRIDE/override.conf"
79-
[Service]
80-
ExecStart=
81-
EOF
82-
parameter="$(grep "ExecStart" "/etc/systemd/system/getty.target.wants/$selected_tty_device" | cut -d ' ' -f2-)"
83-
AUTOLOGIN="ExecStart=-/sbin/agetty --autologin $username $parameter"
84-
echo "$AUTOLOGIN" >> "$SYSTEMD_OVERRIDE/override.conf"
73+
i="${i//\"}"
74+
j=$((3 * i + 1))
75+
service="${RTUI_CHECKLIST[$j]}"
76+
set_autologin_status "$username" "$service" "ON"
8577
done
86-
if passwd --delete "$username" >/dev/null
87-
then
88-
msgbox "Configuration succeeded"
89-
fi
78+
79+
msgbox "Auto login settings has been updated."
9080
}
9181

9282
__user() {

0 commit comments

Comments
 (0)