OpenWrt 编译 | 一种使用 git submodule 方式实现一键更新多个外部软件包

文章目录

一、问题背景

当我们在自定义编译 OpenWrt 时,有时候我们需要导入一些外部的软件包,有些软件包的 git 仓库地址是符合 feeds 规则的,例如 openwrt/packages 的仓库https://github.com/openwrt/packages,此时可以直接编辑 feeds.conf 文件,添加

shell 复制代码
src-git packages https://github.com/openwrt/packages.git

此时再执行 ./scripts/feeds update; ./scripts/feeds install -a 命令即可更新和安装 openwrt/packages 的仓库的软件包。

但是,有些仓库的地址是直接提供源码的,非 feeds 规则,例如

shell 复制代码
grep: feeds/argon/Makefile:#: No such file or directory
grep: call: No such file or directory
grep: BuildPackage: No such file or directory
grep: OpenWrt: No such file or directory
grep: buildroot: No such file or directory
grep: signature/Makefile: No such file or directory
feeds/argon.tmp/info/.files-packageinfo.mk:1: *** target pattern contains no '%'.  Stop.

因此,当存在多个这样的仓库的时候,每个仓库只能手动更新,在编译的时候较为不方便。而当前发 OpenWrtfeeds 管理暂不支持直接更新目录,因此需要另外寻找一个方式,实现方便更新多个仓库的目的。

本文将详细介绍一种使用 git submodule 方式实现一键更新多个外部软件包的方法。

二、新建Git仓库

由于放在 package/ 目录下的软件包,在执行 ./scripts/feeds update -a 命令的时候,自动被搜集作为软件包使用。因此首先,我们需要在 package/ 目录下建立一个专门存放外部仓库的目录,例如起名为 custom。随后我们通过 cd 命令切到此目录,随后执行以下命令创建新仓库

shell 复制代码
git init

随后在此仓库通过 git submodule add git路径 路径名 命令创建 submodule,例如添加两个子仓库

shell 复制代码
git submodule add https://github.com/jerrykuku/luci-app-argon-config.git luci-app-argon-config
git submodule add https://github.com/jerrykuku/luci-theme-argon.git luci-theme-argon/

最后执行更新仓库命令

shell 复制代码
git submodule update --remote --recursive

此时会有如下输出:

shell 复制代码
Cloning into 'package/custom/luci-app-argon-config'...
Cloning into 'package/custom/luci-theme-argon'...
Submodule path 'luci-app-argon-config': checked out 'e043d863574e8f2e77f2b4d8a0d92698e05f77c5'
Submodule path 'luci-theme-argon': checked out '8793e6330d4613e55a2fe8adaf76a749a52fda49'

以后每次只要在 package/custom 目录下执行 git submodule update --remote --recursive 命令即可更新所有的子模块的仓库,即可更新软件包

三、编写命令一键更新

如果每次编译之前都进 package/custom 目录下执行 git submodule update --remote --recursive 命令去更新软件包,也有所麻烦,因此可以将此转换成一个脚本命令,并使用括号 ( ) 创建子 Shell,子 Shell 退出后自动返回原目录,无需手动切换,可以避免因为 cd 命令执行之后,影响后续的命令执行。此命令如下:

shell 复制代码
(cd package/custom && git submodule update --remote --recursive)

将此命令合并到 feeds 更新中,即为

bash 复制代码
./scripts/feeds update -a && (cd package/custom && git submodule update --remote --recursive) && ./scripts/feeds install -a 

四、验证结果

如何验证所编写脚本是否正常呢?我们可以在某个子仓库下执行 git reset --hard hash 将子仓库回退到历史版本,之后在 OpenWrt 的主目录下执行 (cd package/custom && git submodule update --remote --recursive),观察其输出,是否成功更新了子仓库。

此时,会有类似以下的打印,即表示脚本执行正常。

shell 复制代码
Submodule path 'luci-app-argon-config': checked out 'e043d863574e8f2e77f2b4d8a0d92698e05f77c5'
相关推荐
星轨初途4 小时前
数据结构排序算法详解(5)——非比较函数:计数排序(鸽巢原理)及排序算法复杂度和稳定性分析
c语言·开发语言·数据结构·经验分享·笔记·算法·排序算法
xixixi777774 小时前
解析一下传输安全——“它是什么”,更是关于“它为何存在”、“如何实现”以及“面临何种挑战与未来”
网络·安全·通信
jerryinwuhan6 小时前
socket由浅入深
网络
weixin_377634846 小时前
【Git使用】PyCharm中的Git使用
ide·git·pycharm
_Minato_7 小时前
计算机系统知识总结——指令系统
经验分享·软考·计算机系统
AI科技星7 小时前
为什么变化的电磁场才产生引力场?—— 统一场论揭示的时空动力学本质
数据结构·人工智能·经验分享·算法·计算机视觉
xu_yule7 小时前
网络和Linux网络-3(套接字编程)TCP网络通信代码
linux·网络·tcp/ip
爱吃泡芙的小白白8 小时前
vscode、anaconda、git、python配置安装(自用)
ide·git·vscode·python·anaconda·学习记录
asdzx678 小时前
如何使用 C# 将 RTF 转换为 PDF
经验分享