This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var_empty(){ | |
# var_empty "_varname" | |
# var_empty "_array[index]" | |
# var_empty "_dict[key]" | |
# Returns 0 if a variable is set to an empty string | |
[[ -z ${!1-unset} ]] && return 0 || return 1 | |
} | |
var_gettype(){ | |
# var_gettype "_varname" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
explode(){ | |
# explode <delimiter> <string> <array_name_to_be_referenced> | |
# Splits string by delimiter and fills input array where each value is each string that was deparated | |
# Works on arrays and dicts. Will overwrite if the array is not empty... | |
[ "$#" -ne "3" ] && return 1 | |
[[ "$(declare -p -- "${3}" 2>/dev/null)" != "declare -a "* ]] && [[ "$(declare -p -- "${3}" 2>/dev/null)" != "declare -A "* ]] && return 1 | |
local -n _arr="$3" | |
OLDIFS=$IFS | |
IFS=$1 read -ra _arr <<< "$2" | |
IFS=$OLDIFS; unset OLDIFS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Most functions use direct referencing for dict compatibility and key referencing when indexes/keys may not be in a sequential numeric order. | |
# inarray is the only function that you expand the entire array as an argument i.e. "${_arr[@]}" | |
array_empty(){ | |
# array_empty "_arrayname" | |
# uses direct reference | |
# Returns 0 if an array is empty. Returns 1 otherwise | |
# Works on arrays and dicts | |
[[ "$#" -ne "1" ]] && return 1 | |
[[ "${!1@a}" != [aA] ]] && return 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Call `setup_ssh_socket` to setup the control socket (function will return once | |
# the socket is ready to go), and `ssh_target` will connect using the control socket. | |
# Assumes TARGET_HOST variable is set. | |
# The connection is automatically closed when the script exists. | |
# TARGET_HOST="wolever.net" | |
# setup_ssh_control_socket | |
# ssh_target "hostname" | |
debug() { | |
echo "DEBUG: $*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
nodes="-nodes" | |
if [[ "$1" == "-des" ]]; then | |
nodes="" | |
shift | |
fi | |
if [[ ! "$1" || ! "$2" || "$1" =~ "^-" ]]; then |