-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2204rpi-chromiumsetup.sh
117 lines (90 loc) · 2.75 KB
/
2204rpi-chromiumsetup.sh
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
# Make Chromium autostart, fx. in preparation for OS2Display.
set -ex
# Initialize parameters
TIME=$1
URL=$2
WIDTH=$3
HEIGHT=$4
ORIENTATION=$5
# Setup Chromium user.
# useradd will fail on multiple runs, so prevent that
if ! id chrome &>/dev/null; then
useradd chrome -m -p 12345 -s /bin/bash -U
fi
chfn -f Chrome chrome
# Autologin default user
mkdir -p /etc/systemd/system/[email protected]
cat << EOF > /etc/systemd/system/[email protected]/override.conf
[Service]
ExecStart=
ExecStart=-/sbin/agetty --noissue --autologin chrome %I $TERM
Type=idle
EOF
# Create script to rotate screen
cat << EOF > /usr/local/bin/rotate_screen.sh
#!/usr/bin/env bash
set -x
sleep $TIME
export XAUTHORITY=/home/chrome/.Xauthority
# Rotate screen
active_monitors=(\$(xrandr --listactivemonitors -display :0 | grep -v Monitors | awk '{ print \$4; }'))
# If more than one monitor, rotate them all.
for m in "\${active_monitors[@]}"
do
xrandr --output \$m --rotate $ORIENTATION -display :0
done
EOF
chmod +x /usr/local/bin/rotate_screen.sh &
# Create a script dedicated to launch chromium, which both xinit or any wm
# launches, to avoid logic duplication, fx. having to update chromium settings
# in multiple files
# If this script's path/name is changed, remember to change it in
# install_wm_keyboard.sh as well
#
# password-store=basic and enable-offline-auto-reload does not exist as policies so we add them as flags.
CHROMIUM_SCRIPT='/usr/share/os2borgerpc/bin/start_chromium.sh'
mkdir --parents "$(dirname "$CHROMIUM_SCRIPT")"
cat << EOF > "$CHROMIUM_SCRIPT"
#!/bin/sh
WM=\$1
IURL="$URL"
IWIDTH="$WIDTH"
IHEIGHT="$HEIGHT"
COMMON_SETTINGS="--password-store=basic --enable-offline-auto-reload"
KIOSK="--kiosk"
INCOGNITO=""
if [ "\$WM" == "wm" ]
then
chromium-browser "\$KIOSK" "\$IURL" "\$COMMON_SETTINGS"
else
exec chromium-browser "\$KIOSK" "\$IURL" --window-size="\$IWIDTH","\$IHEIGHT" --window-position=0,0 "\$COMMON_SETTINGS"
fi
EOF
chmod +x "$CHROMIUM_SCRIPT"
# Launch chrome upon startup
XINITRC="/home/chrome/.xinitrc"
cat << EOF > $XINITRC
#!/bin/sh
xset s off
xset s noblank
xset -dpms
# Dev note: We used to have "sleep 20" here but we removed it.
# Re-add if it causes timing issues. That said such potential issues should be
# solveable simple by raising the sleep parameter to rotate_screen.sh
/usr/local/bin/rotate_screen.sh
# Launch chromium with its non-WM settings
exec $CHROMIUM_SCRIPT nowm
EOF
CHROME_POLICY_FILE="/var/snap/chromium/current/policies/managed/os2borgerpc-defaults.json"
mkdir --parents "$(dirname "$CHROME_POLICY_FILE")"
cat << EOF > $CHROME_POLICY_FILE
{
"AutoplayAllowed":true,
"TranslateEnabled":false
}
EOF
# Start X upon login
if ! grep -q -- 'startx' "$XINITRC"; then # Ensure idempotency
echo "startx" >> /home/chrome/.profile
fi