How kunijiwa/n1-immortalwrt-build works
1. What this repo is
- This is not a full OpenWrt source tree. It is a customization layer on top of the ImmortalWrt ImageBuilder framework, focused on building a Phicomm N1 side-router firmware.
- The repository’s job is to turn a generic ImmortalWrt base image into a highly stripped, preconfigured N1-specific firmware.
2. Primary build entrypoint
- The main build path is driven by GitHub Actions in .github/workflows/build-N1.yml.
- That workflow delegates to n1/build.sh, which acts as the build coordinator for this specific device/profile.
3. Build-time control plane
- n1/build.sh is the orchestration layer: it likely validates the target firmware, selects the right architecture/profile, and assembles the final ImageBuilder invocation.
- shell/check-firmware.sh is a guardrail script used to confirm the base firmware/imagebuilder environment is compatible before building.
- arch/arch.conf.sh defines architecture precedence/selection, which matters because ImageBuilder builds are target-specific.
4. Package selection philosophy
- shell/exclude-packages.sh is the core package policy file.
- The README describes a “positive declaration + precise exclusion” approach: keep only the packages needed for the N1 side-router use case and explicitly remove unneeded components.
- This is the main mechanism behind the repo’s “minimal, clean, no redundancy” firmware positioning.
5. Runtime features baked into the image
- The firmware is preloaded with several user-facing components:
- OpenClash
- Aria2
- FileBrowser
- Argon theme
- Amlogic/N1 box tooling
- These are not separate runtime services from the repo’s perspective; they are embedded into the firmware image during build.
6. Filesystem overlay and configuration injection
- The files/ directory is an overlay that gets copied into the final root filesystem.
- files/etc/config/aria2 contains the default Aria2 configuration.
- files/etc/aria2/clean.sh and files/etc/aria2/delete.sh are Aria2-side helper scripts, likely used for download cleanup and deletion behavior.
- files/etc/uci-defaults/99-custom.sh is especially important: it runs on first boot to apply device-specific initialization.
7. First-boot initialization flow
- The image is designed to self-configure on first startup for side-router deployment.
- The first-boot script is responsible for:
- obtaining an IP address via DHCP
- splitting br-lan
- disabling the DHCP service
- This makes the N1 behave like a bypass/side router rather than a conventional LAN gateway.
8. Network and access model
- The README states the default network model is DHCP client mode, with DHCP server disabled.
- Firewall defaults are adjusted to allow inbound traffic on the WAN side, matching a side-router topology.
- The default admin password is password, indicating the build aims for immediate usability after flashing.
9. OpenClash and rule-data boundary
- OpenClash is included as a packaged capability, but its main engine/kernel is not prebundled according to the README.
- The intended flow is: flash firmware → first boot → enter LuCI/OpenClash → download the required Meta core and update GEO data.
- This keeps the build smaller and shifts large, fast-changing artifacts to post-install setup.
10. What is intentionally removed
- The image removes a wide range of features the N1 doesn’t need in this role:
- physical device drivers
- PPPoE dial-up
- IPv6 client components
- filesystem utilities
- This is a deliberate size/performance tradeoff aligned with the “bypass router” use case.
11. Repository boundaries
- The repo contains build logic, package policy, and filesystem overlays, but not the full firmware source.
- External dependencies are the ImmortalWrt ImageBuilder framework and the package feeds/plugins it references.
- GitHub Actions is the only visible automation/infrastructure layer in this repo.
12. How to diagram it
- A clear architecture diagram should show:
- GitHub Actions triggering the build
- build.sh orchestrating build steps
- arch/config + firmware check + package exclusion shaping the image
- files/ overlay injecting runtime defaults and scripts
- the resulting N1 firmware image
- first boot uci-defaults applying network/DHCP changes
- the final runtime services: LuCI/OpenClash/Aria2/FileBrowser on the device
Main entry points: build.sh Build Script · files Files Overlay · exclude-packages.sh Package Policy · 99-custom.sh First Boot Init
Components 15
Automation
CI entrypoint and build trigger
- GitHub Actions · Triggers the N1 build pipeline
.github/workflows/build-N1.yml
Build Control
Scripts that select target, validate environment, and shape the image
- Build Script · Coordinates the N1 ImageBuilder build
n1/build.sh - Arch Config · Defines architecture precedence and profile selection
arch/arch.conf.sh - Firmware Check · Verifies the base ImageBuilder/firmware environment
shell/check-firmware.sh - Package Policy · Explicitly removes unneeded packages for the N1 image
shell/exclude-packages.sh - ImageBuilder · ImmortalWrt ImageBuilder used to assemble the firmware
Image Overlay
Filesystem additions and first-boot customization inside the firmware
- Files Overlay · Content copied into the final root filesystem
files - Aria2 Config · Preseeds Aria2 runtime settings
files/etc/config/aria2 - Aria2 Hooks · Cleanup and delete helpers for Aria2
files/etc/aria2 - First Boot Init · Applies device-specific configuration on first boot
files/etc/uci-defaults/99-custom.sh - Side-router Setup · Switches to DHCP client mode, splits br-lan, disables DHCP server
- N1 Firmware · Stripped, preconfigured ImmortalWrt image for the Phicomm N1
- Baked-in Apps · LuCI, OpenClash, Aria2, FileBrowser, Argon theme, and N1 tooling
- OpenClash Core · Downloaded after flashing rather than prebundled
- Phicomm N1 · Side-router hardware running the customized firmware
Connections 16
- GitHub Actions → Build Script: runs · Workflow delegates to the device-specific build script
- Build Script → ImageBuilder: invokes · Build script assembles the final ImageBuilder command
- Build Script → Arch Config: selects target · Chooses architecture/profile settings for the N1
- Build Script → Firmware Check: validates · Ensures the base build environment is compatible
- Build Script → Package Policy: filters packages · Applies the repo's minimal package policy
- Package Policy → ImageBuilder: feeds policy · Package exclusions shape the generated image
- Files Overlay → ImageBuilder: overlays · Filesystem content is copied into the rootfs during image creation
- Files Overlay → Aria2 Config: contains · Overlay provides default Aria2 configuration
- Files Overlay → Aria2 Hooks: contains · Overlay provides Aria2 cleanup and delete hooks
- Files Overlay → First Boot Init: contains · Overlay provides first-boot initialization logic
- ImageBuilder → N1 Firmware: produces · ImageBuilder outputs the customized N1 firmware image
- First Boot Init → Side-router Setup: configures · First-boot script changes WAN/LAN behavior for side-router use
- Side-router Setup → Phicomm N1: applies on · Device boots into DHCP-client bypass-router mode
- N1 Firmware → Baked-in Apps: includes · The firmware ships with preloaded user-facing components
- Baked-in Apps → Phicomm N1: runs on · Installed apps are available after flashing and boot
- Baked-in Apps → OpenClash Core: defers core · Main OpenClash core is downloaded after first boot