#!/bin/sh
#
# source: http://www.freedesktop.org/~lanius/pyxdg-0.19.tar.gz
#
# maintainer: gmg (g.monpontet@gmail.com)
#

#------------------Set Some Variables

soft='pyxdg'
softversion='0.19'
packageversion='66.1'

arch='i486'
cpu='i686'

buildir=$(pwd)
srcpkg="$buildir/$soft-$softversion.tar.gz"
src="$buildir/$soft-$softversion"
package="$soft-$softversion-$arch-$packageversion"
dest="$buildir/$package"

cd $buildir
rm -rf $src
tar -xvzf $srcpkg
rm -f $dest.tar.gz
rm -rf $dest
mkdir -p $dest

#------------------Set correct permissions

cd $src
chown -R root:root .
find . \
 \( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) \
 -exec chmod 755 {} \; -o \
 \( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \
 -exec chmod 644 {} \;
python setup.py install --root=$dest

find $dest | xargs file | grep -e "shared object" -e "executable" | grep ELF \
  | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null

#-----------------Make the slack-desc files

mkdir -p $dest/install
cat << EOF > $dest/install/slack-desc
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description.  Line
# up the first '|' above the ':' following the base package name, and the '|'
# on the right side marks the last column you can put a character in.  You must
# make exactly 11 lines for the formatting to be correct.  It's also
# customary to leave one space after the ':'.

     |-----handy-ruler---------------------------------------------------------|
pyxdg: pyxdg - is a python library to access freedesktop.org standards
pyxdg:
pyxdg: PyXDG is a python library to access freedesktop.org standards. Currently
pyxdg: supported are:
pyxdg: - Base Directory Specification Version 0.6
pyxdg: - Menu Specification Version 1.0-draft1
pyxdg: - Desktop Entry Specification Version 0.9.4
pyxdg: - Icon Theme Specification Version 0.8
pyxdg: - Recent File Spec 0.2
pyxdg: - Shared-MIME-Database Specification 0.13
pyxdg:
EOF

mkdir -p $dest/usr/doc/$soft-$softversion
cp -a AUTHORS ChangeLog COPYING INSTALL PKG-INFO README TODO $dest/usr/doc/$soft-$softversion

mkdir -p $dest/usr/src/$soft-$softversion
cp -a $buildir/build-$soft.sh $dest/usr/src/$soft-$softversion

#-------------------Make the packages and the md5sum

cd $dest
makepkg -l y -c n $dest.txz

cd $buildir
md5sum $package.txz > $package.md5