[UPDATE] - base function check

This commit is contained in:
Guillaume ASTIER 2025-02-04 11:36:37 +01:00
parent 98b48eac23
commit ed23d23c48
9 changed files with 129 additions and 0 deletions

View File

@ -0,0 +1,5 @@
#!/bin/bash
## 1.1.1.1 Ensure cramfs kernel module is not available (Automated)
echo '/bin/true' > /etc/modprobe.d/cramfs.conf

View File

@ -0,0 +1 @@
../../server/1/1.1.1.1.0/

View File

@ -0,0 +1,7 @@
#!/bin/bash
## 1.1.1.1 Ensure cramfs kernel module is not available (Automated)
[[ ! -f /etc/modprobe.d/cramfs.conf ]] && ((CptErr++))
[[ -z $(cat /etc/modprobe.d/cramfs.conf|grep '/bin/true') ]] && ((CptErr++))
Check ${CptErr}

View File

@ -0,0 +1 @@
../../server/1/1.1.1.1.0

6
pem-cyber-linux.d/config Normal file
View File

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

View File

@ -0,0 +1,57 @@
#!/bin/bash
function Usage(){
echo "$(basename $0) [-c/-a] -l [1/2]"
echo "-c : Check the system"
echo "-a : Apply cyber"
echo "-l : Level (1 or 2)"
echo "-t : Type (desktop/server)"
[[ ! -z $1 ]] && echo "ERROR [$1] $2"
exit $1
}
function LogTest() {
# LogTest ${Res} ${Action} ${TEST}
if [[ ${1} -ne 0 ]]
then
echo -e "\n### ${2} - [RESULT] - ${3} : FAILED"
else
echo -e "\n### ${2} - [RESULT] - ${3} : SUCESS"
fi | tee -a ${LogDir}/${3}.log
}
function GetArg(){
OPTSTRING="hcal:t:"
while getopts ${OPTSTRING} opt; do
case ${opt} in
a) Action=Apply;;
c) Action=Check;;
l) Level=${OPTARG};;
t) Type=${OPTARG};;
h) Usage;;
?) echo "Invalid option: -${OPTARG}."; exit 1;;
esac
done
}
function CheckArg(){
[[ -z ${Level} ]] && Usage 2 ": No Level selected"
[[ -z ${Action} ]] && Usage 1 ": No action selected"
[[ -z ${Type} ]] && Usage 3 ": No Type selected"
[[ ${Level} -gt 2 ]] && Usage 4 ": Level need to be 1 or 2"
true
}
function GetRoot() {
if [[ $(id -u) -ne 0 ]]
then
Usage 5 ": You need to be root"
fi
}

View File

View File

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

43
pem-cyber-linux.sh Executable file
View File

@ -0,0 +1,43 @@
#!/bin/bash
## source de la configuration
source $(realpath $(dirname $0))/$(echo $(basename $0)| sed 's/.sh/.d/g')/config
## source des functions de base
source ${DirFct}/function
GetRoot
OPTSTRING="hcal:t:"
while getopts ${OPTSTRING} opt; do
case ${opt} in
a) Action=Apply;;
c) Action=Check;;
l) Level=${OPTARG};;
t) Type=${OPTARG};;
h) Usage;;
?) echo "Invalid option: -${OPTARG}."; exit 1;;
esac
done
CheckArg
source ${DirFct}/function_${Action}
[[ $Level -eq 2 ]] && RealLevel=\* || RealLevel=1
DirAction=$(realpath $(dirname $0))/${Action}/${Type}/${RealLevel}
[[ ! -d ${LogDir} ]] && mkdir -p ${LogDir} || true
for File in $(find ${DirAction} -type f -name run.sh| sort -n)
do
cd $(dirname ${File})
Test=$(basename $(dirname ${File}))
export CptErr=0
bash ${Debug} ./run.sh &> ${LogDir}/${Test}.log
LogTest ${?} ${Action} ${Test}
done