From 3e3031ee279d381f5513941391109e7a38a5f632 Mon Sep 17 00:00:00 2001 From: Guillaume Astier Ruiz Date: Tue, 4 Feb 2025 19:33:27 +0100 Subject: [PATCH] update function --- Apply/server/1/0.0.0.0.0/run.sh | 9 +++++++++ Apply/server/1/1.1.1.1.0/run.sh | 4 +++- pem-cyber-linux.d/config | 5 +++-- pem-cyber-linux.d/function_Apply | 23 +++++++++++++++++++++++ pem-cyber-linux.d/function_Check | 1 - 5 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 Apply/server/1/0.0.0.0.0/run.sh diff --git a/Apply/server/1/0.0.0.0.0/run.sh b/Apply/server/1/0.0.0.0.0/run.sh new file mode 100644 index 0000000..bcc9e87 --- /dev/null +++ b/Apply/server/1/0.0.0.0.0/run.sh @@ -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 ]] + + diff --git a/Apply/server/1/1.1.1.1.0/run.sh b/Apply/server/1/1.1.1.1.0/run.sh index 05ee10b..33a9f97 100644 --- a/Apply/server/1/1.1.1.1.0/run.sh +++ b/Apply/server/1/1.1.1.1.0/run.sh @@ -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" + diff --git a/pem-cyber-linux.d/config b/pem-cyber-linux.d/config index 36b997e..fc5b6f9 100644 --- a/pem-cyber-linux.d/config +++ b/pem-cyber-linux.d/config @@ -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) diff --git a/pem-cyber-linux.d/function_Apply b/pem-cyber-linux.d/function_Apply index e69de29..daf2bef 100644 --- a/pem-cyber-linux.d/function_Apply +++ b/pem-cyber-linux.d/function_Apply @@ -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 + diff --git a/pem-cyber-linux.d/function_Check b/pem-cyber-linux.d/function_Check index d88cca1..52a401c 100644 --- a/pem-cyber-linux.d/function_Check +++ b/pem-cyber-linux.d/function_Check @@ -3,7 +3,6 @@ function Check(){ if [[ $1 -ne 0 ]] then CheckRes=1 - return 1 fi } export -f Check