#!/bin/sh
#
# kTm port by Juzer
#
#       regards to hns & psych
#

# local config:
BUILD="1"
PACKAGE="mysql"

check() {
# Checking for configuration
# Downloading sources lists
INSTALLED="`ls -1 $PACKAGES/packages/|grep $PACKAGE|cut -d "-" -f 1,2`"
$WGET -q ftp://sunsite.icm.edu.pl/pub/unix/mysql/Downloads/MySQL-4.0/
NEW=`grep $PACKAGE-4 index.html|grep -v win|grep .tar.gz|cut -d / -f 9|cut -d '"' -f 1|sed -e s/.tar.*//|tail -1`
#Checking for new version
    checkpkg
# clean
rm index.html
}

download() {
# Downloading version from "${VERFILE}"
$WGET -P $DOWNL ftp://sunsite.icm.edu.pl/pub/unix/mysql/Downloads/MySQL-4.0/$SRC.tar.gz
}

build() {
# Creating new
tar zxvf $DOWNL/$SRC.tar.gz
cd $SRC
./configure \
    --prefix=/usr \
    --with-mysqld-user=mysql \
    --with-unix-socket-path=/var/run/mysql/mysql.sock \
    --localstatedir=/var/lib/mysql \
    --without-bench \
    --with-extra-charsets=complex --without-docs \
    --host=$TARGET --build=$TARGET || exit
make || exit
make install DESTDIR=$PKG || exit
cd $PKG
strip --strip-unneeded $PKG/usr/bin/* $PKG/usr/libexec/*
# 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
cp $PKG/usr/share/mysql/mysql.server $PKG/etc/rc.d/mysql.server.new
rm -f $PKG/usr/info/dir
    postbuild
}

source "${DATA:-/usr/lib/ktm}/ktm.ports.sh"

