• OpenWrt之feeds.conf.default详解


    OpenWrt之feeds.conf.default详解


    文件内容

    src-git-full packages https://git.openwrt.org/feed/packages.git
    src-git-full luci https://git.openwrt.org/project/luci.git
    src-git-full routing https://git.openwrt.org/feed/routing.git
    src-git-full telephony https://git.openwrt.org/feed/telephony.git
    #src-git-full video https://github.com/openwrt/video.git
    #src-git-full targets https://github.com/openwrt/targets.git
    #src-git-full oldpackages http://git.openwrt.org/packages.git
    #src-link custom /usr/src/openwrt/custom-feed
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    OpenWrt的feeds.conf.default, 是添加一些应用和包的文件, 看过之后下面解析命令用法


    命令解释

    • 先说# , 这个是注释用, 不会有人不知道吧

    • 这个文件主要是由scripts/feeds这个perl脚本控制着, 贴一个命令的定义

      my %update_method = (
      	'src-svn' => {
      		'init'		=> "svn checkout '%s' '%s'",
      		'update'	=> "svn update",
      		'controldir'	=> ".svn",
      		'revision'	=> "svn info | grep 'Revision' | cut -d ' ' -f 2 | tr -d '\n'"},
      	'src-cpy' => {
      		'init'		=> "cp -Rf '%s' '%s'",
      		'update'	=> "",
      		'revision'	=> "echo -n 'local'"},
      	'src-link' => {
      		'init'		=> "ln -s '%s' '%s'",
      		'update'	=> "",
      		'revision'	=> "echo -n 'local'"},
      	'src-dummy' => {
      		'init'		=> "true '%s' && mkdir '%s'",
      		'update'	=> "",
      		'revision'	=> "echo -n 'dummy'"},
      	'src-git' => {
      		'init'          => "git clone --depth 1 '%s' '%s'",
      		'init_branch'   => "git clone --depth 1 --branch '%s' '%s' '%s'",
      		'init_commit'   => "git clone '%s' '%s' && cd '%s' && git checkout -b '%s' '%s' && cd -",
      		'update'	=> "git pull --ff-only",
      		'update_force'	=> "git pull --ff-only || (git reset --hard HEAD; git pull --ff-only; exit 1)",
      		'post_update'	=> "git submodule update --init --recursive",
      		'controldir'	=> ".git",
      		'revision'	=> "git rev-parse --short HEAD | tr -d '\n'"},
      	'src-git-full' => {
      		'init'          => "git clone '%s' '%s'",
      		'init_branch'   => "git clone --branch '%s' '%s' '%s'",
      		'init_commit'   => "git clone '%s' '%s' && cd '%s' && git checkout -b '%s' '%s' && cd -",
      		'update'	=> "git pull --ff-only",
      		'update_force'	=> "git pull --ff-only || (git reset --hard HEAD; git pull --ff-only; exit 1)",
      		'post_update'	=> "git submodule update --init --recursive",
      		'controldir'	=> ".git",
      		'revision'	=> "git rev-parse --short HEAD | tr -d '\n'"},
      	'src-gitsvn' => {
      		'init'	=> "git svn clone -r HEAD '%s' '%s'",
      		'update'	=> "git svn rebase",
      		'controldir'	=> ".git",
      		'revision'	=> "git rev-parse --short HEAD | tr -d '\n'"},
      	'src-bzr' => {
      		'init'		=> "bzr checkout --lightweight '%s' '%s'",
      		'update'	=> "bzr update",
      		'controldir'	=> ".bzr"},
      	'src-hg' => {
      		'init'		=> "hg clone '%s' '%s'",
      		'update'	=> "hg pull --update",
      		'controldir'	=> ".hg"},
      	'src-darcs' => {
      		'init'    => "darcs get '%s' '%s'",
      		'update'  => "darcs pull -a",
      		'controldir' => "_darcs"},
      );
      
      # src-git: pull broken
      # src-cpy: broken if `basename $src` != $name
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16
      • 17
      • 18
      • 19
      • 20
      • 21
      • 22
      • 23
      • 24
      • 25
      • 26
      • 27
      • 28
      • 29
      • 30
      • 31
      • 32
      • 33
      • 34
      • 35
      • 36
      • 37
      • 38
      • 39
      • 40
      • 41
      • 42
      • 43
      • 44
      • 45
      • 46
      • 47
      • 48
      • 49
      • 50
      • 51
      • 52
      • 53
      • 54
      • 55
      • 56
      • 57

    src-svn与src-gitsvn

    'src-svn' => {
    		'init'		=> "svn checkout '%s' '%s'",
    		'update'	=> "svn update",
    		'controldir'	=> ".svn",
    		'revision'	=> "svn info | grep 'Revision' | cut -d ' ' -f 2 | tr -d '\n'"},
    'src-gitsvn' => {
    		'init'	=> "git svn clone -r HEAD '%s' '%s'",
    		'update'	=> "git svn rebase",
    		'controldir'	=> ".git",
    		'revision'	=> "git rev-parse --short HEAD | tr -d '\n'"},
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 用法:
    src-svn NueXini_Packages https://github.com/NueXini/NueXini_Packages/trunk/
    # 拉取默认分支
    src-svn NueXini_Packages https://github.com/NueXini/NueXini_Packages/branches/v20220620
    # 拉取指定分支
    src-svn NueXini_Packages https://github.com/NueXini/NueXini_Packages/trunk/luci-app-disableipv6/
    # 拉取指定文件夹
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    src-gitsvn NueXini_Packages https://github.com/NueXini/NueXini_Packages.git
    
    • 1

    src-git与src-git-full

    'src-git' => {
    		'init'          => "git clone --depth 1 '%s' '%s'",
    		'init_branch'   => "git clone --depth 1 --branch '%s' '%s' '%s'",
    		'init_commit'   => "git clone '%s' '%s' && cd '%s' && git checkout -b '%s' '%s' && cd -",
    		'update'	=> "git pull --ff-only",
    		'update_force'	=> "git pull --ff-only || (git reset --hard HEAD; git pull --ff-only; exit 1)",
    		'post_update'	=> "git submodule update --init --recursive",
    		'controldir'	=> ".git",
    		'revision'	=> "git rev-parse --short HEAD | tr -d '\n'"},
    		
    'src-git-full' => {
    		'init'          => "git clone '%s' '%s'",
    		'init_branch'   => "git clone --branch '%s' '%s' '%s'",
    		'init_commit'   => "git clone '%s' '%s' && cd '%s' && git checkout -b '%s' '%s' && cd -",
    		'update'	=> "git pull --ff-only",
    		'update_force'	=> "git pull --ff-only || (git reset --hard HEAD; git pull --ff-only; exit 1)",
    		'post_update'	=> "git submodule update --init --recursive",
    		'controldir'	=> ".git",
    		'revision'	=> "git rev-parse --short HEAD | tr -d '\n'"},
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 这两者共同操作是git clone区别是clone的深度不一样, src-git-full是全clone, 而src-git的深度为--depth 1
    • 用法: src-git-full / src-git-full 保存的文件夹名 仓库地址
    • 注: 后面可指定 分支, tag, commit , 不填则是拉取默认分支
    src-git NueXini_Packages https://github.com/NueXini/NueXini_Packages.git;main
    # 指定branch
    src-git NueXini_Packages https://github.com/NueXini/NueXini_Packages.git;v20220620
    # 指定tag
    src-git NueXini_Packages https://github.com/NueXini/NueXini_Packages.git^47e35dd380b88d5cffc267eabe7a125da86d194b
    # 指定commit
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    src-cpy与src-link

    'src-cpy' => {
    		'init'		=> "cp -Rf '%s' '%s'",
    		'update'	=> "",
    		'revision'	=> "echo -n 'local'"},
    'src-link' => {
    		'init'		=> "ln -s '%s' '%s'",
    		'update'	=> "",
    		'revision'	=> "echo -n 'local'"},
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    这两个命令的唯一区别是src-cpy会复制一份源到feeds目录, src-link则是ln -s创建一个软链接, 我个人是比较倾向src-link的, 这样可以修改源码能及时响应.

    • 用法: src-cpy / src-link 保存的文件名 源目录
    • src-link必须是完整的绝对路径
    src-link NueXini_Packages package/NueXini_Packages
    # 拉取package目录下的NueXini_Packages目录
    
    • 1
    • 2

    其他的src命令

    • bzr, hg, darcs 一些其他的分布式版本控制系统, 基本很少用到, 可以自行参考命令解释了解使用方法

    feeds命令用法

    sub usage() {
    	print <<EOF;
    Usage: $0  [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 :  List packages of specified feed.
    	    -d : Use specified delimiter to distinguish rows (default: spaces)
    	    -f :            List feeds in feeds.conf compatible format (when using -s).
    	install [options] : Install a package
    	Options:
    	    -a :           Install all packages from all feeds or from the specified feed using the -p option.
    	    -p : 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] : Search for a package
    	Options:
    	    -r : Only search in this feed
    	uninstall -a|: 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.
    EOF
    	exit(1);
    }
    
    my %commands = (
    	'list' => \&list,
    	'update' => \&update,
    	'install' => \&install,
    	'search' => \&search,
    	'uninstall' => \&uninstall,
    	'feed_config' => \&feed_config,
    	'clean' => sub {
    		system("rm -rf ./feeds ./package/feeds ./target/linux/feeds");
    	}
    );
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44

    branch与commit的分割符号

    sub update_feed_via($$$$$) {
    	my $type = shift;
    	my $name = shift;
    	my $src = shift;
    	my $relocate = shift;
    	my $force = shift;
    
    	my $m = $update_method{$type};
    	my $localpath = "./feeds/$name";
    	my $safepath = $localpath;
    	$safepath =~ s/'/'\\''/;
    	my ($base_branch, $branch) = split(/;/, $src, 2);
    	my ($base_commit, $commit) = split(/\^/, $src, 2);
    
    	if( $relocate || !$m->{'update'} || !-d "$localpath/$m->{'controldir'}" ) {
    		system("rm -rf '$safepath'");
    		if ($m->{'init_branch'} and $branch) {
    			system(sprintf($m->{'init_branch'}, $branch, $base_branch, $safepath)) == 0 or return 1;
    		} elsif ($m->{'init_commit'} and $commit) {
    			system(sprintf($m->{'init_commit'}, $base_commit, $safepath, $safepath, $commit, $commit)) == 0 or return 1;
    		} else {
    			system(sprintf($m->{'init'}, $src, $safepath)) == 0 or return 1;
    		}
    	} elsif ($m->{'init_commit'} and $commit) {
    		# in case git hash has been provided don't update the feed
    	} else {
    		my $update_cmd = $m->{'update'};
    		if ($force && exists $m->{'update_force'}) {
    			$update_cmd = $m->{'update_force'};
    		}
    		system("cd '$safepath'; $update_cmd") == 0 or return 1;
    	}
    	if ($m->{'post_update'}) {
    		my $cmd = $m->{'post_update'};
    		system("cd '$safepath'; $cmd") == 0 or return 1;
    	}
    
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 透过以上代码, 主要能看见branchcommit的分割是不一样的
    • branch用的分割符号是;
    • commit用的分割符号是^
    my ($base_branch, $branch) = split(/;/, $src, 2);
    my ($base_commit, $commit) = split(/\^/, $src, 2);
    
    • 1
    • 2

    branch与tag的区别

    • tag就是给commit的hash校验和取的一个名字,比较直观,方便记忆和使用

    • tag就像是一个里程碑一个标志一个点,branch是一个新的征程一条线;tag是静态的,branch要向前走;

    • tag 对应某次 commit, 是一个点,是不可移动的。
      branch 对应一系列 commit,是很多点连成的一根线,有一个HEAD 指针,是可以依靠 HEAD 指针移动的。

      所以,两者的区别决定了使用方式,改动代码用 branch ,不改动只查看用 tag。

    • 参考https://git-scm.com/book/zh/v2/Git-%E5%9F%BA%E7%A1%80-%E6%89%93%E6%A0%87%E7%AD%BE


    Enjoy it ~

  • 相关阅读:
    『现学现忘』Docker相关概念 — 2、云计算的服务模式
    Revit建模中如何快速画好幕墙?
    【react】基础知识补充及原理【粗略版】
    算法训练 第八周
    2023年9月 少儿编程 中国电子学会图形化编程等级考试Scratch编程一级真题解析(判断题)
    一分钟了解什么是限流
    云原生时代,让软件架构设计行云流水的奥秘
    操作系统—— I/O 相关知识
    FPGA学习笔记(九)SPI学习总结及stm32的HAL库下SPI配置
    MQ学习总结
  • 原文地址:https://blog.csdn.net/a924282761/article/details/125997419