From 6b7ef000a02d2fc446064aa789a522f209518337 Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Tue, 17 Nov 2020 16:40:59 -0500 Subject: [PATCH] clean up script base --- bin/bubble_common | 56 +++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/bin/bubble_common b/bin/bubble_common index 16407b34..1171cd54 100755 --- a/bin/bubble_common +++ b/bin/bubble_common @@ -2,8 +2,8 @@ # # Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/ # -function die { - if [[ -z "${SCRIPT}" ]] ; then +function die() { + if [[ -z "${SCRIPT}" ]]; then echo 1>&2 "${1}" else echo 1>&2 "${SCRIPT}: ${1}" @@ -11,60 +11,64 @@ function die { exit 1 } -function handle_help_request () { +function handle_help_request() { - if [[ -z "${2}" ]] ; then + if [[ -z "${2}" ]]; then return fi - if [[ ${2} == "-h" || ${2} == "--help" ]] ; then + if [[ ${2} == "-h" || ${2} == "--help" ]]; then while IFS='' read -r line || [[ -n "$line" ]]; do - if [[ ${line} =~ ^#.* ]] ; then - if [[ ! ${line} =~ ^#!/bin/bash.* ]] ; then + if [[ ${line} =~ ^#.* ]]; then + if [[ ! ${line} =~ ^#!/bin/bash.* ]]; then echo "${line}" fi else break fi - done < "${1}" + done <"${1}" exit 1 fi } -function make_temp () { +function make_temp() { prefix="${1}" suffix="${2}" echo "$(mktemp ${prefix}.${suffix}.XXXXXXXX)" } -function make_temp_dir () { +function make_temp_dir() { prefix="${1}" suffix="${2}" echo "$(mktemp -d ${prefix}.${suffix}.XXXXXXXX)" } -function quote_args () { - args="" - for i in "$@"; do - if [[ "$i" =~ \ |\' ]] ; then - i="${i//\\/\\\\}" - args="$args \"${i//\"/\\\"}\"" - else - args="$args ${i}" - fi - done - echo -n ${args} +function quote_args() { + args="" + for i in "$@"; do + if [[ "$i" =~ \ |\' ]]; then + i="${i//\\/\\\\}" + args="$args \"${i//\"/\\\"}\"" + else + args="$args ${i}" + fi + done + echo -n ${args} } -handle_help_request ${0} ${1} +handle_help_request "${0}" "${1}" # Ensure we can find run.sh if [[ -z "${BUBBLE_SCRIPTS}" ]] ; then - RUN_SH="$(find $(cd $(dirname ${0}) && pwd) -type f -name "run.sh" | head -1)" + BC_DIR="$(cd "$(dirname "${0}")" && pwd)" + RUN_SH="$(find "${BC_DIR}" -type f -name "run.sh" | head -1)" if [[ -z "${RUN_SH}" ]] ; then RUN_SH="$(find . -type f -name "run.sh" | head -1)" fi + if [[ -z "${RUN_SH}" ]] ; then + RUN_SH="$(find ${BC_DIR}/../../bubble -type f -name "run.sh" | head -1)" + fi if [[ -z "${RUN_SH}" ]] ; then die "run.sh script not found. Set BUBBLE_SCRIPTS to be the directory containing run.sh" fi @@ -107,7 +111,7 @@ if [[ -z "${BUBBLE_JAR}" ]] ; then elif [[ -f "${BUBBLE_SCRIPTS}/../bubble.jar" ]] ; then BUBBLE_JAR="${BUBBLE_SCRIPTS}/../bubble.jar" else - BUBBLE_JAR="$(find ${BUBBLE_SCRIPTS}/../bubble-server/target -type f -name "bubble*.jar" | head -1)" + BUBBLE_JAR="$(find "${BUBBLE_SCRIPTS}/../bubble-server/target" -type f -name "bubble*.jar" | head -1)" fi fi if [[ -z "${BUBBLE_JAR}" ]] ; then @@ -115,8 +119,8 @@ if [[ -z "${BUBBLE_JAR}" ]] ; then fi # Check to see if we are on the PATH, if not suggest that we could be -BUBBLE_BIN="$(cd $(dirname ${0}) && pwd)" -if [[ -z "${BUBBLE_SKIP_PATH_WARNING}" && -z "$(which $(basename ${0}))" ]] ; then +BUBBLE_BIN="$(cd "$(dirname "${0}")" && pwd)" +if [[ -z "${BUBBLE_SKIP_PATH_WARNING}" && -z "$(which "$(basename "${0}")")" ]] ; then echo 1>&2 "Note: ${BUBBLE_BIN} is not on your PATH. To make things easier, add it to your PATH:" echo 1>&2 "" echo 1>&2 "export PATH=\${PATH}:${BUBBLE_BIN}"