From 66daa051754e6d98e4926519de608901b85a4d4b Mon Sep 17 00:00:00 2001 From: fatalerrors Date: Mon, 6 Sep 2021 14:40:35 +0200 Subject: [PATCH] Improved comments --- lib/aaa_errors.sh | 12 +++++++++++- lib/display.sh | 4 ++++ lib/filefct.sh | 6 ++++++ lib/pkgman.sh | 12 ++++++++++++ lib/services.sh | 16 ++++++++++++++-- 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/lib/aaa_errors.sh b/lib/aaa_errors.sh index 2e7b48e..3c0362e 100644 --- a/lib/aaa_errors.sh +++ b/lib/aaa_errors.sh @@ -7,6 +7,8 @@ # https://opensource.org/licenses/BSD-3-Clause # ------------------------------------------------------------------------------ + + # ------------------------------------------------------------------------------ # Exit with error function die() { @@ -27,6 +29,8 @@ function die() } export -f die + +# ------------------------------------------------------------------------------ function terminate() { prnt E "$1 reçu, sortie immédiate." @@ -35,6 +39,9 @@ function terminate() trap "terminate 'Ctrl + C'" SIGINT trap "terminate 'SIGTERM'" SIGTERM + +# ------------------------------------------------------------------------------ +# Function triggered on error function error() { local parent_lineno="$1" @@ -52,10 +59,11 @@ function error() fi #awk 'NR>L-4 && NR>>":""),$0 }' L=$1 $0 } - # Trigger error function on error trap "error ${LINENO}; backtrace; exit 255" ERR + +# ------------------------------------------------------------------------------ # Print a backtrace function backtrace { @@ -70,6 +78,8 @@ function backtrace echo "==============================" } + +# ------------------------------------------------------------------------------ # Test and exit if not root (or any UID 0 user) check_root() { diff --git a/lib/display.sh b/lib/display.sh index faba9d2..4b283f1 100644 --- a/lib/display.sh +++ b/lib/display.sh @@ -7,6 +7,8 @@ # https://opensource.org/licenses/BSD-3-Clause # ------------------------------------------------------------------------------ + +# ------------------------------------------------------------------------------ # Standard 16 colors display declaration export DEFAULTFG="\e[0;39m" export DEFAULTBG="\e[0;49m" @@ -82,6 +84,8 @@ export On_IPurple='\e[0;105m' export On_ICyan='\e[0;106m' export On_IWhite='\e[0;107m' + +# ------------------------------------------------------------------------------ # Affiche le status avec en-tête coloré et timestamp # (valeur de $1 : I=info, W=warning, E=error, m=des espaces (allignement) # pas d'entête si autre) diff --git a/lib/filefct.sh b/lib/filefct.sh index c48bc64..502ddf6 100644 --- a/lib/filefct.sh +++ b/lib/filefct.sh @@ -7,6 +7,8 @@ # https://opensource.org/licenses/BSD-3-Clause # ------------------------------------------------------------------------------ + +# ------------------------------------------------------------------------------ # Define normalised time display, filename friendly stdtime() { @@ -14,6 +16,8 @@ stdtime() } export -f stdtime + +# ------------------------------------------------------------------------------ # Backup original installation files # (or any old files if runned several time on same file) backupdist() @@ -35,6 +39,8 @@ backupdist() } export -f backupdist + +# ------------------------------------------------------------------------------ # Install file to the host (specific first then general) # Todo: implement wildcard support installfile() diff --git a/lib/pkgman.sh b/lib/pkgman.sh index ef160c1..8c53494 100644 --- a/lib/pkgman.sh +++ b/lib/pkgman.sh @@ -7,6 +7,8 @@ # https://opensource.org/licenses/BSD-3-Clause # ------------------------------------------------------------------------------ + +# ------------------------------------------------------------------------------ # Upgrade package database pkgupdt() { @@ -15,6 +17,8 @@ pkgupdt() } export -f pkgupdt + +# ------------------------------------------------------------------------------ # Installation pkginst() { @@ -30,6 +34,8 @@ pkginst() } export -f pkginst + +# ------------------------------------------------------------------------------ # Upgrade pkgupgd() { @@ -38,6 +44,8 @@ pkgupgd() } export -f pkgupgd + +# ------------------------------------------------------------------------------ # Uninstallation pkgrem() { @@ -53,6 +61,8 @@ pkgrem() } export -f pkgrem + +# ------------------------------------------------------------------------------ # Cleanup pkgautorem() { @@ -60,3 +70,5 @@ pkgautorem() $PKG_MAN $COM_AUTOREM } export -f pkgautorem + +#EOF diff --git a/lib/services.sh b/lib/services.sh index be2052d..0c82604 100644 --- a/lib/services.sh +++ b/lib/services.sh @@ -7,6 +7,9 @@ # https://opensource.org/licenses/BSD-3-Clause # ------------------------------------------------------------------------------ + +# ------------------------------------------------------------------------------ +# Common code controling services scripts # Syntax exec_serv svcname command exec_serv() { @@ -25,22 +28,31 @@ exec_serv() $lineexec } + +# ------------------------------------------------------------------------------ +# Start one or more service svc_start() { for svc in $@; do - exec_serv $svc start + exec_serv $svc start done } export -f svc_start + +# ------------------------------------------------------------------------------ +# Restart one or more services svc_restart() { for svc in $@; do - exec_serv $svc restart + exec_serv $svc restart done } export -f svc_restart + +# ------------------------------------------------------------------------------ +# Stop one or more services svc_stop() { for svc in $@; do