-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathautologin.sh
More file actions
executable file
·61 lines (50 loc) · 1.28 KB
/
Copy pathautologin.sh
File metadata and controls
executable file
·61 lines (50 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
#shellcheck disable=2016
# Setup auto login with or without password
BLUE="\033[34m"
GREEN="\033[32m"
RED="\033[31m"
RESET="\033[0m"
tty="${2:-tty1}"
user="${3:-$LOGNAME}"
if ! [[ $tty =~ tty[0-9] ]]; then
echo "invalid tty name '$tty'"
exit 1
fi
service_name="getty@$tty"
service_dir="/etc/systemd/system/$service_name.service.d"
enable() {
sudo mkdir -pv "$service_dir"
echo "$service" | sudo tee "$service_dir/override.conf" >/dev/null
sudo systemctl enable "$service_name"
echo -e "Auto login for user $BLUE$user$RESET ${GREEN}created$RESET on $BLUE$tty$RESET"
}
case "$1" in
reset)
if sudo rm -rv "$service_dir" ; then
echo -e "Auto login on $BLUE$tty$RESET has been ${RED}disabled$RESET"
else
echo -e "Auto login was already ${RED}disabled$RESET on $tty"
fi
exit
;;
full)
service='
[Service]
ExecStart=
ExecStart=-/usr/bin/agetty --autologin '"$user"' --noclear %I $TERM
Type=simple'
enable
;;
username)
service='
[Service]
ExecStart=
ExecStart=-/usr/bin/agetty --skip-login --login-options '"$user"' --noclear %I $TERM'
enable
;;
*)
echo 'please pick either `full`, `username` or reset'
exit 1
;;
esac