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

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
    

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'"},
  • 用法:
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/
# 拉取指定文件夹
src-gitsvn NueXini_Packages https://github.com/NueXini/NueXini_Packages.git

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'"},
  • 这两者共同操作是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

'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-cpy会复制一份源到feeds目录, src-link则是ln -s创建一个软链接, 我个人是比较倾向src-link的, 这样可以修改源码能及时响应.

  • 用法: src-cpy / src-link 保存的文件名 源目录
src-link NueXini_Packages package/NueXini_Packages
# 拉取package目录下的NueXini_Packages目录

其他的src命令

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

feeds命令用法

sub usage() {
	print <<EOF;
Usage: $0 <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.
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");
	}
);

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;
}
  • 透过以上代码, 主要能看见branchcommit的分割是不一样的
  • branch用的分割符号是;
  • commit用的分割符号是^
my ($base_branch, $branch) = split(/;/, $src, 2);
my ($base_commit, $commit) = split(/\^/, $src, 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 ~

张贴在2