首页 > 其他分享 >用bash脚本快速生成/管理openwrt .config配置文件

用bash脚本快速生成/管理openwrt .config配置文件

时间:2023-11-15 10:45:58浏览次数:34  
标签:set TARGET 配置文件 config 64 CONFIG bash x86

Openwrt自带的图形化配置工具非常方便,但如果自己编译的时候经常要改设置,需要选中或者取消的package散落在图形配置的各个角落,那无疑是非常痛苦的一件事,下面用bash脚本来优化这一流程。

下面以生成x86固件为例

首先备份你已有的.config配置文件,然后make menuconfig,在架构中选中x86->x86_64->generic x86/64>,根据你的需求配置好架构,然后保存为template.config模板文件。

打开这个模板文件,现在里面的是你所选架构(板子)的所有默认配置了,后面需要什么包就从里面搜索就行。文件开头是架构信息,复制出来

#
# Automatically generated file; DO NOT EDIT.
# OpenWrt Configuration
#
CONFIG_MODULES=y
CONFIG_HAVE_DOT_CONFIG=y
CONFIG_HOST_OS_LINUX=y
# CONFIG_HOST_OS_MACOS is not set
# CONFIG_TARGET_airoha is not set
# CONFIG_TARGET_sunxi is not set
# CONFIG_TARGET_meson is not set
# CONFIG_TARGET_silicon is not set
# CONFIG_TARGET_apm821xx is not set
# CONFIG_TARGET_ath25 is not set
# CONFIG_TARGET_ath79 is not set
# CONFIG_TARGET_bcm27xx is not set
# CONFIG_TARGET_bcm53xx is not set
# CONFIG_TARGET_bcm47xx is not set
# CONFIG_TARGET_bcm4908 is not set
# CONFIG_TARGET_bcm63xx is not set
# CONFIG_TARGET_bmips is not set
# CONFIG_TARGET_octeon is not set
# CONFIG_TARGET_gemini is not set
# CONFIG_TARGET_mpc85xx is not set
# CONFIG_TARGET_mxs is not set
# CONFIG_TARGET_lantiq is not set
# CONFIG_TARGET_malta is not set
# CONFIG_TARGET_pistachio is not set
# CONFIG_TARGET_mvebu is not set
# CONFIG_TARGET_kirkwood is not set
# CONFIG_TARGET_mediatek is not set
# CONFIG_TARGET_ramips is not set
# CONFIG_TARGET_at91 is not set
# CONFIG_TARGET_tegra is not set
# CONFIG_TARGET_layerscape is not set
# CONFIG_TARGET_imx is not set
# CONFIG_TARGET_octeontx is not set
# CONFIG_TARGET_oxnas is not set
# CONFIG_TARGET_armvirt is not set
# CONFIG_TARGET_ipq40xx is not set
# CONFIG_TARGET_ipq60xx is not set
# CONFIG_TARGET_ipq806x is not set
# CONFIG_TARGET_ipq807x is not set
# CONFIG_TARGET_realtek is not set
# CONFIG_TARGET_rockchip is not set
# CONFIG_TARGET_sifiveu is not set
# CONFIG_TARGET_arc770 is not set
# CONFIG_TARGET_archs38 is not set
# CONFIG_TARGET_omap is not set
# CONFIG_TARGET_uml is not set
# CONFIG_TARGET_zynq is not set
CONFIG_TARGET_x86=y
CONFIG_TARGET_x86_64=y
# CONFIG_TARGET_x86_generic is not set
# CONFIG_TARGET_x86_legacy is not set
# CONFIG_TARGET_x86_geode is not set
# CONFIG_TARGET_MULTI_PROFILE is not set
CONFIG_TARGET_x86_64_DEVICE_generic=y
CONFIG_HAS_SUBTARGETS=y
CONFIG_HAS_DEVICES=y
CONFIG_TARGET_BOARD="x86"
CONFIG_TARGET_SUBTARGET="64"
CONFIG_TARGET_PROFILE="DEVICE_generic"
CONFIG_TARGET_ARCH_PACKAGES="x86_64"
CONFIG_DEFAULT_TARGET_OPTIMIZATION="-Os -pipe"

其中的注释可以删除掉,然后新建一个bash脚本gen-config-x86.sh

#!/bin/bash

[[ -f .config ]] && mv .config .config.bak
touch .config

# 刚才的架构信息
echo '
CONFIG_TARGET_x86=y
CONFIG_TARGET_x86_64=y
CONFIG_TARGET_x86_64_DEVICE_generic=y
CONFIG_HAS_SUBTARGETS=y
CONFIG_HAS_DEVICES=y
CONFIG_TARGET_BOARD="x86"
CONFIG_TARGET_SUBTARGET="64"
CONFIG_TARGET_PROFILE="DEVICE_generic"
CONFIG_TARGET_ARCH_PACKAGES="x86_64"
' >>.config

