update..
This commit is contained in:
@@ -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
|
||||
|
||||
# remove whitespace from os_dist and os_version
|
||||
os_dist="${os_dist// /}"
|
||||
os_version="${os_version// /}"
|
||||
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
|
||||
|
||||
# Nur Major-Version extrahieren (z.B. 12 aus 12.5)
|
||||
os_version=${os_version%%.*}
|
||||
}
|
||||
|
||||
detect_os_2 ()
|
||||
|
||||
68
snippets/passwd_generator-00.sh
Executable file
68
snippets/passwd_generator-00.sh
Executable 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
76
snippets/passwd_generator-01.sh
Executable 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
62
snippets/passwd_generator-02.sh
Executable 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 ""
|
||||
Reference in New Issue
Block a user