diff --git a/awk/src/base.awk b/awk/src/base.awk index ae59617..65c79fe 100644 --- a/awk/src/base.awk +++ b/awk/src/base.awk @@ -2,3 +2,4 @@ @include "base.core.awk" @include "base.array.awk" @include "base.date.awk" +@include "base.tools.awk" diff --git a/awk/src/base.tools.awk b/awk/src/base.tools.awk new file mode 100644 index 0000000..64f6d89 --- /dev/null +++ b/awk/src/base.tools.awk @@ -0,0 +1,20 @@ +BEGIN { + srand() +} + +function get_random_password( password, max, LETTERS) { + LETTERS = "AZERTYUIOPQSDFGHJKLMWXCVBNazertyuiopqsdfghjklmwxcvbn0123456789" + max = length(LETTERS) + password = "" + for (i = 0; i < 16; i++) { + password = password substr(LETTERS, int(rand() * max), 1) + } + return password +} + +function should_generate_password() { + return $0 ~ /XXXRANDOMXXX/ +} +function generate_password() { + sub(/XXXRANDOMXXX/, get_random_password()) +} diff --git a/bash/src/base.tools.sh b/bash/src/base.tools.sh index 5b1ddd3..1a7f800 100644 --- a/bash/src/base.tools.sh +++ b/bash/src/base.tools.sh @@ -88,3 +88,14 @@ function testsame() { diff -q "$@" >&/dev/null; } function: testdiff "tester si deux fichiers sont différents en mode silencieux" function testdiff() { ! diff -q "$@" >&/dev/null; } + +function: should_update "faut-il mettre à jour le \$1 qui est construit à partir de \$2..@" +function should_update() { + local dest="$1"; shift + local source + for source in "$@"; do + [ -f "$source" ] || continue + [ "$source" -nt "$dest" ] && return 0 + done + return 1 +}