cookutils view doc/general-questions.md @ rev 1150

Show recent broken packages first
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Feb 19 15:32:45 2022 +0000 (2022-02-19)
parents 6867a12b73aa
children
line source
1 # General questions
3 ## `sed` or patches?
5 Sometimes I come across cases where `sed` is used to change some values in the
6 source code or to add / remove / change some parts of the source code.
7 It may look like a good idea for a one-time job, but you will encounter
8 problems in the future when you upgrade the package.
10 `sed` works quietly and it is impossible to understand whether it found what
11 was needed to be found, whether it replaced what we wanted? Maybe this change
12 is already in the new sources and we no longer need `sed` command?
14 If we consider only the updated sources, sometimes it is impossible
15 to understand the essence of the `sed` changes. And then you have to download
16 and analyze the old sources.
18 Feel free to use patches. The `patch` is smart enough to find the necessary
19 lines in the new sources and also it will signal to you if your changes have
20 already been made in the sources or if the sources has changed so much that
21 your intervention is required.
23 Go from `sed` to `patch` is easy. You must use the `-o.backup` option (value
24 after the `-o` you can change). For example, you used this code:
26 ```bash
27 sed -i '/debug/ s|true|false|' config
28 ```
30 Now apply the changes saving the original file:
32 ```bash
33 sed -i.orig '/debug/ s|true|false|' config
34 ```
36 Create a patch using the original and modified files:
38 ```bash
39 diff ./config.orig ./config > ../../stuff/patches/config.patch
40 ```
42 Now you can use the created patch and remove the `sed` command.