#!/bin/sh
# Set initial variables:
PKGNAM=acpid
VERSION=1.0.4
BUILD=2

. /etc/pkghelpers
pkghelpers_env

rm -rf $PKG
mkdir -p $PKG # place for the package to be built

cd $TMP
rm -rf acpid-$VERSION
tar xzvf $CWD/acpid-$VERSION.tar.gz
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 {} \;

# GCC 4 fix
sed -i 's#int len = sizeof(struct sockaddr_un)#socklen_t len = sizeof(struct sockaddr_un)#' ud_socket.c || exit 1

make
strip acpid
mkdir -p $PKG/usr/sbin
cat acpid > $PKG/usr/sbin/acpid
chmod 755 $PKG/usr/sbin/acpid
chown -R root:root $PKG/usr/sbin
mkdir -p $PKG/usr/man/man8
cat acpid.8 | gzip -9c > $PKG/usr/man/man8/acpid.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
chmod 755 $PKG/etc/acpi/acpi_handler.sh
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

# Build the package:
cd $PKG
pkghelpers_fixup
pkghelpers_makepkg
