amelioration rajout foncion getMAchineNumber

This commit is contained in:
2021-10-08 15:15:33 +02:00
parent 1ac9cb9e50
commit 62b5f7f6e4

View File

@@ -4,6 +4,20 @@ function e {
echo -ne "${1};"
}
# get machine number from name
# arg1: name of machine
function getMachineNumber {
latest=${1: -2}
left=${latest:0:1}
match='[0-9]'
if [[ "$left" =~ $match ]] ; then
echo $latest
else
echo ${1: -1}
fi
}
# file age
# return 0 if given file mtime is older than given age (in day)
# arg1: file
@@ -158,15 +172,17 @@ function fileMustNOTContains {
}
# Ok if given user exists
# Arg1: user
# Arg1: chroot dir
# Arg2: user
function userExists {
if ( grep -iq $1 /etc/passwd ) ; then e 1 ; else e 0 ; fi
if ( grep -iq $2 ${1}/etc/passwd ) ; then e 1 ; else e 0 ; fi
}
# Ok if given group exists
# Arg1: group
# Arg1: chroot
# Arg2: group
function groupExists {
if ( grep -iq $1 /etc/group ) ; then e 1 ; else e 0 ; fi
if ( grep -iq $2 ${root}/etc/group ) ; then e 1 ; else e 0 ; fi
}
# insert hostname at beginning of result line
@@ -240,7 +256,7 @@ function commandStdoutPattern {
local command=$2
local pattern="$3"
result=$(chroot ${chroot} bash -c "$command")
result=$(chroot ${chroot} bash -c "$command" 2> /dev/null)
if ( echo -n "$result" | grep -qiE "${pattern}" ) ; then echo -ne "1;" ; else echo -ne "0;" ; fi
}