Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
docs:guide-developer:uci-defaults [2021/02/27 22:38] – [Integrating custom settings] formatting vgaeteradocs:guide-developer:uci-defaults [2023/10/14 09:08] (current) – [UCI defaults] vgaetera
Line 7: Line 7:
 To set some system defaults the first time the device boots, create a script in the directory ''/etc/uci-defaults''. To set some system defaults the first time the device boots, create a script in the directory ''/etc/uci-defaults''.
  
-All scripts in that folder are automatically executed by ''/etc/init.d/boot'':+All scripts in that directory are automatically executed by the ''boot'' service:
   * 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 17: Line 17:
 ===== Integrating custom settings ===== ===== Integrating custom settings =====
 See also: See also:
-[[docs:guide-developer:build-system:use-buildsystem#custom_files|Build system - Custom files]], +[[docs:guide-developer:toolchain:use-buildsystem#custom_files|Build system - Custom files]], 
-[[docs:guide-user:additional-software:imagebuilder#files_variable|Image builder - Custom files]]+[[docs:guide-user:additional-software:imagebuilder#custom_files|Image builder - Custom files]]
  
 Easiest way to include uci-defaults scripts in your firmware may be as custom files. Easiest way to include uci-defaults scripts in your firmware may be as custom files.
Line 25: Line 25:
 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 ''/overlay''). 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 ''/overlay'').
 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 << EOF_cat > /etc/uci-defaults/xx_customizations +cat << "EOF" > /etc/uci-defaults/99-custom 
-uci -q batch << EOF+uci -q batch << EOI
 set network.lan.ipaddr='192.168.178.1' set network.lan.ipaddr='192.168.178.1'
-commit network 
 set wireless.@wifi-device[0].disabled='0' set wireless.@wifi-device[0].disabled='0'
 set wireless.@wifi-iface[0].ssid='OpenWrt0815' set wireless.@wifi-iface[0].ssid='OpenWrt0815'
-commit wireless 
 add dhcp host add dhcp host
 set dhcp.@host[-1].name='bellerophon' set dhcp.@host[-1].name='bellerophon'
 set dhcp.@host[-1].ip='192.168.2.100' set dhcp.@host[-1].ip='192.168.2.100'
 set dhcp.@host[-1].mac='a1:b2:c3:d4:e5:f6' set dhcp.@host[-1].mac='a1:b2:c3:d4:e5:f6'
-commit dhcp 
 rename firewall.@zone[0]='lan' rename firewall.@zone[0]='lan'
 rename firewall.@zone[1]='wan' rename firewall.@zone[1]='wan'
 rename firewall.@forwarding[0]='lan_wan' rename firewall.@forwarding[0]='lan_wan'
-commit firewall+EOI
 EOF EOF
-EOF_cat 
 </code> </code>
  
Line 63: Line 59:
 This will make sure, when the key has the correct value set, that the script exits cleanly and gets removed from ''/etc/uci-defaults'' as explained above. This will make sure, when the key has the correct value set, that the script exits cleanly and gets removed from ''/etc/uci-defaults'' as explained above.
  
-===== Example scripts =====+===== Examples ===== 
 +  * [[docs:guide-user:additional-software:imagebuilder#restricting_root_access|Restricting root access]] 
 +  * [[https://github.com/openwrt/openwrt/tree/master/package/base-files/files/etc/uci-defaults|uci-defaults @ base-files]] 
 +  * [[https://github.com/freifunk-berlin/firmware-packages/tree/master/defaults|uci-defaults @ Freifunk Berlin]] 
 +  * [[https://github.com/ffulm/firmware/blob/master/files/etc/uci-defaults/50_freifunk-setup|uci-defaults @ Freifunk Ulm]] 
 +  * [[https://github.com/richb-hanover/OpenWrtScripts/blob/main/config-openwrt.sh|config-openwrt @ richb-hanover]]
  
-The following ''uci-defaults'' scripts can probably be used as inspiration: 
- 
-  * the ''base-files'' package [[https://git.openwrt.org/?p=openwrt/openwrt.git;a=tree;f=package/base-files/files/etc/uci-defaults;hb=HEAD|has a few uci-defaults scripts]] 
-  * the [[https://github.com/freifunk-berlin/firmware|Freifunk Berlin firmware]] makes [[https://github.com/freifunk-berlin/firmware-packages/tree/master/defaults|heavy use of uci-defaults scripts]] 
-  * the [[https://wiki.freifunk-ulm.de|Freifunk Ulm]] community does all its configuration in a [[https://github.com/ffulm/firmware/blob/master/files/etc/uci-defaults/50_freifunk-setup|huge uci-defaults script]] 
  • Last modified: 2021/02/27 22:38
  • by vgaetera