OpenWrt之Feeds
Feeds在OpenWrt中扮演着至关重要的角色,它们允许用户根据自己的需求定制和扩展路由器的功能。通过安装不同的Feed,用户可以添加新的软件包、更新现有软件包或删除不再需要的软件包。
什么是Feed?🍤
Feed是OpenWRT中的软件包集合,这些软件包可以使用一个统一的地址来获取。
软件包可以分布在远程服务器、版本控制系统、本地文件系统以及其他可以通过feed方法使用单个名称(路径/URL)寻址的位置。这样用户可以不必关心软件包的存储位置,减少软件包与核心代码的耦合。
Feed更新之后存在于feeds/<feed_name>
目录,安装之后存在于package/feeds/<feed_name>
目录。
Feeds包含两个部分,分别是feeds配置文件feeds.conf
或feeds.conf.default
(其中每一行都为一个feed的配置)和脚本scripts/feeds
。feeds脚本通过解析配置文件中的每一行然后使用指定方法从配置的源地址下载feed,下载成功之后可以在feeds/<feed_name>
目录中看到feed详细内容。
Feeds配置🥐
在feeds.conf
配置文件中,每一行为一个feed配置。
如果feeds.conf
不存在,则使用默认配置feeds.conf.default
。
feeds.conf.default
的内容如下:
src-git packages https://git.openwrt.org/feed/packages.git;openwrt-23.05
src-git luci https://git.openwrt.org/project/luci.git;openwrt-23.05
src-git routing https://git.openwrt.org/feed/routing.git;openwrt-23.05
src-git telephony https://git.openwrt.org/feed/telephony.git;openwrt-23.05
#src-git video https://github.com/openwrt/video.git
#src-git targets https://github.com/openwrt/targets.git
#src-git management https://github.com/openwrt-management/packages.git
#src-git oldpackages http://git.openwrt.org/packages.git
#src-link custom /usr/src/openwrt/custom-feed
feeds.conf
配置格式如下:
- 每行配置了一个feed
- 每个feed包含3个部分并以空格分隔,feed方法、feed名称以及feed源
- 解析时忽略空行,多余空白和注释
- 注释以“#”开始并延伸到行尾
以第1行为例,表示一个feed配置,其中src-git
为feed方法,packages
为feed名称,https://git.openwrt.org/feed/packages.git;openwrt-23.05
是feed中所有软件包的下载位置。
git
方法可以指定分支或提交,格式如下:
src-git local_feed_name https://example.com/repo_name/something.git;branch_name
src-git local_feed_name https://example.com/repo_name/something.git^commit_hash
Feed名称用于标识feed,并作为创建用于保存有关feed信息的多个文件和目录名称的基础。Feed源指向软件包的下载位置,可以位于远程服务器、版本控制系统、本地文件系统或其他支持feed方法的位置。
Feed方法🥗
Feed方法 | 说明 |
---|---|
src-bzr | 使用bzr从源路径/URL下载数据 |
src-cpy | 从源路径复制数据。源路径为OpenWRT根路径的相对路径或绝对路径 |
src-darcs | 使用darcs从源路径下载数据 |
src-git | 使用git从源路径下载数据,指定depth为1 |
src-git-full | 使用git从源路径下载数据,完成克隆 |
src-hg | 使用hg从源路径下载数据 |
src-link | 指向源路径的符号链接。必须为绝对路径(存疑) |
src-svn | 使用svn从源路径下载数据 |
使用Feeds🍟
feeds脚本用于将feeds配置文件(feeds.conf
或feeds.conf.default
)中来自各种feed源的软件包整合到OpenWRT构建系统中。
- 通过feed源来更新feed。
- 安装来自feed的特定软件包。
从feeds配置源中更新feed到本地
在./scripts/feeds update
步骤中,feeds脚本从feeds配置文件中列出的源获取feed,然后复制到feeds目录中。成功执行之后,每个feed中的软件包信息都在feeds/<feed_name>/<package_name>
目录中,但它们尚未包含在OpenWRT构建系统中,因为它们不在packages/
目录中。
下面是更新完feed的结果,以及packages
和luci
feed(packages
和luci
分别为两个feed名,在上面的feeds.default.conf
中配置)包含的软件包信息:
blduan@ubuntu24:~/projects/open_source/openwrt/feeds$ ls -l
# 脚本从配置文件中指定的配置更新feeds的结果
total 32
lrwxrwxrwx 1 blduan blduan 49 Nov 21 23:43 base -> /home/blduan/projects/open_source/openwrt/package
drwxrwxr-x 13 blduan blduan 4096 Nov 21 23:22 luci
lrwxrwxrwx 1 blduan blduan 21 Nov 21 23:24 luci.index -> luci.tmp/.packageinfo
lrwxrwxrwx 1 blduan blduan 20 Nov 21 23:24 luci.targetindex -> luci.tmp/.targetinfo
drwxrwxr-x 3 blduan blduan 4096 Nov 21 23:24 luci.tmp
drwxrwxr-x 18 blduan blduan 4096 Nov 21 23:17 packages
lrwxrwxrwx 1 blduan blduan 25 Nov 21 23:24 packages.index -> packages.tmp/.packageinfo
lrwxrwxrwx 1 blduan blduan 24 Nov 21 23:24 packages.targetindex -> packages.tmp/.targetinfo
drwxrwxr-x 3 blduan blduan 4096 Nov 21 23:24 packages.tmp
drwxrwxr-x 32 blduan blduan 4096 Nov 21 23:22 routing
lrwxrwxrwx 1 blduan blduan 24 Nov 21 23:24 routing.index -> routing.tmp/.packageinfo
lrwxrwxrwx 1 blduan blduan 23 Nov 21 23:24 routing.targetindex -> routing.tmp/.targetinfo
drwxrwxr-x 3 blduan blduan 4096 Nov 21 23:24 routing.tmp
drwxrwxr-x 6 blduan blduan 4096 Nov 21 23:22 telephony
lrwxrwxrwx 1 blduan blduan 26 Nov 21 23:24 telephony.index -> telephony.tmp/.packageinfo
lrwxrwxrwx 1 blduan blduan 25 Nov 21 23:24 telephony.targetindex -> telephony.tmp/.targetinfo
drwxrwxr-x 3 blduan blduan 4096 Nov 21 23:24 telephony.tmp
blduan@ubuntu24:~/open_source/openwrt/openwrt/feeds/packages$ ls -l
# packages feed目录
total 108
-rw-rw-r-- 1 blduan blduan 11502 Nov 19 07:34 CONTRIBUTING.md
-rw-rw-r-- 1 blduan blduan 17992 Nov 19 07:34 LICENSE
-rw-rw-r-- 1 blduan blduan 999 Nov 19 07:34 README.md
drwxrwxr-x 24 blduan blduan 4096 Nov 19 07:34 admin
drwxrwxr-x 22 blduan blduan 4096 Nov 19 07:34 devel
drwxrwxr-x 3 blduan blduan 4096 Nov 19 07:34 fonts
drwxrwxr-x 5 blduan blduan 4096 Nov 19 07:34 ipv6
drwxrwxr-x 7 blduan blduan 4096 Nov 19 07:34 kernel
drwxrwxr-x 123 blduan blduan 4096 Nov 19 07:34 lang
drwxrwxr-x 284 blduan blduan 12288 Nov 19 07:34 libs
drwxrwxr-x 18 blduan blduan 4096 Nov 19 07:34 mail
drwxrwxr-x 31 blduan blduan 4096 Nov 19 07:34 multimedia
drwxrwxr-x 366 blduan blduan 12288 Nov 19 07:34 net
drwxrwxr-x 23 blduan blduan 4096 Nov 19 07:34 sound
drwxrwxr-x 289 blduan blduan 12288 Nov 19 07:34 utils
blduan@ubuntu24:~/projects/open_source/openwrt/feeds/luci$ ls -l
# luci feed目录
total 80
-rw-rw-r-- 1 blduan blduan 3922 Nov 21 23:22 CONTRIBUTING.md
-rw-rw-r-- 1 blduan blduan 11356 Nov 21 23:22 LICENSE
-rw-rw-r-- 1 blduan blduan 356 Nov 21 23:22 NOTICE
-rw-rw-r-- 1 blduan blduan 1206 Nov 21 23:22 README.md
drwxrwxr-x 104 blduan blduan 4096 Nov 21 23:22 applications drwxrwxr-x 3 blduan blduan 4096 Nov 21 23:22 build
drwxrwxr-x 8 blduan blduan 4096 Nov 21 23:22 collections
drwxrwxr-x 3 blduan blduan 4096 Nov 21 23:22 contrib
drwxrwxr-x 4 blduan blduan 4096 Nov 21 23:22 docs
-rw-rw-r-- 1 blduan blduan 576 Nov 21 23:22 jsdoc.conf.json
drwxrwxr-x 17 blduan blduan 4096 Nov 21 23:22 libs
-rw-rw-r-- 1 blduan blduan 11154 Nov 21 23:22 luci.mk
drwxrwxr-x 13 blduan blduan 4096 Nov 21 23:22 modules
-rw-rw-r-- 1 blduan blduan 173 Nov 21 23:22 package.json
drwxrwxr-x 29 blduan blduan 4096 Nov 21 23:22 protocols
drwxrwxr-x 6 blduan blduan 4096 Nov 21 23:22 themes
安装feed到openwrt文件系统中
在./scripts/feeds install
步骤中,feeds脚本首先在package/feeds
目录下创建对应feed的目录,然后将update
中获取的每个feed中的软件包都软链接到package/feeds/<feed_name>
文件夹(比如将名为packages
的feed软连接到package/feeds/packages
)中。
成功执行之后,就可以使用软件包路径执行特定于软件包的make操作了,比如make package/feeds/<feed_name>/<package_name>
。
下面给出了成功安装feed的结果,其中显示在package/feed
中创建的目录,以及将每个feed
下的软件包软链接到对应位置(package/feeds/<feed_name>/<package_name>
)。
blduan@ubuntu24:~/projects/open_source/openwrt/package/feeds$ ls -l
total 60
drwxrwxr-x 2 blduan blduan 12288 Nov 21 23:44 luci
drwxrwxr-x 2 blduan blduan 36864 Nov 21 23:44 packages drwxrwxr-x 2 blduan blduan 4096 Nov 21 23:44 routing
drwxrwxr-x 2 blduan blduan 4096 Nov 21 23:44 telephony
blduan@ubuntu24:~/open_source/openwrt/openwrt/package/feeds/packages$ ls -l
total 52
lrwxrwxrwx 1 blduan blduan 40 Nov 20 03:37 2to3 -> ../../../feeds/packages/lang/python/2to3
lrwxrwxrwx 1 blduan blduan 41 Nov 20 03:37 Flask -> ../../../feeds/packages/lang/python/Flask
lrwxrwxrwx 1 blduan blduan 40 Nov 20 03:37 aardvark-dns -> ../../../feeds/packages/net/aardvark-dns
lrwxrwxrwx 1 blduan blduan 33 Nov 20 03:37 acl -> ../../../feeds/packages/utils/acl
lrwxrwxrwx 1 blduan blduan 32 Nov 20 03:37 acme -> ../../../feeds/packages/net/acme
...
blduan@ubuntu24:~/projects/open_source/openwrt/package/feeds/luci$ ls -l
total 16
lrwxrwxrwx 1 blduan blduan 43 Nov 21 23:44 csstidy -> ../../../feeds/luci/contrib/package/csstidy
lrwxrwxrwx 1 blduan blduan 36 Nov 21 23:44 luci -> ../../../feeds/luci/collections/luci
lrwxrwxrwx 1 blduan blduan 45 Nov 21 23:44 luci-app-acl -> ../../../feeds/luci/applications/luci-app-acl
lrwxrwxrwx 1 blduan blduan 46 Nov 21 23:44 luci-app-acme -> ../../../feeds/luci/applications/luci-app-acme
lrwxrwxrwx 1 blduan blduan 49 Nov 21 23:44 luci-app-adblock -> ../../../feeds/luci/applications/luci-app-adblock
lrwxrwxrwx 1 blduan blduan 54 Nov 21 23:44 luci-app-adblock-fast -> ../../../feeds/luci/applications/luci-app-adblock-fast
lrwxrwxrwx 1 blduan blduan 57 Nov 21 23:44 luci-app-advanced-reboot -> ../../../feeds/luci/applications/luci-app-advanced-reboot
lrwxrwxrwx 1 blduan blduan 47 Nov 21 23:44 luci-app-alist -> ../../../feeds/luci/applications/luci-app-alist
lrwxrwxrwx 1 blduan blduan 49 Nov 21 23:44 luci-app-apinger -> ../../../feeds/luci/applications/luci-app-apinger
lrwxrwxrwx 1 blduan blduan 47 Nov 21 23:44 luci-app-aria2 -> ../../../feeds/luci/applications/luci-app-aria2
lrwxrwxrwx 1 blduan blduan 60 Nov 21 23:44 luci-app-attendedsysupgrade -> ../../../feeds/luci/applications/luci-app-attendedsysupgrade
lrwxrwxrwx 1 blduan blduan 48 Nov 21 23:44 luci-app-babeld -> ../../../feeds/luci/applications/luci-app-babeld
feeds脚本🥚
$ ./scripts/feeds help
Usage: ./scripts/feeds <command> [options]
Commands:
list [options]: List feeds, their content and revisions (if installed)
Options:
-n : List of feed names.
-s : List of feed names and their URL.
-r <feedname>: List packages of specified feed.
-d <delimiter>: Use specified delimiter to distinguish rows (default: spaces)
-f : List feeds in feeds.conf compatible format (when using -s).
install [options] <package>: Install a package
Options:
-a : Install all packages from all feeds or from the specified feed using the -p option.
-p <feedname>: Prefer this feed when installing packages.
-d <y|m|n>: Set default for newly installed packages.
-f : Install will be forced even if the package exists in core OpenWrt (override)
search [options] <substring>: Search for a package
Options:
-r <feedname>: Only search in this feed
uninstall -a|<package>: Uninstall a package
Options:
-a : Uninstalls all packages.
update -a|<feedname(s)>: Update packages and lists of feeds in feeds.conf .
Options:
-a : Update all feeds listed within feeds.conf. Otherwise the specified feeds will be updated.
-i : Recreate the index only. No feed update from repository is performed.
-f : Force updating feeds even if there are changed, uncommitted files.
clean: Remove downloaded/generated files.
可以通过scripts/feeds
脚本来使用Feeds。其中大多数命令都需要本地可用的feed信息,因此需要先运行update
命令。
命令 | 说明 |
---|---|
clean | 删除本地存储的feed数据,包括feed索引和feed中所有软件包的数据(不会删除install创建的符号链接),这是通过删除feeds目录及其子目录完成的。 |
install | 安装软件包及其依赖。创建package/feeds/$feed_name/$package_name 指向feeds/$feed_name/$package_name 的符号链接,以便在配置过程中将软件包包含在内 |
list | 从feed索引文件中读取并展示软件包列表。索引文件存储在feeds目录下,命名方式为$feed_name.index |
search | 读取feed元数据并列出匹配的软件包 |
uninstall | 将每个feed从其源位置下载到feeds目录的子目录中,子目录名称与feed名相对应。然后将feed中的软件包信息解析到索引文件中,以供list和search命令使用。 |
update | 将每个feed从其源位置下载到feeds目录的子目录中,子目录名称与feed名相对应。然后将feed中的软件包信息解析到索引文件中,以供list和search命令使用 |
示例,检出packages
和luci
两个feed:./scripts/feeds update packages luci
。
检出软件包之后还需要进行安装,只有在安装之后,才会在配置界面中使用。
创建自定义package和feeds🌭
opkg安装卸载ipk🍕
上面编译成功之后会生成一个ipk包,例如helloworld_1.0-1_i386_pentium4.ipk。
安装ipk:opkg instal <xxx>.ipk
移除ipk:opkg remove <xxx>.ipk
列出ipk:opkg list
root@OpenWrt:/tmp# opkg install helloworld_1.0-1_i386_pentium4.ipk
Installing helloworld (1.0-1) to root...
Configuring helloworld.
root@OpenWrt:/tmp# ls
TZ helloworld_1.0-1_i386_pentium4.ipk luci-indexcache.fdcd5e66.json run usr
board.json hosts opkg-lists shm
dhcp.leases lib overlay state
dnsmasq.d lock resolv.conf sysinfo
etc log resolv.conf.d tmp
root@OpenWrt:/tmp# which helloworld
/usr/bin/helloworld
root@OpenWrt:/tmp# helloworld
Hello, world!
root@OpenWrt:/tmp# opkg remove helloworld
Removing package helloworld from root...
root@OpenWrt:/tmp# which helloworld
root@OpenWrt:/tmp# opkg list
base-files - 1563-r24138-cd9998ef1b
busybox - 1.36.1-1
ca-bundle - 20230311-1
cgi-io - 2022-08-10-901b0f04-21
dnsmasq - 2.90-2
dropbear - 2022.82-6
e100-firmware - 20230804-1
...
参考文章🥨
- 原文作者:生如夏花
- 原文链接:https://DBL2017.github.io/post/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/openwrt/openwrt%E4%B9%8Bfeeds/
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。