From d1a2759ef647fb5d57af98cb1deaf99642af3137 Mon Sep 17 00:00:00 2001 From: levasseur Date: Mon, 25 Oct 2021 15:48:40 +0200 Subject: [PATCH] added lib/utils.sh and reorganised some files according to it --- lib/support.sh | 26 -------------------------- lib/utils.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 26 deletions(-) create mode 100644 lib/utils.sh diff --git a/lib/support.sh b/lib/support.sh index cd1935c..74b7e5e 100644 --- a/lib/support.sh +++ b/lib/support.sh @@ -101,30 +101,4 @@ show_version() } export -f show_version - -# ------------------------------------------------------------------------------ -# Get module name from module file -get_mod_name() -{ - if [[ $# -ne 1 ]]; then - prnt E "get_mod_name(): Bad number of parameters." - die 11 --force - fi - echo $(basename $1 | cut -f 1 -d '.') -} -export -f get_mod_name - - -# ------------------------------------------------------------------------------ -# Set system proxy vars -set_system_proxy() -{ - # Declare proxy system vars if needed and if not already declared - if [[ -n $PROXYSRV && -n $PROXYSRVPORT && -z $NO_PROXY ]]; then - export http_proxy=${http_proxy:-"http://$PROXYSRV:$PROXYSRVPORT/"} - export https_proxy=${https_proxy:-"http://$PROXYSRV:$PROXYSRVPORT/"} - fi -} -export -f set_system_proxy - # EOF diff --git a/lib/utils.sh b/lib/utils.sh new file mode 100644 index 0000000..5d8e038 --- /dev/null +++ b/lib/utils.sh @@ -0,0 +1,46 @@ +# ------------------------------------------------------------------------------ +# Various utilitary functions +# This file is part of the init.sh project +# Copyright (c) 2019-2021 Geoffray Levasseur +# ------------------------------------------------------------------------------ +# This file is distributed under 3-clause BSD license. +# The complete license agreement can be obtained at: +# https://opensource.org/licenses/BSD-3-Clause +# ------------------------------------------------------------------------------ + + +# ------------------------------------------------------------------------------ +# Check if a function exists, return 0 if so +function_exists() { + declare -f -F $1 > /dev/null + return $? +} + + +# ------------------------------------------------------------------------------ +# Get module name from module file +get_mod_name() +{ + if [[ $# -ne 1 ]]; then + prnt E "get_mod_name(): Bad number of parameters." + die 11 --force + fi + echo $(basename $1 | cut -f 1 -d '.') +} +export -f get_mod_name + + +# ------------------------------------------------------------------------------ +# Set system proxy vars +set_system_proxy() +{ + # Declare proxy system vars if needed and if not already declared + if [[ -n $PROXYSRV && -n $PROXYSRVPORT && -z $NO_PROXY ]]; then + export http_proxy=${http_proxy:-"http://$PROXYSRV:$PROXYSRVPORT/"} + export https_proxy=${https_proxy:-"http://$PROXYSRV:$PROXYSRVPORT/"} + fi +} +export -f set_system_proxy + + +# EOF