This commit is contained in:
2026-03-04 14:03:46 +01:00
parent a4a1e10448
commit 5e11e5c915
4 changed files with 246 additions and 20 deletions

View File

@@ -1,32 +1,52 @@
#!/usr/bin/env bash #!/usr/bin/env bash
detect_os_1 () { detect_os_1 () {
if [[ -r /etc/os-release ]]; then
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
. /etc/os-release . /etc/os-release
os_dist=$ID os_dist="$ID"
os_version=${VERSION_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 fi
# remove whitespace from os_dist and os_version # Nur Major-Version extrahieren (z.B. 12 aus 12.5)
os_dist="${os_dist// /}" os_version=${os_version%%.*}
os_version="${os_version// /}"
} }
detect_os_2 () detect_os_2 ()

68
snippets/passwd_generator-00.sh Executable file
View File

@@ -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

76
snippets/passwd_generator-01.sh Executable file
View File

@@ -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

62
snippets/passwd_generator-02.sh Executable file
View File

@@ -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<length; i++ )); do
random_string+=$(random_char "$all_chars")
done
# Mische die Zeichenkette, um die Reihenfolge der Zeichen zufällig zu machen
random_string=$(echo "$random_string" | fold -w1 | shuf | tr -d '\n')
# Ausgabe des generierten Strings
echo "$random_string"
}
echo
for ((i=0; i<=9; i++)); do
echo -en "\t$i: "
echo "$(generate_random_string "${LENGTH}")"
done
echo ""