#!/bin/bash

# variables
CWD=$(pwd)

PRGNAM=$(basename $CWD)
VERSION=${VERSION:-"trunk"}
ARCH=noarch
BUILD=1

TAG=gwh
TMP=/tmp/$TAG
PKG=$TMP/pkg-$PRGNAM
OUTPUT=/tmp

PREFIX=/usr

# nettoyage préalable
rm -fr $PKG $TMP/$PRGNAM

mkdir -p $PKG$PREFIX/bin/

# mise en place
wget -c https://raw.github.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -O $PKG$PREFIX/bin/wp-cli

chmod 0755 $PKG$PREFIX/bin/wp-cli

VERSION=$(sudo -u apache $PKG$PREFIX/bin/wp-cli cli version | cut -d\  -f2)

# embaumement
mkdir -p $PKG/install
cat <<EOF > $PKG/install/slack-desc
$PRGNAM: $PRGNAM (A command line interface for WordPress)
$PRGNAM:
$PRGNAM: WP-CLI is a set of command-line tools for managing WordPress installations.
$PRGNAM: You can update plugins, set up multisite installs and much more, without
$PRGNAM: using a web browser.
$PRGNAM:
$PRGNAM:
$PRGNAM:
$PRGNAM:
$PRGNAM: http://wp-cli.org/
$PRGNAM:
EOF

# empaquetage
cd $PKG
rm -f $PKG/{,usr/}lib$(uname -m | grep -o 64)/*.la
/sbin/makepkg --linkadd y --chown n --prepend $OUTPUT/$PRGNAM-$(echo $VERSION | sed 's/-//g')-$ARCH-$BUILD$TAG.txz