LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   14.0RC2 vs. 13.37: strange Bash script failure (http://www.linuxquestions.org/questions/slackware-14/14-0rc2-vs-13-37-strange-bash-script-failure-4175423536/)

kikinovak 08-23-2012 02:03 AM

14.0RC2 vs. 13.37: strange Bash script failure
 
Hi,

I'm using a "master" build script to build my extra packages, so once Slackware is installed, I can pretty much launch the script, and it will fetch stuff and build it in the right order. Here's what the script looks like:

Code:

#!/bin/sh
# Copyright (c) 2012 Niki Kovacs <info@microlinux.fr>
# -----------------------------------------------------------------------------
#
# This script builds Slackware packages listed in the 'packages'
# file. It puts them in the Slackware directory. If the package already exists
# in slackware/ *and* if it's already installed, the script skips to the next
# package, otherwise it builds and installs the package, until all packages
# listed in the package file are built.

CWD=`pwd`
SOURCEDIR=${CWD}/source
case $(uname -m) in
  x86_64) OUTPUT=$CWD/slackware/x86_64 ;;
  *    ) OUTPUT=$CWD/slackware/i486 ;;
esac
export OUTPUT

# Set the number of parallel make jobs
if [ -z "$NUMJOBS" ]; then
  case $(uname -m) in
    x86_64) NUMJOBS="-j4" ;;
    *    ) NUMJOBS="-j2" ;;
  esac
  export NUMJOBS="$NUMJOBS"
fi

PACKAGES=$(egrep -v '(^\#)|(^\s+$)' $CWD/packages)

for PACKAGE in ${PACKAGES} ; do
  if [ -r ${OUTPUT}/${PACKAGE}-[0-9]*.tgz ] ; then
    if [ -r /var/log/packages/${PACKAGE}-[0-9]* ] ; then
      continue
    fi
  fi
  echo
  echo "+=============================================================================="
  echo "| Building package ${PACKAGE}..."
  echo "+=============================================================================="
  echo
  sleep 3

  (
    cd ${SOURCEDIR}/${PACKAGE} || exit 1
    ./${PACKAGE}.SlackBuild || exit 1
  )
  upgradepkg --reinstall --install-new ${OUTPUT}/${PACKAGE}-[0-9]*.tgz || exit 1
done

echo
echo "+=============================================================================="
echo "| Successfully built and installed all packages !"
echo "+=============================================================================="
echo

Rough description of what the script does:

1) it reads the names of packages to build in an external 'packages' file, which is basically a list, one package per line, with a few comments.

2) It checks if the package has already been built before AND if it's installed.

3) If not, it builds the package, puts it into the OUTPUT directory and installs it.

Now strangely enough, the script works perfectly with 13.37 (as it has always worked with previous versions of Slackware since around 10.2).

But under 14.0RC2, it fails. I get a "binary operator expected" message at the if... then statements that do the testing if the package is installed and present in the OUTPUT directory.

What happens is if a package is installed AND it's in the OUTPUT directory, the script fails and builds it anyway, instead of skipping to the next package that's not yet built/installed.

Any idea what's wrong here?

kikinovak 08-23-2012 03:08 AM

OK, I guess I got the culprit. I took a peek in /var/log/packages, and it seems like 'upgradepkg' has got a new behaviour. When I use it with --reinstall --install-new on an already installed package, I get a second entry in /var/log/packages, the second one having a timestamp added to the tag.

Considering that, it's normal my test fails, since if [ -r FILE ] expects a single file as an argument and fails when there are more than one.

Phew.

ruario 08-23-2012 03:19 AM

Why would you ever use --reinstall and --install-new together? I think they are supposed to be mutually exclusive. I mean, just look at what the options are called. If it is new, it isn't a reinstall and if it is a reinstall it isn't new.

ruario 08-23-2012 03:23 AM

Just take out --reinstall. The packages that are already installed with the same version number will be skipped by upgradepkg anyway and new packages will be installed.

phenixia2003 08-23-2012 04:09 AM

Quote:

