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

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

check() {
# Checking for configuration
# Downloading sources lists
INSTALLED=`ls -1 $PACKAGES/packages/|grep $PACKAGE-|cut -d "-" -f 1,2`
$WGET -q ftp://ftp.tpnet.pl/d2/ftp.openssh.com/pub/OpenBSD/OpenSSH/portable/
NEW=`grep $PACKAGE index.html |grep .tar.gz|cut -d '>' -f 2|cut -d '<' -f 1|sed -e s/.tar.*//|sort -t p -k +1,2|tail -1`
#Checking for new version
    checkpkg
# clean
rm index.html
}

download() {
# Downloading version from "${VERFILE}"
$WGET -P $DOWNL ftp://ftp.tpnet.pl/d2/ftp.openssh.com/pub/OpenBSD/OpenSSH/portable/$SRC.tar.gz
}

build() {
# Creating new
tar zxvf $DOWNL/$SRC.tar.gz
cd $SRC
./configure \
  --prefix=/usr \
  --sysconfdir=/etc/ssh \
  --without-pam \
  --with-md5-passwords \
  --with-tcp-wrappers \
  --with-default-path="/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin" \
  --with-ipv4-default \
  --with-privsep-path=/var/empty \
  --with-privsep-user=sshd \
  $TARGET || exit
make || exit
make install DESTDIR=$PKG || exit
(
    cd $PKG/usr/man/man1
    ln -sf ssh.1.gz slogin.1.gz
)
mkdir -p $PKG/var/empty
chmod 755 $PKG/var/empty
rm -f $PKG/etc/ssh/ssh_host_dsa_key
rm -f $PKG/etc/ssh/ssh_host_dsa_key.pub
rm -f $PKG/etc/ssh/ssh_host_rsa_key
rm -f $PKG/etc/ssh/ssh_host_rsa_key.pub
rm -f $PKG/etc/ssh/ssh_host_key
rm -f $PKG/etc/ssh/ssh_host_key.pub
if [ -d /etc/ssh ]; then
mv $PKG/etc/ssh/ $PKG/etc/ssh.new
fi
mkdir -p $PKG/etc/rc.d
cp $CWD/rc.sshd $PKG/etc/rc.d/
if [ -r /etc/rc.d/rc.sshd ];then
mv $PKG/etc/rc.d/rc.sshd $PKG/etc/rc.d/rc.sshd.new
fi
( cd contrib
  cp -a ssh-copy-id $PKG/usr/bin/ssh-copy-id
  chmod 755 $PKG/usr/bin/ssh-copy-id
  cp ssh-copy-id.1 $PKG/usr/man/man1/
)
    postbuild
}

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

