You are not logged in.

#1 2009-10-26 04:09:09

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

[Unknown] Bash: Why does this script break my environment?

I'm trying to build a script to do a couple makepkg tasks and it looks like I'm having trouble with a function breaking the environment.  The function does several commands and then breaks makepkg.  After I run the script, makepkg runs as if no options are entered:

makepkg -g
==> Check: Installer is the correct size.
==> Extracting archive...
==> Copying files...
cp: cannot overwrite non-directory `/var/abs/local/personal/worldofgoo/pkg/usr/share/games/worldofgoo/WorldOfGoo' with directory `WorldOfGoo'

==> ERROR: An unknown error has occurred. Exiting...

Instead of the expected:

makepkg -g                               
==> Retrieving Sources...                
  -> Found worldofgoo.desktop in build dir
==> Generating checksums for source files...
                                            
md5sums=('e49849a66aa50065d4d548653a33cc23')

Here's the script it just started happening when I added the function.  I think it has to do with the curly brackets that awk uses.

#!/bin/bash
# mp - makepkg package building tasks

# Add md5sums following source array in PKGBUILD
md5add () {

  # Delete previous md5sum entries
  sed -i '/^md5sums/,/).*$/d' PKGBUILD

  # Add md5sums to end if PKGBUILD
  makepkg -g >> PKGBUILD

  # Move md5sums to follow source array
  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

  if [ -f /tmp/PKGBUILD.tmp ]; then
    mv /tmp/PKGBUILD.tmp PKGBUILD
  fi

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

# Options
case $1 in
  p ) if [ ! -f ./PKGBUILD ]; then
        echo "No PKGBUILD in this directory ($(pwd))"
        exit; else
        makepkg -sf
      fi
      ;;
  s ) if [ ! -f ./PKGBUILD ]; then
        echo "No PKGBUILD in this directory ($(pwd))"
        exit 1; else
        echo "adding md5sums"
        md5add
        makepkg -f --source
      fi
      ;;
  * ) # Display usage if full argument isn't given
      echo " ${0##*/} <option> - makepkg building tasks:"
      echo "   p - build package              (also installs dependencies)"
      echo "   s - build source-only tarball  (adds md5sums, tars for submission)"
      exit
      ;;
esac

I have to restart to reset the environment (logout doesn't work) so I'l like to be able to fix this big_smile.  Any ideas?

Last edited by Gen2ly (2009-10-30 15:19:17)


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

Offline

#2 2009-10-27 01:37:08

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

Re: [Unknown] Bash: Why does this script break my environment?

Huh.  What can I say, I tried it today and it worked.   ...go figure.  I'm going to keep this open though until I can do some further testing.


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

Offline

#3 2009-10-30 15:18:31

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

Re: [Unknown] Bash: Why does this script break my environment?

Just reinstalled and not having it come up again.  Putting this in wonderland.

Last edited by Gen2ly (2009-10-30 15:18:44)


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

Offline

Board footer

Powered by FluxBB