Skip to content

Commit

Permalink
fix: fix syntax error in net module (#191)
Browse files Browse the repository at this point in the history
* fix: fix syntax error in net module

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

* chore: add patch script

This adds a script that can be used to patch MainsailOS to latest changes

Adds README.md for usage

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

Signed-off-by: Stephan Wendel <me@stephanwe.de>
  • Loading branch information
KwadFan committed Dec 30, 2022
1 parent efe1b68 commit cb890af
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 9 deletions.
11 changes: 11 additions & 0 deletions patches/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Patches

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

## 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!
135 changes: 135 additions & 0 deletions patches/patch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/usr/bin/env bash

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

# Error Handling
set -eo pipefail

# Debug
# set -x

### Variables
# shellcheck disable=SC2034
DEBIAN_FRONTEND="noninteractive"

# Global Vars
MAINSAILOS_VER="1.0.1"

TITLE="\e[31mMainsailOS Patcher\e[0m - Patch OS to latest changes (MainsailOS ${MAINSAILOS_VER})"
RELEASE_FILE="/etc/mainsailos-release"
BASE_DL_URL="https://raw.githubusercontent.com/mainsail-crew/MainsailOS/develop"

# 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_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"
}

# Helper Funcs

## CHeck Version
check_version(){
local version
version="$(grep "1\.[0-9]\.[0-9]" "${RELEASE_FILE}" 2> /dev/null || true)"
if [[ -z "${version}" ]]; then
echo_red "Minimum required MainsailOS Version is 1.0.0! ... [Exiting]"
exit 1
fi
}

# Patch Funcs

# patch mainsailos-release file
patch_release_file(){
sudo sed -i 's|[0-9]\.[0-9]\.[0-9]|'"${MAINSAILOS_VER}"'|' "${RELEASE_FILE}"
}

## This patches udev rules error
## See https://github.com/mainsail-crew/MainsailOS/issues/190
## Keep function naming convention for patches!
## For ex: patch from 1.0.0 to 1.0.1 is named patch_101

patch_101(){
local dl_file
dl_file="${BASE_DL_URL}/src/modules/net/filesystem/usr/local/bin/pwrsave-udev"
echo_blue "Running Wifi Powersave Patch ..."
echo -e "Search for pwrsave-udev script ..."
if [[ ! -f "/usr/local/bin/powersave-udev" ]]; then
echo -e "Script not found! Installing ..."
sudo wget -O "/usr/local/bin/pwrsave-udev" "${dl_file}"
sudo chmod +x "/usr/local/bin/pwrsave-udev"
echo -e "Script not found! Installing ... \t${MP_OK}"
else
echo -e "Script found! ... \t${MP_SK}"
fi

echo -e "Search for udev Rule file ..."
if [[ ! -f "/etc/udev/rules.d/070-wifi-powersave.rules" ]]; then
echo -e "udev rule not found! Installing ..."
sudo bash -c '/usr/local/bin/pwrsave-udev create'
sudo bash -c '/usr/local/bin/pwrsave-udev off'
echo -e "udev rule not found! Installing ...\t${MP_OK}"
else
echo -e "udev Rule found! ... \t${MP_SK}"
fi
echo_blue "Running Wifi Powersave Patch ... ${MP_OK}"
}


### Main

# Step 1: Print Header
print_header

# Step 2: Check Version requirement
check_version

# Step 3: Apply patches
patch_101

# Step 4: Patch release file to match versions
patch_release_file

# Step 5: Print footer
print_footer
4 changes: 2 additions & 2 deletions src/modules/net/config
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# shellcheck disable=all

# Use disable power save for wifi module
[ -n "$NETWORK_DISABLE_PWRSAVE" ] || NETWORK_DISABLE_PWRSAVE=yes
[ -n "$NET_DISABLE_PWRSAVE" ] || NET_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 "$NETWORK_PWRSAVE_TYPE" ] || NETWORK_PWRSAVE_TYPE=udev
[ -n "$NET_PWRSAVE_TYPE" ] || NET_PWRSAVE_TYPE=udev
13 changes: 6 additions & 7 deletions src/modules/net/start_chroot_script
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
# Last modification: August/2022
#
########
set -x
set -e
set -Ee

export LC_ALL=C

Expand Down Expand Up @@ -56,32 +55,32 @@ echo '/sbin/iptables -t mangle -I POSTROUTING 1 -o wlan0 -p udp --dport 123 -j T
echo 'exit 0' >> /etc/rc.local

# Install powersave option
if [ "$NETWORK_DISABLE_PWRSAVE" == "yes" ]; then
if [ "$NET_DISABLE_PWRSAVE" == "yes" ]; then

# Copy pwrsave script
unpack filesystem/usr/local/bin /usr/local/bin root

# Use rc.local
if [ "$NETWORK_PWRSAVE_TYPE" == "rclocal" ]; then
if [ "$NET_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 [ "$NETWORK_PWRSAVE_TYPE" == "service" ]; then
if [ "$NET_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 [ "$NETWORK_PWRSAVE_TYPE" == "udev" ]; then
if [ "$NET_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 [ "$NETWORK_PWRSAVE_TYPE" != "udev" ]; then
if [ "$NET_PWRSAVE_TYPE" != "udev" ]; then
rm -f /usr/local/bin/pwrsave-udev
else
rm -f /usr/local/bin/pwrsave
Expand Down

0 comments on commit cb890af

Please sign in to comment.