diff --git a/config/armbian/bananapim2zero b/config/armbian/bananapim2zero index 9c19be38d..d3bfac98b 100644 --- a/config/armbian/bananapim2zero +++ b/config/armbian/bananapim2zero @@ -3,8 +3,8 @@ # shellcheck enable=require-variable-braces # Image source -DOWNLOAD_URL_CHECKSUM="${DOWNLOAD_BASE_URL}/armbian-bananapi_m2_zero_bullseye.img.xz.sha256" -DOWNLOAD_URL_IMAGE="${DOWNLOAD_BASE_URL}/armbian-bananapi_m2_zero_bullseye.img.xz" +DOWNLOAD_URL_CHECKSUM="${DOWNLOAD_BASE_URL}/armbian-bananapi_m2_zero_bookworm.img.xz.sha256" +DOWNLOAD_URL_IMAGE="${DOWNLOAD_BASE_URL}/armbian-bananapi_m2_zero_bookworm.img.xz" # export Variables export BASE_ARCH diff --git a/config/armbian/default b/config/armbian/default index ed699d4a8..c6e329839 100644 --- a/config/armbian/default +++ b/config/armbian/default @@ -18,12 +18,12 @@ BASE_IMAGE_RASPBIAN="no" # partition resizing BASE_ROOT_PARTITION="2" -BASE_IMAGE_ENLARGEROOT=2500 +BASE_IMAGE_ENLARGEROOT=3500 BASE_IMAGE_RESIZEROOT=600 # Compress not needed due compression done in workflow BASE_RELEASE_COMPRESS=no # Modules are valid for 32bit and 64bit images -MODULES="base(pkgupgrade,udev_fix,armbian(armbian_net,mainsailos,klipper,is_req_preinstall,moonraker,mainsail,timelapse,crowsnest,sonar))" +MODULES="base(pkgupgrade,udev_fix,armbian(headless_nm,mainsailos,klipper,is_req_preinstall,moonraker,mainsail,timelapse,crowsnest,sonar))" # export Variables export DOWNLOAD_BASE_URL diff --git a/config/armbian/orangepi3lts b/config/armbian/orangepi3lts index fad40eb06..a81dbaa06 100644 --- a/config/armbian/orangepi3lts +++ b/config/armbian/orangepi3lts @@ -5,8 +5,8 @@ BASE_ARCH="arm64" # Image source -DOWNLOAD_URL_CHECKSUM="${DOWNLOAD_BASE_URL}/armbian-orangepi3_lts_bullseye.img.xz.sha256" -DOWNLOAD_URL_IMAGE="${DOWNLOAD_BASE_URL}/armbian-orangepi3_lts_bullseye.img.xz" +DOWNLOAD_URL_CHECKSUM="${DOWNLOAD_BASE_URL}/armbian-orangepi3_lts_bookworm.img.xz.sha256" +DOWNLOAD_URL_IMAGE="${DOWNLOAD_BASE_URL}/armbian-orangepi3_lts_bookworm.img.xz" # export Variables export BASE_ARCH diff --git a/config/armbian/orangepi4lts b/config/armbian/orangepi4lts index 6fbcf889a..0bc5cb703 100644 --- a/config/armbian/orangepi4lts +++ b/config/armbian/orangepi4lts @@ -5,8 +5,8 @@ BASE_ARCH="arm64" # Image source -DOWNLOAD_URL_CHECKSUM="${DOWNLOAD_BASE_URL}/armbian-orangepi4_lts_bullseye.img.xz.sha256" -DOWNLOAD_URL_IMAGE="${DOWNLOAD_BASE_URL}/armbian-orangepi4_lts_bullseye.img.xz" +DOWNLOAD_URL_CHECKSUM="${DOWNLOAD_BASE_URL}/armbian-orangepi4_lts_bookworm.img.xz.sha256" +DOWNLOAD_URL_IMAGE="${DOWNLOAD_BASE_URL}/armbian-orangepi4_lts_bookworm.img.xz" # export Variables export BASE_ARCH diff --git a/config/armbian/orangepi_zero2 b/config/armbian/orangepi_zero2 index 76a09f1de..83ea234c8 100644 --- a/config/armbian/orangepi_zero2 +++ b/config/armbian/orangepi_zero2 @@ -5,8 +5,8 @@ BASE_ARCH="arm64" # Image source -DOWNLOAD_URL_CHECKSUM="${DOWNLOAD_BASE_URL}/armbian-orangepi_zero2_bullseye.img.xz.sha256" -DOWNLOAD_URL_IMAGE="${DOWNLOAD_BASE_URL}/armbian-orangepi_zero2_bullseye.img.xz" +DOWNLOAD_URL_CHECKSUM="${DOWNLOAD_BASE_URL}/armbian-orangepi_zero2_bookworm.img.xz.sha256" +DOWNLOAD_URL_IMAGE="${DOWNLOAD_BASE_URL}/armbian-orangepi_zero2_bookworm.img.xz" # export Variables export BASE_ARCH diff --git a/config/orangepi/default b/config/orangepi/default index 68e88d276..87261b95c 100644 --- a/config/orangepi/default +++ b/config/orangepi/default @@ -18,7 +18,7 @@ BASE_IMAGE_RASPBIAN="no" # partition resizing BASE_ROOT_PARTITION="2" -BASE_IMAGE_ENLARGEROOT=2500 +BASE_IMAGE_ENLARGEROOT=3500 BASE_IMAGE_RESIZEROOT=600 # Compress not needed due compression done in workflow BASE_RELEASE_COMPRESS=no diff --git a/config/raspberry/default b/config/raspberry/default index 18d0d138d..912eab802 100644 --- a/config/raspberry/default +++ b/config/raspberry/default @@ -4,17 +4,15 @@ # Declare Variables before exporting. # See https://www.shellcheck.net/wiki/SC2155 -# New locations after Bullseye turned into 'oldstable' -DOWNLOAD_BASE_URL="https://downloads.raspberrypi.org/raspios_oldstable_lite_arm64/images/raspios_oldstable_lite_arm64-2023-12-06/2023-12-05-raspios-bullseye-arm64-lite.img.xz" -DOWNLOAD_URL_CHECKSUM="${DOWNLOAD_BASE_URL}.sha256" -DOWNLOAD_URL_IMAGE="${DOWNLOAD_BASE_URL}.torrent" - -BASE_IMAGE_ENLARGEROOT=4500 +BASE_IMAGE_ENLARGEROOT=5500 BASE_IMAGE_RESIZEROOT=600 # Compress not needed due compression done in workflow BASE_RELEASE_COMPRESS=no # Modules are valid for 32bit and 64bit images -MODULES="base(pkgupgrade,udev_fix,mainsailos(net,piconfig,klipper,is_req_preinstall,moonraker,timelapse,mainsail,crowsnest,sonar,password-for-sudo),postrename)" +MODULES="base(pkgupgrade,udev_fix,mainsailos(headless_nm,piconfig,klipper,is_req_preinstall,moonraker,timelapse,mainsail,crowsnest,sonar,password-for-sudo),postrename)" + +DOWNLOAD_URL_CHECKSUM="https://downloads.raspberrypi.org/raspios_lite_arm64_latest.sha256" +DOWNLOAD_URL_IMAGE="https://downloads.raspberrypi.org/raspios_lite_arm64_latest.torrent" # export Variables export DOWNLOAD_BASE_URL diff --git a/config/raspberry/rpi32 b/config/raspberry/rpi32 index 9bee05d46..c2591f68c 100644 --- a/config/raspberry/rpi32 +++ b/config/raspberry/rpi32 @@ -4,10 +4,8 @@ # Declare Variables before exporting. # See https://www.shellcheck.net/wiki/SC2155 -# New locations after Bullseye turned into 'oldstable' -DOWNLOAD_BASE_URL="https://downloads.raspberrypi.org/raspios_oldstable_lite_armhf/images/raspios_oldstable_lite_armhf-2023-12-06/2023-12-05-raspios-bullseye-armhf-lite.img.xz" -DOWNLOAD_URL_CHECKSUM="${DOWNLOAD_BASE_URL}.sha256" -DOWNLOAD_URL_IMAGE="${DOWNLOAD_BASE_URL}.torrent" +DOWNLOAD_URL_CHECKSUM="https://downloads.raspberrypi.org/raspios_lite_armhf_latest.sha256" +DOWNLOAD_URL_IMAGE="https://downloads.raspberrypi.org/raspios_lite_armhf_latest.torrent" export DOWNLOAD_BASE_URL export DOWNLOAD_URL_CHECKSUM diff --git a/config/raspberry/rpi64 b/config/raspberry/rpi64 index 3a29f75e2..bcc9e8e66 100644 --- a/config/raspberry/rpi64 +++ b/config/raspberry/rpi64 @@ -12,4 +12,4 @@ export BASE_ARCH ### JSON sniplet Setup ### NOTE: Please see all config files for setup variables!!! # shellcheck disable=SC2034 -JSON_SUPPORTED_SBC="pi3-64bit pi4-64bit" +JSON_SUPPORTED_SBC="pi3-64bit pi4-64bit pi5-64bit" diff --git a/config/raspberry/rpi64-ks b/config/raspberry/rpi64-ks index 103f4f8e6..dc19b6aea 100644 --- a/config/raspberry/rpi64-ks +++ b/config/raspberry/rpi64-ks @@ -6,12 +6,15 @@ BASE_ARCH="arm64" +BASE_IMAGE_ENLARGEROOT=6500 + # Changed modules -MODULES="base,pkgupgrade,udev_fix,mainsailos(net,piconfig,klipper,is_req_preinstall,moonraker,timelapse,mainsail,klipperscreen,crowsnest,sonar,password-for-sudo),postrename" +MODULES="base(pkgupgrade,udev_fix,mainsailos(net,piconfig,klipper,is_req_preinstall,moonraker,timelapse,mainsail,klipperscreen,crowsnest,sonar,password-for-sudo),postrename)" # export variables export BASE_ARCH export MODULES +export BASE_IMAGE_ENLARGEROOT ### JSON sniplet Setup ### NOTE: Please see all config files for setup variables!!! diff --git a/src/modules/headless_nm/config b/src/modules/headless_nm/config new file mode 100755 index 000000000..709af4ff8 --- /dev/null +++ b/src/modules/headless_nm/config @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +#Shebang for better file detection +#### headless_nm install module +#### +#### Written by Stephan Wendel aka KwadFan +#### Copyright 2024 - till today +#### https://github.com/mainsail-crew/MainsailOS +#### +#### This File is distributed under GPLv3 +#### + +# shellcheck disable=all + +# Use disable power save for wifi module +[ -n "$HEADLESS_NM_DISABLE_PWRSAVE" ] || HEADLESS_NM_DISABLE_PWRSAVE=yes + +# Type of power save rclocal/service/udev +# rclocal - backwards compatibility, runs via rc.local +# service - will add an systemd.service to enable or disable behavior +# on reboots +# udev - creates a udev rules that should affect all wifi devices. + +[ -n "$HEADLESS_NM_PWRSAVE_TYPE" ] || HEADLESS_NM_PWRSAVE_TYPE=udev diff --git a/src/modules/headless_nm/filesystem/boot/WiFi-README.txt b/src/modules/headless_nm/filesystem/boot/WiFi-README.txt new file mode 100644 index 000000000..e32757a63 --- /dev/null +++ b/src/modules/headless_nm/filesystem/boot/WiFi-README.txt @@ -0,0 +1,59 @@ +Wifi-README.txt + +################################################################################ +#### IMPORTANT WARNING #### +################################################################################ +#### #### +#### First, make sure you have a decent text editor of your choice. #### +#### Notepad++, VSCode, SublimeText or similar are recommended. #### +#### #### +#### Do not use Wordpad to edit this file, it will corrupt it and your #### +#### configuration will not work. #### +#### #### +#### If you use Textedit to edit this file, #### +#### be sure to use "plain text format" and "disable smart quotes" #### +#### in "Textedit > Preferences", otherwise Textedit will use #### +#### incompatible characters and your network configuration won't work! #### +#### #### +################################################################################ + +How do I setup a new network on my OS_NAME ? +-------------------------------------------- + +1.) Copy and paste the 'headless_nm.txt.template'. + Rename this file to 'headless_nm.txt' + +2.) Now open the file with your favourite text editor. + Windows and MacOS users please read the note above! + + This file is pretty self explaining, just the 'REGDOMAIN' + needs some explaination: + + Valid country codes are: + + GB (United Kingdom) + FR (France) + DE (Germany) + US (United States) + SE (Sweden) + + For a complete list, please visit https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 + +3.) Remove the SD card afterwards. + +4.) Almost done... Please put the SD card back into your SBC and wait for it to connect. + +NOTE: + +Plug in a monitor and watch the console output to get its IP address or +consult your router's setup page to get this information. + +You could also try to reach it by its hostname. + + http://.local + +If you did not change the hostname during the initial flash, you could use + + http://OS_NAME.local + +5.) Enjoy OS_NAME :) diff --git a/src/modules/headless_nm/filesystem/boot/headless_nm.txt.template b/src/modules/headless_nm/filesystem/boot/headless_nm.txt.template new file mode 100644 index 000000000..18d5d1a3f --- /dev/null +++ b/src/modules/headless_nm/filesystem/boot/headless_nm.txt.template @@ -0,0 +1,14 @@ +#### Headless Wifi configuration + +# Your Wifis SSID +SSID="" + +# Your WiFis password +PASSWORD="" + +# Is your SSID in hidden state? [true/false] +HIDDEN="false" + +# Wifi Country code +# See Wifi-README.txt for details! +REGDOMAIN="US" diff --git a/src/modules/headless_nm/filesystem/etc/systemd/system/disable-wifi-pwr-mgmt.service b/src/modules/headless_nm/filesystem/etc/systemd/system/disable-wifi-pwr-mgmt.service new file mode 100644 index 000000000..ab9f2805d --- /dev/null +++ b/src/modules/headless_nm/filesystem/etc/systemd/system/disable-wifi-pwr-mgmt.service @@ -0,0 +1,22 @@ +#### Disable wifi power_save +#### +#### Written by Stephan Wendel aka KwadFan +#### Copyright 2022 +#### https://github.com/mainsail-crew/MainsailOS +#### +#### This File is distributed under GPLv3 +#### +#### Note: This is based on: +#### https://www.intel.com/content/www/us/en/support/articles/000006168/boards-and-kits.html + +[Unit] +Description=Disable power management for wlan0 +After=network.target + +[Service] +Type=oneshot +StandardOutput=tty +ExecStart=/usr/local/bin/pwrsave off + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/src/modules/headless_nm/filesystem/etc/systemd/system/headless_nm.service b/src/modules/headless_nm/filesystem/etc/systemd/system/headless_nm.service new file mode 100644 index 000000000..a9e226805 --- /dev/null +++ b/src/modules/headless_nm/filesystem/etc/systemd/system/headless_nm.service @@ -0,0 +1,20 @@ +#### headless_nm service +#### +#### Written by Stephan Wendel aka KwadFan +#### Copyright 2024 +#### https://github.com/mainsail-crew/MainsailOS +#### +#### This File is distributed under GPLv3 +#### + +[Unit] +Description=Setup Wifi on headless machines using NetworkManager +Before=network.target NetworkManager.service + +[Service] +Type=oneshot +StandardOutput=tty +ExecStart=/usr/local/bin/headless_nm + +[Install] +WantedBy=multi-user.target diff --git a/src/modules/headless_nm/filesystem/etc/udev/rules.d/070-wifi-powersave.rules b/src/modules/headless_nm/filesystem/etc/udev/rules.d/070-wifi-powersave.rules new file mode 100644 index 000000000..61a7f8591 --- /dev/null +++ b/src/modules/headless_nm/filesystem/etc/udev/rules.d/070-wifi-powersave.rules @@ -0,0 +1,4 @@ +ACTION=="add", \ +SUBSYSTEM=="net", \ +KERNEL=="wlan*" \ +RUN+="/usr/sbin/iw %k set power_save off" diff --git a/src/modules/headless_nm/filesystem/usr/local/bin/headless_nm b/src/modules/headless_nm/filesystem/usr/local/bin/headless_nm new file mode 100755 index 000000000..44649e34f --- /dev/null +++ b/src/modules/headless_nm/filesystem/usr/local/bin/headless_nm @@ -0,0 +1,183 @@ +#!/usr/bin/env bash +#### headless_nm +#### +#### Written by Stephan Wendel aka KwadFan +#### Copyright 2024 - till today +#### https://github.com/mainsail-crew/MainsailOS +#### +#### This File is distributed under GPLv3 +#### + +#### Description: +#### This is a wrapper for network manager to be able to setup +#### Wifi connections on headless SBC. +#### Takes setup from a file in /boot (/boot/firmware) and recreates +#### Raspberrys 'preconfigured.nmconnection' + +#### Copyright hint: This file contains code snippets from +#### Raspberrys raspi-config therefore it applies also there license +#### and copyrights! +#### See https://github.com/RPi-Distro/raspi-config/blob/bookworm/LICENSE + +#### It also reuses parts of raspberry-sys-mods +#### See https://github.com/RPi-Distro/raspberrypi-sys-mods/blob/bookworm/usr/lib/raspberrypi-sys-mods/imager_custom + +set -e + +# Global Vars +DISTRO="" +CMDLINE="/boot/firmware/cmdline.txt" +ARMBIANENV="/boot/armbianEnv.txt" +UUID="" +PSK_HASH="" +KEYMGMT="wpa-psk" +CONNFILE=/etc/NetworkManager/system-connections/preconfigured.nmconnection +SETUPFILE="$(find /boot -name "headless_nm.txt")" +REGDOMAIN="" +CFG80211="/etc/modprobe.d/cfg80211.conf" + + +# functions +log() { + local msg + msg="${1}" + logger -t headless_nm "${msg}" +} + +get_distro() { + local armbian rpi + armbian="$(find /boot -name "$(basename ${ARMBIANENV})")" + rpi="$(find /boot -name "$(basename ${CMDLINE})")" + log "Determine distribution ..." + if [[ -n "${armbian}" ]]; then + DISTRO="armbian" + elif [[ -n "${rpi}" ]]; then + DISTRO="rpi" + else + DISTRO="" + log "Could not determine distribution ... Exiting!" + exit 1 + fi + if [[ -n "${DISTRO}" ]]; then + log "Using setup profile: ${DISTRO} ..." + fi +} + +get_config() { + # shellcheck disable=SC1090 + source "${SETUPFILE}" +} + +gen_uuid() { + log "Generating UUID for connection..." + UUID="$(uuid -v4)" + declare -r UUID +} + +gen_nmconnection() { +cat <<- EOF >"${CONNFILE}" +[connection] +id=preconfigured +uuid=${UUID} +type=wifi +[wifi] +mode=infrastructure +ssid=${SSID} +hidden=${HIDDEN,,} +[ipv4] +method=auto +[ipv6] +addr-gen-mode=default +method=auto +[proxy] +EOF +} + +gen_keymgmt() { + PSK_HASH="$(gen_psk)" + if [[ -n "${PASSWORD}" ]]; then + cat <<- EOF >>${CONNFILE} +[wifi-security] +key-mgmt=${KEYMGMT} +psk=${PSK_HASH} +EOF +fi +} + +gen_psk() { + wpa_passphrase "${SSID}" "${PASSWORD}" | sed -n "/^.*[ \t]psk.*/s/[ \t]psk=//p" +} + +set_regdomain() { + log "Set registration domain to '${REGDOMAIN}' ..." + # Shameless borrowed from + # https://github.com/RPi-Distro/raspi-config/blob/d22643ade3851c42648f3676e577a622c34af49a/raspi-config#L830C3-L832C5 + if ! ischroot; then + iw reg set "${REGDOMAIN}" + fi + # set permanent + case "${DISTRO}" in + "rpi") + # Shameless borrowed from + # https://github.com/RPi-Distro/raspi-config/blob/d22643ade3851c42648f3676e577a622c34af49a/raspi-config#L822C3-L825C15 + sed -i \ + -e "s/\s*cfg80211.ieee80211_regdom=\S*//" \ + -e "s/\(.*\)/\1 cfg80211.ieee80211_regdom=$REGDOMAIN/" \ + "${CMDLINE}" + ;; + "armbian") + if [[ -f "${CFG80211}" ]]; then + rm -f "${CFG80211}" + fi + echo "options cfg80211 ieee80211_regdom=${REGDOMAIN}" > "${CFG80211}" + ;; + esac +} + +# MAIN +main() { + # Determine base distribution + get_distro + + # Check setup file is present + if [[ -f "${SETUPFILE}" ]]; then + log "Configuration file found in ${SETUPFILE}, continuing...\n" + else + log "Configuration file not found! Nothing to do, exiting...\n" + exit 0 + fi + + # Generate UUID + gen_uuid + + # Remove preconfiguration if present + if [[ -f "${CONNFILE}" ]]; then + rm -f "${CONNFILE}" + fi + + # Read config file + get_config + + # Generate preconfigured.nmconnection file + gen_nmconnection + + # Add key management and psk to preconfigured.nmconnection file + gen_keymgmt + + # Set REGDOMAIN + set_regdomain + + # NetworkManager only accepts 0600 permissions for configs + chmod 0600 "${CONNFILE}" + + # Cleanup + PSK_HASH="" + PASSWORD="" + SSID="" + log "Configuration successful written ..." + rm -f "${SETUPFILE}" +} + +if [[ "${BASH_SOURCE[0]}" = "${0}" ]]; then + main +fi diff --git a/src/modules/headless_nm/filesystem/usr/local/bin/pwrsave b/src/modules/headless_nm/filesystem/usr/local/bin/pwrsave new file mode 100755 index 000000000..c9d9417c8 --- /dev/null +++ b/src/modules/headless_nm/filesystem/usr/local/bin/pwrsave @@ -0,0 +1,90 @@ +#!/bin/bash +#### Disable wifi power_save +#### +#### Written by Stephan Wendel aka KwadFan +#### Copyright 2022 +#### https://github.com/mainsail-crew/MainsailOS +#### +#### This File is distributed under GPLv3 +#### +#### Note: This is based on: +#### https://www.intel.com/content/www/us/en/support/articles/000006168/boards-and-kits.html + + +## Error handling +set -eou pipefail + +## Debug Mode +#set -x + +### Message func +function help_msg { + echo -e "Usage:\n" + echo -e "\tpwrsave [ on | off ]" + echo -e "\t\ton\tEnables Power Management of 'wlan0'" + echo -e "\t\toff\tDisables Power Management of 'wlan0'\n" + exit 1 +} + +function has_wifi { + LC_ALL=C iwconfig wlan0 &> /dev/null && echo "0" || echo "1" +} + +function check_wifi_present { + # make sure to exit if command missing + if [ -z "$(command -v iwconfig)" ]; then + echo -e "Command 'iwconfig' not found ... [EXITING]" + exit 1 + fi + if [ "$(has_wifi)" != "0" ]; then + echo -e "[ \e[33mWARN\e[0m ] No WiFi hardware present ... [SKIPPED]" + exit 0 + fi +} + +function disable_pwr_save { + iwconfig wlan0 power off + echo -e "[ \e[32mOK\e[0m ] Disabled Power Management for wlan0" +} + + +function enable_pwr_save { + iwconfig wlan0 power on + echo -e "[ \e[32mOK\e[0m ] Enabled Power Management for wlan0" +} + + +### MAIN +function main { + local arg + if [ "$(id -u)" != "0" ]; then + echo -e "\n$(basename "${0}"): This script needs root priviledges!\n" + exit 1 + fi + if [ "${#}" == "0" ]; then + echo -e "$(basename "${0}"): No argument set!" + help_msg + fi + if [ "${#}" -gt 1 ]; then + echo -e "$(basename "${0}"): Too many arguments set!" + help_msg + fi + arg="${1}" + case "${arg}" in + "on") + check_wifi_present + enable_pwr_save + ;; + "off") + check_wifi_present + disable_pwr_save + ;; + ?|*) + echo -e "$(basename "${0}"): Unknown argument '${arg}' !" + help_msg + ;; + esac +} + +main "${@}" +exit 0 diff --git a/src/modules/headless_nm/filesystem/usr/local/bin/pwrsave-udev b/src/modules/headless_nm/filesystem/usr/local/bin/pwrsave-udev new file mode 100755 index 000000000..45c6a5030 --- /dev/null +++ b/src/modules/headless_nm/filesystem/usr/local/bin/pwrsave-udev @@ -0,0 +1,104 @@ +#!/bin/bash +#### Disable wifi power_save +#### +#### Written by Stephan Wendel aka KwadFan +#### Copyright 2022 +#### https://github.com/mainsail-crew/MainsailOS +#### +#### This File is distributed under GPLv3 +#### +#### Note: This is based on: +#### https://www.intel.com/content/www/us/en/support/articles/000006168/boards-and-kits.html + + +## Error handling +set -eou pipefail + +## Debug Mode +#set -x + +### Message func +function help_msg { + echo -e "Usage:\n" + echo -e "\tpwrsave-udev [ on | off | create ]" + echo -e "\t\ton\tEnables Power Management via udev rule" + echo -e "\t\toff\tDisables Power Management via udev rule" + echo -e "\t\tcreate\tCreate Power Management udev rule\n" + exit 1 +} + + +### Check rule exist +function check_rule { + if [ ! -f /etc/udev/rules.d/070-wifi-powersave.rules ]; then + echo -e "[ \e[31mERROR\e[0m ] Udev Rule for WiFi Powermanagement not found!" + help_msg + fi +} + +function disable_pwr_save { + sed -i 's/on/off/' /etc/udev/rules.d/070-wifi-powersave.rules + echo -e "[ \e[32mOK\e[0m ] Disabled Power Management" +} + + +function enable_pwr_save { + sed -i 's/off/on/' /etc/udev/rules.d/070-wifi-powersave.rules + echo -e "[ \e[32mOK\e[0m ] Enabled Power Management" +} + +function create_rule { +if [ -f /etc/udev/rules.d/070-wifi-powersave.rules ]; then + echo -e "[ \e[33mSKIPPED\e[0m ] Udev rule already exists!" + exit 0 +fi + +cat << EOF > /etc/udev/rules.d/070-wifi-powersave.rules +ACTION=="add", \ +SUBSYSTEM=="net", \ +KERNEL=="wlan*" \ +RUN+="/usr/sbin/iw %k set power_save off" +EOF +echo -e "[ \e[32mOK\e[0m ] Created Udev rule ... \n" +echo -e "Please 'reboot' to take changes effect.\n" +} + + + +### MAIN +function main { + local arg + if [ "$(id -u)" != "0" ]; then + echo -e "\n$(basename "${0}"): This script needs root priviledges!\n" + exit 1 + fi + if [ "${#}" == "0" ]; then + echo -e "$(basename "${0}"): No argument set!" + help_msg + fi + if [ "${#}" -gt 1 ]; then + echo -e "$(basename "${0}"): Too many arguments set!" + help_msg + fi + arg="${1}" + if [ "${arg}" == "create" ]; then + create_rule + exit 0 + fi + check_rule + case "${arg}" in + "on") + enable_pwr_save + ;; + "off") + disable_pwr_save + ;; + ?|*) + echo -e "$(basename "${0}"): Unknown argument '${arg}' !" + help_msg + ;; + esac +} + +main "${@}" +exit 0 diff --git a/src/modules/headless_nm/start_chroot_script b/src/modules/headless_nm/start_chroot_script new file mode 100755 index 000000000..e51059cd1 --- /dev/null +++ b/src/modules/headless_nm/start_chroot_script @@ -0,0 +1,71 @@ +#!/usr/bin/env bash +#Shebang for better file detection +#### headless_nm install module +#### +#### Written by Stephan Wendel aka KwadFan +#### Copyright 2024 - till today +#### https://github.com/mainsail-crew/MainsailOS +#### +#### This File is distributed under GPLv3 +#### + +set -Ee + +export LC_ALL=C + +# shellcheck disable=SC1091 +source /common.sh +install_cleanup_trap + +# Install dependencies +apt-get update +apt-get install -y uuid + +# Install scripts +unpack filesystem/usr/local/bin /usr/local/bin root +unpack filesystem/boot /boot root +unpack filesystem/etc /etc root + +# Enable Service +systemctl_if_exists enable headless_nm.service + +# set OS_NAME in Wifi-README.txt according to DIST_NAME +if [ -f "/boot/WiFi-README.txt" ]; then + sed -i 's|OS_NAME|'"${DIST_NAME}"'|g' /boot/WiFi-README.txt +fi + +# Install powersave option +if [ "$HEADLESS_NM_DISABLE_PWRSAVE" == "yes" ]; then + + # Use rc.local + if [ "$HEADLESS_NM_PWRSAVE_TYPE" == "rclocal" ]; then + echo_green "Modifying /etc/rc.local ..." + sed -i 's@exit 0@@' /etc/rc.local + (echo "# Disable WiFi Power Management"; \ + echo 'echo "Disabling power management for wlan0 ..."' ; \ + echo "/usr/local/bin/pwrsave off"; echo "exit 0") >> /etc/rc.local + fi + # Use service + if [ "$HEADLESS_NM_PWRSAVE_TYPE" == "service" ]; then + echo_green "Installing disable-wifi-pwr-mgmt service ..." + unpack filesystem/etc/systemd/system /etc/systemd/system root + systemctl_if_exists enable disable-wifi-pwr-mgmt.service + fi + # Use udev rule + if [ "$HEADLESS_NM_PWRSAVE_TYPE" == "udev" ]; then + echo_green "Installing WiFi Power Management udev rule ..." + unpack filesystem/etc/udev/rules.d /etc/udev/rules.d root + fi + # strip out unneeded script, depending on choose + if [ "$HEADLESS_NM_PWRSAVE_TYPE" != "udev" ]; then + rm -f /usr/local/bin/pwrsave-udev + else + rm -f /usr/local/bin/pwrsave + fi +fi + +# Remove scripts if powersave option is not used. +if [ "$HEADLESS_NM_DISABLE_PWRSAVE" == "no" ]; then + rm -f /usr/local/bin/pwrsave-udev + rm -f /usr/local/bin/pwrsave +fi diff --git a/src/modules/piconfig/start_chroot_script b/src/modules/piconfig/start_chroot_script index 483f8adf8..2ac22c378 100644 --- a/src/modules/piconfig/start_chroot_script +++ b/src/modules/piconfig/start_chroot_script @@ -64,7 +64,10 @@ check_install_pkgs i2c-tools echo_green "Disabling Bluetooth related services..." systemctl_if_exists disable hciuart.service systemctl_if_exists disable bluetooth.service -systemctl_if_exists disable bluealsa.service +# bookworm patch +if ! grep "bookworm" /etc/os-release; then + systemctl_if_exists disable bluealsa.service +fi # Step 11: Increase swapfile size if [[ -f "${PICONFIG_SWAP_CONF_FILE}" ]]; then diff --git a/src/modules/postrename/filesystem/root/postrename b/src/modules/postrename/filesystem/root/postrename index afd2f994f..a762a7bcf 100644 --- a/src/modules/postrename/filesystem/root/postrename +++ b/src/modules/postrename/filesystem/root/postrename @@ -121,7 +121,7 @@ patch_polkit_rules() { sed -i 's/pi/'"${DEFAULT_USER}"'/g' "${polkit_dir}/moonraker.rules" fi if [[ -f "${polkit_usr_dir}/moonraker.rules" ]]; then - sed -i 's/pi/'"${DEFAULT_USER}"'/g' "${polkit_usr_dir}/moonraker.rules" + sed -i 's/ "pi"/ \"'"${DEFAULT_USER}"'\"/g' "${polkit_usr_dir}/moonraker.rules" fi if [[ -f "${polkit_legacy_dir}/10-moonraker.pkla" ]]; then sed -i 's/pi/'"${DEFAULT_USER}"'/g' "${polkit_legacy_dir}/10-moonraker.pkla"