#!/bin/bash
#  Copyright (C) 2010, 2011  Matias A. Fonzo, <selk@dragora.org>
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.

set -e

CWD=$(pwd)

TMP=${TMP:-/tmp/sources}
OUT=${OUT:-/tmp/packages}

V=2.6
ARCH=noarch
B=2

PKG=${TMP}/package-pkgsystem

rm -rf $PKG
mkdir -p $PKG $OUT

cd $PKG

( cd ${CWD}/tools
  for file in * ; do
    install --mode=0750 --owner=0:0 $file -D ${PKG}/sbin/$file
  done
)
( cd ${CWD}/commands
  for file in * ; do
    install --mode=0750 --owner=0:0 $file \
     -D ${PKG}/usr/libexec/pkg/commands/$file
  done
)
( cd ${CWD}/language
  for file in * ; do
    install --mode=0644 --owner=0:0 $file \
     -D ${PKG}/usr/libexec/pkg/language/$file
  done  
)

# Add the documentation:
( cd ${CWD}
  mkdir -p ${PKG}/usr/doc/pkgsystem-${V}
  cp -a \
   AUTHORS ChangeLog COPYING CREDITS \
   ${PKG}/usr/doc/pkgsystem-${V}
)

# Copy the description files:
mkdir -p ${PKG}/description
cp ${CWD}/description/* ${PKG}/description/

makepkg ${OUT}/pkgsystem-${V}-${ARCH}-${B}.tlz