Originally Posted by kikinovak (Post 4761808)
OK, I guess I got the culprit. I took a peek in /var/log/packages, and it seems like 'upgradepkg' has got a new behaviour. When I use it with --reinstall --install-new on an already installed package, I get a second entry in /var/log/packages, the second one having a timestamp added to the tag.

Considering that, it's normal my test fails, since if [ -r FILE ] expects a single file as an argument and fails when there are more than one.

Phew.

Hello,

I guess your issue is elsewhere since nothing (except pkgtool's version number) has been changed in upgradepkg since 13.37 :
Code:

$ diff -Nausr 13.37/ 14.0/

Files 13.37//install/slack-desc and 14.0//install/slack-desc are identical
Files 13.37//sbin/explodepkg and 14.0//sbin/explodepkg are identical
Files 13.37//sbin/installpkg and 14.0//sbin/installpkg are identical
Files 13.37//sbin/makebootdisk and 14.0//sbin/makebootdisk are identical
Files 13.37//sbin/makepkg and 14.0//sbin/makepkg are identical
diff -Nausr 13.37//sbin/pkgtool 14.0//sbin/pkgtool
--- 13.37//sbin/pkgtool 2011-03-07 19:14:54.000000000 +0100
+++ 14.0//sbin/pkgtool  2012-08-09 20:38:10.000000000 +0200
@@ -212,7 +212,7 @@
  CMD_START="true"
  rm -f $TMP/SeT*
  while [ 0 ]; do
-  dialog --title "Slackware Package Tool (pkgtool version 13.37)" \
+  dialog --title "Slackware Package Tool (pkgtool version 14.0)" \
 --menu "\nWelcome to the Slackware package tool.\n\
 \nWhich option would you like?\n" 17 75 7 \
 "Current" "Install packages from the current directory" \
Files 13.37//sbin/removepkg and 14.0//sbin/removepkg are identical
Files 13.37//sbin/upgradepkg and 14.0//sbin/upgradepkg are identical
Files 13.37//usr/man/man8/explodepkg.8 and 14.0//usr/man/man8/explodepkg.8 are identical
Files 13.37//usr/man/man8/installpkg.8 and 14.0//usr/man/man8/installpkg.8 are identical
Files 13.37//usr/man/man8/makepkg.8 and 14.0//usr/man/man8/makepkg.8 are identical
Files 13.37//usr/man/man8/pkgtool.8 and 14.0//usr/man/man8/pkgtool.8 are identical
Files 13.37//usr/man/man8/removepkg.8 and 14.0//usr/man/man8/removepkg.8 are identical
Files 13.37//usr/man/man8/upgradepkg.8 and 14.0//usr/man/man8/upgradepkg.8 are identical
Files 13.37//var/log/setup/setup.70.install-kernel and 14.0//var/log/setup/setup.70.install-kernel are identical
Files 13.37//var/log/setup/setup.80.make-bootdisk and 14.0//var/log/setup/setup.80.make-bootdisk are identical
Files 13.37//var/log/setup/setup.htmlview and 14.0//var/log/setup/setup.htmlview are identical
Files 13.37//var/log/setup/setup.services and 14.0//var/log/setup/setup.services are identical


After looking at upgradepkg's code, the "TIMESTAMP" are used to mark packages to remove (starting at line #286) :

Code:

# Showtime.  Let's do the upgrade.  First, we will rename all the
# installed packages with this basename to make them easy to remove later:

TIMESTAMP=$(date +%Y-%m-%d,%T)
...
for installed_package in $ROOT/var/log/packages/$SHORT* ; do
  if [ "$(package_name $installed_package)" = "$SHORT" ]; then
    mv $installed_package ${installed_package}-upgraded-$TIMESTAMP
  fi
done

And, starting at line #348 :
Code:

    for rempkg in *-$TIMESTAMP ; do
      if [ "$VERBOSE" = "verbose" ]; then
        ROOT=$ROOT /sbin/removepkg $rempkg


--
SeB


All times are GMT -5. The time now is 12:57 PM.