Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions src/usr/lib/rsetup/cli/system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion src/usr/lib/rsetup/tui/system/system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]]
Expand Down
44 changes: 17 additions & 27 deletions src/usr/lib/rsetup/tui/user/user.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down