Skip to content

Commit

Permalink
v8.2
Browse files Browse the repository at this point in the history
- DietPi-Software | Chromium: Install libpam-systemd and enable systemd-logind, required for non-root users to start Chromium via startx without additional permissions
- DietPi-Software | Chromium: Remove unused and obsolete Chromium flags
- DietPi-Software | Chromium: Install Chromium flags only system wide, via own config file, use correct path on RPi until Buster
- DietPi-Software | Chromium: Use startx in autostart script as non-root user, to get required permissions via systemd-logind
- DietPi-Patches | Remove and migrate Chromium config files
  • Loading branch information
MichaIng committed Feb 19, 2022
1 parent 5e2dda0 commit f5dedc3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 47 deletions.
9 changes: 9 additions & 0 deletions .update/patches
Expand Up @@ -661,6 +661,15 @@ Patch_8_2()
[[ -f '/etc/bashrc.d/dietpi-pine64-cursorfix.sh' ]] && G_EXEC rm /etc/bashrc.d/dietpi-pine64-cursorfix.sh
grep -q '^8723bs$' /etc/modules && G_EXEC sed -i '/^8723bs$/d' /etc/modules
fi

# Remove and migrate Chromium config files
[[ $G_HW_MODEL -gt 9 && -f '/root/.chromium-browser.init' ]] && G_EXEC rm /root/.chromium-browser.init
if [[ $G_DISTRO == 5 && $G_HW_MODEL -le 9 && -d '/etc/chromium.d' ]]
then
[[ -f '/etc/chromium.d/custom_flags' ]] && G_EXEC mv /etc/{chromium.d/custom_flags,chromium-browser/customizations/dietpi}
G_EXEC rm -R /etc/chromium.d
fi
[[ -f '/etc/chromium.d/custom_flags' ]] && G_EXEC mv /etc/chromium.d/{custom_flags,dietpi}
}

# v6.35 => v7 migration
Expand Down
73 changes: 26 additions & 47 deletions dietpi/dietpi-software
Expand Up @@ -9863,53 +9863,29 @@ _EOF_
# Apply preference index
INDEX_BROWSER=-2

# libpam-systemd: Required for non-root users to start Chromium from console via "startx"
if (( $G_HW_MODEL > 9 ))
then
G_AGI chromium
G_AGI chromium libpam-systemd

# RPi: Use RPi repo package including non-free FFmpeg codecs integration
else
G_AGI chromium-browser chromium-codecs-ffmpeg-extra
G_AGI chromium-browser chromium-codecs-ffmpeg-extra libpam-systemd

# Bullseye: Enable hardware codecs
(( $G_DISTRO < 6 )) || /boot/dietpi/func/dietpi-set_hardware rpi-codec 1
fi

# Allow root and disable sandbox under root (blank screen without): https://peter.sh/experiments/chromium-command-line-switches/
local export_options="export CHROMIUM_FLAGS=\"\$CHROMIUM_FLAGS \
--test-type \
--no-sandbox \
--temp-profile \
--user-data-dir \
--disable-smooth-scrolling \
--disable-low-res-tiling \
--enable-low-end-device-mode \
--num-raster-threads=$G_HW_CPU_CORES \
--profiler-timing=0 \
--disable-composited-antialiasing"

# RPi: Leave OpenGL choice to user, as it also depends on RPi model
if (( $G_HW_MODEL < 10 ))
then
:

# x86_64: OpenGL
elif [[ $G_HW_ARCH == 10 ]]
then
:

# GLES
else
export_options+=' --use-gl=egl'
fi

export_options+='"'

[[ -d '/etc/chromium.d' ]] || G_EXEC mkdir /etc/chromium.d
echo "$export_options" > /etc/chromium.d/custom_flags

# Chromium 60+
G_EXEC cp /etc/chromium.d/custom_flags /root/.chromium-browser.init
# Flags: Allow root (disable sandbox) and minimise CPU usage: https://peter.sh/experiments/chromium-command-line-switches/
local flags="export CHROMIUM_FLAGS=\"\$CHROMIUM_FLAGS --no-sandbox --test-type --disable-smooth-scrolling --disable-low-res-tiling --enable-low-end-device-mode --num-raster-threads=$G_HW_CPU_CORES --disable-composited-antialiasing"
# - RPi: Leave OpenGL choice to user, as it also depends on RPi model
# - x86_64: OpenGL
# - Else: GLES
(( $G_HW_MODEL < 10 || $G_HW_ARCH == 10 )) && flags+='"' || flags+=' --use-gl=egl"'
# - RPi Buster: Uses /etc/chromium-browser/customizations, else /etc/chromium.d: https://github.com/RPi-Distro/chromium-browser/commit/f4a599d
local path='chromium.d'
(( $G_DISTRO > 5 || $G_HW_MODEL > 9 )) || path='chromium-browser/customizations'
echo "$flags" > "/etc/$path/dietpi"

