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

prog=`basename $0 .bash`
ROLE=toxcore
PREFIX=/usr/local
LOCAL_DOCTEST=/usr/local/bin/testforge_run_doctest3.bash
DOCTEST=${LOCAL_DOCTEST}

. /usr/local/bin/usr_local_tput.bash
# we install into /usr/local/bin and it takes precedence
# export PATH=$PREFIX/bin:$PATH

. $PREFIX/src/usr_local_src.bash || exit 2
[ `id -u` -eq 0 ] && ERROR $prog should not be run as root && exit 3

if [ "$#" -eq 0 ] ; then
    cd $PREFIX/src || exit 2
    WD=$PWD

    bash c-toxcore.bash # || exit 13$?
    bash tox_profile.bash # || 14$?
    bash stem_examples.bash # || 14$?
    bash exclude_badExits.bash
#    sh mitogen.bash
    #    sh toxcore_docker.bash || exit 14$?
#    which sdwdate >/dev/null 2>/dev/null || \
#	[ -f $PREFIX/bin/sdwdate.bash ] || \
#	sh sdwdate.bash

    bash analyze-ssl.bash
    bash gridfire.bash # || exit 16$?
    bash pyassuan.bash #|| exit 17$?
    bash tinfoilhat.shmoo.com.bash
    #    sh negotiator.bash
    bash kernelexpect.bash
    bash kernel-hardening-checker.bash
    
    # bash dracut-055.bash
    bash toxygen_wrapper.bash
    
    [ -d testssl.sh ] || \
	sh testssl.bash || exit 19$?
    
    exit 0

elif [ "$1" = 'check' ] ; then
    exit 0
    msys_run_checks_pip3
    msys_var_local_src_prog_key check || exit 10$?
    exit $?

elif [ "$1" = 'lint' ] ; then
#    ols_run_tests_shellcheck $ROLE || exit 2$?
    msys_var_local_src_prog_key $1 || exit 21$?
    msys_run_tests_pylint ||  exit 22$?
    exit 0

elif [ "$1" = 'test' ] ; then
    exit 0
    msys_var_local_src_prog_key $1 || exit 30$?
    msys_check_pips_inst 
    msys_gentoo_test_imports  || exit 32$?
    #hangs    /usr/bin/expect gpgkey_test_gpg.exp foobar || exit 31$?

elif [ "$1" = 'doctest' ] ; then # 8*
    msys_var_local_src_prog_key $1 || exit 8$?
    ${DOCTEST} /usr/local/share/doc/txt/${ROLE}3.txt
    
fi
