improved doc, added missing headers, file manipulation error management improved

This commit is contained in:
fatalerrors
2021-09-03 20:07:15 +02:00
parent 89164cfdb1
commit 9f584fcd65
5 changed files with 64 additions and 39 deletions

View File

@@ -39,14 +39,14 @@ module name. If that option is provided, the module list is mandatory.
In that situation, no change should be done to the system.
- **-j, --jump**: Jump the checks and goes directly to system transformation.
That option should only be run after successfull checks (eg. after using the
**--checkonly** option).
\--checkonly option).
- **-k, --keep-going**: The scripts will try to continue even if errors occurs.
Thus some unrecoverable errors might stop the script anyway if it not allowing
Thus some unrecoverable errors might stop the script anyway if it's not allowing
it to work. Please use with care as it might leads to unexpected results.
- **-r, --resume**: Restart an interrupted process with the last executed module
that failed.
- **-R, --no-root-check**: Désactive la vérification des droits root (ou UID 0).
- **-h, --help**: Affiche des informations sur l'usage de la ligne de commande.
- **-R, --no-root-check**: Disable checks on root rights (or the 0 UID).
- **-h, --help**: Display informations on command line usage.
- **-l, --logfile**: Specify a custom name for the logfile. Standard logfile is
named init-hostname-date-time.log in the log subdirectory. That file can also
be customized using the LOGFILE environement variable.
@@ -63,8 +63,8 @@ and catch errors that could occurs while loading library files. In the opposite
the zzz_main_fct.sh file have to be loaded last, because it's widely using
previously declared libraries.
After that a basic command line parameter treatment is done. That allows the use
of --version and --help options in user space. Those options just display
After that, a basic command line parameter treatment is done. That allows the
use of --version and --help options in user space. Those options just display
informations and don't require any superuser rights and exit at that point of
execution. Everything after that will require administrator rights and the
script will exit with error at that point if not superuser.
@@ -150,7 +150,8 @@ on the way to have the job done, used variable could massively change ;
- y might be incremented in case simple functionnality addition or basic
improvements, existing variable might not change but new ones could appears ;
- z might be incremented only when correcting problems and/or bugs (+n fix => +n
to increment), variable should not change.
to increment), variable should not change unless this is the only way to fix a
problem.
Unless only configuration files have been changed, any change in the code
implies an increment of a version number in the code **and** a git commit.
@@ -181,22 +182,30 @@ export -f precheck_@template@
The following table is giving a list of error code with explanation:
| Code | Meaning |
|:----------|:----------------------------------------|
| 0 | No error |
| 1 | Command line syntax error |
| 2 | Unable to find configuration |
| 3 | Missing library file or function |
| 4 | No root rights |
| 5 | Malformed module list |
| 10 | Function call error |
| 11 | Bad function call |
| 12 | Error copying files |
| 13 | Bad target filesystem |
| 50..100 | Error in module execution |
| 128 | Abortion due to external cause |
| 150..200 | Error in module checks |
| Code | Meaning |
|:----------|:------------------------------------|
| 0 | No error |
| 1 | Command line syntax error |
| 2 | Misuse of Bash builtin |
| 3 | Missing library file or function |
| 4 | No root rights |
| 5 | Malformed module list |
| 6 | Unable to find configuration |
| 7 | Misuse of script internal function |
| 11 | Bad function call |
| 12 | Error copying files |
| 13 | Bad target filesystem |
| 50..100 | Error in module execution |
| 126 | Command exists but not executable |
| 127 | Command not found |
| 128 | Abortion due to external cause |
| 150..200 | Error in module checks |
| 255 | Exit status out of range |
Additionaly to exit codes, the script will try to produce a call stack to help
you in the debugging process. If you find a bug outside modules or in the basic
provided module, please contact the author. Of course, if you also have a patch,
your mail will be even more welcomed!
## Contact and more information

View File

@@ -7,6 +7,14 @@
# The complete license agreement can be obtained at:
# https://opensource.org/licenses/BSD-3-Clause
# ------------------------------------------------------------------------------
# Global variables:
# * INSTALL_MODE: if dev is declared here, packages will be installed one by
# one instead of sending the whole package list to the package manage
# * LOGFILE: Define manually output log file name. Can be superseeded through
# command line parameter. ATTENTION: That variable cannot be set in
# configuration file as it is treated before loading those, so it must be
# defined before calling that script.
# ------------------------------------------------------------------------------
# trace ERR through pipes
set -o pipefail

View File

@@ -19,32 +19,36 @@ export -f stdtime
backupdist()
{
[[ $# -lt 1 ]] &&
prnt E "backupdist(): Au moins un argument requis." &&
prnt E "backupdist(): At least one argument is required." &&
exit 11
for file in $@; do
if [[ -e ${file} ]]; then
local tmpstmp=$(stdtime)
prnt I "Création d'une sauvegarde de ${file} du $tmpstmp..."
cp -av $file $file.dist.$tmpstmp
if [[ -f ${file} ]]; then
local tmstmp=$(stdtime)
prnt I "Création d'une sauvegarde de ${file} du $tmstmp..."
if [[ ! cp -av $file $file.dist.$tmstmp ]]; then
else
prnt E "backupdist(): Le paramètre fournis ($file) n'est pas un fichier."
die 7
fi
done
}
export -f backupdist
# Install file to the host (specific first then general)
# Todo: implement wildcard support
installfile()
{
local filelist=""
local i=0
[[ $# -lt 2 ]] && (
prnt E "installfile(): Au moins deux arguments requis."
prnt E "installfile(): At least two arguments are required."
die 11
)
[[ $(echo $@ | grep "\*\|\?") ]] && (
prnt E "installfile(): Les wildcards sont interdits."
die 10
prnt E "installfile(): Wildcards are not authorized."
die 7
)
for arg in $@; do
@@ -59,15 +63,19 @@ installfile()
done
for i in $filelist; do :; done
if [[ ! $i==/* ]]; then
prnt E "installfile(): Target must be on the root filesystem."
prnt E "installfile(): Target must be on the root filesystem and fuul path must be provided."
die 13
fi
prnt I "Création du répertoire $(dirname $i) si nécessaire..."
mkdir -pv $(dirname $i)
if [[ -d $(dirname $i) ]]; then
prnt I "Création du répertoire $(dirname $i) d'accueil..."
if [[ ! mkdir -pv $(dirname $i) ]]; then
prnt E "installfile(): Can't create target dirrectory!"
die 12
fi
prnt I "Copie des fichiers ${filelist}..."
cp -av $filelist || (
prnt E "installfile(): Couldn't copy some required files..." &&
if [[ ! cp -av $filelist ]]; then
prnt E "installfile(): Couldn't copy some required files!" &&
die 12
)
fi
}
export -f installfile

View File

@@ -100,7 +100,7 @@ load_configuration()
. $MYPATH/conf/init.conf.sh
else
prnt E "Aucune configuration trouvée, impossible de continuer."
die 2 --force
die 6 --force
fi
fi
}

View File

@@ -25,7 +25,7 @@ install_mkagent()
precheck_install_mkagent()
{
[[ -n $MK_SERVER ]] && (
prnt E "Serveur check_mk non déclaré."
prnt E "Undeclared check_mk server."
die 162
)
}