#!/bin/sh
# Set initial variables:
PKGNAM=usbutils
VERSION=${VERSION:-0.72}
BUILD=${BUILD:-2}

. /etc/pkghelpers
pkghelpers_env

rm -rf $PKG
mkdir -p $PKG

cd $TMP
rm -rf usbutils-$VERSION
tar xjvf $CWD/usbutils-$VERSION.tar.bz2
cd usbutils-$VERSION

chown -R root:root .
find . -perm 666 -exec chmod 644 {} \;
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 {} \;

# Enable the building of usbmodules, still needed for now on 2.4 systems:
zcat $CWD/usbutils.usbmodules.diff.gz | patch -p1 --verbose || exit 1

# Fetch the latest usb.ids:
rm -f usb.ids
sh ./update-usbids.sh

./configure \
  --prefix=/usr \
  --sbindir=/sbin

make -j1 || exit 1
make install DESTDIR=$PKG || exit 1

mkdir -p $PKG/usr/doc/usbutils-$VERSION
cp -a \
  AUTHORS COPYING ChangeLog NEWS README \
  $PKG/usr/doc/usbutils-$VERSION

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

# Build the package:
cd $PKG
pkghelpers_fixup
pkghelpers_makepkg
