Help me update my HFSC shaper scripts for fw4/nftables

Generally, maybe an easy to use install/unistall script for the first use would help new users? Something like this:

Summary

install.sh

#!/bin/sh

echo "Starting the installation process..."

# Checking and installing required packages
REQUIRED_PACKAGES="kmod-sched ip-full kmod-veth tc"
for pkg in $REQUIRED_PACKAGES; do
    if ! opkg list-installed | grep -q "^$pkg "; then
        echo "Installing $pkg..."
        opkg update && opkg install "$pkg"
    fi
done

echo "Downloading and setting up scripts..."

# Download and set execution permissions for the scripts
wget -O /etc/SimpleHFSCgamerscript.sh https://raw.githubusercontent.com/dlakelan/routerperf/nftables/SimpleHFSCgamerscript.sh && chmod a+x /etc/SimpleHFSCgamerscript.sh
wget -O /etc/hotplug.d/iface/13-SimpleHFSCGamerScriptHotplug https://raw.githubusercontent.com/dlakelan/routerperf/nftables/13-SimpleHFSCGamerScriptHotplug
mkdir -p /usr/share/nftables.d/ruleset-post/ && wget -O /usr/share/nftables.d/ruleset-post/dscptag.nft https://raw.githubusercontent.com/dlakelan/routerperf/nftables/dscptag.nft

echo "Configuring veth interface..."

# Configure the veth interface
uci set network.veth=interface
uci set network.veth.proto='none'
uci set network.veth.ifname='lanveth'
uci set network.veth.device='lanveth'
uci commit network

echo "Checking for LAN firewall zone and adding veth interface if it exists..."

LAN_ZONE_NAME=$(uci show firewall | grep -E "firewall.@zone\[.*\].name='lan'" | cut -d'.' -f2)
if [ ! -z "$LAN_ZONE_NAME" ]; then
    uci add_list firewall.$LAN_ZONE_NAME.network='veth'
    uci commit firewall
    /etc/init.d/firewall reload
    echo "veth interface added to LAN firewall zone."
else
    echo "LAN firewall zone does not exist, skipping addition."
fi

echo "Reloading network service..."
/etc/init.d/network reload

echo "Installation completed successfully!"

uninstall.sh

#!/bin/sh

echo "Starting the uninstallation process..."

echo "Removing specific scripts..."

# Remove the specific script and its configuration
rm -f /etc/SimpleHFSCgamerscript.sh
rm -f /etc/hotplug.d/iface/13-SimpleHFSCGamerScriptHotplug
rm -f /usr/share/nftables.d/ruleset-post/dscptag.nft

echo "Removing veth interface configuration..."

# Remove the veth interface configuration
uci delete network.veth
uci commit network

echo "Checking for LAN firewall zone to remove veth interface..."

LAN_ZONE_NAME=$(uci show firewall | grep -E "firewall.@zone\[.*\].name='lan'" | cut -d'.' -f2)
if [ ! -z "$LAN_ZONE_NAME" ]; then
    uci del_list firewall.$LAN_ZONE_NAME.network='veth'
    uci commit firewall
    /etc/init.d/firewall reload
    echo "veth interface removed from LAN firewall zone."
else
    echo "LAN firewall zone does not exist, skipping removal."
fi

echo "Reloading network service..."
/etc/init.d/network reload

echo "Uninstallation completed successfully!"

Here is how you can use it:

Download the Installation Script: Once logged into your router, enter the following command to download the installation script to the root directory:

cd /root
wget https://raw.githubusercontent.com/dlakelan/routerperf/master/install.sh && chmod +x install.sh

Run the Installation Script: Execute the script by typing:

./install.sh

The script will automatically handle the installation process, including downloading necessary files, setting up the veth interface, and adding it to the LAN firewall zone.

Uninstallation Guide

If you wish to revert the changes made by the installation script, follow these steps:

  1. Download the Uninstallation Script: Use the following command to download the uninstallation script to the root directory:
cd /root
wget https://raw.githubusercontent.com/dlakelan/routerperf/master/uninstall.sh && chmod +x uninstall.sh

Run the Uninstallation Script: Execute the script by typing:

./uninstall.sh

The script will remove the configurations applied during the installation, including removing the veth interface from the network and firewall configurations.

After installing you will still have to edit the files according to your needs…

  1. Edit edit SimpleHFSCgamerscript.sh under:
/etc/SimpleHFSCgamerscript.sh

to set your WAN and LAN interfaces, your network speeds, and the speed you reserve for your game (GAMEUP and GAMEDOWN)

  1. edit the dscptag.nft script under:
/usr/share/nftables.d/ruleset-post/dscptag.nft
  1. Run the script
/etc/SimpleHFSCgamerscript.sh