# 选中的软件包
enable_packages=(
	luci-app-diskman # luci-app-应用
	luci-app-diskman_INCLUDE_btrfs_progs # package的二级菜单选项
	kmod-usb3 # 内核模块等
	minicom # 命令行工具
)
for ((i = 0; i < ${#enable_packages[@]}; i++)); do
	echo "CONFIG_PACKAGE_${enable_packages[i]}=y" | tee -a .config
done

# 主要用于禁用默认配置里选中的luci-app-,其他地方的默认配置不建议去动
disable_packages=(
	luci-app-turboacc
)
for ((i = 0; i < ${#disable_packages[@]}; i++)); do
	echo "CONFIG_PACKAGE_${disable_packages[i]}=n" | tee -a .config
done

module_packages=(
	luci-app-mwan3
)
for ((i = 0; i < ${#module_packages[@]}; i++)); do
	echo "CONFIG_PACKAGE_${module_packages[i]}=m" | tee -a .config
done

make defconfig

这个脚本里方便修改需要的软件包和需要禁用的包,集中管理,具体有那些可以设置,可以在刚才的template.config模板文件里查找,包括软件包的二级菜单选项,都可以这样设置,很方便。

make defconfig之前,.config文件里是这样的

CONFIG_TARGET_x86=y
CONFIG_TARGET_x86_64=y
CONFIG_TARGET_x86_64_DEVICE_generic=y
CONFIG_HAS_SUBTARGETS=y
CONFIG_HAS_DEVICES=y
CONFIG_TARGET_BOARD="x86"
CONFIG_TARGET_SUBTARGET="64"
CONFIG_TARGET_PROFILE="DEVICE_generic"
CONFIG_TARGET_ARCH_PACKAGES="x86_64"
CONFIG_PACKAGE_luci-app-diskman=y
CONFIG_PACKAGE_luci-app-diskman_INCLUDE_btrfs_progs=y
CONFIG_PACKAGE_kmod-usb3=y
CONFIG_PACKAGE_minicom=y
CONFIG_PACKAGE_luci-app-turboacc=n
CONFIG_PACKAGE_luci-app-mwan3=m

执行make defconfig之后,对于ym的选项,会自动补齐相关的依赖,n的模块会取消选中,取消依赖。

通过这种方法添加的软件包主要是luci-app-服务,kmod内核模块,以及一些命令行工具,太底层的lib不要去动,defconfig会帮我们补齐的。

如果有多个不同架构的设备,可以创建对应的gen-config-{arch}.sh脚本,然后根据需求在里面添加所需的应用的驱动包。

标签:set,TARGET,配置文件,config,64,CONFIG,bash,x86
From: https://www.cnblogs.com/lavateinn/p/17833164.html

相关文章

  • layui.config详解
    原文链接:https://www.python100.com/html/80540.html下载layui的官网首页:https://www.bejson.com/doc/layui/index.html一、layui.config什么意思(谐音:类UI)在了解layui.config之前,我们需要先了解layui静态文件加载器。它是一个简化的资源加载器,可以自动为模块分析和处理其依......
  • Nacos共享配置(shared-configs)和扩展配(extension-config)
    原文地址:https://www.jianshu.com/p/8715072d3f4c一、共享配置(shared-configs)和扩展配(extension-config)日常开发中,多个模块可能会有很多共用的配置,比如数据库连接信息,Redis连接信息,RabbitMQ连接信息,监控配置等等。那么此时,我们就希望可以加载多个配置,多个项目共享同一个......
  • 使用 npm config set script-shell 实现跨平台的脚本执行需求
    npmconfigsetscript-shellC:\\app\\Git20180223\\bin\\bash.exe这个命令的准确含义是设置npm的脚本(shell)执行环境为"C:\app\Git20180223\bin\bash.exe"。这个命令用于修改npm的配置,具体来说,它修改了npm的一个配置项,该配置项用于指定在执行npm脚本时使用的shell程序。在这个......
  • dotnet 发布程序,并指定端口和配置文件运行
    发布命令发布时,进入到Host文件夹路径下dotnetpublish-cXXX发布完成会生成一个XXX文件夹,里面\net6.0\publish就是发布的程序了运行命令运行时,进入到publish文件夹,并在此处打开终端设置运行端口为8888,使用配置文件appSettings.XXX.jsondotnet[Host].dll--urls"http......
  • scrapy解析数据,配置文件,整站爬取cnblogs,持久化
    1scrapy解析数据......
  • 牛客[编程题] HJ66 配置文件恢复
    HJ66 配置文件恢复 中等  通过率:36.66%  时间限制:1秒  空间限制:32M  描述有6条配置命令,它们执行的结果分别是:命   令执   行resetreset whatreset boardboard faultboard addwhere to addboard deleteno board at......
  • 无涯教程-批处理 - NET CONFIG函数
    显示您当前的服务器或工作组设置。NETCONFIG-语法NETCONFIGNETCONFIG-示例NETCONFIG运行上面代码输出Thefollowingrunningservicescanbecontrolled:ServerWorkstationThecommandcompletedsuccessfully.参考链接https://www.learnfk.com/batch-......
  • ansible的配置文件的解析
    一:/etc/ansible/ansible.cfg这个文件默认被分为8段[defaults]:通用配置项[inventory]:与主机清单相关的配置项[privilege_escalation]:特权升级相关的配置项[ssh_connection]:使用openssh连接相关的配置项[persistent_connection]:持久连接的配置项[acclelrate]:加速模式配置项[......
  • [20231109]bash shell快捷键alt+number的问题.txt
    [20231109]bashshell快捷键alt+number的问题.txt--//前一阵子,我想实现12行合并1行的输出,理论讲要使用paste命令加入12个-.输入命令时候要数输入了多少-.我知道bashshell有一--//个快捷键alt+number可以产生连续输入某个字符,但是我一直不知道如何关掉这个功能.有时候误触发这......
  • vue-cli-service vue.config.js配置 productionSourceMap与webpack中的devtool 关联详
    https://webpack.js.org/configuration/devtool/https://cli.vuejs.org/zh/config/#productionsourcemap https://github.com/vuejs/vue-cli/blob/f0f254e4bc81ed322eeb9f7de346e987e845068e/packages/%40vue/cli-service/lib/config/prod.js#L7 可以在源码中看到if(pro......