#!/bin/sh
# -*- mode: sh; tab-width: 8; encoding: utf-8-unix -*-

prog=`basename $0 .bash`
PREFIX=/usr/local
[ -f /usr/local/etc/testforge/testforge.bash ] && \
  . /usr/local/etc/testforge/testforge.bash
ROLE=toxcore

PKG=analyze-ssl.pl
GIT_HUB=github.com
GIT_USER=noxxi
GIT_DIR=p5-ssl-tools
URL=raw.githubusercontent.com//master/$PKG.sh
URL=github.com/$GIT_USER/$GIT_DIR/raw/master/$PKG

. $PREFIX/src/var_local_src.bash

cd $PREFIX/src || exit 2
WD=$PWD

if [ "$#" -eq 0 ] ; then
    if [ ! -f $PKG ] ; then

	[ -d $PREFIX/net/Http/$GIT_HUB ] || mkdir $PREFIX/net/Http/$GIT_HUB
	if [ -e $PREFIX/net/Http/$URL ] ; then
	    ip route | grep -q ^default || { DEBUG "$0 not connected" ; exit 0 ; }
	    wget -xc -P $PREFIX/net/Http https://$URL
	fi
    fi

    [ -f  $PKG ] || cp -p $PREFIX/net/Http/$URL .

    if [ ! -e $PREFIX/bin/$PKG.bash ] ; then
	cat > $PREFIX/bin/$PKG.bash << EOF
#!/bin/sh
# -*- mode: sh; tab-width: 8; encoding: utf-8-unix -*-
ROLE=text
# https://$GIT_HUB/$GIT_USER/$GIT_DIR/
cd $PREFIX/src/ || exit 1
exec perl $PKG "\$@"
EOF
	chmod 755 $PREFIX/bin/$PKG.bash
    fi

    exit 0

elif [ "$1" = 'test' ] ; then # 3*
    $PREFIX/bin/$PKG.bash --help || exit 30
fi
