From 7cfc338337313e4b0639a4b39b7cbd903d464bdc Mon Sep 17 00:00:00 2001 From: MichaIng Date: Mon, 26 Apr 2021 20:24:14 +0200 Subject: [PATCH] v7.1 + DietPi-Set_hardware | Work around an issue where on RPi "alsactl -g store" can fail in circumstances that need to be investigated further + DietPi-Set_hardware | RPi OpenGL: Do not force a specific framebuffer size as e.g. the console frequency can still be chosen freely and depending on the VC4 mode, the framebuffer otherwise is not used. + DietPi-Set_hardware | Minor coding, especially further apply G_EXEC error handler where applicable --- dietpi/func/dietpi-set_hardware | 129 ++++++++++++++------------------ 1 file changed, 58 insertions(+), 71 deletions(-) diff --git a/dietpi/func/dietpi-set_hardware b/dietpi/func/dietpi-set_hardware index 199776868a..affa569965 100644 --- a/dietpi/func/dietpi-set_hardware +++ b/dietpi/func/dietpi-set_hardware @@ -68,7 +68,7 @@ $FP_SCRIPT rpi-eeprom ARMBIAN=0 FP_UENV='/tmp/uEnv.txt' for i in /boot/u{e,E}nv.txt; do [[ -f $i ]] && FP_UENV=$i && break; done - unset i + unset -v i fi @@ -126,7 +126,7 @@ $FP_SCRIPT rpi-eeprom # Comment extended start setting G_EXEC sed -i '/^[[:blank:]]*start_x=/c\#start_x=1' /boot/config.txt - # Add modules blacklist, which are otherwise loaded by default since kernel 4.19 + # Add modules blacklist, which are otherwise loaded by default since kernel 4.19/5.10 echo -e 'blacklist bcm2835_codec\nblacklist bcm2835_v4l2\nblacklist bcm2835_isp' > /etc/modprobe.d/dietpi-disable_rpi_camera.conf else @@ -148,32 +148,31 @@ $FP_SCRIPT rpi-eeprom G_CONFIG_INJECT 'program_usb_boot_mode=' 'program_usb_boot_mode=1' /boot/config.txt - cat << _EOF_ > /etc/systemd/system/dietpi-rm_program_usb_boot_mode.service + cat << '_EOF_' > /etc/systemd/system/dietpi-rm_program_usb_boot_mode.service [Unit] Description=DietPi-rm_program_usb_boot_mode.service -After=dietpi-boot.service [Service] Type=oneshot RemainAfterExit=yes -ExecStartPre=$(command -v sed) -i '/^[[:blank:]]*program_usb_boot_mode=/d' /boot/config.txt -ExecStartPre=$(command -v systemctl) disable dietpi-rm_program_usb_boot_mode -ExecStart=$(command -v rm) /etc/systemd/system/dietpi-rm_program_usb_boot_mode.service +ExecStartPre=/bin/sed -i '/^[[:blank:]]*program_usb_boot_mode=/d' /boot/config.txt +ExecStartPre=/bin/systemctl disable dietpi-rm_program_usb_boot_mode +ExecStart=/bin/rm /etc/systemd/system/dietpi-rm_program_usb_boot_mode.service [Install] WantedBy=multi-user.target _EOF_ - systemctl daemon-reload - systemctl enable dietpi-rm_program_usb_boot_mode + G_EXEC systemctl daemon-reload + G_EXEC systemctl enable dietpi-rm_program_usb_boot_mode elif [[ $INPUT_DEVICE_VALUE == 'disable' ]]; then - sed -i '/^[[:blank:]]*program_usb_boot_mode=/d' /boot/config.txt + G_EXEC sed -i '/^[[:blank:]]*program_usb_boot_mode=/d' /boot/config.txt if [[ -f '/etc/systemd/system/dietpi-rm_program_usb_boot_mode.service' ]]; then - systemctl disable dietpi-rm_program_usb_boot_mode - rm /etc/systemd/system/dietpi-rm_program_usb_boot_mode.service + G_EXEC systemctl disable --now dietpi-rm_program_usb_boot_mode + G_EXEC rm /etc/systemd/system/dietpi-rm_program_usb_boot_mode.service fi @@ -192,15 +191,15 @@ _EOF_ (( $G_HW_MODEL == 4 )) || { Unsupported_Input_Name; return 1; } # Exit path for non-RPi4 - # Install required APT package, be failsafe and install/upgrade VC firmware and bootloader as well + # Install required APT package G_AGUP - G_AGI rpi-eeprom libraspberrypi-bin raspberrypi-bootloader + G_AGI rpi-eeprom # Update/flash new bootloader and VL805 USB firmware to EEPROM rpi-eeprom-update -a - # Required? Enable update service to run on every boot - systemctl enable rpi-eeprom-update + # Failsafe + G_EXEC systemctl enable rpi-eeprom-update } @@ -275,7 +274,7 @@ _EOF_ # - Disable HDMI hotplug detection, which requires it to be generally responsive/active G_CONFIG_INJECT 'hdmi_ignore_hotplug=' 'hdmi_ignore_hotplug=1' /boot/config.txt # - Disable SDTV on RPi4 - sed -i '/^[[:blank:]]*enable_tvout=/c\#enable_tvout=0' /boot/config.txt + G_EXEC sed -i '/^[[:blank:]]*enable_tvout=/c\#enable_tvout=0' /boot/config.txt # Odroid C2 elif (( $G_HW_MODEL == 12 )); then @@ -295,13 +294,13 @@ _EOF_ # RPi if (( $G_HW_MODEL < 10 )); then - sed -i '/^[[:blank:]]*framebuffer_width=/c\#framebuffer_width=16' /boot/config.txt - sed -i '/^[[:blank:]]*framebuffer_height=/c\#framebuffer_height=16' /boot/config.txt - sed -i '/^[[:blank:]]*max_framebuffer_width=/c\#max_framebuffer_width=16' /boot/config.txt - sed -i '/^[[:blank:]]*max_framebuffer_height=/c\#max_framebuffer_height=16' /boot/config.txt - sed -i '/^[[:blank:]]*hdmi_blanking=/c\#hdmi_blanking=0' /boot/config.txt - sed -i '/^[[:blank:]]*hdmi_ignore_hotplug=/c\#hdmi_ignore_hotplug=0' /boot/config.txt - sed -i '/^[[:blank:]]*enable_tvout=/c\#enable_tvout=0' /boot/config.txt + G_EXEC sed -i '/^[[:blank:]]*framebuffer_width=/c\#framebuffer_width=16' /boot/config.txt + G_EXEC sed -i '/^[[:blank:]]*framebuffer_height=/c\#framebuffer_height=16' /boot/config.txt + G_EXEC sed -i '/^[[:blank:]]*max_framebuffer_width=/c\#max_framebuffer_width=16' /boot/config.txt + G_EXEC sed -i '/^[[:blank:]]*max_framebuffer_height=/c\#max_framebuffer_height=16' /boot/config.txt + G_EXEC sed -i '/^[[:blank:]]*hdmi_blanking=/c\#hdmi_blanking=0' /boot/config.txt + G_EXEC sed -i '/^[[:blank:]]*hdmi_ignore_hotplug=/c\#hdmi_ignore_hotplug=0' /boot/config.txt + G_EXEC sed -i '/^[[:blank:]]*enable_tvout=/c\#enable_tvout=0' /boot/config.txt # Odroid C2 elif (( $G_HW_MODEL == 12 )); then @@ -336,18 +335,24 @@ _EOF_ if [[ -f '/etc/systemd/system/justboom-ir-mpd.service' ]]; then - systemctl disable --now justboom-ir-mpd - rm -R /etc/systemd/system/justboom-ir-mpd.service* + G_EXEC systemctl disable --now justboom-ir-mpd + G_EXEC rm /etc/systemd/system/justboom-ir-mpd.service fi + [[ -d '/etc/systemd/system/justboom-ir-mpd.service.d' ]] && G_EXEC rm -R /etc/systemd/system/justboom-ir-mpd.service.d - sed -i '/^[[:blank:]]*dtoverlay=gpio-ir/d' /boot/config.txt + G_EXEC sed -i '/^[[:blank:]]*dtoverlay=gpio-ir/d' /boot/config.txt # Disable Odroids - elif (( $G_HW_MODEL < 20 )) && [[ -f '/etc/systemd/system/odroid-remote.service' ]]; then + elif (( $G_HW_MODEL < 20 )); then - systemctl disable --now odroid-remote - rm -R /etc/systemd/system/odroid-remote.service* + if [[ -f '/etc/systemd/system/odroid-remote.service' ]]; then + + G_EXEC systemctl disable --now odroid-remote + G_EXEC rm /etc/systemd/system/odroid-remote.service + + fi + [[ -d '/etc/systemd/system/odroid-remote.service.d' ]] && G_EXEC rm -R /etc/systemd/system/odroid-remote.service.d fi @@ -382,12 +387,8 @@ _EOF_ fi - # All - # - systemd - systemctl enable lircd - - # - Lircd conf for Odroid Remote - cat << _EOF_ > /etc/lirc/lircd.conf + # Config + cat << '_EOF_' > /etc/lirc/lircd.conf begin remote name lircd.conf @@ -423,6 +424,8 @@ begin remote end remote _EOF_ + # Service + G_EXEC systemctl enable --now lircd elif [[ $INPUT_DEVICE_VALUE == 'justboom_ir_remote' ]]; then @@ -432,7 +435,8 @@ _EOF_ G_CONFIG_INJECT 'dtoverlay=gpio-ir' 'dtoverlay=gpio-ir,gpio_pin=25' /boot/config.txt - cat << _EOF_ > /etc/lirc/hardware.conf + # Config + cat << '_EOF_' > /etc/lirc/hardware.conf LIRCD_ARGS="--uinput" LOAD_MODULES=true DRIVER="default" @@ -441,8 +445,7 @@ MODULES="lirc_rpi" LIRCD_CONF="" LIRCMD_CONF="" _EOF_ - - cat << _EOF_ > /etc/lirc/lircd.conf + cat << '_EOF_' > /etc/lirc/lircd.conf begin remote name lircd.conf @@ -481,11 +484,10 @@ begin remote end remote _EOF_ - # MPD control G_AG_CHECK_INSTALL_PREREQ mpc - cat << _EOF_ > /root/.lircrc + cat << '_EOF_' > /root/.lircrc begin prog = irexec button = KEY_ENTER @@ -532,7 +534,6 @@ button = KEY_MENU config = mpc repeat off end _EOF_ - # Service cat << _EOF_ > /etc/systemd/system/justboom-ir-mpd.service [Unit] @@ -545,8 +546,8 @@ ExecStart=$(command -v irexec) [Install] WantedBy=default.target _EOF_ - systemctl daemon-reload - systemctl enable --now justboom-ir-mpd + G_EXEC systemctl daemon-reload + G_EXEC systemctl enable --now justboom-ir-mpd elif [[ $INPUT_DEVICE_VALUE != 'none' ]]; then @@ -579,17 +580,18 @@ ExecStart=$(command -v ethtool) -s $iface speed $speed_mbit duplex full autoneg [Install] WantedBy=ifup@$iface.service _EOF_ - systemctl daemon-reload - systemctl enable --now ethtool_force_speed + G_EXEC systemctl daemon-reload + G_EXEC systemctl enable --now ethtool_force_speed elif [[ $INPUT_DEVICE_VALUE == 'disable' ]]; then # 0 is converted to "disable" if [[ -f '/etc/systemd/system/ethtool_force_speed.service' ]]; then - systemctl disable --now ethtool_force_speed - rm -R /etc/systemd/system/ethtool_force_speed.service* + G_EXEC systemctl disable --now ethtool_force_speed + G_EXEC rm /etc/systemd/system/ethtool_force_speed.service fi + [[ -d '/etc/systemd/system/ethtool_force_speed.service.d' ]] && G_EXEC rm -R /etc/systemd/system/ethtool_force_speed.service.d else @@ -606,8 +608,8 @@ _EOF_ (( $G_HW_MODEL > 9 )) && { Unsupported_Input_Name; return 1; } # Exit path for non-RPi - # Always remove previous vc4 overlay entry - sed -i '/^[[:blank:]]*dtoverlay=vc4-/d' /boot/config.txt + # Always remove previous VC4 overlay entry + G_EXEC sed -i '/^[[:blank:]]*dtoverlay=vc4-/d' /boot/config.txt if [[ $INPUT_DEVICE_VALUE == 'vc4-kms-v3d' || $INPUT_DEVICE_VALUE == 'vc4-kms-v3d-pi4' || $INPUT_DEVICE_VALUE == 'vc4-fkms-v3d' ]]; then @@ -622,10 +624,6 @@ _EOF_ G_CONFIG_INJECT "dtoverlay=$INPUT_DEVICE_VALUE" "dtoverlay=$INPUT_DEVICE_VALUE" /boot/config.txt - # Set 1080p by default - G_CONFIG_INJECT 'framebuffer_width=' 'framebuffer_width=1920' /boot/config.txt - G_CONFIG_INJECT 'framebuffer_height=' 'framebuffer_height=1080' /boot/config.txt - elif [[ $INPUT_DEVICE_VALUE != 'disable' ]]; then Unknown_Input_Mode @@ -988,9 +986,10 @@ _EOF_ if [[ -f '/etc/systemd/system/odroid-lcd35.service' ]]; then G_EXEC systemctl disable --now odroid-lcd35 - G_EXEC rm -R /etc/systemd/system/odroid-lcd35.service* + G_EXEC rm /etc/systemd/system/odroid-lcd35.service fi + [[ -d '/etc/systemd/system/odroid-lcd35.service.d' ]] && G_EXEC rm -R /etc/systemd/system/odroid-lcd35.service.d [[ -f '/etc/X11/xorg.conf.d/99-odroid-lcd35.conf' ]] && G_EXEC rm /etc/X11/xorg.conf.d/99-odroid-lcd35.conf } @@ -1250,12 +1249,10 @@ Do you want to continue and disable the serial login console?' || return 1 local i for i in /etc/sysctl{,.d/*}.conf do - [[ $i != '/etc/sysctl.d/dietpi-disable_ipv6.conf' && -f $i ]] || continue grep -q '^[[:blank:]]*net.ipv6.conf.[^[:blank:]]*.disable_ipv6[[:blank:]]*=' "$i" || continue i=$(readlink -f $i) # https://github.com/MichaIng/DietPi/issues/3003#issuecomment-669464255 sed -i 's/^[[:blank:]]*net.ipv6.conf.[^[:blank:]]*.disable_ipv6[[:blank:]]*=/#&/' "$i" - done } @@ -1291,10 +1288,8 @@ Do you want to continue and disable the serial login console?' || return 1 local i for i in /etc/apt/apt.conf.d/* do - [[ ! -f $i || $i == *'99-dietpi-force-ipv4' ]] && continue sed -i 's/^[[:blank:]]*Acquire::ForceIPv[46][[:blank:]]*=/#&/' "$i" - done } @@ -1356,10 +1351,8 @@ Do you want to continue and disable the serial login console?' || return 1 # cfg80211 last for ((i=$(( ${#aWIFI_MODULES[@]} - 1 )); i>=0; i--)) do - echo "blacklist ${aWIFI_MODULES[$i]}" >> /etc/modprobe.d/dietpi-disable_wifi.conf modprobe -rf "${aWIFI_MODULES[$i]}" 2> /dev/null - done if G_WHIP_YESNO 'Would you like to purge all WiFi related APT packages? @@ -1394,9 +1387,7 @@ _EOF_ # cfg80211 first for i in "${aWIFI_MODULES[@]}" do - modprobe "$i" 2> /dev/null - done # Delay to allow modules + WPA2-Enterprise being fully loaded and avoid device not found error @@ -1539,10 +1530,8 @@ Do you want to continue and DISABLE Bluetooth now?' || return 1 # ttyFIQ[0-9]: https://github.com/MichaIng/DietPi/issues/1829#issuecomment-398302497 for i in /dev/tty{S,AMA,SAC}[0-9] do - [[ -e $i ]] || continue INPUT_ADDITIONAL=${i/\/dev\/} Serial_Main - done # On RPi enable primary UART device @@ -1606,20 +1595,16 @@ Do you want to continue and DISABLE Bluetooth now?' || return 1 # ttyFIQ[0-9]: https://github.com/MichaIng/DietPi/issues/1829#issuecomment-398302497 for i in /dev/tty{S,AMA,SAC}[0-9] do - [[ -e $i ]] || continue INPUT_ADDITIONAL=${i/\/dev\/} Serial_Main - done # Cleanup: Disable for left non-existent devices for i in /etc/systemd/system/getty.target.wants/serial-getty@* do - [[ -e $i ]] || continue i=${i%.service} INPUT_ADDITIONAL=${i##*@} Serial_Main - done # On RPi disable primary UART device @@ -1658,7 +1643,7 @@ Do you want to continue and DISABLE Bluetooth now?' || return 1 # - Remove stored amixer state [[ -f '/var/lib/alsa/asound.state' ]] && G_EXEC rm /var/lib/alsa/asound.state - # - Reset active amixer state + # - Reset active amixer state ("-g" option has been added upstream: https://github.com/alsa-project/alsa-utils/issues/75) [[ $INPUT_DEVICE_VALUE != 'none' && -f '/proc/asound/cards' && $( 9 )) || G_EXEC_NOFAIL=1 G_EXEC alsactl -g store # Buster: Avoid alsa-state.service start if its config file does not exist: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=932209