wrt-base is a maintenance baseline for ImmortalWrt and OpenWrt routers. It turns one-off tasks such as installing tools, running checks, and preparing backups into repeatable, versioned scripts, so you have a stable operational starting point for the system itself.
This repository does not turn a router into a primary development machine. It only manages the system baseline.
- Install the maintenance toolset with one command: Automatically detects
opkgorapkso you do not need per-firmware branches. - Health check script: Checks time, NTP, disk, memory, load, outbound IPv4/IPv6 connectivity, DNS, and package manager availability in one pass, with cron-friendly text or
--jsonoutput. - Baseline report script: Prints a descriptive snapshot of firmware, kernel, resources, network, and package counts as text or JSON, so you can capture the device state before and after maintenance.
- Configuration backup script: Bundles the
sysupgradebackup with the installed package list, feed configuration, crontab, and a device manifest into a single timestamped archive. - Customizable install set: Add site-specific packages through a config file (
/etc/wrt-base/install-tools.confor--config FILE) without editing the script. - POSIX sh implementation: Runs natively on BusyBox ash with no bash or make dependency.
- Built-in tests:
sh tests/run.shruns syntax checks, shellcheck when available, and unit tests. - VS Code Remote-SSH baseline: Includes the OpenSSH client/server, SFTP server, tar, gzip, and related runtime packages needed for the VS Code Remote-SSH extension to install its server on OpenWrt.
- Single-package failures do not abort the run: If the network is unstable or a package is unavailable in the current feed, installation continues and summarizes warnings at the end.
# 1. Clone the repository onto the router.
# On opkg firmware (OpenWrt 23.05 / ImmortalWrt 24.10):
opkg update && opkg install git git-http ca-bundle
# On apk firmware (newer OpenWrt snapshots):
apk update && apk add git git-http ca-bundle
git clone https://github.com/kangmingxuan/wrt-base.git /root/wrt-base
cd /root/wrt-base
# 2. Preview the package list.
sh scripts/install-tools.sh --print-only
# 3. Install the toolset.
sh scripts/install-tools.sh
# 4. Run the health check.
sh scripts/health-check.shClone directly on the router rather than copying a checkout from another machine. Copying from macOS in particular (tar, scp, finder copies) can introduce AppleDouble
._*metadata files that corrupt the Git pack index on the device.
scripts/
install-tools.sh # Tool installation with opkg/apk auto-detection
health-check.sh # Health checks for time, NTP, disk, memory, load, network, DNS
baseline-report.sh # Descriptive device snapshot as text or JSON
backup-config.sh # Configuration backup (sysupgrade + extras) into a tar.gz
lib/ # Shared shell library files sourced by scripts
tests/
run.sh # Test entry point (sh -n + shellcheck + unit tests)
Makefile # Run make help to see optional shortcuts
README.zh-CN.md # Simplified Chinese README
All commands run directly with sh and do not depend on make. If your workstation has make installed, make help provides matching shortcuts.
| Command | Description |
|---|---|
sh tests/run.sh |
Run the full test suite (syntax, shellcheck, unit tests) |
sh scripts/install-tools.sh --print-only |
Print the packages that full mode would install |
sh scripts/install-tools.sh |
Install the full toolset (requires root) |
sh scripts/install-tools.sh --minimal |
Install the minimal toolset (requires root) |
sh scripts/health-check.sh |
Run the health check |
sh scripts/health-check.sh --json |
Run the health check and print JSON results |
sh scripts/baseline-report.sh |
Print a baseline snapshot report |
sh scripts/backup-config.sh |
Create a configuration backup archive (requires root) |
| Set | Contents | Intended Use |
|---|---|---|
| base (always installed) | bash, ca-bundle, curl, git, git-http, jq, less, nano, tmux | Required to maintain this repository and pull remote configuration |
| minimal (always installed) | bind-dig, ip-full, openssl-util, tcpdump or tcpdump-mini | Minimum set for network and TLS troubleshooting |
| full (added by default) | coreutils, coreutils-install, diffutils, ethtool, findutils-*, gawk, grep, gzip, htop, iperf3, iputils-*, libstdcpp6, lsof, openssh-client, openssh-server, openssh-sftp-server, procps-ng-*, python3-light, ripgrep, rsync, sed, strace, tar, tree, unzip |
Full maintenance experience, including a better baseline for VS Code Remote-SSH and code-server workflows |
--minimal skips the full set.
To install extra site-specific packages without editing the script, list them (one package per line, # starts a comment) in /etc/wrt-base/install-tools.conf, or point --config FILE at another file. The default path can be overridden with OWRT_INSTALL_CONFIG, and --no-config ignores the default file. Extra packages are added on top of the selected mode.
install is added via coreutils-install. OpenWrt and ImmortalWrt package feeds ship GNU install as a split package instead of guaranteeing it through the coreutils meta-package, so the repository now installs it explicitly.
For the first installation on a small router, prefer --minimal and add only the extras you actually need through the config file, instead of starting with the full set:
mkdir -p /etc/wrt-base
cat > /etc/wrt-base/install-tools.conf <<'EOF'
coreutils-nohup
lsof
ss
EOF
sh scripts/install-tools.sh --minimalThis keeps openssh-server and Python off the device, which matters when Dropbear is already configured as the only management entry point. You can re-run the script with --full later once the baseline is stable.
Snapshot firmware installs packages from the official OpenWrt snapshot feed, which can be very slow from some regions (notably mainland China, where double-digit KB/s rates and timeouts on multi-MB packages are common). Keep in mind:
- An apparently stalled install is usually still downloading. Re-running
sh scripts/install-tools.sh --skip-updateis safe: already-installed packages are skipped and only the failed ones are retried. - If you build a custom snapshot image, bake the common packages into the image instead of installing them on the device afterwards.
- Prefer a trusted local proxy or a router-level proxy path over arbitrary third-party snapshot mirrors: snapshot feeds move fast, and a stale mirror can break kernel module (
kmod-*) installation due to kernel ABI drift.
On the current x86_64 feed, --minimal installs about 10.8 MiB and --full installs about 18.8 MiB, including the auto-selected tcpdump package and excluding filesystem/overlay overhead. Actual usage varies by target, feed, and package availability.
Packet capture is selected automatically based on free storage: if at least 16384 KB is available, the script installs the full tcpdump; otherwise it installs tcpdump-mini. You can override the decision with OWRT_TCPDUMP_VARIANT=full|mini|auto, and OWRT_STORAGE_FREE_KB is available for testing that logic.
sh scripts/health-check.sh \
--disk 85 \
--mem 90 \
--load 2 \
--skip-time \
--skip-net \
--quiet--disk 85: warn when disk usage is 85% or higher.--mem 90: warn when memory usage is 90% or higher.--load 2: warn when 1-minute load divided by CPU count exceeds 2.--skip-time: skip the system time and NTP checks, which is useful before NTP sync or in CI.--skip-net: skip HTTPS outbound, DNS, and IPv6 checks.--quiet: print only abnormal items, which is useful for cron.--json: print results as a JSON document on stdout, which is convenient for monitoring.--check-rom: apply the disk threshold to/romas well.
The disk check covers / and /overlay. The read-only /rom squashfs image always reports 100% used on OpenWrt, so it is excluded by default; pass --check-rom if you really want it checked.
The NTP check uses procd (/etc/init.d/sysntpd status) when available. The IPv6 check only tests outbound connectivity when the device has a global IPv6 address; devices without IPv6 are reported as a pass.
Exit status: 0 means every check passed; 1 means at least one check failed.
sh scripts/baseline-report.sh # human-readable text
sh scripts/baseline-report.sh --json # flat JSON object
sh scripts/baseline-report.sh --output /root/baseline.txtThe report summarizes firmware, kernel, architecture, uptime, CPU/memory/disk/load, egress IPv4/IPv6 addresses, and installed package counts. Capture it before a maintenance window and again afterwards to see what changed.
sh scripts/backup-config.sh \
--output-dir /root/backups \
--keep 5--output-dir DIR: where to write the archive (default:/root/backups).--keep N: keep only theNmost recent backups in the output directory (0keeps all).--dry-run: stage and list the files without writing the final archive.
Each run produces a timestamped wrt-backup-<host>-<timestamp>.tar.gz containing the standard sysupgrade backup plus the installed package list, feed configuration, root crontab, and a device manifest. Copy the archive off the device before any risky maintenance operation.
sh tests/run.shDo not submit changes with failing tests. tests/run.sh auto-discovers tests/test_*.sh, so add a matching test whenever you add a new script.