Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| docs:guide-developer:uci-defaults [2019/10/19 14:32] – Add links to example scripts zorun | docs:guide-developer:uci-defaults [2023/10/14 09:08] (current) – [UCI defaults] vgaetera | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== UCI defaults ====== | ====== UCI defaults ====== | ||
| + | See also: [[docs: | ||
| + | |||
| //OpenWrt// relies on UCI, the //Unified Configuration Interface//, | //OpenWrt// relies on UCI, the //Unified Configuration Interface//, | ||
| UCI defaults provides a way to preconfigure your images, using UCI. | UCI defaults provides a way to preconfigure your images, using UCI. | ||
| Line 5: | Line 7: | ||
| To set some system defaults the first time the device boots, create a script in the directory ''/ | To set some system defaults the first time the device boots, create a script in the directory ''/ | ||
| - | All scripts in that folder | + | All scripts in that directory |
| * If they exit with code 0 they are deleted afterwards. | * If they exit with code 0 they are deleted afterwards. | ||
| * Scripts that exit with non-zero exit code are not deleted and will be re-executed at the next boot until they also successfully exit. | * Scripts that exit with non-zero exit code are not deleted and will be re-executed at the next boot until they also successfully exit. | ||
| Line 14: | Line 16: | ||
| ===== Integrating custom settings ===== | ===== Integrating custom settings ===== | ||
| + | See also: | ||
| + | [[docs: | ||
| + | [[docs: | ||
| + | |||
| + | Easiest way to include uci-defaults scripts in your firmware may be as custom files. | ||
| You can preload custom settings by adding batch scripts containing UCI commands into the ''/ | You can preload custom settings by adding batch scripts containing UCI commands into the ''/ | ||
| The path is identical for the buildroot and the image generator. | The path is identical for the buildroot and the image generator. | ||
| The scripts will be run **after** the flashing process - in case of upgrading, that also includes appending the existing configuration to the JFFS2 partition (mounted as ''/ | The scripts will be run **after** the flashing process - in case of upgrading, that also includes appending the existing configuration to the JFFS2 partition (mounted as ''/ | ||
| Scripts should not be executable. | Scripts should not be executable. | ||
| - | To ensure your scripts are not interfering with any other scripts, make sure they get executed last by giving them a high prefix (e.g. //xx_customizations//). | + | To ensure your scripts are not interfering with any other scripts, make sure they get executed last by giving them a high prefix (e.g. //xx_custom//). |
| A basic script could look like this: | A basic script could look like this: | ||
| <code bash> | <code bash> | ||
| - | cat << | + | cat << |
| - | #!/bin/sh | + | uci -q batch << |
| - | uci -q batch << | + | set network.lan.ipaddr=' |
| + | set wireless.@wifi-device[0].disabled=' | ||
| + | set wireless.@wifi-iface[0].ssid=' | ||
| add dhcp host | add dhcp host | ||
| - | set dhcp.@host[0].name=' | + | set dhcp.@host[-1].name=' |
| - | set network.@host[0].ip=' | + | set dhcp.@host[-1].ip=' |
| - | set network.@host[0].mac=' | + | set dhcp.@host[-1].mac=' |
| + | rename firewall.@zone[0]=' | ||
| + | rename firewall.@zone[1]=' | ||
| + | rename firewall.@forwarding[0]=' | ||
| + | EOI | ||
| EOF | EOF | ||
| - | EOF_cat | ||
| </ | </ | ||
| + | This is a simple example to set up the LAN IP address, SSID, enable Wi-Fi, configure a static DHCP lease, rename firewall zone and forwarding sections. | ||
| Once the script has run successfully and exited cleanly (exit status 0), it will be removed from ''/ | Once the script has run successfully and exited cleanly (exit status 0), it will be removed from ''/ | ||
| You can still consult the original in ''/ | You can still consult the original in ''/ | ||
| Line 46: | Line 59: | ||
| This will make sure, when the key has the correct value set, that the script exits cleanly and gets removed from ''/ | This will make sure, when the key has the correct value set, that the script exits cleanly and gets removed from ''/ | ||
| - | ===== Example scripts | + | ===== Examples |
| - | + | * [[docs: | |
| - | The following '' | + | * [[https:// |
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| - | * the '' | ||
| - | * the [[https:// | ||