From 5e11e5c915ca29695d977150ddde87187934da85 Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 4 Mar 2026 14:03:46 +0100 Subject: [PATCH] update.. --- snippets/detect_os.sh | 60 +++++++++++++++++--------- snippets/passwd_generator-00.sh | 68 +++++++++++++++++++++++++++++ snippets/passwd_generator-01.sh | 76 +++++++++++++++++++++++++++++++++ snippets/passwd_generator-02.sh | 62 +++++++++++++++++++++++++++ 4 files changed, 246 insertions(+), 20 deletions(-) create mode 100755 snippets/passwd_generator-00.sh create mode 100755 snippets/passwd_generator-01.sh create mode 100755 snippets/passwd_generator-02.sh diff --git a/snippets/detect_os.sh b/snippets/detect_os.sh index 70b091b..dd642a7 100755 --- a/snippets/detect_os.sh +++ b/snippets/detect_os.sh @@ -1,32 +1,52 @@ #!/usr/bin/env bash detect_os_1 () { - - if $(which lsb_release > /dev/null 2>&1) ; then - - os_dist="$(lsb_release -i | awk '{print tolower($3)}')" - os_version="$(lsb_release -r | awk '{print tolower($2)}')" - os_codename="$(lsb_release -c | awk '{print tolower($2)}')" - - if [[ "$os_dist" = "debian" ]]; then - if $(echo "$os_version" | grep -q '\.') ; then - os_version=$(echo "$os_version" | cut --delimiter='.' -f1) - fi - fi - - elif [[ -e "/etc/os-release" ]]; then + if [[ -r /etc/os-release ]]; then . /etc/os-release - os_dist=$ID - os_version=${VERSION_ID} + os_dist="$ID" + os_version="$VERSION_ID" + # Familie bestimmen + if [[ "$ID" == "debian" ]] || [[ "$ID_LIKE" == *"debian"* ]]; then + os_family="debian" + elif [[ "$ID" == "rhel" ]] || [[ "$ID_LIKE" == *"rhel"* ]]; then + os_family="rhel" + elif [[ "$ID" == "arch" ]] || [[ "$ID_LIKE" == *"arch"* ]]; then + os_family="arch" + else + os_family="$ID" + fi + + elif which lsb_release > /dev/null 2>&1 ; then + + local dist version + + dist=$(lsb_release -is 2>/dev/null | tr '[:upper:]' '[:lower:]') + version=$(lsb_release -rs 2>/dev/null | cut -d. -f1) # Major Version + + os_dist="$dist" + os_version="$version" + + case "$dist" in + debian|ubuntu|linuxmint) + os_family="debian" + ;; + rhel|centos|rocky|fedora) + os_family="rhel" + ;; + arch) + os_family="arch" + ;; + *) + os_family="$dist" + ;; + esac fi - # remove whitespace from os_dist and os_version - os_dist="${os_dist// /}" - os_version="${os_version// /}" - + # Nur Major-Version extrahieren (z.B. 12 aus 12.5) + os_version=${os_version%%.*} } detect_os_2 () diff --git a/snippets/passwd_generator-00.sh b/snippets/passwd_generator-00.sh new file mode 100755 index 0000000..283b33a --- /dev/null +++ b/snippets/passwd_generator-00.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash + +LENGTH=$1 +LENGTH=${LENGTH:=12} + + +is_number() { + + return $(test ! -z "${1##*[!0-9]*}" > /dev/null 2>&1); + + # - also possible + # - + #[[ ! -z "${1##*[!0-9]*}" ]] && return 0 || return 1 + #return $([[ ! -z "${1##*[!0-9]*}" ]]) +} + + +regexp_digit="([23456789].*){2}" +regexp_special_char="([-_/\.%+~].*){2}" +regexp_not_alowed="([0ODl18B])" + +if ! is_number $LENGTH ; then + echo "" + echo " [ Error]: Given parameter for password length '$LENGTH' is NOT a positiv Number!" + echo "" + exit 1 +fi + +if [[ $LENGTH -le 9 ]]; then + echo "" + echo " [ Error]: Given parameter for password length '$LENGTH' is too short!" + echo " Minimum length is '10'." + echo "" + exit 1 +fi + + + +for ((i=0; i<=9; i++)); do + + while [ 1 ] ; do + + # - Generate Passwort + _passwd="$(head -c 300 /dev/urandom | tr -cd 'a-zA-Z0-9-_/\.%+~' | head -c $LENGTH)" + #echo "$_passwd" + + # - Check Password + # - + if [[ "$_passwd" =~ $regexp_not_alowed ]] ; then + continue + fi + if [[ ! "$_passwd" =~ $regexp_special_char ]] ; then + continue + fi + if [[ ! "$_passwd" =~ $regexp_digit ]] ; then + continue + fi + + echo -n "$i: " + echo "$_passwd" + + break + + done + +done + +exit 0 diff --git a/snippets/passwd_generator-01.sh b/snippets/passwd_generator-01.sh new file mode 100755 index 0000000..275087b --- /dev/null +++ b/snippets/passwd_generator-01.sh @@ -0,0 +1,76 @@ +#!/usr/bin/env bash + +LENGTH=$1 +LENGTH=${LENGTH:=12} + + +is_number() { + + return $(test ! -z "${1##*[!0-9]*}" > /dev/null 2>&1); + + # - also possible + # - + #[[ ! -z "${1##*[!0-9]*}" ]] && return 0 || return 1 + #return $([[ ! -z "${1##*[!0-9]*}" ]]) +} + + +regexp_digit="([23456789].*){2}" +if [[ ${LENGTH} -gt 24 ]]; then + regexp_special_char="([-_/\.+~].*){6}" +elif [[ ${LENGTH} -gt 16 ]]; then + regexp_special_char="([-_/\.+~].*){5}" +elif [[ ${LENGTH} -gt 12 ]]; then + regexp_special_char="([-_/\.+~].*){4}" +else + regexp_special_char="([-_/\.+~].*){3}" +fi +regexp_not_alowed="([0ODl18B])" + +if ! is_number $LENGTH ; then + echo "" + echo " [ Error]: Given parameter for password length '$LENGTH' is NOT a positiv Number!" + echo "" + exit 1 +fi + +if [[ $LENGTH -le 9 ]]; then + echo "" + echo " [ Error]: Given parameter for password length '$LENGTH' is too short!" + echo " Minimum length is '10'." + echo "" + exit 1 +fi + + + +for ((i=0; i<=9; i++)); do + + while [ 1 ] ; do + + # - Generate Passwort + _passwd="$(head -c 300 /dev/urandom | tr -cd 'a-zA-Z0-9-/\.+_' | head -c $LENGTH)" + #echo "$_passwd" + + # - Check Password + # - + if [[ "$_passwd" =~ $regexp_not_alowed ]] ; then + continue + fi + if [[ ! "$_passwd" =~ $regexp_special_char ]] ; then + continue + fi + if [[ ! "$_passwd" =~ $regexp_digit ]] ; then + continue + fi + + echo -n "$i: " + echo "$_passwd" + + break + + done + +done + +exit 0 diff --git a/snippets/passwd_generator-02.sh b/snippets/passwd_generator-02.sh new file mode 100755 index 0000000..b66f48b --- /dev/null +++ b/snippets/passwd_generator-02.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash + +LENGTH=$1 +LENGTH=${LENGTH:=12} + +random_char() { + local chars="$1" + echo -n "${chars:RANDOM%${#chars}:1}" +} + +# Funktion zur Generierung eines zufälligen Strings mit den angegebenen Anforderungen +generate_random_string() { + local length="$1" + + # Überprüfen, ob die Länge größer als 8 ist + if [[ "$length" -le 8 ]]; then + echo "Fehler: Die Länge muss größer als 8 Zeichen sein." + return 1 + fi + + # Zeichenmengen + + # not allowed: 0ODl18B + + local lower="abcdefghijkmnopqrstuvwxyz" + #local upper="ABCDEFGHIJKLMNOPQRSTUVWXYZ" + local upper="ACEFGHIJKLMNPQRSTUVWXYZ" + #local digits="0123456789" + local digits="2345679" + #local special="!@#$%^&*()_+-=[]{}|;:,.<>?/" + local special="__+---///...." + + # Generiere mindestens ein Zeichen aus jeder Kategorie + local random_string=$(random_char "$lower") + random_string+=$(random_char "$upper") + random_string+=$(random_char "$digits") + random_string+=$(random_char "$special") + random_string+=$(random_char "$special") + + # Fülle den Rest der Zeichenkette mit zufälligen Zeichen aus allen Kategorien + local all_chars="$lower$upper$digits$special" + for (( i=${#random_string}; i