#!/bin/bash set -eu -o pipefail # This is a simple shell script edits a database rules config # using a `jq` expression SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" usage() { echo "$0 " exit 1 } edit_db_rules() { "${SCRIPT_DIR}"/edit_db_rules "$@" } declare -a tmps cleanup() { # https://stackoverflow.com/questions/7577052/bash-empty-array-expansion-with-set-u rm -rf ${tmps[@]+"${tmps[@]}"} } trap cleanup EXIT main() { if [ $# -lt 3 ]; then usage fi local host="${1}" local db_name="${2}" local jq_expr="${3}" if ! command -v sponge &> /dev/null; then echo "sponge could not be found; please install moreutils" exit fi local tmp tmp="$(mktemp)" tmps+=("${tmp}") cat >"${tmp}" <