#!/bin/sh
# Build and install MySQL on AlphaSlack
# by:  David Cantrell <david@slackware.com>
# Currently maintained by:  Patrick Volkerding <volkerdi@slackware.com>
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-mysql
VERSION=4.0.22
ARCH=alpha
BUILD=1
TARGET=$ARCH-alphaslack-linux

mkdir -p $PKG
( cd $TMP
rm -rf mysql-$VERSION
tar xjf $CWD/mysql-$VERSION.tar.bz2
cd mysql-$VERSION
chown -R root.root .
find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 666 -exec chmod 644 {} \;
find . -perm 664 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;
./configure --prefix=/usr \
    --with-mysqld-user=mysql \
    --with-unix-socket-path=/var/run/mysql/mysql.sock \
    --localstatedir=/var/lib/mysql \
    --enable-assembler \
    --without-raid \
    --without-debug \
    --enable-thread-safe-client \
    --without-bench \
    --with-extra-charsets=complex \
    --program-prefix="" \
    --program-suffix="" \
    $TARGET
# --without-readline
make
make install DESTDIR=$PKG
# Strip ELF objects:
( 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
)
mkdir -p $PKG/etc
( cd support-files
  cp my-huge.cnf my-large.cnf my-medium.cnf my-small.cnf $PKG/etc )
# install docs
mkdir -p $PKG/usr/doc/mysql-$VERSION/Docs
# Don't need the (huge) INSTALL-SOURCE... the source is installed already.
#cp -a COPYING* INSTALL-SOURCE MIRRORS README /usr/doc/mysql-$VERSION
cp -a COPYING* MIRRORS README $PKG/usr/doc/mysql-$VERSION
( cd Docs
  cp -a INSTALL-BINARY *.html *.txt Flags \
     $PKG/usr/doc/mysql-$VERSION/Docs )
# Also too large to justify since the .html version is right there:
rm $PKG/usr/doc/mysql-$VERSION/Docs/manual.txt
find $PKG/usr/doc/mysql-$VERSION -type f -exec chmod 644 {} \;
find $PKG/usr/doc/mysql-$VERSION/Docs/Flags/ -empty | xargs rm -f
# this is the directory where databases are stored
mkdir -p $PKG/var/lib/mysql
chown mysql.mysql $PKG/var/lib/mysql
chmod 750 $PKG/var/lib/mysql
# this is where the socket is stored
mkdir -p $PKG/var/run/mysql
chown mysql.mysql $PKG/var/run/mysql
chmod 755 $PKG/var/run/mysql
# Do not include the test suite:
rm -r $PKG/usr/mysql-test
# Add init script:
mkdir -p $PKG/etc/rc.d
# This is intentionally chmod 644.
zcat $CWD/rc.mysqld.gz > $PKG/etc/rc.d/rc.mysqld.new
# Install script:
# Add some handy library symlinks:
if [ -r $PKG/usr/lib/mysql/libmysqlclient.so.12 ]; then
  ( cd $PKG/usr/lib
    rm -f libmysqlclient.so libmysqlclient.so.12
    ln -sf mysql/libmysqlclient.so .
    ln -sf mysql/libmysqlclient.so.12 .
  )
fi
if [ -r $PKG/usr/lib/mysql/libmysqlclient_r.so.12 ]; then
  ( cd $PKG/usr/lib
    rm -f libmysqlclient_r.so libmysqlclient_r.so.12
    ln -sf mysql/libmysqlclient_r.so .
    ln -sf mysql/libmysqlclient_r.so.12 .
  )
fi
# Packaging standards:
chown -R root.bin $PKG/usr/bin
rm -f $PKG/usr/info/dir
gzip -9 $PKG/usr/info/*
gzip -9 $PKG/usr/man/man?/*.?
mkdir -p $PKG/install
zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh
cat $CWD/slack-desc > $PKG/install/slack-desc
# Build package:
cd $PKG
makepkg -l y -c n $TMP/mysql-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/mysql.build.log
