This repository has been archived on 2022-02-20. You can view files and clone it, but cannot push or open issues/pull-requests.
bash-shell-base/function/helpers

46 lines
915 B
Bash

#!/bin/bash
valid_ip()
{
local ip=$1
local stat=1
local res
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS
IFS='.'
ip=($ip)
IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
res=$([ $? == 0 ] && echo true || echo false)
else
res=false
fi
echo $res
}
get_domain() {
local domain
domain=$(echo $1 | awk -F\. '{print $(NF-1) FS $NF}')
echo "$domain"
}
# must be json as a string, depends on jq
get_prop_value () {
local value
# echo in $1 get $2
value=$(echo $1 | jq -r .$2)
echo $value
}
mounted () {
[[ ! $1 ]] && echo no mount point to test && return 2
mountpoint "$1" &> /dev/null && echo yes || return 1
}
is_array() {
local variable_name=$1
[[ "$(declare -p $variable_name 2>/dev/null)" =~ "declare -a" ]]
}