Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ more about cake-autorate. This is the history of changes.

<!-- Zep7RkGZ52|NEW ENTRY MARKER, DO NOT REMOVE -->

## [Unreleased]

- Introduce support for running on Debian/Ubuntu

## 2026-03-04 - Version 3.5.0

- Introduce MQTT data export functionality
Expand Down
39 changes: 39 additions & 0 deletions INSTALLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,45 @@ required tools. To use it:
sh /tmp/cake-autorate_setup.sh
```

## Installation on Debian/Ubuntu

- Set up [cake-on-wan](https://github.com/sbivol/cake-on-wan)

- Install prerequisites:

```bash
sudo apt install fping jq
```

- Install cake-autorate:

```bash
wget -O /tmp/cake-autorate_setup.sh https://raw.githubusercontent.com/lynxthecat/cake-autorate/master/setup.sh
sudo sh /tmp/cake-autorate_setup.sh
```

- Enable the service (assuming your WAN link is _wan1_):

```bash
sudo systemctl enable cake-autorate@wan1.service
```

- Change the configuration and restart the service:

```bash
sudo cp /etc/cake-autorate/config.{primary,wan1}.sh
sudoedit /etc/cake-autorate/config.wan1.sh
sudo systemctl restart cake-autorate@wan1.service
```

For multiple WAN interfaces, enable additional services and duplicate the configuration:

```bash
sudo cp /etc/cake-autorate/config.wan{1,2}.sh
sudoedit /etc/cake-autorate/config.wan2.sh
sudo systemctl enable --now cake-autorate@wan2.service
```

## Initial Configuration Steps (OpenWrt and Asus Merlin)

- For a fresh install, you will need to undertake the following steps.
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ no reliable means to adjust the bandwidth on the fly.
**cake-autorate** bridges this gap.

**cake-autorate** presently supports installation on devices running
on an [OpenWrt router](https://openwrt.org) or an
[Asus Merlin router](https://www.asuswrt-merlin.net/).
on an [OpenWrt router](https://openwrt.org), an
[Asus Merlin router](https://www.asuswrt-merlin.net/), or an OS from the Debian family.

### Status

Expand Down Expand Up @@ -132,7 +132,7 @@ always testing for the true maximum as explained above).
The baseline bandwidth is likely optimally either the minimum
bandwidth or somewhere close thereto (e.g. the compromise bandwidth).

## Installation on OpenWrt or Asus Merlin
## Installation

Read the installation instructions in the separate
[INSTALLATION](./INSTALLATION.md) page.
Expand Down
28 changes: 28 additions & 0 deletions cake-autorate@.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[Unit]
Description=cake-autorate for %I
BindsTo=sys-subsystem-net-devices-%i.device
After=sys-subsystem-net-devices-%i.device

[Service]
AmbientCapabilities=CAP_NET_ADMIN
AmbientCapabilities=CAP_NET_RAW
CapabilityBoundingSet=CAP_NET_ADMIN
CapabilityBoundingSet=CAP_NET_RAW
Environment="CAKE_AUTORATE_SCRIPT_PREFIX=/opt/cake-autorate" "CAKE_AUTORATE_CONFIG_PREFIX=/etc/cake-autorate"
ExecStart=/opt/cake-autorate/cake-autorate.sh ${CAKE_AUTORATE_CONFIG_PREFIX}/config.%I.sh
NoNewPrivileges=true
PrivateTmp=true
ProtectHome=true
Restart=on-failure
RestartMode=direct
RestartSec=5
RestrictAddressFamilies=AF_INET
RestrictAddressFamilies=AF_INET6
RestrictAddressFamilies=AF_NETLINK
RestrictAddressFamilies=AF_UNIX
RuntimeDirectory=cake-autorate
StandardOutput=journal
TimeoutStopSec=15

[Install]
WantedBy=multi-user.target
36 changes: 33 additions & 3 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ main() {
set -eu

# Setup dependencies to check for
DEPENDENCIES="jsonfilter tar grep cmp mktemp bash"
DEPENDENCIES="tar grep cmp mktemp bash"

# Set up remote locations and branch
BRANCH="${CAKE_AUTORATE_BRANCH:-${2-master}}"
Expand Down Expand Up @@ -62,24 +62,39 @@ main() {
if [ "${x}" = "openwrt" ]
then
MY_OS=openwrt
DEPENDENCIES="jsonfilter ${DEPENDENCIES}"
[ -z "${SCRIPT_PREFIX}" ] && SCRIPT_PREFIX=/root/cake-autorate
[ -z "${CONFIG_PREFIX}" ] && CONFIG_PREFIX=/root/cake-autorate
break
fi
done

# Check if OS is part of the Debian family
for x in ${ID_LIKE:-}
do
if [ "${x}" = "debian" ]
then
MY_OS=debian
DEPENDENCIES="jq ${DEPENDENCIES}"
[ -z "${SCRIPT_PREFIX}" ] && SCRIPT_PREFIX=/opt/cake-autorate
[ -z "${CONFIG_PREFIX}" ] && CONFIG_PREFIX=/etc/cake-autorate
break
fi
done

# Check if OS is ASUSWRT-Merlin
if [ "$(uname -o)" = "ASUSWRT-Merlin" ]
then
MY_OS=asuswrt
DEPENDENCIES="jsonfilter ${DEPENDENCIES}"
[ -z "${SCRIPT_PREFIX}" ] && SCRIPT_PREFIX=/jffs/scripts/cake-autorate
[ -z "${CONFIG_PREFIX}" ] && CONFIG_PREFIX=/jffs/configs/cake-autorate
fi

# If we are not running on OpenWRT or ASUSWRT-Merlin, exit
if [ "${MY_OS}" = "unknown" ]
then
printf "This script requires OpenWrt or ASUSWRT-Merlin\n" >&2
printf "The current operating system is not supported\n" >&2
return 1
fi

Expand Down Expand Up @@ -127,7 +142,13 @@ main() {

# Get the latest commit to download
[ -z "${__CAKE_AUTORATE_SETUP_SH_EXEC_COMMIT:-}" ] && \
commit=$(download_url "${API_URL}" | jsonfilter -e @.sha) || \
if [ "${MY_OS}" = "openwrt" ] || [ "${MY_OS}" = "asuswrt" ]
then
JSON_CMD="jsonfilter -e @.sha"
else
JSON_CMD="jq -r .sha"
fi
commit=$(download_url "${API_URL}" | ${JSON_CMD}) || \
commit="${__CAKE_AUTORATE_SETUP_SH_EXEC_COMMIT}"
if [ -z "${commit:-}" ];
then
Expand Down Expand Up @@ -239,6 +260,11 @@ main() {
chmod +x /etc/init.d/mqtt-publisher
fi

if [ "${MY_OS}" = "debian" ]
then
mv "${tmp}/cake-autorate@.service" "/etc/systemd/system/"
fi

# Get version and generate a file containing version information
cd "${SCRIPT_PREFIX}"
version=$(grep -m 1 ^cake_autorate_version= "${SCRIPT_PREFIX}/cake-autorate.sh" | cut -d= -f2 | cut -d'"' -f2)
Expand Down Expand Up @@ -267,6 +293,10 @@ main() {
printf '%s\n' " chmod +x /opt/etc/init.d/S99cake-autorate"
printf '%s\n\n' "See also: https://github.com/RMerl/asuswrt-merlin.ng/wiki/User-scripts"
;;
"debian")
printf '%s\n' "Run as a service with:"
printf '%s\n\n' " systemctl enable --now cake-autorate@<interface>.service"
;;
*)
;;
esac
Expand Down
37 changes: 29 additions & 8 deletions uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ main() {
fi
done

# Check if OS is part of the Debian family
for x in ${ID_LIKE:-}
do
if [ "${x}" = "debian" ]
then
MY_OS=debian
[ -z "${SCRIPT_PREFIX}" ] && SCRIPT_PREFIX=/opt/cake-autorate
[ -z "${CONFIG_PREFIX}" ] && CONFIG_PREFIX=/etc/cake-autorate
break
fi
done

# Check if OS is ASUSWRT-Merlin
if [ "$(uname -o)" = "ASUSWRT-Merlin" ]
then
Expand All @@ -47,21 +59,30 @@ main() {
# If we are not running on OpenWRT or ASUSWRT-Merlin, exit
if [ "${MY_OS}" = "unknown" ]
then
printf "This script requires OpenWrt or ASUSWRT-Merlin\n" >&2
printf "The current operating system is not supported\n" >&2
return 1
fi

# Stop cake-autorate before continueing
if [ -x /etc/init.d/cake-autorate ]
if [ "${MY_OS}" = "asuswrt" ] || [ "${MY_OS}" = "openwrt" ]
then
/etc/init.d/cake-autorate stop || :
# Stop cake-autorate before continuing
if [ -x /etc/init.d/cake-autorate ]
then
/etc/init.d/cake-autorate stop || :
fi
if [ -x /etc/init.d/mqtt-publisher ]
then
/etc/init.d/mqtt-publisher stop || :
fi
rm -f /etc/init.d/cake-autorate /etc/rc.d/*cake-autorate
rm -f /etc/init.d/mqtt-publisher /etc/rc.d/*mqtt-publisher
fi
if [ -x /etc/init.d/mqtt-publisher ]

if [ "${MY_OS}" = "debian" ]
then
/etc/init.d/mqtt-publisher stop || :
systemctl disable --now cake-autorate@.service || :
rm -f /etc/systemd/system/cake-autorate@.service
fi
rm -f /etc/init.d/cake-autorate /etc/rc.d/*cake-autorate
rm -f /etc/init.d/mqtt-publisher /etc/rc.d/*mqtt-publisher

# Check if an instance of cake-autorate is already running and exit if so
if [ -d /var/run/cake-autorate ]
Expand Down