Development/Howto/Specfile Hacks
From Mandriva Community Wiki
This page serves as a copy and paste resource... (because I have a hard time remembering...). Small fixes that you can use to fix issues in rpm spec files.
Contents[hide] |
[edit] rpmlint fixes
rpmlint has recently started to nag about CRLF files (Carriage Return + Line Feed). These are mostly files made using that OS from the evil empire. To fix this, you could do:
BuildRequires: file %setup # strip away annoying ^M find . -type f|xargs file|grep 'CRLF'|cut -d: -f1|xargs perl -p -i -e 's/\r//' find . -type f|xargs file|grep 'text'|cut -d: -f1|xargs perl -p -i -e 's/\r//'
(for some reason some ms files are not caught by the above, please tell me why...)
Other tools that also could be used are dos2unix, tr, sed, etc. I tried to use dos2unix for a while, but it totally trashed the mysql-query-browser-1.1.7 build...
Only time, trial and error will tell which method is the best..., I guess?
You may also get some warnings about included CVS/SVN files, and I usually fix that like this:
%setup if [ -d ./CVS ]; then echo "Fixing strange attribs" find . -type d -perm 0700 -exec chmod 755 {} \; find . -type f -perm 0555 -exec chmod 755 {} \; find . -type f -perm 0444 -exec chmod 644 {} \; fi for i in `find . -type d -name CVS` `find . -type d -name .svn` `find . -type f -name .cvs\*` `find . -type f -name .#\*`; do if [ -e "$i" ]; then rm -rf $i; fi >&/dev/null done
[edit] One liners
Extract all spec files from main and contrib:
cd /extract/directory/location for i in /SRPMS/main/*.rpm; do rpm2cpio $i | cpio -mi \*.spec; done for i in /SRPMS/contrib/*.rpm; do rpm2cpio $i | cpio -mi \*.spec; done
Note: Correct spec file naming is crucial in this example, if not some will get owerwritten.
[edit] Search and replace
Multiline search and replace using perl (thanks goes to RafaelGarciaSuarez)
Suppose you have two lines in a file like this: known_line1 known_line2 And you want to replace these with something else, this is how to do it: perl -pi -e -0777 's/known_line1\nknown_line2/two other lines/g' the_file ms windows users will have to use -i.bak like so: perl -i.bak -0777 -pe 's/known_line1\nknown_line2/two other lines/g' the_file