openwrt advanced configuration
openwrt高级配置(汗 照着标题就翻译过来了
)
openwrt Kamikaze 8.09的一般配置文件都在目录 /etc/config 下面,可以使用脚本来调用参数和设置参数。 比如 sbin/wifi(函数库在 madwifi.sh 脚本)里面就是这样配置本机上的无线网卡的。
一般来说,每个configure文件都是由一些 section 组成的,section 里面包含了option ,option 都会有一个值。 section定义包含了type和name ,其中 name不是必须定义的,若没有定义,系统会按照cfg**的形式分配给该section一个name。
举例来说,wifi的配置文件 /etc/config/wireless 内容如下:
******************************file: /etc/config/wireless ******************************************
config wifi-device wifi0
option type atheros
option channel auto
option hwmode 11g
option disabled 0
config wifi-iface
option device wifi0
option network lan
option mode adhoc
option ssid OpenWrt
option encryption none
*****************************************************************************************************
这个配置文件里面有两个section, 其type分别是wifi-device 和wifi-iface。其中wifi-device拥有一个name是 wifi0 而wifi-iface没有。
可以看到,option 具体设置了驱动或者应用程序的配置,每一项option都有name和value。
##################################华丽的分割线#######################
利用脚本可以配置这些configure file 。
首先,脚本需要添加. /etc/functions.sh库。然后,使用命令config_load <name> 来加载相应的配置文件,<name>代表配置文件的文件名,函数会在 /etc/config 目录下寻找名字为 name 的文件。
配置文件加载后,可以使用函数 config_cb() option_cb() config_foreach() config_get() 以及命令config_foreach 。详细使用如下:
1)config_cb()和option_cb() 函数是指每一个section或option执行的callback函数。就是说,config_load 命令加载的config文件中 , 每一个section都会调用config_cb()一次,每一个option都会调用option_cb()一次。其中,最后一个section的name可以用CONFIG_SECTION引用到。在所有section被调用完之后,config_cb()还会被调用一次,需要注意的是,config_cb()和option_cb() 函数需要在config_load 命令前定义(在. /etc/functions.sh被添加后)。
代码如下:
config_cb() {
local type="$1"
local name="$2"
# commands to be run for every section
}
注:变量$1 和$2分别代表section的type和name
option_cb() {
# commands to be run for every option
}
注:变量$1 和$2分别代表option的name和value
2)config_foreach命令在config_load后使用,方法如下:
config_foreach <function name> [<sectiontype>] [<arguments...>]
这条命令表示对每一个section都执行函数function name,该函数在其他地方定义。函数的参数 $1表示该section的name。如果添加sectiontype ,则只有该type的section才可以执行function name 函数。
3)config_get 命令,很简单,不作解释。
# print the value of the option
config_get <section> <option>
# store the value inside the variable
config_get <variable> <section> <option>
注:section栏填写的是section的name,注意文件中没有设定的name是由系统分配的,此种情况最好还是用config_cb()或者option_cb()函数来完成功能比较好。
4)config_set 命令:
config_set <section> <option> <value>
这个 也很简单不做解释 。只是貌似不能更改实际文件中的option的value而已,仅仅是在当前load的“文件下”。
脚本实例:
file: config_custom.sh
#this scripts is for advanced configure test , by huasion
. /etc/functions.sh
config_cb(){
local type="$1"
local name="$2"
if [ "$1" != "" ] && [ "$2" != "" ]; then
echo "my type is $1, my name is $2"
fi
#echo "last my type is $1, my name is $2"
}
option_cb(){
echo "option is $1 and option name is $2"
}
test(){
echo "fisrt varible is $1"
}
config_load wireless
echo "now do the last job"
config_get foo wifi0 type
echo "$foo"
echo "$CONFIG_SECTION"
config_get wifi0 channel
config_set wifi0 hwmode 11b
config_foreach test wifi-iface
#file is over
file: /etc/config/wireless
config wifi-device wifi0
option type atheros
option channel auto
option hwmode 11g
# REMOVE THIS LINE TO ENABLE WIFI:
#option disabled 1
config wifi-iface
option device wifi0
option network lan
option mode adhoc
option ssid OpenWrt
option encryption none
config wifi-device wifi1
option type atheros
option channel auto
# REMOVE THIS LINE TO ENABLE WIFI:
#option disabled 1
config wifi-iface
option device wifi1
option network lan
option mode adhoc
option ssid OpenWrt
option encryption none
#file is over
执行结果如下:
my type is wifi-device, my name is wifi0
option is type and option name is atheros
option is channel and option name is auto
option is hwmode and option name is 11g
my type is wifi-iface, my name is cfg03c84e
option is device and option name is wifi0
option is network and option name is lan
option is mode and option name is adhoc
option is ssid and option name is OpenWrt
option is encryption and option name is none
my type is wifi-device, my name is wifi1
option is type and option name is atheros
option is channel and option name is auto
my type is wifi-iface, my name is cfg0695cf
option is device and option name is wifi1
option is network and option name is lan
option is mode and option name is adhoc
option is ssid and option name is OpenWrt
option is encryption and option name is none
now do the last job
atheros
cfg0695cf
auto
option is hwmode and option name is 11b
fisrt varible is cfg03c84e
fisrt varible is cfg0695cf
打不动字了 分析以上结果就可以清晰地看到每个函数在什么时候被调用,参数情况和函数都做了些什么事,完了,撒花。
openwrt advanced configuration的更多相关文章
- Advanced Configuration Tricks
Advanced Configuration Tricks Configuration of zend-mvc applications happens in several steps: Initi ...
- Google Analytics Advanced Configuration - Google Analytics 高级配置
该文档提供了Android SDK v3的部分元素的高级配置说明. Overview - 概述 Android Google Analytics SDK提供了Tracker类,应用可以用它给Googl ...
- 搭建OpenWrt开发环境(包括编译过程)
OpenWrt是一个高度模块化.高度自动化的嵌入式linux发行版,其编译和安装过程比普通的linux发行版而言,要简单太多了.如果您是新手,您那恐惧的心大可放到肚子里,呵呵.对于新手来说最麻烦的恐怕 ...
- ./scripts/feeds update -a OpenWrt大招系列
./scripts/feeds update -a Updating feed 'packages' from 'https://github.com/openwrt/packages.git' .. ...
- CentOS6 上OpenWRT交叉编译
目的不是为了编译固件,而是为了一个是编译可执行文件,放倒op的路由器上跑,另一个目的是安装一些开源软件折腾下(例如ss-lib),需要打包成 .ipk 格式 路由设备信息 erya@ERYA:~$ c ...
- openwrt undefined reference to ‘getpwent_r’
由于须要安装 su sudo useradd groupadd chown login 等用户管理命令,会訪问passwd文件. 用到了 getpwant_r 函数.详细是哪个命令引起的,临时不知. ...
- 使用外部 toolchain 编译 openwrt
默认编译 openwrt 时会先编译一套 toolchain. 这个步骤耗时较长. 使用外部 toolchain 可以多个 project 共用一套 toolchain , 而且也不重再编译它了. 省 ...
- Nginx - Configuration File Syntax
Configuration Directives The Nginx configuration file can be described as a list of directives organ ...
- Openwrt 远程调试
此文已由作者吴志勐授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 本文以自己的程序WFD为例: 1,为路由器固件刷上gdbserver 在宿主端,使用make menucon ...
随机推荐
- Semaphore的介绍和使用
转自:http://www.itzhai.com/the-introduction-and-use-of-semaphore.html 相关介绍 public class Semaphore exte ...
- Oracle 字符集的查看和修改 -转
一.什么是Oracle字符集 Oracle字符集是一个字节数据的解释的符号集合,有大小之分,有相互的包容关系.ORACLE 支持国家语言的体系结构允许你使用本地化语言来存储,处理,检索数据.它使数据库 ...
- Android笔记:触摸事件的分析与总结----TouchEvent处理机制
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://glblong.blog.51cto.com/3058613/1559320 ...
- [LeetCode#204]Factorial Trailing Zeroes
Problem: Description: Count the number of prime numbers less than a non-negative number, n. Analysis ...
- c语言运算符号详细说明
C语言中具有右结合性的运算符包括所有单目运算符以及赋值运算符(=)和条件运算符.其它都是左结合性. 判断表达式计算顺序时,先按优先级高的先计算,优先级低的后计算,当优先级相同时再按结合性,或从左至右顺 ...
- MVC5 学习整理
一.概述 MVC简介: • 模型(Model) “数据模型”(Model)用于封装与应用程序的业务逻辑相关的数据以及对数据的处理方法.“模型”有对数据直接访问的权力,例如对数据库的访问.“ ...
- leetcode 最大矩形和
1.枚举法(超时) public class Solution { public int largestRectangleArea(int[] height) { int max=-1; for(in ...
- NOI题库7624 山区建小学(162:Post Office / IOI2000 POST OFFICE [input] )
7624:山区建小学 Description 政府在某山区修建了一条道路,恰好穿越总共m个村庄的每个村庄一次,没有回路或交叉,任意两个村庄只能通过这条路来往.已知任意两个相邻的村庄之间的距离为di(为 ...
- 在Ubuntu中设置中文输入法
在Ubuntu中设置中文输入法 */--> pre { background-color: #2f4f4f;line-height: 1.6; FONT: 10.5pt Consola,&quo ...
- Axure初体验:简单交互、通过按钮切换图片
前言: 之前是一直用processon的UI原型设计,后来感觉只能完成静态页面的processon满足不了原型设计的需求,断网时候也不方便修改.展示.最终还是决定学习动态页面的制作,所选工具为原型设计 ...