Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix syntax error in net module #191

Merged
merged 11 commits into from
Dec 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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