krebs / minikrebs

Openwrt Profile Builder
Do What The F*ck You Want To Public License
23 stars 9 forks source link

Do not hardcode eth0 in traits/network/client-mode/files/etc/config/network #8

Open probonopd opened 8 years ago

probonopd commented 8 years ago

I have a couple of devices, and the name of the main Ethernet port is different on each one: eth0, eth0.1, eth1.

Bad things happen if the image contains the wrong name in /etc/configuration/network. For example, the A5-V11 router uses eth0.1 rather than eth0 or eth1, so be aware of that in order for the wired Ethernet to work. You need to change /etc/configuration/network accordingly or the device will not be accessible after flashing without using a serial adapter to unbrick (or possibly OpenWrt Failsafe).

I see there has been work in this area https://github.com/krebscode/minikrebs/commit/51a66f78c48f7cca9ea7d187f5410a026d8b27af

Is it possible to configure https://github.com/krebscode/minikrebs/blob/master/traits/network/client-mode/files/etc/config/network in a way that it does not hardcode eth0?

<makefu> firstrun.d ist eigentlich recht cool
<probono> wo finde ich die doku oder ein beispiel?
<makefu> dort kann man auch shell libs laden die sowas supporten
<makefu> ummm in einen von den aktuelleren traits
<makefu> funzt so
<makefu> datei in <trait>/files//etc/firstrun.d/44_my_script 
<makefu> wird ausgeführt beim ersten lauf
<makefu> (und danach nicht mehr)
<makefu> ausser es explodiert
probonopd commented 8 years ago

There are files like ./builder/target/linux/ar71xx/base-files/etc/uci-defaults/02_network which seem to have the required information, I am just not sure how to make use of them for the https://github.com/krebscode/minikrebs/blob/master/traits/network/client-mode/files/etc/config/network file.

makefu commented 8 years ago

Sorry for the delay, network/client-mode uses an old way to handle configuration (directly writes to /etc/config/network ). New traits use the firstrun.d facility to write uci configuration.

For a sample see https://github.com/krebscode/minikrebs/blob/master/traits/network/wifi-client/files/etc/firstrun.d/10_wifi_client in /etc/firstrun.d you write files which will be evaluated 'once' (or throw an error). In these scripts you can call uci to configure and store the changes.

Regards

probonopd commented 8 years ago

How is that different from using target/linux/ar71xx/base-files/etc/uci-defaults/ or files/etc/uci-defaults/ which seems to be the official OpenWrt way of doing things?

See http://wiki.openwrt.org/doc/uci#defaults:

To set some system defaults the first time the device boots, create a script in the folder /etc/uci-defaults/.

All scripts in that folder are automatically executed by /etc/init.d/boot and if they exited with code 0 deleted afterwards (scripts that did not exit with code 0 are not deleted and will be re-executed during 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 ok and have been deleted).

Probably the OpenWrt way is to drop a file into etc/uci-defaults which does additional configuration after the OpenWrt-provided scripts there have run.

Please see what I have written at https://github.com/probonopd/minikrebs/issues/1#issuecomment-167539921 - not tested yet, though (I don't have a serial console available right now for testing in case it goes bad...)

makefu commented 8 years ago

oh oh, it seems i have rebuilt something which existed before in openwrt anyway :\ But the idea is the same, write a script dump it in etc/uci-default and it will evaluate on first boot. Thanks for the heads-up.

probonopd commented 8 years ago

I don't see how this commit closes this issue...

makefu commented 8 years ago

somehow while merging your code github decided to close this issue ...