You are not logged in.
Pages: 1
Hi Boardies!
I'm working on a script to automatically generate PKGBUILDs for my custom kernels (For my 3 systems I need 3 custom kernel packages).
Each PKGBUILD needs the md5 checksum block, which I can generate with "makepkg -c > PKGBUILD".
Here is the problem
This command writes the checksums at the end of the PKGBUILD file. This isn't a clean solution. The checksums should wrote before the "build()" function.
Because of that I need a trickly bash command, which search (grep maybe?) the "build() "-line and writes the md5-checksum block before that line.
I tested around with egrep, but I can't isolate the line-number of "build()" and I don't know how to paste the md5-checksums be at the position (line - 1)!
I hope somebody can help me. Thanks for your answers
Best regards,
Flasher
Offline
You probably want to use either awk or sed or a combination of the two. I'm not too good with either of them anymore, so I'll refer to their comprehensive and confusing man pages.
Dusty
Offline
could this be what you are looking for ?
Other sed commands
11. For every line with string1, put string2 on the beginning of the preceding line
sed '/string1/a\
string2' filename
Offline
A simple perl script would be appropriate. The easiest way to approach this problem (actual perl programmers feel free to correct me) is to do the following:
iterate over the file, pulling each line into a string appended to an array
iterate over the array, printing each line. If build() is matched, print md5sum, then the line.
write the corrected file to stdout
Here's one I called test.pl
#!/usr/bin/perl
#Add MD5SUM to file
#Read from stdin into @file
while (<>) {
chomp;
push(@file, $_);
}
foreach my $a (@file) {
if ($a =~ /build\(\)/) {
print "MD5SUM\n";
}
print "$a\n";
}
Then the following command:
cat PKGBUILD | ./test.pl > temp
mv temp PKGBUILD
Produces an identical PKGBUILD with the word MD5SUM printed on the line above build().
Cthulhu For President!
Offline
Hi!
Perfect! Many thanks for your efforts
Greetings,
Flasher
Offline
Wouldn't it be simpler to do it this way?
#!/usr/bin/perl
#Add MD5SUM to file
my $md5sum = shift @ARGV;
#Read from stdin into @file
while (<>) {
if(/build\(\)/) {
print "md5sums=('$md5sum')\n";
}
print;
}
But I don't know the real PKGBUILD syntax (and also buttons' works, but I just wanted to have some fun)
Offline
Notwithstanding all the above, let me just add the following note:
This command writes the checksums at the end of the PKGBUILD file. This isn't a clean solution. The checksums should wrote before the "build()" function.
The checksums can be anywhere, just like any other PKGBUILD element. It is incorrect to say that they should be in a specific place. You may have a preference for them to be somewhere other than the end of the PKGBUILD, but that's a different matter altogether.
Offline
Pages: 1