#!/bin/bash

#
# Name:         _shellcheck.sh
# Version:      1.0.1
#
# (c) 2022, Rapidseedbox, alexey@rapidseedbox.com
#


while read _app ; do
    _header="no"
    _ret="$( shellcheck -e SC2034,SC2140 "install_${_app}.sh" )"
    _rc=$?
    if [ "${_rc}" != "0" ] ; then
        if [ "${_header}" = "no" ] ; then
            _header="yes"
            echo -e "\n\n${_app}:"
            echo -e "==========================="
        fi
        echo -e "\ninstall_${_app}.sh: Check RC: [${_rc}]"
        echo -e "--------------------------------------------------------------"
        echo -e "${_ret}"
    fi
    if [ -e "uninstall_${_app}.sh" ] ; then
        _ret="$( shellcheck -e SC2034,SC2140 "uninstall_${_app}.sh" )"
        _rc=$?
        if [ "${_rc}" != "0" ] ; then
            if [ "${_header}" = "no" ] ; then
                _header="yes"
                echo -e "\n\n${_app}:"
                echo -e "==========================="
            fi
            echo -e "\nuninstall_${_app}.sh: Check RC: [${_rc}]"
            echo -e "--------------------------------------------------------------"
            echo -e "${_ret}"
        fi
    fi
    if [ -e "upgrade_${_app}.sh" ] ; then
        _ret="$( shellcheck -e SC2034,SC2140 "upgrade_${_app}.sh" )"
        _rc=$?
        if [ "${_rc}" != "0" ] ; then
            if [ "${_header}" = "no" ] ; then
                _header="yes"
                echo -e "\n\n${_app}:"
                echo -e "==========================="
            fi
            echo -e "\nupgrade_${_app}.sh: Check RC: [${_rc}]"
            echo -e "--------------------------------------------------------------"
            echo -e "${_ret}"
        fi
    fi
done < <( find . -mindepth 1 -maxdepth 1 -name "install_*.sh" \
              | sed -e 's|^./install_\(.*\)\.sh$|\1|' \
              | sort )
