#!/bin/bash
# packager/author    : tsuren
# sources locations  : http://users.zenwalk.org/user-accounts/tsuren/zenmanual/
# last revised       : 10/04/2008

softname='zenmanual'
softversion='0.9.1'
packageversion='52.1'

arch='noarch'

# parameters needed for the build process
buildir=$(pwd)
srcpkg="$buildir/$softname-$softversion.tar.bz2"
src="$buildir/$softname-$softversion"
package="$softname-$softversion-$arch-$packageversion"
dest="$buildir/$package"

# prepare the build result directory
rm -rf $dest
mkdir -p $dest
mkdir -p $dest/install
mkdir -p $dest/usr/doc/$softname-$softversion
mkdir -p $dest/usr/share/$softname
mkdir -p $dest/usr/share/icons/hicolor/scalable/apps/
mkdir -p $dest/usr/share/applications
mkdir -p $dest/usr/src/$softname-$softversion

# put slack-desc in place
cat <<EOF > $dest/install/slack-desc
   |-----handy-ruler------------------------------------------------------|
$softname: Zenwalk GNU/Linux Manual 
$softname:
$softname: By reading this manual, you will be able to:
$softname: 
$softname: - Burn a Zenwalk ISO image on a CD
$softname: - Install Zenwalk
$softname: - Use the Zenwalk Tools
$softname: - Have fun learning this ;)
$softname:
$softname: 
$softname:
EOF

# make the .desktop file
cat << "EOF" > $dest/usr/share/applications/$softname.desktop
[Desktop Entry]
Encoding=UTF-8
Exec=iceweasel file:///usr/share/zenmanual/index.html
Icon=zenmanual
Type=Application
Categories=Application;System;
Name=Zenwalk Manual
GenericName=The Zenwalker's guide
EOF

# put the manual in place
cd $buildir
tar xjvf $srcpkg
cd $src
cp -rf en/* $dest/usr/share/zenmanual/

# Add default doc
cp -a \
      AUTHORS COPYING TODO ChangeLog manual_en.xml \
      $dest/usr/doc/$softname-$softversion

# Make the package freedesktop compliant
cp $src/$softname.svg $dest/usr/share/icons/hicolor/scalable/apps/$softname.svg

# put the ZenWalk build in the right directory
cp $buildir/build-$softname.sh $dest/usr/src/$softname-$softversion

# set target permissions
chown -R root:root $dest

cd $dest
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 {} \;
find . -type d -exec chmod 755 {} \;

# real packaging work:
cd $dest
makepkg -l y -c n $dest.tgz

# computes the md5sum signature for the package
cd $buildir
md5sum $package.tgz > $package.md5
