#!/bin/bash

set -e 

VERSION=$(head -1 ChangeLog.txt|awk '{print $2}')
BUILD=${BUILD:-6_microlinux}

CWD=`pwd`
TMP=${TMP:-/tmp}
PKG=$TMP/slackpkg+-$VERSION

OUTPUT=${OUTPUT:-$TMP}

rm -rf $PKG
mkdir -p $PKG

cd $PKG
mkdir -p etc/slackpkg/
mkdir -p usr/libexec/slackpkg/functions.d/
mkdir -p usr/doc/slackpkg+-$VERSION/
mkdir -p install/

cp $CWD/slackpkgplus.sh usr/libexec/slackpkg/functions.d/
cp $CWD/zdialogplus.sh usr/libexec/slackpkg/functions.d/
cp $CWD/makeinstlog.sh usr/libexec/slackpkg/makeinstlog.sh
#cp $CWD/README usr/doc/slackpkg+-$VERSION/
cp $CWD/ChangeLog.txt usr/doc/slackpkg+-$VERSION/
cp $CWD/repositories.txt usr/doc/slackpkg+-$VERSION/
cp $CWD/setupmultilib.sh usr/doc/slackpkg+-$VERSION/
cp $CWD/slackpkg+.SlackBuild usr/doc/slackpkg+-$VERSION/
cp $CWD/slackpkgplus.*.sample usr/doc/slackpkg+-$VERSION/
cp $CWD/greylist etc/slackpkg/greylist.new
cp $CWD/slack-desc install/
cat $CWD/doinst.sh|sed "s/SLPVERSION/$VERSION/" > install/doinst.sh
cat $CWD/notifymsg.conf > etc/slackpkg/notifymsg.conf.new

chmod +x usr/libexec/slackpkg/functions.d/slackpkgplus.sh
chmod +x usr/libexec/slackpkg/functions.d/zdialogplus.sh
chmod +x usr/libexec/slackpkg/makeinstlog.sh
chmod +x usr/doc/slackpkg+-$VERSION/setupmultilib.sh


makepkg -l y -c y $OUTPUT/slackpkg+-$VERSION-noarch-$BUILD.txz
