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'
相关推荐
网络研究院1 小时前
网络安全和基础设施安全局 (CISA) 表示微分段不再是可选的
网络·安全·web安全·零信任·微分段
xie_pin_an1 小时前
网络原理与编程实战:从 TCP/IP 到 HTTP/HTTPS
网络·tcp/ip·http
teeeeeeemo1 小时前
如何做HTTP优化
前端·网络·笔记·网络协议·http
weisian1512 小时前
HTTP协议-4-浏览器是怎么抉择HTTP版本的?
网络·网络协议·http
神鸟云4 小时前
DELL服务器 R系列 IPMI的配置
linux·运维·服务器·网络·边缘计算·pcdn
herderl4 小时前
**僵尸进程(Zombie Process)** 和**孤儿进程(Orphan Process)**
linux·运维·服务器·网络·网络协议
亲爱的非洲野猪4 小时前
令牌桶(Token Bucket)和漏桶(Leaky Bucket)细节对比
网络·算法·限流·服务
天意生信云4 小时前
生信分析自学攻略 | R软件和Rstudio的安装
经验分享·r语言
G_H_S_3_5 小时前
【网络运维】Playbook项目实战:基于 Ansible Playbook 一键部署 LNMP 架构服务器
linux·运维·服务器·网络·ansible