Merge branch 'master' of ssh://apo.geoffray-levasseur.org/share/services/git/legos

This commit is contained in:
levasseur
2021-09-15 16:58:08 +02:00
5 changed files with 75 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
# init.sh developper's reference # init.sh developper's reference
## Getting started ## Getting started
This is a programmer reference. It's not intended to be a manual, be a reference This is a programmer reference. It's not intended to be a manual, but a reference
for all internal functions, so you can easily build your own modules. This for all internal functions, so you can easily build your own modules. This
suppose you already read the [Readme file](../README.md). Creating modules suppose you already read the [Readme file](../README.md). Creating modules
will also requires some good knowledge of Bash programming. will also requires some good knowledge of Bash programming.
@@ -9,4 +9,70 @@ will also requires some good knowledge of Bash programming.
## The aaa_error.sh file ## The aaa_error.sh file
### Functions ### Functions
#### check_root #### check_root
Check if user is root. If user is not root, script execution is interupted and
exit with error.
This function have no parameter.
If the variable NO_ROOT_CHECK is set to true the function always exit without
error and no check is done.
#### die
Trigger an error, print a backtrace and exit the script, unless KEEPGOING
variable is set to true. In that situation we just display a warning.
If the parameter --force is given, we exit even if the KEEPGOING variable is set
to true.
#### noerror
Allow te execution of a command bypassing the error management system. The purpose
is to allow execution of test returning normally a non zero value without
triggering an error and the following exit.
If the first parameter is --noout all the outputs are disabled. The other
parameters are the raw command line to execute.
The function echoes the error code returned by the executed command.
### Other functionnalities
The simple integration of aaa_error.sh file into a script, will change the script
behaviour. The following Bash signals will be trapped:
- **ERR**: The ERR signal is triggered every time Bash encounter an error or if
a command return a non zero value. The function called on that signal will stop
execution of the script displaying an error message with error code and a backtrace
to help identify the error origin.
- **SIGINT**: That signal is trigerred when Ctrl + C is pressed by the user. That
signal will be interpreted only if the command is a Bash internal. If an executable
receive the signal it will be interpreted with the own executable mechanisms. We
will exit after cleanup.
- **SIGTERM**: That signal is typically the result of an external kill of the bash
process running the script. We will exit after cleanup.
## The display.sh file
### Functions
#### prnt
Print a message with timestamp and header. The header depends on first parameter
will be collored and have a fixed lenght so text is always alligned.
The first parameter is the header type, having those possible values:
- **I**: Display an informative message in green
- **W**: Display a warning in yellow
- **E**: Display an error in red
- **m**: Display a message without header but alligned
- Anything else will be treated as the message and will loose alignment.
Second parameter is the message to display.
### Other functionnalities
Using that script will declare many easy to remember variables containing Bash
color codes :
- Standard codes depending on your environment: DEFAULTFG, DEFAULTBG, DEFAULTCOL=${DEFAULTBG}${DEFAULTFG}
- Regular Colors: Black, Red, Green, Yellow, Blue, Purple, Cyan, White
- Bold: BBlack, BRed, BGreen, BYellow, BBlue, BPurple, BCyan, BWhite
- Underline: UBlack, URed, UGreen, UYellow, UBlue, UPurple, UCyan, UWhite
- Background: On_Black, On_Red, On_Green, On_Yellow, On_Blue, On_Purple, On_Cyan, On_White
- High Intensity: IBlack, IRed, IGreen, IYellow, IBlue, IPurple, ICyan, IWhite
- Bold High Intensity: BIBlack, BIRed, BIGreen, BIYellow, BIBlue, BIPurple, BICyan, BIWhite
- High Intensity backgrounds: On_IBlack, On_IRed, On_IGreen, On_IYellow, On_IBlue, On_IPurple, On_ICyan, On_IWhite

View File

@@ -108,7 +108,7 @@ load_configuration
process_commandline_and_vars process_commandline_and_vars
# Declare proxy system vars if needed and if not already declared # Declare proxy system vars if needed and if not already declared
if [[ -n $PROXYSRV && -n $PROXYSRVPORT ]]; then if [[ -n $PROXYSRV && -n $PROXYSRVPORT && -z $NO_PROXY ]]; then
export http_proxy=${http_proxy:-"http://$PROXYSRV:$PROXYSRVPORT/"} export http_proxy=${http_proxy:-"http://$PROXYSRV:$PROXYSRVPORT/"}
export https_proxy=${https_proxy:-"http://$PROXYSRV:$PROXYSRVPORT/"} export https_proxy=${https_proxy:-"http://$PROXYSRV:$PROXYSRVPORT/"}
fi fi

View File

@@ -93,8 +93,8 @@ export On_IWhite='\e[0;107m'
prnt() { prnt() {
case $1 in case $1 in
"I") "I")
HEADS="[ ${IGreen}info${DEFAULTFG} ]" HEADS="[ ${IGreen}info${DEFAULTFG} ]"
shift shift ##
;; ;;
"W") "W")
HEADS="[${IYellow}Attention${DEFAULTFG}]" HEADS="[${IYellow}Attention${DEFAULTFG}]"

View File

@@ -33,6 +33,8 @@ Options :
-k, --keep-going Continue l'execution en cas d'erreur. -k, --keep-going Continue l'execution en cas d'erreur.
-r, --resume Reprend l'execution là ou elle s'est arrêté. -r, --resume Reprend l'execution là ou elle s'est arrêté.
-R, --no-root-check Ne pas vérifier les droits root (ou UID 0) -R, --no-root-check Ne pas vérifier les droits root (ou UID 0)
-P, --no-proxy Ne pas utiliser de proxy lors de l'utilisation de
ce script (n'empêche pas leur configuration via modules)
-h, --help Affiche ce texte d'aide. -h, --help Affiche ce texte d'aide.
-l, --logfile <nom> Nom du fichier de log. Peut aussi être changé -l, --logfile <nom> Nom du fichier de log. Peut aussi être changé
via la variable d'environnement LOGFILE. via la variable d'environnement LOGFILE.

View File

@@ -59,6 +59,9 @@ read_commandline()
"-R"|"--no-root-check") "-R"|"--no-root-check")
export NO_ROOT_CHECK=true export NO_ROOT_CHECK=true
;; ;;
"-P"|"--no-proxy")
export NO_PROXY=true
;;
"-l"|"--logfile") "-l"|"--logfile")
local want_logfile=true local want_logfile=true
;; ;;