UCI defaults
OpenWrt relies on UCI, the Unified Configuration Interface, to configure its core services. UCI defaults provides a way to preconfigure your images, using UCI.
OpenWrt は、その主要サービスを設定するために UCI (統一構成インターフェース) に依存しています。UCI のデフォルト機能は、UCI を使用してイメージを事前構成する方法を提供します。
To set some system defaults the first time the device boots, create a script in the directory /etc/uci-defaults.
デバイスが初めて起動する際にシステムのデフォルト設定を行うには、/etc/uci-defaults ディレクトリにスクリプトを作成します。
All scripts in that directory are automatically executed by the boot service:
そのディレクトリ内のすべてのスクリプトは、起動サービスによって自動的に実行されます:
If they exit with code 0 they are deleted afterwards.
スクリプトがコード0で終了した場合、それらはその後削除されます。
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.
非ゼロの終了コードで終了したスクリプトは削除されず、次回の起動時に再実行され、正常に終了するまで繰り返されます。
In a live router you can see the existing UCI defaults scripts in /rom/etc/uci-defaults , as /etc/uci-defaults itself is typically empty (after all scripts have been run successfully and have been deleted).
稼働中のルーターでは、/rom/etc/uci-defaults に既存の UCI デフォルトスクリプトがあり、/etc/uci-defaults 自体は通常空です(すべてのスクリプトが正常に実行され削除された後)。
UCI defaults scripts can be created by packages or they can be inserted into the build manually as custom files.
UCI デフォルトスクリプトはパッケージによって作成される場合もあれば、カスタムファイルとしてビルドに手動で挿入される場合もあります。
Integrating custom settings
カスタム設定の組み込み
Easiest way to include uci-defaults scripts in your firmware may be as custom files.
ファームウェアに uci-defaults スクリプトを含める最も簡単な方法は、おそらくカスタムファイルとして追加することでしょう。
You can preload custom settings by adding batch scripts containing UCI commands into the /files/etc/uci-defaults directory.
UCI コマンドを含むバッチスクリプトを /files/etc/uci-defaults ディレクトリに追加することで、カスタム設定をプリロードできます。
The path is identical for the buildroot and the image generator.
このパスはビルドルートとイメージジェネレータの両方で同じです。
訳注: buildrootとimage generatorがそれぞれ何を指してるのか不明だが、ビルド前のツリーとビルドされたrootfsでパスが同じになるってこと?
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).
スクリプトはフラッシュ処理後に実行され、アップグレードの場合には既存の設定を JFFS2 パーティション(/overlay としてマウント)に追加することも含まれます。
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_custom).
他のスクリプトと干渉しないように、スクリプトに高いプレフィックス(例:xx_custom)を付けて、最後に実行されるようにしてください。
A basic script could look like this:
基本的なスクリプトは次のようになります:
code:sh
cat << "EOF" > /etc/uci-defaults/99-custom
uci -q batch << EOI
set network.lan.ipaddr='192.168.178.1'
set wireless.@wifi-device0.disabled='0' set wireless.@wifi-iface0.ssid='OpenWrt0815' add dhcp host
set dhcp.@host-1.name='bellerophon' set dhcp.@host-1.ip='192.168.2.100' set dhcp.@host-1.mac='a1:b2:c3:d4:e5:f6' rename firewall.@zone0='lan' rename firewall.@zone1='wan' rename firewall.@forwarding0='lan_wan' EOI
EOF
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 /etc/uci-defaults.
You can still consult the original in /rom/etc/uci-defaults if needed.