确定应应用补丁的顺序的工具?

Tool that figures out order in which patches should be applied?

背景:

我正在尝试让 Ubuntu 在 FIPS 模式下工作。我需要 FIPSify 的软件包之一是 openssh。根据 CentOS openssh *.spec 文件,他们在 openssh 源代码之上应用的补丁之一是 openssh-6.6-fips.patch。然而,debian 打包代码根本没有那个补丁所以我想从 CentOS "borrow" 它并在 Ubuntu.

上使用

问题:

不幸的是,由于 CentOS 在生成它之前应用了其他补丁,因此这个 openssh-6.6-fips.patch 补丁不能完全应用在 ubuntu openssh 源代码之上。我有所有的补丁,但要不冲突地应用它们并不容易,因为我不知道补丁依赖性。

是否有一个工具可以自动执行此过程,并且作为输入可以从 Ubuntu 获取 openssh 源代码、CentOS 的补丁和我想应用的 "target" 补丁。然后在输出中它会告诉我是否(以及如何)应用这些 CentOS 补丁而不触发冲突?

为此使用的工具是一个版本控制系统,我将展示(完全未经测试)git 我将如何做的命令。

## Create repository ##
$ mkdir workdir
$ cd workdir
$ git init
$ touch .gitignore             # \   Creates a first commit
$ git add .gitignore           #  >  for the branches to
$ git commit -m .gitignore     # /   have in common

## Import debian source code ##
$ git checkout -b debian master
$ tar zxvf /the/debian/source/code.tgz
$ git add .
$ git commit -m "Base debian source code"

## Import centos source code ##
$ git checkout -b centos master
$ tar zxvf /the/centos/source/code.tgz
$ git add .
$ git commit -m "Base centos source code"

## Apply centos rpm patches ##
$ pacth -p1 < /the/file/listed/as/patch1/in/spec/file
$ git add .
$ git commit -m the_pacth1_file_name

$ pacth -p1 < /the/file/listed/as/patch2/in/spec/file
$ git add .
$ git commit -m the_pacth2_file_name

$ # repeat for all the patches up till, including openssh-6.6-fips.patch

到目前为止,该命令只为您提供了一个 git 存储库,其中包含构建包时使用的最终源代码。然而,由于补丁存储为单独的提交(这是关键),我们可以根据需要进行标准版本控制操作和include/exclude部分分支。

所以假设 openssh-6.6-fips.patch 是补丁号 5 只是为了选择一个数字,你的问题是它不能完全适用于 ubuntu 源,因为 done 中有一些额外的变化在它构建的补丁 1 到 4 中,对吧?

一个合适的版本控制系统会跟踪父版本与版本的关系,如果幸运的话,它会自己找出解决冲突的方法,否则它可能会放弃,你需要手动解决它,但无论如何,版本控制系统是处理此类情况的最佳工具。

因此,如果您想要从 centos 源代码获得的唯一补丁是 openssh-6.6-fips.patch,那么您可以在基本 centos 源代码提交之上创建一个仅包含此补丁的新分支,然后将该分支重新定位到 ubuntu 分支。然后,该重新提交的提交将为您提供一个补丁,该补丁将干净利落地应用到 ubuntu 源代码

$ git checkout -b fips centos
$ git rebase -i master      # Pick only the first base commit
                            # and the openssh-6.6-fips.patch
$ # Resolve conflicts if any and check in

现在你有一个分支 fips,它只包含 centos 基本源代码和 fips 提交。然后你想把它变基到 ubuntu 分支上。

# Rebase from (excluding) one behind the top of fips branch,
# to (including) the tip of the fips branch
$ git rebase --onto ubuntu fips^ fips
# Resolve and check in any conflicts should there be any
$ git format-patch ubuntu..fips

最后一个命令将为您提供一个补丁文件,您可以将其应用干净,您可以将其添加到打包代码中。

OpenSSH 不是 "from" Ubuntu(或 CentOS)。两者都使用特定版本,并对其应用补丁。 RPM 规范文件按应用顺序列出补丁。这些补丁已调整为与用作基本版本的特定版本的 OpenSSH 一起使用。

如果没有很好地理解OpenSSH,您会发现很难将部分补丁适配到不同的版本(或不同的打包系统)。

同样,由于 OpenSSH 被其他包使用,您会发现在重建包并将其替换到您的 Ubuntu 系统中时会出现问题。

可以使用规范文件作为指南,按顺序应用补丁,并配置 OpenSSH 的第二个副本以安装在非系统目录中,例如,/usr/local/openssh-fips(使用配置脚本的 --prefix 选项)。