#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-acpid

VERSION=1.0.8
ARCH=${ARCH:-x86_64}
BUILD=1

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
rm -rf $PKG
mkdir -p $PKG # place for the package to be built

cd $TMP
rm -rf acpid-$VERSION
tar xvf $CWD/acpid-$VERSION.tar.?z* || exit 1
cd acpid-$VERSION
chown -R root:root .
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 {} \;
make || exit 1
strip acpid acpi_listen
mkdir -p $PKG/usr/sbin
cat acpid > $PKG/usr/sbin/acpid
chmod 755 $PKG/usr/sbin/acpid
mkdir -p $PKG/usr/bin
cat acpi_listen > $PKG/usr/bin/acpi_listen
chmod 755 $PKG/usr/bin/acpi_listen
mkdir -p $PKG/usr/man/man8
cat acpid.8 | gzip -9c > $PKG/usr/man/man8/acpid.8.gz
cat acpi_listen.8 | gzip -9c > $PKG/usr/man/man8/acpi_listen.8.gz
mkdir -p $PKG/usr/doc/acpid-$VERSION
cp -a Changelog README \
  $PKG/usr/doc/acpid-$VERSION
cp -a samples $PKG/usr/doc/acpid-$VERSION
mkdir -p $PKG/etc/acpi/events
zcat $CWD/acpi_handler.sh.gz > $PKG/etc/acpi/acpi_handler.sh.new
chmod 755 $PKG/etc/acpi/acpi_handler.sh.new
zcat $CWD/default.gz > $PKG/etc/acpi/events/default
mkdir -p $PKG/etc/rc.d
zcat $CWD/rc.acpid.gz > $PKG/etc/rc.d/rc.acpid
chmod 755 $PKG/etc/rc.d/rc.acpid
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh

# Build the package:
cd $PKG
makepkg -l y -c n $TMP/acpid-$VERSION-$ARCH-$BUILD.txz

