improved doc, added missing headers, file manipulation error management improved
This commit is contained in:
53
README.md
53
README.md
@@ -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.
|
In that situation, no change should be done to the system.
|
||||||
- **-j, --jump**: Jump the checks and goes directly to system transformation.
|
- **-j, --jump**: Jump the checks and goes directly to system transformation.
|
||||||
That option should only be run after successfull checks (eg. after using the
|
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.
|
- **-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.
|
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
|
- **-r, --resume**: Restart an interrupted process with the last executed module
|
||||||
that failed.
|
that failed.
|
||||||
- **-R, --no-root-check**: Désactive la vérification des droits root (ou UID 0).
|
- **-R, --no-root-check**: Disable checks on root rights (or the 0 UID).
|
||||||
- **-h, --help**: Affiche des informations sur l'usage de la ligne de commande.
|
- **-h, --help**: Display informations on command line usage.
|
||||||
- **-l, --logfile**: Specify a custom name for the logfile. Standard logfile is
|
- **-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
|
named init-hostname-date-time.log in the log subdirectory. That file can also
|
||||||
be customized using the LOGFILE environement variable.
|
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
|
the zzz_main_fct.sh file have to be loaded last, because it's widely using
|
||||||
previously declared libraries.
|
previously declared libraries.
|
||||||
|
|
||||||
After that a basic command line parameter treatment is done. That allows the use
|
After that, a basic command line parameter treatment is done. That allows the
|
||||||
of --version and --help options in user space. Those options just display
|
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
|
informations and don't require any superuser rights and exit at that point of
|
||||||
execution. Everything after that will require administrator rights and the
|
execution. Everything after that will require administrator rights and the
|
||||||
script will exit with error at that point if not superuser.
|
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
|
- y might be incremented in case simple functionnality addition or basic
|
||||||
improvements, existing variable might not change but new ones could appears ;
|
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
|
- 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
|
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.
|
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:
|
The following table is giving a list of error code with explanation:
|
||||||
|
|
||||||
| Code | Meaning |
|
| Code | Meaning |
|
||||||
|:----------|:----------------------------------------|
|
|:----------|:------------------------------------|
|
||||||
| 0 | No error |
|
| 0 | No error |
|
||||||
| 1 | Command line syntax error |
|
| 1 | Command line syntax error |
|
||||||
| 2 | Unable to find configuration |
|
| 2 | Misuse of Bash builtin |
|
||||||
| 3 | Missing library file or function |
|
| 3 | Missing library file or function |
|
||||||
| 4 | No root rights |
|
| 4 | No root rights |
|
||||||
| 5 | Malformed module list |
|
| 5 | Malformed module list |
|
||||||
| 10 | Function call error |
|
| 6 | Unable to find configuration |
|
||||||
| 11 | Bad function call |
|
| 7 | Misuse of script internal function |
|
||||||
| 12 | Error copying files |
|
| 11 | Bad function call |
|
||||||
| 13 | Bad target filesystem |
|
| 12 | Error copying files |
|
||||||
| 50..100 | Error in module execution |
|
| 13 | Bad target filesystem |
|
||||||
| 128 | Abortion due to external cause |
|
| 50..100 | Error in module execution |
|
||||||
| 150..200 | Error in module checks |
|
| 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
|
## Contact and more information
|
||||||
|
|
||||||
|
|||||||
10
init.sh
10
init.sh
@@ -7,7 +7,15 @@
|
|||||||
# The complete license agreement can be obtained at:
|
# The complete license agreement can be obtained at:
|
||||||
# https://opensource.org/licenses/BSD-3-Clause
|
# 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
|
# trace ERR through pipes
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
|
|||||||
@@ -19,32 +19,36 @@ export -f stdtime
|
|||||||
backupdist()
|
backupdist()
|
||||||
{
|
{
|
||||||
[[ $# -lt 1 ]] &&
|
[[ $# -lt 1 ]] &&
|
||||||
prnt E "backupdist(): Au moins un argument requis." &&
|
prnt E "backupdist(): At least one argument is required." &&
|
||||||
exit 11
|
exit 11
|
||||||
|
|
||||||
for file in $@; do
|
for file in $@; do
|
||||||
if [[ -e ${file} ]]; then
|
if [[ -f ${file} ]]; then
|
||||||
local tmpstmp=$(stdtime)
|
local tmstmp=$(stdtime)
|
||||||
prnt I "Création d'une sauvegarde de ${file} du $tmpstmp..."
|
prnt I "Création d'une sauvegarde de ${file} du $tmstmp..."
|
||||||
cp -av $file $file.dist.$tmpstmp
|
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
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
export -f backupdist
|
export -f backupdist
|
||||||
|
|
||||||
# Install file to the host (specific first then general)
|
# Install file to the host (specific first then general)
|
||||||
|
# Todo: implement wildcard support
|
||||||
installfile()
|
installfile()
|
||||||
{
|
{
|
||||||
local filelist=""
|
local filelist=""
|
||||||
local i=0
|
local i=0
|
||||||
|
|
||||||
[[ $# -lt 2 ]] && (
|
[[ $# -lt 2 ]] && (
|
||||||
prnt E "installfile(): Au moins deux arguments requis."
|
prnt E "installfile(): At least two arguments are required."
|
||||||
die 11
|
die 11
|
||||||
)
|
)
|
||||||
[[ $(echo $@ | grep "\*\|\?") ]] && (
|
[[ $(echo $@ | grep "\*\|\?") ]] && (
|
||||||
prnt E "installfile(): Les wildcards sont interdits."
|
prnt E "installfile(): Wildcards are not authorized."
|
||||||
die 10
|
die 7
|
||||||
)
|
)
|
||||||
|
|
||||||
for arg in $@; do
|
for arg in $@; do
|
||||||
@@ -59,15 +63,19 @@ installfile()
|
|||||||
done
|
done
|
||||||
for i in $filelist; do :; done
|
for i in $filelist; do :; done
|
||||||
if [[ ! $i==/* ]]; then
|
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
|
die 13
|
||||||
fi
|
fi
|
||||||
prnt I "Création du répertoire $(dirname $i) si nécessaire..."
|
if [[ -d $(dirname $i) ]]; then
|
||||||
mkdir -pv $(dirname $i)
|
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}..."
|
prnt I "Copie des fichiers ${filelist}..."
|
||||||
cp -av $filelist || (
|
if [[ ! cp -av $filelist ]]; then
|
||||||
prnt E "installfile(): Couldn't copy some required files..." &&
|
prnt E "installfile(): Couldn't copy some required files!" &&
|
||||||
die 12
|
die 12
|
||||||
)
|
fi
|
||||||
}
|
}
|
||||||
export -f installfile
|
export -f installfile
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ load_configuration()
|
|||||||
. $MYPATH/conf/init.conf.sh
|
. $MYPATH/conf/init.conf.sh
|
||||||
else
|
else
|
||||||
prnt E "Aucune configuration trouvée, impossible de continuer."
|
prnt E "Aucune configuration trouvée, impossible de continuer."
|
||||||
die 2 --force
|
die 6 --force
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ install_mkagent()
|
|||||||
precheck_install_mkagent()
|
precheck_install_mkagent()
|
||||||
{
|
{
|
||||||
[[ -n $MK_SERVER ]] && (
|
[[ -n $MK_SERVER ]] && (
|
||||||
prnt E "Serveur check_mk non déclaré."
|
prnt E "Undeclared check_mk server."
|
||||||
die 162
|
die 162
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user