[b75d30]: install / slackware / pwsafe.SlackBuild  Maximize  Restore  History

Download this file

182 lines (161 with data), 4.9 kB

#! /bin/bash

# Password Safe build script 
#--
# Last edited: 15.09.2013
#--

if [ $UID = 0 ]; then
	echo "There is no need to run this build script as root. You'll be"
	echo "asked for your root password at package creation time (if you"
	echo "haven't installed fakeroot)."
	echo -n "Type \"take risk\" to continue: "
	read RISK
	test "$RISK" = "take risk" || exit 1
fi

PRGNAM=pwsafe
VERSION=${VERSION:-0.92beta}
ARCH=${ARCH:-x86_64} # i[345]6 or x86_64
BUILD_ID=${BUILD_ID:-1}
BUILDER_ID=${BUILDER_ID:-kan}
OUTPUT=${OUTPUT:-$(pwd)/packages}
LOGS=${LOGS:-$(pwd)/logs}
##
MAKEDIR=$(pwd)/../..
BINDIR=$(pwd)/../../src/ui/wxWidgets/GCCUnicodeRelease
DOCSRCDIR=$(pwd)/../../docs
XMLSRCDIR=$(pwd)/../../xml
HELPSRCDIR=$(pwd)/../../help
ISRCDIR=$(pwd)/../../src/ui/wxWidgets/I18N
##
PKGNAME=${PRGNAM}-${VERSION/-/.}-$ARCH-$BUILD_ID$BUILDER_ID
##
PREFIX="/usr"
DOCDIR=$PREFIX/share/doc/$PRGNAM-$VERSION
HELPDIR=$PREFIX/share/doc/$PRGNAM-$VERSION/help
XMLDIR=$PREFIX/share/$PRGNAM/xml
MANDIR=$PREFIX/man
PIXMAPDIR=$PREFIX/share/pixmaps
APPDIR=$PREFIX/share/applications
IDIR=$PREFIX/share/locale
##
OPTIMIZE="-O2"
DATE=$(LC_ALL=C /bin/date +%d-%b-%Y)
PKG=$(pwd)/package-${PRGNAM}
MYDIR=$(pwd)

MAKE_OPTIONS="-j3 release"

#exit after errors
set -e
trap 'echo "$0 FAILED at line ${LINENO}" | tee $LOGS/error-${PRGNAM}.log' ERR
# Catch unitialized variables:
set -u
#catch non-zero status in pipes
set -o pipefail
P1=${1:-1}

case "$ARCH" in
  i[3456]86) SLKCFLAGS="$OPTIMIZE -march=$ARCH -mtune=$ARCH"
             SLKLDFLAGS=""; LIBDIRSUFFIX=""
             ;;
  x86_64)    SLKCFLAGS="$OPTIMIZE -fPIC"
             SLKLDFLAGS="-L/usr/lib64"; LIBDIRSUFFIX="64"
             ;;
esac

umask 022


# Create working directories:
mkdir -p $LOGS
mkdir -p $OUTPUT
mkdir -p $PKG
# always erase old package's contents
rm -rf $PKG/*

## Package building
echo Building ...
export LDFLAGS="$SLKLDFLAGS"
export CXXFLAGS="$SLKCFLAGS -I/usr/include/ykpers-1"
export CFLAGS="$SLKCFLAGS -I/usr/include/ykpers-1"

#make binaries
cd $MAKEDIR
echo "- cleanup"
make clean
echo "- binaries"
make $MAKE_OPTIONS 2>&1 | tee $LOGS/make-${PRGNAM}.log || exit 1
echo "- help"
cd $HELPSRCDIR
make
echo "- i18n"
cd $ISRCDIR
make mos

#collect files before packaging
#copy binaries
mkdir -p $PKG/$PREFIX/bin
cp $BINDIR/pwsafe $PKG/$PREFIX/bin
#copy docs
mkdir -p $PKG/$DOCDIR/help
cp $DOCSRCDIR/* $PKG/$DOCDIR
cp $MAKEDIR/README* $MAKEDIR/LICENSE $PKG/$DOCDIR
cp $MYDIR/../copyright $PKG/$DOCDIR
mkdir -p $PKG/$HELPDIR
cp $HELPSRCDIR/help*.zip $PKG/$HELPDIR
#move man pages to mandir
mkdir -p $PKG/$MANDIR/man1
mv $PKG/$DOCDIR/*.1 $PKG/$MANDIR/man1
#copy lang
mkdir -p $PKG/$IDIR
cp -R $ISRCDIR/mos/* $PKG/$IDIR
#copy XML files
mkdir -p $PKG/$XMLDIR
cp $XMLSRCDIR/* $PKG/$XMLDIR
#copy buildscript
mkdir -p $PKG/usr/src/slackbuild
cp -a $MYDIR/$PRGNAM.SlackBuild $PKG/usr/src/slackbuild/
mkdir -p $PKG/$PIXMAPDIR
cp $MYDIR/../graphics/pwsafe.png $PKG/$PIXMAPDIR
mkdir -p $PKG/$APPDIR
cp $MYDIR/../desktop/pwsafe.desktop $PKG/$APPDIR
#prepare package
cd $PKG
# remove debugging symbols
find . -print0 | xargs -0 file | grep "executable" | grep ELF | cut -f 1 -d : | xargs -0 strip --strip-unneeded 2> /dev/null || true
find . -print0 | xargs -0 file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs -0 strip --strip-unneeded 2> /dev/null || true

# fix permissions
find $PKG -type f -print0 | xargs -0 --no-run-if-empty chmod 644 
chmod 755 $PKG/$PREFIX/bin/*

# compress doc files > 4 kB
find $PKG/$DOCDIR -type f -size +4k ! -iname *.htm ! -iname *.html ! -iname *.sh -print0 |
	xargs -0 --no-run-if-empty /bin/gzip --verbose --best
# Compress and link manpages, if any:
if [ -d $PKG/$PREFIX/man ]; then
  ( cd $PKG/$PREFIX/man
    for mandir in $(find . -type d -name "man*") ; do
      ( cd $mandir
        for page in $( find . -type l -maxdepth 1) ; do
          ln -s $( readlink $page ).gz $page.gz
          rm $page
        done
        gzip -9 *.*
      )
    done
  )
fi

mkdir -p $PKG/install

# make slack-desc package description file
cp $MYDIR/slack-desc $PKG/install/slack-desc
echo "$PRGNAM: build at $DATE" >> $PKG/install/slack-desc

set +o xtrace

ROOTCOMMANDS="set -o errexit -o xtrace -o pipefail ; cd $PKG;
    chown -R root:root . ;"
ROOTCOMMANDS="$ROOTCOMMANDS
    if [ -x /usr/bin/requiredbuilder ]; then /usr/bin/requiredbuilder -v -b -p -y .; fi ;
    /sbin/makepkg --linkadd y --chown n $OUTPUT/$PKGNAME.tgz 2>&1 | tee $LOGS/makepkg-${PRGNAM}.log ;
    cd $OUTPUT ;
    md5sum $PKGNAME.tgz > $PKGNAME.tgz.md5 ;
    rm -rf $PKG"

if [ $UID = 0 ]; then
    eval $ROOTCOMMANDS
    set +o xtrace
elif [ -x /usr/bin/fakeroot ]; then
    echo "Entering fakeroot environment."
    echo $ROOTCOMMANDS | /usr/bin/fakeroot
else
    echo "Please enter your root password."
    /bin/su -c "$ROOTCOMMANDS"
fi

echo "Package is ready in $OUTPUT/$PKGNAME.tgz"
#####