How do i change file contents using shell script?

so i wanted to create a shell script to help me configure the network&firewall settings for every fresh install but i having a hard time learning how to edit a file using a script.

so from the default network settings :
image

and edit it to :

Please help , thanks in advance.

if you're thinking of shell scripting, it's not an openwrt questiom.

most of the settings can be configured using uci commands, which will then
be written to file.

1 Like

Have you looked at using uci : https://openwrt.org/docs/guide-user/base-system/uci

General reading: https://openwrt.org/docs/guide-user/start

2 Likes

i thought that cuz openwrt is Unix based it is common

no i haven't , i'll read what you've sent thanks

after reading the UCI documentation, it is what im looking for.
Thank you for that, however the question remains can i create an .sh file with the uci as its contents

For configuring fresh installs, the uci-defaults can be used to place scripts to run on first-boot.

1 Like

what about installing packages like Openvpn and adblock??
the commands used are "opkg install"

how does it relate to your initial question ?

oo sorry, just curious whether it is possible to add the commands there or not

opkg install ?

sure.

1 Like

thanks, that is really helpful information.
i'll test it out in a bit

It sounds like a good use of Imagebuilder with an integrated uci-defaults script. That’s how I build my images.

2 Likes

im new to this , really hard to understand

"create a shell script" - yes this is possible on openwrt too, as it is linux system. but this is basic linux question not owrt specific i'm afraid.

"configure the network&firewall settings" - owrt using a system called UCI to do configurations. there is a command line tool uci (also there is Luci the web UI which also using uci as backend), with uci you can add/change/delete configuration items. the configuration is then stored in files in /etc/config directory. e.g. the file /etc/config/network is the file representation of the uci network subsystem.

"every fresh install" - if you want customized installation there is imagebuilder service which let's you create your own owrt image with pre-installed custom packages. if you are not using imagebuilder the default image is get installed and then later you have to install packages via opkg install tool manually. but this only means pre-installed package not pre-configured settings. for latter you can use the uci-defaults solution.

hope this helps to understand why you received the links as reply previously.

yes there will be a learning curve you cannot skip :wink: use the wiki documents and search either the forum, or as openwrt content is very well indexed by search engines you just use your favorite search engine. if you still have openwrt related specific question not yet answered feel free to ask in the forum.

1 Like

I think have go without the image builder, I can't find my device on the list.

Thanks for the time to help answering the question.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.