#!/bin/sh
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-pcmcia-cs
VERSION=3.2.8
ARCH=alpha
BUILD=1

rm -rf $PKG
mkdir -p $PKG
( cd $TMP
rm -rf pcmcia-cs-$VERSION
tar xjf $CWD/pcmcia-cs-$VERSION.tar.bz2
cd pcmcia-cs-$VERSION
chown -R root:root .
zcat $CWD/pcmcia-cs.dhcpcd.diff.gz | patch -p1 --verbose
mkdir -p $PKG/usr/doc/pcmcia-cs-$VERSION
cp -a BUGS COPYING LICENSE MAINTAINERS doc/PCMCIA-HOWTO doc/PCMCIA-PROG README* SUPPORTED.CARDS $PKG/usr/doc/pcmcia-cs-$VERSION
chmod 644 $PKG/usr/doc/pcmcia-cs-$VERSION/*
make clean || exit
./Configure --noapm --nopnp --trust --kernel=/usr/src/linux --noprompt --current --bsd || exit
make all || exit 1
make install PREFIX=$PKG || exit 1
# I see no good reason to make these setuid root.
# If you want to be crazy (or have no "problem" users :-), change 'em yourself.
chmod 755 $PKG/sbin/cardctl
#chmod 755 $PKG/usr/X11R6/bin/xcardinfo
# This version of rc.pcmcia has been modified to probe for the proper PCIC.
mkdir -p $PKG/etc/rc.d
zcat $CWD/rc.pcmcia.gz > $PKG/etc/rc.d/rc.pcmcia
mv $PKG/etc/rc.d/rc.pcmcia $PKG/etc/rc.d/rc.pcmcia.new
# Patch the config.opts for the correct WebGear wireless defaults:
( cd $PKG ; zcat $CWD/config.opts.diff.gz | patch -p1 --backup --suffix=.orig )
# Remove original version (the changes are well commented within the file):
rm -f $PKG/etc/pcmcia/config.opts.orig
chmod 644 $PKG/etc/pcmcia/*.opts
# Move config files to *.new:
( cd $PKG/etc/pcmcia
  for file in *.opts ; do
    mv $file ${file}.new
  done
)
( cd $PKG
  find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
  find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)
# Compress and if needed symlink the man pages:
if [ -d $PKG/usr/man ]; then
  ( cd $PKG/usr/man
    for manpagedir in $(find . -type d -name "man*") ; do
      ( cd $manpagedir
        for eachpage in $( find . -type l -maxdepth 1) ; do
          ln -s $( readlink $eachpage ).gz $eachpage.gz
          rm $eachpage
        done
        gzip -9 *.?
      )
    done
  )
fi
mkdir -p $PKG/install
zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
makepkg -l y -c n ../pcmcia-cs-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/pcmcia-cs.build.log
