@@ -29,6 +29,11 @@ CHROMIUM_SCRIPT='/usr/share/os2borgerpc/bin/start_chromium.sh'
29
29
ROTATE_SCREEN_SCRIPT_PATH=" /usr/share/os2borgerpc/bin/rotate_screen.sh"
30
30
OLD_ROTATE_SCREEN_SCRIPT_PATH=" /usr/local/bin/rotate_screen.sh"
31
31
ENVIRONMENT_FILE=" /etc/environment"
32
+ AUTOLOGIN_SCRIPT=" /usr/share/os2borgerpc/bin/autologin.sh"
33
+ AUTOLOGIN_COUNTER=" /etc/os2borgerpc/login_counter.txt"
34
+ COUNTER_RESET_SERVICE=" /etc/systemd/system/reset_login_counter.service"
35
+ REBOOT_SCRIPT=" /usr/share/os2borgerpc/bin/chromium_error_reboot.sh"
36
+ MAXIMUM_CONSECUTIVE_AUTOLOGINS=3
32
37
33
38
if ! get_os2borgerpc_config os2_product | grep --quiet kiosk; then
34
39
echo " Dette script er ikke designet til at blive anvendt på en regulær OS2borgerPC-maskine."
47
52
48
53
# Note: The empty ExecStart is not insignificant!
49
54
# By default the value is appended, so the empty line changes it to an override
55
+ # We make agetty use our own login-program instead of /bin/login
56
+ # so we can customize the behavior
50
57
cat
<< EOF > /etc/systemd/system/[email protected] /override.conf
51
58
[Service]
52
59
ExecStart=
53
- ExecStart=-/sbin/agetty --noissue --autologin $CUSER %I $TERM
60
+ ExecStart=-/sbin/agetty --noissue --login-program $AUTOLOGIN_SCRIPT -- autologin $CUSER %I $TERM
54
61
Type=idle
55
62
EOF
56
63
64
+ # Create the autologin script
65
+
66
+ # Ensure that the folder exists
67
+ mkdir --parents " $( dirname $AUTOLOGIN_SCRIPT ) "
68
+
69
+ cat << EOF > $AUTOLOGIN_SCRIPT
70
+ #! /usr/bin/env bash
71
+ COUNTER=\$ (cat $AUTOLOGIN_COUNTER )
72
+ COUNTER=\$ ((COUNTER+1))
73
+ echo \$ COUNTER > $AUTOLOGIN_COUNTER
74
+ if [ \$ COUNTER -le $MAXIMUM_CONSECUTIVE_AUTOLOGINS ]; then
75
+ if [ \$ COUNTER -gt 1 ]; then
76
+ # Sleep before autologin attempts other than the first
77
+ sleep 10
78
+ fi
79
+ # Autologin as $CUSER
80
+ /bin/login -f $CUSER
81
+ else
82
+ # Regular login prompt
83
+ /bin/login
84
+ fi
85
+ EOF
86
+
87
+ # To maintain the functionality of the error reboot script
88
+ if [ -f " $REBOOT_SCRIPT " ]; then
89
+ sed --in-place --expression " \@else@{ n; n; s@/bin/login@$REBOOT_SCRIPT @ }" \
90
+ --expression " s/Regular login prompt/Reboot the computer/" $AUTOLOGIN_SCRIPT
91
+ fi
92
+
93
+ chmod 700 $AUTOLOGIN_SCRIPT
94
+
95
+ # Create login counter
96
+ echo " 0" > $AUTOLOGIN_COUNTER
97
+
98
+ # Create service to reset counter when
99
+ # the computer is booted
100
+ cat << EOF > $COUNTER_RESET_SERVICE
101
+ [Unit]
102
+ Description=Reset the autologin counter when the computer starts
103
+
104
+ [Service]
105
+ Type=oneshot
106
+ ExecStart=sh -c 'echo "0" > $AUTOLOGIN_COUNTER '
107
+
108
+ [Install]
109
+ WantedBy=multi-user.target
110
+ EOF
111
+
112
+ systemctl enable --now " $( basename $COUNTER_RESET_SERVICE ) "
113
+
57
114
# Create script to rotate screen
58
115
59
116
# ...remove the rotate script from its previous location
60
117
rm --force $OLD_ROTATE_SCREEN_SCRIPT_PATH
61
118
62
- # Make the new folder
63
- mkdir --parents " $( dirname $ROTATE_SCREEN_SCRIPT_PATH ) "
64
-
65
119
cat << EOF > $ROTATE_SCREEN_SCRIPT_PATH
66
120
#!/usr/bin/env sh
67
121
153
207
154
208
# Start X upon login
155
209
PROFILE=" /home/$CUSER /.profile"
156
- if ! grep --quiet -- ' for i in' $PROFILE ; then # Ensure idempotency
157
- # This first line cleans up after the previous version of the script
158
- sed --in-place " /startx/d" $PROFILE
210
+ if ! grep --quiet -- ' exit' $PROFILE ; then # Ensure idempotency
211
+ # This first line cleans up after previous versions of the script
212
+ sed --in-place --expression " /startx/d" --expression " /for i in/d" --expression " /sleep/d" \
213
+ --expression " /done/d" --expression " /chromium_error_reboot/d" $PROFILE
159
214
cat << EOF >> $PROFILE
160
- for i in 1 2 3; do
161
- startx
162
- sleep 10
163
- done
215
+ startx
216
+ exit
164
217
EOF
165
218
fi
0 commit comments