BashScripts.org
http://bashscripts.org/forum/

Spec files
http://bashscripts.org/forum/viewtopic.php?f=8&t=124
Page 1 of 1

Author:  hawkwind [ Thu Aug 25, 2005 8:23 pm ]
Post subject:  Spec files

I've done a few bash scripts myself, and I'm not even sure if bash would be the best way to do this, but here goes anyways.

I constantly build rpms for Mandriva and always have to edit the spec files before building them with certain criteria. I was wondering if someone has or can do a bash script to accomplish something.

I'm wanting to add 2 lines to a spec file under the %changelog section of the file now. The two lines I need/want have to be exactly as I have them below, followed by a blank line and the two lines have to start on the first line after the %changelog line in the spec file

* Thu Aug 25 2005 Cliff Wade <[email protected]>
- Built for the SoS Rpm Repository located at: http://seerofsouls.com

They have to be exactly like that, with the * and the - in the beginning as shown above. The day, month date and year need to be the current day, month, date, and year that the script is run and the lines added to the spec file.

When you rebuild anywhere from 10 to 80 .src.rpms per day, it gets a little old typing that once, then copy/pasting it to each and every spec file. I'd like to be able to run something like ./changelog.sh *.spec and it add that line to every spec file in the directory, keeping the name of the spec file in tact as well.

If any further info is needed, please let me know here and I will gladly provide it ASAP.

Thanks in advance!

The box said: Requires Windows 98 or better, So I installed Linux!
Registered Linux User #362532
http://seerofsouls.com
http://linuxfordummies.org
http://doomsickle.com
IRC server: irc.freenode.net in #LFD

Author:  jbsnake [ Thu Aug 25, 2005 8:34 pm ]
Post subject: 

hey hawkwind... nice to have you here :)
just a couple questions
1) is this file a text file (i'm assuming it is)
2) maybe you can post an example spec file... not the whole thing if it's long but atleast a section before and after where the lines need to be added
3) i see a date there on the first line... does that need to be dynamic or a static "trademark" date?

ok...maybe a few questions instead of a couple :wink:

Author:  hawkwind [ Thu Aug 25, 2005 8:35 pm ]
Post subject:  Actual spec file

Here is a link to an actual spec file. This one has already been edited as the rpms have already been created from this file.

http://doomsickle.com/cairo.spec

The date needs to be the current date of when the script is run by myself. So if it's Mon Sep 19 2005 then it needs to put that date into the file.

Author:  jbsnake [ Thu Aug 25, 2005 9:44 pm ]
Post subject: 

here you go...
crude...yet affective :)
Code:
#!/bin/bash

cur_date=`date +"%a %b %d %Y"`
cur_date="* $cur_date"
info="$cur_date Cliff Wade <[email protected]>\n"
info2="- Built for the SoS Rpm Repository located at: http://seerofsouls.com\n"

for file in *.spec
do
        filename="$file"
        echo $filename
        until ! read buffer
        do
                if [[ "$buffer" = "%changelog" ]]
                then
                        echo -e "%changelog\n${info}${info2}"  >> newfile2.spec
                else
                        echo "$buffer"  >> newfile2.spec
                fi
        done < "${file}"

        mv newfile2.spec "$filename"
done

if that is executed in the directory of the .spec files it should do what you want

Author:  crouse [ Thu Aug 25, 2005 10:21 pm ]
Post subject: 

I like mine better :P

Code:
#!/bin/bash
cur_date=`date +" %a %b %d %Y"`
info="Cliff Wade <[email protected]>"
moreinfo="- Built for the SoS Rpm Repository located at: http:\/\/seerofsouls.com"
echo "Editing .spec files" ; for i in *.spec ; do
sed -e "s/%changelog/%changelog \n *$cur_date $info \n $moreinfo \n  /" $i > newfile.spec
mv newfile.spec $i ; done ; echo "Finished"; exit

Author:  jbsnake [ Thu Aug 25, 2005 10:44 pm ]
Post subject: 

yea yea yea...
:P

Author:  hawkwind [ Fri Aug 26, 2005 8:56 am ]
Post subject:  add2spec.sh

All I can say is: You guys ROCK!!!!

I have tried them both, and they work flawlessly and just as I wanted. Thank you both very very much.

The box said: Requires Windows 98 or better, So I installed Linux!
Registered Linux User #362532
http://seerofsouls.com
http://linuxfordummies.org
http://doomsickle.com
IRC server: irc.freenode.net in #LFD

Author:  crouse [ Fri Aug 26, 2005 9:39 am ]
Post subject: 

glad we could help ;)

Page 1 of 1 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com