Difference between revisions of "Patch and diff"
Andypflueger (talk | contribs) |
Andypflueger (talk | contribs) m |
||
Line 14: | Line 14: | ||
diff -r -N -b -u html.orig html > app-patch.diff | diff -r -N -b -u html.orig html > app-patch.diff | ||
* This then can go into the install script as follows: | * This then can go into the install script as follows: | ||
− | patch -p0 -E << EOF | + | patch -p0 -E << 'EOF' |
.... contents of app-patch.diff here .... | .... contents of app-patch.diff here .... | ||
− | EOF | + | 'EOF' |
Note: If patching a single file above, after the 'patch -p0 -E' and before the '<< EOF', insert the filename of file to be patched. Otherwise, installer will attempt to prompt for File to patch and then skip immediately since its automated. | Note: If patching a single file above, after the 'patch -p0 -E' and before the '<< EOF', insert the filename of file to be patched. Otherwise, installer will attempt to prompt for File to patch and then skip immediately since its automated. |
Latest revision as of 17:51, 12 September 2009
This is an "advanced" technique for install scripts to
- Reduce the size of install scripts
- Make them more forward compatible for the future
- Make them more robust
The Idea
The idea is simple: install by hand, make changes to make it work, then compare against the pristine sources, generating a patch that later does automatically what you did by hand
- Setup the app for installation as a webapp (say in html). Save a pristine copy as html.orign
- Make changes in html/ only
- Find out the diff of what you made:
diff -r -N -b -u html.orig html > app-patch.diff
- This then can go into the install script as follows:
patch -p0 -E << 'EOF' .... contents of app-patch.diff here .... 'EOF'
Note: If patching a single file above, after the 'patch -p0 -E' and before the '<< EOF', insert the filename of file to be patched. Otherwise, installer will attempt to prompt for File to patch and then skip immediately since its automated.
Testing the patch ahead of time
It is strongly encouraged that you test the patch before attempting trial-and-error runs in the install script, which can be time consuming and error prone. This is basically simulating the install script applying the patch.
To do this, do this:
mv html html.modified cp -a html.orig html mv html.orig html.pristine
(the last step is to prevent patch from accidentally patching html.orig)
then try your patch against html dir (which is now like the original):
patch -p0 -E < app-patch.diff
There is a --dry-run option for patch that lends itself useful for previewing the patch without it actually patching files.
Doing this will save you a lot of trial-and-error in the installer.
If you have an problems, remove html and then
cp -a html.pristine html
(or unpack the app again and rename it to make the root html/)