# Desktop shortcut: chromium-browser.desktop on RPi
if (( $G_HW_MODEL > 9 ))
Expand All @@ -9924,18 +9900,15 @@ _EOF_
cat << '_EOF_' > /var/lib/dietpi/dietpi-software/installed/chromium-autostart.sh
#!/bin/dash
# Autostart run script for kiosk mode, based on @AYapejian: https://github.com/MichaIng/DietPi/issues/1737#issue-318697621
# - Please see /root/.chromium-browser.init (and /etc/chromium.d/custom_flags) for additional falgs.

# Command line switches: https://peter.sh/experiments/chromium-command-line-switches/
# --test-type gets rid of some of the Chromium warnings that you may or may not care about in kiosk on a LAN
# --pull-to-refresh=1
# --ash-host-window-bounds="400,300"

# Resolution to use for kiosk mode, should ideally match current system resolution
RES_X=$(sed -n '/^[[:blank:]]*SOFTWARE_CHROMIUM_RES_X=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
RES_Y=$(sed -n '/^[[:blank:]]*SOFTWARE_CHROMIUM_RES_Y=/{s/^[^=]*=//p;q}' /boot/dietpi.txt)

CHROMIUM_OPTS="--kiosk --test-type --window-size=${RES_X:-1280},${RES_Y:-720} --start-fullscreen --start-maximized --window-position=0,0"
# Command line switches: https://peter.sh/experiments/chromium-command-line-switches/
# - Review and add custom flags in: /etc/chromium.d
# --test-type: Disables some warnings that may disturb in kiosk mode
CHROMIUM_OPTS="--kiosk --test-type --window-size=${RES_X:-1280},${RES_Y:-720} --window-position=0,0"

# If you want tablet mode, uncomment the next line.
#CHROMIUM_OPTS+=' --force-tablet-mode --tablet-ui'
Expand All @@ -9947,8 +9920,13 @@ URL=$(sed -n '/^[[:blank:]]*SOFTWARE_CHROMIUM_AUTOSTART_URL=/{s/^[^=]*=//p;q}' /
FP_CHROMIUM=$(command -v chromium-browser)
[ "$FP_CHROMIUM" ] || FP_CHROMIUM=$(command -v chromium)

exec xinit "$FP_CHROMIUM" $CHROMIUM_OPTS --homepage "${URL:-https://dietpi.com/}"
# Use "startx" as non-root user to get required permissions via systemd-logind
STARTX='xinit'
[ "$USER" == 'root' ] || STARTX='startx'

exec "$STARTX" "$FP_CHROMIUM" $CHROMIUM_OPTS "${URL:-https://dietpi.com/}"
_EOF_
[[ $path == 'chromium.d' ]] || G_EXEC sed -i 's/chromium\.d/chromium-browser/customizations/' /var/lib/dietpi/dietpi-software/installed/chromium-autostart.sh
G_EXEC chmod +x /var/lib/dietpi/dietpi-software/installed/chromium-autostart.sh

fi
Expand Down Expand Up @@ -15852,10 +15830,11 @@ _EOF_
# Reload systemd units
G_EXEC systemctl daemon-reload

# Unmask systemd-logind if Kodi was installed, it's set in dietpi.txt or libpam-systemd was installed
# Unmask systemd-logind if Kodi or Chromium were installed, it's set in dietpi.txt or libpam-systemd was installed
if [[ $(readlink /etc/systemd/system/systemd-logind.service) == '/dev/null' ]] &&
{ (( ${aSOFTWARE_INSTALL_STATE[31]} == 1 )) || grep -q '^[[:blank:]]*AUTO_UNMASK_LOGIND=1' /boot/dietpi.txt || dpkg-query -s 'libpam-systemd' &> /dev/null; }; then
{ (( ${aSOFTWARE_INSTALL_STATE[31]} == 1 || ${aSOFTWARE_INSTALL_STATE[113]} == 1 )) || grep -q '^[[:blank:]]*AUTO_UNMASK_LOGIND=1' /boot/dietpi.txt || dpkg-query -s 'libpam-systemd' &> /dev/null; }; then

G_DIETPI-NOTIFY 2 'Enabling systemd-logind'
# dbus is required for systemd-logind to start
dpkg-query -s dbus &> /dev/null || G_AGI dbus
G_EXEC systemctl unmask dbus
Expand Down

0 comments on commit f5dedc3

Please sign in to comment.