This repository has been archived on 2022-02-20. You can view files and clone it, but cannot push or open issues or pull requests.
bash-shell-base/function/helpers
David Kebler e25e44a98d added setup directory with set of user and system source files that can be copied in new machine
changed setup.sh to load.sh
startup only loads system repos by default and allows passing directory argument
2020-11-10 14:09:08 -08:00

45 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" ]]
}