程序测试

#!/bin/sh

print() {
  echo -e "\e[32m $1\e[0m"
}

ARCH=${ARCH:-i686}
BUILD=${BUILD:-1}
PKGTYPE=${PKGTYPE:-txz}

if [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686 -pipe"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686 -pipe -fomit-frame-pointer"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2 -fPIC"
  LIBDIRSUFFIX="64"
fi

PACKAGE=`basename "$1" | sed -e 's/\(\.tar.*\|\.t[gb]z.*\|\.zip\|\.egg\)$//' | rev | cut -d- -f2- | rev | tr A-Z a-z`
VERSION=`basename "$1" | sed -e 's/\(\.tar.*\|\.t[gb]z.*\|\.zip\|\.egg\)$//' | rev | cut -d- -f1 | rev | tr A-Z a-z`

CWD=$(pwd)
TMP=${TMP:-/tmp/}
PKG=$TMP/package-$PACKAGE
OUTPUT=${OUTPUT:-/tmp}

prepare() {
  print "$PACKAGE $VERSION prepare..."
  set -e
  rm -rf $PKG
  mkdir -p $TMP $PKG $OUTPUT
  cd $TMP
  rm -rf $PACKAGE-$VERSION/
  [ -r `dirname $1`/`basename $1` ] && tar xf `dirname $1`/`basename $1`
  [ -r $CWD/`basename $1` ] && tar xf $CWD/`basename $1`
  [ -r $CWD/`dirname $1`/`basename $1` ] && tar xf $CWD/`dirname $1`/`basename $1`
  cd ./$PACKAGE-$VERSION/

  find . -perm 666 -exec chmod 644 {} \;
  find . -perm 664 -exec chmod 644 {} \;
  find . -perm 600 -exec chmod 644 {} \;
  find . -perm 444 -exec chmod 644 {} \;
  find . -perm 400 -exec chmod 644 {} \;
  find . -perm 440 -exec chmod 644 {} \;
  find . -perm 777 -exec chmod 755 {} \;
  find . -perm 775 -exec chmod 755 {} \;
  find . -perm 511 -exec chmod 755 {} \;
  find . -perm 711 -exec chmod 755 {} \;
  find . -perm 555 -exec chmod 755 {} \;
  chown -R root:root .
  touch $TMP/$PACKAGE-$VERSION.prepare
}

configure() {
  autoconf() {
    CFLAGS="$SLKCFLAGS" \
    CXXFLAGS="$SLKCFLAGS" \
    ./configure \
      --prefix=/usr \
      --libdir=/usr/lib${LIBDIRSUFFIX} \
      --sysconfdir=/etc \
      --mandir=/usr/man \
      --localstatedir=/var
  }
  print "$PACKAGE $VERSION configure..."
  cd $TMP/$PACKAGE-$VERSION/
  if [ -x ./configure ]; then
    print "autoconf..."
    autoconf
  elif [ -x ./autogen.sh ]; then
    print "autogen..."
    ./autogen.sh
    if test ! -r Makefile; then
      print "./autogen.sh did not run configure, running it now"
      autoconf
    fi
  else
    echo "Can't not configure the package $PACKAGE!"
  fi
  rm $TMP/$PACKAGE-$VERSION.prepare
  touch $TMP/$PACKAGE-$VERSION.configure
}

build() {
  print "$PACKAGE $VERSION building..."
  cd $TMP/$PACKAGE-$VERSION/
  make || exit 1
  make install DESTDIR=$PKG
  rm $TMP/$PACKAGE-$VERSION.configure
  touch $TMP/$PACKAGE-$VERSION.build
}

makepkg() {
  print "$PACKAGE $VERSION makepkg..."
  ( cd $PKG
        find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | \
            xargs strip --strip-unneeded 2> /dev/null || true
        find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | \
            xargs strip --strip-unneeded 2> /dev/null
  )  

# Compress and link manpages, if any:
  if [ -d $PKG/usr/man ]; then
     ( cd $PKG/usr/man
         for manpagedir in $(find . -type d -name "man*") ; do
             ( cd $manpagedir
                 for eachpage in $( find . -type l -maxdepth 1) ; do
                     ln -s $( readlink $eachpage ).gz $eachpage.gz
                     rm $eachpage
                 done
                 gzip -9 *.?
             )
         done
     )
  fi

#Build the Slackware Package
  cd $PKG
  /sbin/makepkg -l y -c n $OUTPUT/$PACKAGE-$VERSION-$ARCH-$BUILD.$PKGTYPE
  rm $TMP/$PACKAGE-$VERSION.build
  print "Cleaning the temp files..."
  rm -rf $TMP/$PACKAGE-$VERSION/
  rm -rf $PKG
}

######################################

[ ! -r $TMP/$PACKAGE-$VERSION.* ] && prepare $1
[ -r $TMP/$PACKAGE-$VERSION.prepare ] && configure
[ -r $TMP/$PACKAGE-$VERSION.configure ] && build
[ -r $TMP/$PACKAGE-$VERSION.build ] && makepkg


show databases;

你可能感兴趣的:(职场,休闲,程序测试)