diff --git a/modules/utility/helpers.mod b/modules/utility/helpers.mod index 2152eab..c3aa329 100644 --- a/modules/utility/helpers.mod +++ b/modules/utility/helpers.mod @@ -1,10 +1,10 @@ #!/bin/bash # 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 + local value + # echo in $1 get $2 + value=$(echo $1 | jq -r .$2) + echo $value } is_array() { @@ -13,20 +13,22 @@ is_array() { } filename() { - # passed entire path - echo $(basename "$1" | rev | cut -f 2- -d '.' | rev) + # passed entire path + echo $(basename "$1" | rev | cut -f 2- -d '.' | rev) } adirname() { - # passed entire path - echo "$(cd "$(dirname "$1")" >/dev/null 2>&1 ; pwd -P )" + # passed entire path + echo "$(cd "$(dirname "$1")" >/dev/null 2>&1 ; pwd -P )" } + + chmod_dirs() { - # passed entire path - local usesudo - [[ $1 == -s ]] && usesudo="sudo" && shift 2 - $usesudo find $1 -type f -exec chmod $2 {} + + # passed entire path + local usesudo + [[ $1 == -s ]] && usesudo="sudo" && shift 2 + $usesudo find $1 -type f -exec chmod $2 {} + } diff --git a/modules/utility/path.sh b/modules/utility/path.sh index 69cc9d0..106c9fb 100644 --- a/modules/utility/path.sh +++ b/modules/utility/path.sh @@ -1,11 +1,23 @@ #!/bin/bash + +# get full absolute bath from a current or parent path function abs-path { local target="$1" if [ "$target" == "." ]; then echo "$(pwd)" - elif [ "$target" == ".." ]; then + elif [ "$target" == ".." ]; then echo "$(dirname "$(pwd)")" else echo "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")" fi } + +isAbsPath() { + if [[ "${1:0:1}" == / || "${1:0:2}" == ~[/a-z] ]] + then + echo "true" + return 0 + else + return 1 + fi +} diff --git a/modules/utility/yaml.sh b/modules/utility/yaml.sh new file mode 100644 index 0000000..01de122 --- /dev/null +++ b/modules/utility/yaml.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# echo loading yaml module +# https://gist.github.com/pkuczynski/8665367 +# read yaml file, second argument (if any) is added prefix +parse_yaml() { + local prefix=$2 + local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034') + sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \ + -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 | + awk -F$fs '{ + indent = length($1)/2; + vname[indent] = $2; + for (i in vname) {if (i > indent) {delete vname[i]}} + if (length($3) > 0) { + vn=""; for (i=0; i