Add short page on UCI defaults
[web.git] / docs / uci_defaults.txt
1 ---
2 ---
3 UCI defaults
4 ============
5
6 == Integrating custom settings through UCI defaults
7
8 LEDE allows you to add custom settings by adding scripts into the 'files/etc/uci-defaults/' directory, which
9 will then be run after flashing. When keeping settings, this should mean the scripts are run *after* the upgrade
10 process flashed the image and appended the saved settings to the JFFS partition (which will be mounted as
11 '/overlay'). The path is identical for the buildroot and the image generator. Scripts should not be executable.
12 To ensure your scripts are not interfering with any other scripts, make sure they get executed last by giving them
13 a high prefix (e.g. 'zzzz_customisations'). A basic script could look like this:
14
15 ---
16 $ cat zzzz_customisations
17 #!/bin/sh
18
19 uci -q batch <<-EOT
20 add dhcp host
21 set dchp.@host[0].name='bellerophon'
22 set network.@host[0].ip='192.168.2.100'
23 set network.@host[0].mac='a1:b2:c3:d4:e5:f6'
24 EOT
25 ---
26
27 Once the script has run successfully and exited cleanly (exit status 0), it will be removed from '/etc/uci-defaults/'.
28 You can still consult the original in '/rom/etc/uci-defaults/' if needed.
29
30
31 == Ensuring scripts don't overwrite custom settings: implementing checks
32
33 Scripts in '/etc/uci-defaults' will get executed at every first boot (ie after a clean install or an upgrade),
34 possibly overwriting already existing values. If this behaviour is undesired, we recommend you implement
35 a test at the top of your script - e.g. probe for a custom setting your script would normally configure:
36
37 ---
38 [ "$(uci -q get system.@system[0].zonename)" = "America/New York" ] && exit 0
39 ---
40
41 This will ensure, when the key has the correct value set, that the script exits cleanly and gets removed from
42 '/etc/uci-defaults/' as explained above.