You are not logged in.

#1 2009-10-16 17:58:28

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

[Solved] Clever-way of putting a md5sum after source in PKGBUILD?

Been trying to find a way to do this.  'makepkg -g >> PKGBUILD' puts the md5sums at the end of the line and was hoping to find a way to put them after the source line.  Been thinking about a way to do this but it's pretty ugly.  Thinking something like this would do:

sed -e '1,/md5sum/d' PKGBUILD > PKGBUILD.tmp
sed -i '/md5sum/,/\t/d' PKGBUILD
makepkg -g PKGBUILD
cat PKGBUILD.tmp >> PKGBUILD
rm PKGBUILD.tmp

But thinking there's got to be a better way.  Has anyone come up (or have any ideas on how to) put md5sums after source?

Last edited by Gen2ly (2009-10-25 16:54:32)


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#2 2009-10-16 18:07:36

Ramses de Norre
Member
From: Leuven - Belgium
Registered: 2007-03-27
Posts: 1,289

Re: [Solved] Clever-way of putting a md5sum after source in PKGBUILD?

Something like this?

sed -i -e "s/^source.*$/&\n$(makepkg -g)/" PKGBUILD

Edit:
To also remove any pre-existing md5sum line,

sed -i -e '/^md5sum/d' -e "s/^source.*$/&\n$(makepkg -g)/" PKGBUILD

Last edited by Ramses de Norre (2009-10-16 18:16:16)

Offline

#3 2009-10-16 18:36:26

shining
Pacman Developer
Registered: 2006-05-10
Posts: 2,043

Re: [Solved] Clever-way of putting a md5sum after source in PKGBUILD?

Does this handle a source split on multiple lines ?

Btw also check out http://bugs.archlinux.org/task/15051

We are still looking for THE way to update checksums tongue


pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))

Offline

#4 2009-10-16 18:46:25

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: [Solved] Clever-way of putting a md5sum after source in PKGBUILD?

This will save me a good bit of time.  I did make one small edit so the entire md5sum gets covered (i.e. spans over one line):

sed -i -e '/^md5sum/,/)/d' -e "s/^source.*$/&\n$(makepkg -g)/" PKGBUILD

Veeerrry nice, Ramses de Norre.  Thanks for the help.

Edit:

shining wrote:

Does this handle a source split on multiple lines ?

....

Last edited by Gen2ly (2009-10-16 18:55:25)


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#5 2009-10-23 04:28:43

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: [Solved] Clever-way of putting a md5sum after source in PKGBUILD?

Heh, you guys are probably gonna get a good laugh out of this but I did find a way to get this to work.  It ain't pretty, but heh... smile

# Remove trailing blank lines
while [ "$(tail -n 1 PKGBUILD)" == "" ]; do
  sed -i '$d' PKGBUILD
done

# Delete previous md5sum entries
sed -i "/^.*'[a-z0-9]\{32\}'.*$/d" PKGBUILD
sed -i "/^md5sums/,/$/d" PKGBUILD

# Save then delete the build section
sed -e '/^build().*$/,$!d' PKGBUILD > /tmp/PKGBUILD.tmp
sed -i '/^build().*$/,$d' PKGBUILD

# Remove trailing blank lines
while [ "$(tail -n 1 PKGBUILD)" == "" ]; do
  sed -i '$d' PKGBUILD
done

# Add md5sums
makepkg -g >> PKGBUILD

# Add two blank lines to seperate variable and build section
echo -e "\n" >> PKGBUILD

# Re-append build section
cat /tmp/PKGBUILD.tmp >> PKGBUILD

Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#6 2009-10-23 05:19:29

makimaki
Member
From: Ireland
Registered: 2009-04-02
Posts: 109

Re: [Solved] Clever-way of putting a md5sum after source in PKGBUILD?

@Gen2ly:
nice smile


====* -- Joke
    O
    \|/ --- Me
    / \             Whooooosh

Offline

#7 2009-10-25 16:53:16

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: [Solved] Clever-way of putting a md5sum after source in PKGBUILD?

I got a couple guys to help me out with this.  Awk it turns out is a much better way to do this.  Ah... awk.  Here's a more-awkward way of doing it: tongue

awk 'BEGIN {
  checkAt = 0
  filesAt = 0
  scanning = 0
}

/md5sums=\(/ {
  checkAt = NR
  scanning = 1
}

/source=\(/ {
  filesAt = NR
  scanning = 1
}

/)$/ {
  if (scanning) {
    if (checkAt > filesAt) {
      checkEnd = NR
    } else {
      filesEnd = NR
    }
    scanning = 0
  }
}

{
  lines[NR] = $0
}

END {
  for (i = 1; i <= NR; ++i) {
    if (checkAt <= i && i <= checkEnd) {
      continue
    }
    print lines[i]
    if (i == filesEnd) {
      for (j = checkAt; j <= checkEnd; ++j) {
        print lines[j]
      }
    }
  }
}' PKGBUILD > /tmp/PKGBUILD.tmp
mv /tmp/PKGBUILD.tmp PKGBUILD

This has the benefit of being able to put the md5sum after the source array even if it's before the source line.  Yah!


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#8 2009-10-25 18:23:39

shining
Pacman Developer
Registered: 2006-05-10
Posts: 2,043

Re: [Solved] Clever-way of putting a md5sum after source in PKGBUILD?

Did you read the bug report comments ? There is a awk one-liner there which works.

But the questions were how to deal with multiple checksums, and how to integrate this with makepkg.


pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))

Offline

#9 2009-10-25 21:26:29

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: [Solved] Clever-way of putting a md5sum after source in PKGBUILD?

Actually, no I must have missed that awk one liner.  Yeah, not bad, not bad.  This, however does deal with multiple-checksums, though I'd admit would be very long one liner smile.


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#10 2009-11-06 19:29:57

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,358

Re: [Solved] Clever-way of putting a md5sum after source in PKGBUILD?

The awk script is really useful smile. Thanks Gen2ly.


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#11 2009-11-07 21:14:39

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: [Solved] Clever-way of putting a md5sum after source in PKGBUILD?

ngoonee wrote:

The awk script is really useful smile. Thanks Gen2ly.

Thanks ngoonee.  Just FYI, now I'm using the sed one again because I forgot about the noextract array being after the sources array.


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

Board footer

Powered by FluxBB