make_directory() {
local path="${1}"
- mkdir -p "${path}"
+ # Exit silently when directory already exists
+ if [ -d "${path}" ]; then
+ return ${EXIT_OK}
+ fi
+
+ if ! mkdir -p "${path}"; then
+ log ERROR "Could not create directory ${path}"
+ return ${EXIT_ERROR}
+ fi
+
+ log DEBUG "Created directory ${path}"
+ return ${EXIT_OK}
}
make_parent_directory() {
list_match "${!param}" yes on true 1
}
+disabled() {
+ local param="${1}"
+
+ list_match "${!param}" no off false 0
+}
+
mac_generate() {
local b="$(random 12)"
[[ ${mac} =~ ^([0-9a-f]{2}\:){5}[0-9a-f]{2}$ ]]
}
+# Converts the given string to lowercase and returns true if it is a valid FQDN
+fqdn_is_valid() {
+ local fqdn="${1}"
+
+ if grep -qP "^(?!:\/\/)(?=.{1,255}$)((.{1,63}\.){1,127}(?![0-9]*$)[a-z0-9-]+\.?)$" <<< "${fqdn,,}"; then
+ return ${EXIT_TRUE}
+ fi
+
+ return ${EXIT_FALSE}
+}
+
uuid() {
echo $(</proc/sys/kernel/random/uuid)
}
local mtu=${2}
case ${proto} in
- ipv4)
+ ethernet|ipv4)
[ ${mtu} -ge 576 ] && [ ${mtu} -le 9000 ]
;;
ipv6)
return ${EXIT_ERROR}
fi
+ # Create destination directory if it doesn't exist, yet
+ if ! make_parent_directory "${dst}"; then
+ return ${EXIT_ERROR}
+ fi
+
if ! fread "${src}" > "${dst}"; then
log ERROR "Could not copy data from ${src} to ${dst}"
return ${EXIT_ERROR}
fi
}
+
+normalize() {
+ local string="$@"
+
+ tr -sc [:alnum:] "-" < <(printf "%s" "${string,,}")
+}
+
+get_driver_from_path() {
+ local path="${1}"
+
+ if file_exists "${path}"; then
+ # Resolve symlink
+ local driver="$(readlink "${path}")"
+
+ # Print module name
+ basename "${driver}"
+ return ${EXIT_OK}
+ fi
+
+ return ${EXIT_ERROR}
+}