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

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

check() {
# Checking for configuration
# Downloading sources lists
INSTALLED=`ls -1 $PACKAGES/packages/|grep $PACKAGE|cut -d "-" -f 1,2`
$WGET -q http://www.openssl.org/source
NEW=`grep $PACKAGE index.html|grep .tar.gz|cut -d '"' -f 4|sort -n|grep -v engine|grep -v md5|sed -e s/.tar.*//|tail -1`
#Checking for new version
    checkpkg
# clean
rm index.html
}

download() {
# Downloading version from "${VERFILE}"
$WGET -P $DOWNL http://www.openssl.org/source/$SRC.tar.gz
}
relink() {
  ORIGLINE=`/bin/ls -l $1`
  LINK=`echo $ORIGLINE | cut -f 9 -d ' '`.gz
  FILE=`echo $ORIGLINE | cut -f 11 -d ' '`.gz
  rm $1
  if [ -r $FILE ]; then
    ln -sf $FILE $LINK
  fi
}

build() {
# Creating new
tar zxvf $DOWNL/$SRC.tar.gz
cd $SRC
export LC_ALL=C
zcat $CWD/patches/openssl.soname.diff.gz | patch -p1 --backup --verbose --suffix=.orig
zcat $CWD/patches/openssl.opts.diff.gz | patch -p1 --backup --verbose --suffix=.orig
./config \
    --prefix=/usr \
    --openssldir=/etc/ssl \
    386 \
    no-mdc2 \
    no-idea \
    no-rc5 \
    shared || exit
make || exit
make install INSTALL_PREFIX=$PKG || exit
( cd $PKG/usr/lib ; ln -sf libcrypto.so.0 libcrypto.so )
( cd $PKG/usr/lib ; ln -sf libssl.so.0 libssl.so )
chown -R root.bin $PKG/usr/bin
mv $PKG/etc/ssl/man $PKG/usr
( cd $PKG/usr/man/man1 ; mv passwd.1 ssl_passwd.1 )
( cd $PKG/usr/man/man3 ; mv rand.3 ssl_rand.3 )
gzip -9v $PKG/usr/man/man?/*
for mandir in man1 man3 man7 ; do
  ( cd $PKG/usr/man/$mandir
    for page in *.? ; do
      relink $page
    done
  )
done
chmod 755 $PKG/usr/lib/pkgconfig
    postbuild
}

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

