update function

This commit is contained in:
Prof Isen 2025-02-04 19:33:27 +01:00
parent 5fc6a2cc3b
commit 3e3031ee27
5 changed files with 38 additions and 4 deletions

View File

@ -0,0 +1,9 @@
#!/bin/bash
## 0.0.0.0.0 test
Apply 0 1 "Test true" [[ -f /etc/passwd ]]
Apply 0 2 "Test false" [[ -f /etc/nofile ]]
Apply 0 3 "Test" [[ -d /etc ]]

View File

@ -2,4 +2,6 @@
## 1.1.1.1 Ensure cramfs kernel module is not available (Automated)
echo '/bin/true' > /etc/modprobe.d/cramfs.conf
Apply 1 1 "cramfs" echo '/bin/true' > /etc/modprobe.d/cramfs.conf
Apply 0 2 "cramfs" echo "tout va bien"

View File

@ -2,6 +2,7 @@
DirFct=$(realpath $(dirname $0))/$(echo $(basename $0)| sed 's/.sh/.d/g')/
DirCheck=$(realpath $(dirname $0))/Check
DirApply=$(realpath $(dirname $0))/Apply
#Debug='-x'
Debug=""
Debug='-x'
#Debug=""
LogDir=/var/log/$(echo $(basename $0) |sed 's/.sh//g')/$(date +%H%m%d%H%M%S)

View File

@ -0,0 +1,23 @@
function Apply(){
ExitError=$1
shift
Step=$1
shift
Txt=$1
shift
Cmd=$@
eval $@
GetRes=$?
if [[ $GetRes -ne 0 ]] && [[ ExitError -eq 1 ]]
then
echo "Fatal Error on step ${Step} : $Cmd"
exit 10
else
[[ $GetRes -ne 0 ]] && echo "WARNING on step ${Step}" || true
fi
}
# Export de la fonction pour être pris en compte dans les sous shell
export -f Apply

View File

@ -3,7 +3,6 @@ function Check(){
if [[ $1 -ne 0 ]]
then
CheckRes=1
return 1
fi
}
export -f Check