Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
becki:linux:diffupgrade [2009-07-04 09:58] becki |
becki:linux:diffupgrade [2011-06-08 16:26] (aktuell) becki |
||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | ====== Upgrading Configuration Files with the Diffutils == | + | ====== Upgrading Configuration Files with a three-way File Merge == |
- | ===== Probelm == | + | ===== Problem == |
- | When upgrading e.g. web based software or the Linux OS you usually have customized the config files to your personal need. Now the config files of the new software version also differ from the original version. What you want is an easy way to get your own modifications into the new config files. | + | When upgrading software (e.g. with [[slack_upgrade|slackpkg]]) you usually have customized the config files to your personal need. Now the config files of the new software version also differ from the original version. What you want is an easy way to get your own modifications into the new config files. |
- | ===== Basic Principle == | + | ===== Solution == |
- | The directory ''old/'' contains the files of the old version of the software (with personal costumizations) whereas ''new/'' is the brandnew pristine version. The following commands merge the personal modifications of the exemplary file ''conf'' from ''old/'' into ''new/'': | + | The solution is exemplified with just 1 configuration file called ''conf'': |
- | mv new/conf new/conf.org | + | * ''conf.org'' is the original config file of old version of the software. Eighter you have created that file by copying //before// you made any modifications to ''conf'' or you can get it again by downloading the old version of the software. |
- | diff3 -m new/conf.org .old/conf.org old/conf > new/conf | + | * ''conf'' is your version of ''conf.org''. You have customized to your needs. |
+ | * ''conf.new'' is the brandnew pristine version coming from the upgrade. | ||
- | An alternative approach is by using the diff/patch commands: | + | The following command merges both the differences between ''conf.org'' and ''conf'' and the differences between ''conf.org'' and ''conf.new'' back into ''conf'': |
- | cd old | + | merge conf conf.org conf.new |
- | diff -u conf.org conf > conf.diff | + | |
- | cd ../new | + | |
- | patch < ../old/conf.diff | + | |
- | Note that you need ''old/conf.org'', which is the original file of old version of the software. Eighter you have created that file by copying //before// you made any modifications to ''conf'' or you can get it again by downloading the old version of the software. | + | After merging it is advisable to rename conf.new to be prepared for a future update: |
- | Sometimes you have to create a file which did not exist before (e.g. ''myConfFile''). In order not to forget such files during update, it is advisable to create an empty counterpart file ''myConfFile.org''. | + | mv conf.new conf.org |
- | ===== Examples where the tools fail == | + | <note tip>All ''*.org'' files can serve as a reminder for you to trace back all the modifications you did to the system. But sometimes you have to create a config file which did not exist before (e.g. ''myConfigFile''). In order not to forget such files during update, it is advisable to create an //empty// counterpart file ''myConfFile.org''.</note> |
- | A manual check after the patch is applied is advisable, for there are sitiation where do not produce the expected results: | + | ===== Example where the tools fail == |
- | ==== diff/patch Failure == | + | A manual check after the patch is applied is advisable, for there are situations imaginable where the tools do not produce the expected results: |
- | + | ||
- | This is an example where diff/patch doesn't work as expected (but diff3 works): | + | |
<code> | <code> | ||
- | old/conf.org: old/conf: new/conf.org desired: result: | + | conf.org: conf: conf.new: desired: result: |
[mitwitz] [mitwitz] [coburg] [coburg] [coburg] | [mitwitz] [mitwitz] [coburg] [coburg] [coburg] | ||
Zeile 47: | Zeile 43: | ||
Franz=8 Franz=-999 Franz=8 | Franz=8 Franz=-999 Franz=8 | ||
Helga=9 Helga=9 Helga=9 | Helga=9 Helga=9 Helga=9 | ||
- | Egon=10 Egon=10 Egon=10 | ||
- | Anton=11 Anton=11 Anton=11 | ||
</code> | </code> | ||
- | ==== diff/patch and diff3 Failure == | + | ===== Alternatives == |
- | This is an example where neither of the tools work as expected: | + | * An alternative to the ''merge'' command is ''diff3'', it should produce the same result:<code bash> |
- | + | diff3 -m conf conf.org conf.new > conf.out | |
- | <code> | + | mv conf.out conf |
- | old/conf.org: old/conf: new/conf.org desired: result: | + | |
- | + | ||
- | [mitwitz] [mitwitz] [coburg] [coburg] [coburg] | + | |
- | Otto=5 Otto=5 Otto=5 Otto=5 Otto=5 | + | |
- | Guenter=6 Guenter=6 Guenter=6 Guenter=6 Guenter=6 | + | |
- | Harry=7 Harry=7 Harry=7 Harry=7 Harry=7 | + | |
- | Franz=8 Franz=-999 Franz=8 Franz=8 Franz=-999 | + | |
- | Helga=9 Helga=9 Helga=9 Helga=9 Helga=9 | + | |
- | Egon=10 Egon=10 Egon=10 Egon=10 Egon=10 | + | |
- | Anton=11 Anton=11 Anton=11 Anton=11 Anton=11 | + | |
- | [mitwitz] [mitwitz] [mitwitz] | + | |
- | Otto=5 Otto=5 Otto=5 | + | |
- | Guenter=6 Guenter=6 Guenter=6 | + | |
- | Harry=7 Harry=7 Harry=7 | + | |
- | Franz=8 Franz=-999 Franz=8 | + | |
- | Helga=9 Helga=9 Helga=9 | + | |
</code> | </code> | ||
+ | * A 2nd alternative to merge are the diff/patch tools. See [[diff patch tips]] | ||