From 787dd858b1d3a4e8a1056a3c58b8c18d86d99ca1 Mon Sep 17 00:00:00 2001 From: Nathaniel Landau Date: Mon, 29 Aug 2016 14:58:16 -0400 Subject: [PATCH] updats --- lib/setupScriptFunctions.sh | 0 lib/sharedFunctions.sh | 91 ++++++++++++++++++++++++++++--------- lib/sharedVariables.sh | 0 lib/utils.sh | 0 4 files changed, 70 insertions(+), 21 deletions(-) mode change 100755 => 100644 lib/setupScriptFunctions.sh mode change 100755 => 100644 lib/sharedFunctions.sh mode change 100755 => 100644 lib/sharedVariables.sh mode change 100755 => 100644 lib/utils.sh diff --git a/lib/setupScriptFunctions.sh b/lib/setupScriptFunctions.sh old mode 100755 new mode 100644 diff --git a/lib/sharedFunctions.sh b/lib/sharedFunctions.sh old mode 100755 new mode 100644 index 5c4f693..59e8b9e --- a/lib/sharedFunctions.sh +++ b/lib/sharedFunctions.sh @@ -127,7 +127,7 @@ function pushover() { # join / var local tmp #var/local/tmp # join , "${FOO[@]}" #a,b,c # ---------------------------------------------- -function join { local IFS="${1}"; shift; echo "${*}"; } +function join() { local IFS="${1}"; shift; echo "${*}"; } # File Checks # ------------------------------------------------------ @@ -266,7 +266,7 @@ function is_os() { function seek_confirmation() { # echo "" input "$@" - if [[ "${force}" == "1" ]]; then + if "${force}"; then notice "Forcing confirmation with '--force' flag set" else read -p " (y/n) " -n 1 @@ -276,7 +276,7 @@ function seek_confirmation() { # Test whether the result of an 'ask' is a confirmation function is_confirmed() { - if [[ "${force}" == "1" ]]; then + if "${force}"; then return 0 else if [[ "${REPLY}" =~ ^[Yy]$ ]]; then @@ -287,7 +287,7 @@ function is_confirmed() { } function is_not_confirmed() { - if [[ "${force}" == "1" ]]; then + if "${force}"; then return 1 else if [[ "${REPLY}" =~ ^[Nn]$ ]]; then @@ -568,34 +568,36 @@ urldecode() { parse_yaml() { # Function to parse YAML files and add values to variables. Send it to a temp file and source it + # https://gist.github.com/DinoChiesa/3e3c3866b51290f31243 which is derived from # https://gist.github.com/epiloque/8cf512c6d64641bde388 # # Usage: # $ parse_yaml sample.yml > /some/tempfile # # parse_yaml accepts a prefix argument so that imported settings all have a common prefix - # (which will reduce the risk of namespace collisions). + # (which will reduce the risk of name-space collisions). # # $ parse_yaml sample.yml "CONF_" - local prefix=$2 - local s - local w - local fs - 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]}} + local prefix=$2 + local s + local w + local fs + 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; + if (length($2) == 0) { conj[indent]="+";} else {conj[indent]="";} + vname[indent] = $2; + for (i in vname) {if (i > indent) {delete vname[i]}} if (length($3) > 0) { - vn=""; for (i=0; i> "${csvFile}" + IFS=$saveIFS + +} + +function json2yaml { + # convert json files to yaml using python and PyYAML + python -c 'import sys, yaml, json; yaml.safe_dump(json.load(sys.stdin), sys.stdout, default_flow_style=False)' < "$1" +} + +function yaml2json() { + # convert yaml files to json using python and PyYAML + python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < "$1" } \ No newline at end of file diff --git a/lib/sharedVariables.sh b/lib/sharedVariables.sh old mode 100755 new mode 100644 diff --git a/lib/utils.sh b/lib/utils.sh old mode 100755 new mode 100644