From ee3a8d91baf0dcf6af0574d218eaff9ca7657a30 Mon Sep 17 00:00:00 2001 From: levasseur Date: Wed, 6 Oct 2021 17:55:04 +0200 Subject: [PATCH] few improvements, consistency fixes --- init.sh | 15 ++++++++------- lib/support.sh | 17 ++++++++++++----- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/init.sh b/init.sh index c445573..08d0407 100755 --- a/init.sh +++ b/init.sh @@ -44,9 +44,6 @@ export MYPATH=$(dirname $(realpath -s $0)) # Get hostname export HOSTNAME=$(hostname) -# System architecture -export SYS_ARCH=$(uname -m) - # Load libraries for lib in $MYPATH/lib/*.sh; do . $lib @@ -69,13 +66,13 @@ function_exists prnt || ( exit 3 ) -# Set system dependent vars -get_os_version $(read_os_release) - # ====================== # ==== Main Program ==== # ====================== +# Set system dependent vars +set_sys_vars $(uname -m) $(get_os_version) + # Initializing global variables export CHECK_ONLY=false export JUMP=false @@ -109,7 +106,11 @@ exec > >(tee -a $LOGFILE) exec 2> >(tee -a $LOGFILE >&2) prnt I "Démarrage d'init version $VERSION." prnt I "Le fichier de log est $LOGFILE." -prnt I "Lancé sur $SYS_DIST version $SYS_VER ($SYS_CODE) architecture $SYS_ARCH" +if [[ -n $SYS_CODE ]]; then + prnt I "Lancé sur $SYS_DIST version $SYS_VER ($SYS_CODE) architecture $SYS_ARCH" +else + prnt I "Lancé sur $SYS_DIST version $SYS_VER architecture $SYS_ARCH" +fi # -- Cannot be a function ends here diff --git a/lib/support.sh b/lib/support.sh index 5a521c2..fdc504b 100644 --- a/lib/support.sh +++ b/lib/support.sh @@ -79,13 +79,16 @@ show_version() local mod= for mod in $MYPATH/modules/*.sh; do - . $mod - local modname=$(get_mod_name $mod) - local version=VER_$modname + # Ran in a subshell to not pollute environment + ( + . $mod + local modname=$(get_mod_name $mod) + local version=VER_$modname - echo -e "\t$BWhite$modname${DEFAULTCOL}: $BGreen${!version}$DEFAULTCOL" + echo -e "\t$BWhite$modname${DEFAULTCOL}: $BGreen${!version}$DEFAULTCOL" - unset modname version + unset modname version + ) done unset mod @@ -100,6 +103,10 @@ 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