Skip to content

Commit

Permalink
fix: fix broken udev package (mainsail-crew#224)
Browse files Browse the repository at this point in the history
* fix: fix broken udev package

Signed-off-by: Stephan Wendel <me@stephanwe.de>

* chore: add patch script

Includes updated patches/README.md

Signed-off-by: Stephan Wendel <me@stephanwe.de>

---------

Signed-off-by: Stephan Wendel <me@stephanwe.de>
  • Loading branch information
KwadFan committed Oct 28, 2023
1 parent 128882f commit 863e857
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 5 deletions.
2 changes: 1 addition & 1 deletion config/armbian/default
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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,armbian(armbian_net,mainsailos,klipper,is_req_preinstall,moonraker,mainsail,timelapse,crowsnest,sonar)"
MODULES="base,udev_fix,armbian(armbian_net,mainsailos,klipper,is_req_preinstall,moonraker,mainsail,timelapse,crowsnest,sonar)"

# export Variables
export DOWNLOAD_BASE_URL
Expand Down
2 changes: 1 addition & 1 deletion config/orangepi/default
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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,orangepi(orangepi_net,mainsailos,klipper,is_req_preinstall,moonraker,mainsail,timelapse,crowsnest,sonar)"
MODULES="base,pkgupgrade,udev_fix,orangepi(orangepi_net,mainsailos,klipper,is_req_preinstall,moonraker,mainsail,timelapse,crowsnest,sonar)"

# export Variables
export DOWNLOAD_BASE_URL
Expand Down
2 changes: 1 addition & 1 deletion config/raspberry/default
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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,mainsailos(net,piconfig,klipper,is_req_preinstall,moonraker,timelapse,mainsail,crowsnest,sonar,password-for-sudo),postrename"
MODULES="base,pkgupgrade,udev_fix,mainsailos(net,piconfig,klipper,is_req_preinstall,moonraker,timelapse,mainsail,crowsnest,sonar,password-for-sudo),postrename"

# export Variables
export BASE_IMAGE_ENLARGEROOT
Expand Down
40 changes: 39 additions & 1 deletion patches/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,48 @@

This Folder contains a script to patch MainsailOS to latest changes.

## Usage
## patch101.sh

This is intended to patch MainsailOS version 1.0.0 to 1.0.1
This fixes an error with WiFi powersave rules.
_**DO NOT RUN THIS ON LATER VERSIONS!!!**_

### Usage:

`curl -sSL https://raw.githubusercontent.com/mainsail-crew/MainsailOS/develop/patches/patch.sh | bash`

This will ask you for sudo password!

In most cases a reboot is required!

## udev-fix.sh

This is intended to patch udev rules which has a Bug in udev package (version: 247.3-7+deb11u2).
Which does not create `/dev/serial/by-id` symlinks for your MCU.\
For further details see:

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1035094

This is fixed by:
https://github.com/systemd/systemd/pull/25246

What we do:

- Running `apt-get update`
- Running `apt-get upgrade --yes`
- `curl`ing the patched rule file from systemd repo
- Copying to desired location in `/etc/udev/rules.d/60-serial.rules`

This overwrites behaviour in the default configuration.
Since this is the version of the master branch of systemd/udev there is no further
need to intervention even on updates.

_**NOTE: DO NOT RUN THIS PATCH IF YOU ARE PRINTING!!!**_

### Usage:

`curl -sSL https://raw.githubusercontent.com/mainsail-crew/MainsailOS/develop/patches/udev-fix.sh | bash`

This will ask you for sudo password!

A reboot is essential!
2 changes: 1 addition & 1 deletion patches/patch.sh → patches/patch101.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
####
#### Written by Stephan Wendel aka KwadFan <me@stephanwe.de>
#### Copyright 2021
#### https://github.com/mainsail-crew/crowsnest
#### https://github.com/mainsail-crew/MainsailOS
####
#### This File is distributed under GPLv3
####
Expand Down
104 changes: 104 additions & 0 deletions patches/udev-fix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env bash

#### Patch Script
#### This will patch MainsailOS udev rule
####
#### Written by Stephan Wendel aka KwadFan <me@stephanwe.de>
#### Copyright 2021
#### https://github.com/mainsail-crew/MainsailOS
####
#### This File is distributed under GPLv3
####

#### This should fix error in udev not creating symlinks fpr serial devices.
#### For details see: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1035094
#### This is fixed by: https://github.com/systemd/systemd/pull/25246
#### To fix this error in MainsailOS we implement that file as 'user rule'.

# shellcheck disable=SC2034

# Error Handling
set -eo pipefail

# Debug
# set -x

### Variables
DEBIAN_FRONTEND="noninteractive"
TITLE="\e[31mMainsailOS Patcher\e[0m - udev rule fix"
UDEV_PKG_VERSION="$(dpkg-query -s udev | grep "Version" | sed 's/Version\: //')"
UDEV_FIX_RAW_RULE_FILE="https://raw.githubusercontent.com/systemd/systemd/main/rules.d/60-serial.rules"
UDEV_FIX_TMP_FILE="/tmp/60-serial.rules"
UDEV_FIX_OUTPUT_FILE="/etc/udev/rules.d/60-serial.rules"

# Message Vars
MP_OK="\e[32mOK\e[0m"
MP_SK="\e[33mSKIPPED\e[0m"

## Helper funcs

## Message Funcs

echo_green(){
echo -e "\e[32m${1}\e[0m"
}

echo_red(){
echo -e "\e[31m${1}\e[0m"
}

echo_blue(){
echo -e "\e[34m${1}\e[0m"
}

echo_yellow(){
echo -e "\e[33m${1}\e[0m"
}

print_header(){
echo -e "${TITLE}\n"
echo_blue "Ahoi!"
echo -e "Please be patient, this might take a while ..."
echo_yellow "HINT: This should also work for any other Debian/Armbian based Distribution\n"
echo_red "\tYou'll be prompted for sudo password!\n"
# Dirty hack to grant root priviledges
sudo echo -e "\n"
echo -e "Trying to patch your system ..."
}

print_footer(){
echo -e "\nThank you for being patient ..."
echo_red "Reboot as soon as possible!\n"
}

# Patch Funcs

patch_udev(){
if [[ -n "${UDEV_PKG_VERSION}" ]] && [[ "${UDEV_PKG_VERSION}" = "247.3-7+deb11u2" ]]; then
echo_red "'udev' version: ${UDEV_PKG_VERSION}, is affected by bug ..."
echo_green "Install patched udev rule from systemd git repository ..."
curl -sSL "${UDEV_FIX_RAW_RULE_FILE}" > "${UDEV_FIX_TMP_FILE}"
sudo cp "${UDEV_FIX_TMP_FILE}" "${UDEV_FIX_OUTPUT_FILE}"
rm -f "${UDEV_FIX_TMP_FILE}"
else
echo_green "'udev' version: ${UDEV_PKG_VERSION}, is NOT affected by bug ... [SKIPPED]"
fi
}

### Main
# Step 1: Print Header
print_header

# Step 2: Run apt-get update
sudo apt-get update

# Step 3: Run apt-get upgrade
sudo apt-get upgrade --yes

# Step 4: Apply patches
patch_udev

# Step 5: Print footer
print_footer

exit 0
20 changes: 20 additions & 0 deletions src/modules/udev_fix/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
#### MainsailOS udev_fix
####
#### Written by Stephan Wendel aka KwadFan <me@stephanwe.de>
#### Copyright 2023 - till today
#### https://github.com/mainsail-crew/MainsailOS
####
#### This File is distributed under GPLv3
####

#### This should fix error in udev not creating symlinks fpr serial devices.
#### For details see: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1035094
#### This is fixed by: https://github.com/systemd/systemd/pull/25246
#### To fix this error in MainsailOS we implement that file as 'user rule'.

#shellcheck disable=all

[[ -n "${UDEV_FIX_RAW_RULE_FILE}" ]] || UDEV_FIX_RAW_RULE_FILE="https://raw.githubusercontent.com/systemd/systemd/main/rules.d/60-serial.rules"
[[ -n "${UDEV_FIX_OUTPUT_FILE}" ]] || UDEV_FIX_OUTPUT_FILE="/etc/udev/rules.d/60-serial.rules"
[[ -n "${UDEV_FIX_PKGS}" ]] || UDEV_FIX_PKGS="systemd udev"
47 changes: 47 additions & 0 deletions src/modules/udev_fix/start_chroot_script
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
#### MainsailOS MainsailOS udev_fix
####
#### Written by Stephan Wendel aka KwadFan <me@stephanwe.de>
#### Copyright 2023 - till today
#### https://github.com/mainsail-crew/MainsailOS
####
#### This File is distributed under GPLv3
####

#### This should fix error in udev not creating symlinks fpr serial devices.
#### For details see: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1035094
#### This is fixed by: https://github.com/systemd/systemd/pull/25246
#### To fix this error in MainsailOS we implement that file as 'user rule'.

# shellcheck enable=require-variable-braces
# Source error handling, leave this in place
set -Ee

# Source CustomPIOS common.sh
# shellcheck disable=SC1091
source /common.sh
install_cleanup_trap


echo_green "Running 'udev' fix ..."

# Step 1: Ensure systemd, udev are up to date (armbian workaround)
if [[ -f /etc/armbian.txt ]]; then
echo_green "Armbian base image detected ..."
echo_green "Updating ${UDEV_FIX_PKGS} first ..."
apt-get update
# Disable shellcheck here, because we need 'word splitting'
# shellcheck disable=SC2086
apt-get --yes install --only-upgrade ${UDEV_FIX_PKGS}
fi

# Step 2: Fix broken udev (remove after debian releases patch)
UDEV_PKG_VERSION="$(dpkg-query -s udev | grep "Version" | sed 's/Version\: //')"

if [[ -n "${UDEV_PKG_VERSION}" ]] && [[ "${UDEV_PKG_VERSION}" = "247.3-7+deb11u2" ]]; then
echo_red "'udev' version: ${UDEV_PKG_VERSION}, is affected by bug ..."
echo_green "Install patched udev rule from systemd git repository ..."
curl -sSL "${UDEV_FIX_RAW_RULE_FILE}" > "${UDEV_FIX_OUTPUT_FILE}"
else
echo_green "'udev' version: ${UDEV_PKG_VERSION}, is NOT affected by bug ... [SKIPPED]"
fi

0 comments on commit 863e857

Please sign in to comment.