Skip to content

Commit

Permalink
Make scripts more quiet (allow errors to bubble up) and fix conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan-M committed Oct 7, 2024
1 parent fb046f2 commit 9bdc523
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 36 deletions.
43 changes: 25 additions & 18 deletions scripts/install/install_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ SCRIPT_NAME="$0"
INDENT_WIDTH=' '
indent=""
non_interactive=false
error_mode=false


# Colors
if [ "$non_interactive" = "true" ]; then
if [ "$non_interactive" = "false" ]; then
num_colors=$(tput colors 2>/dev/null)
if test -n "$num_colors" && test "$num_colors" -ge 8; then
bold="$(tput bold)"
Expand Down Expand Up @@ -66,12 +67,14 @@ fi

# Helper Functions
printf() {
if command -v sed >/dev/null; then
command printf -- "$@" | sed -E "$sed_ignore s/^/$indent/g" # Ignore sole reset characters if defined
else
# Ignore $* suggestion as this breaks the output
# shellcheck disable=SC2145
command printf -- "$indent$@"
if [ "$non_interactive" = "false" ] || [ "$error_mode" = "true" ]; then
if command -v sed >/dev/null; then
command printf -- "$@" | sed -E "$sed_ignore s/^/$indent/g" # Ignore sole reset characters if defined
else
# Ignore $* suggestion as this breaks the output
# shellcheck disable=SC2145
command printf -- "$indent$@"
fi
fi
}

Expand Down Expand Up @@ -116,7 +119,9 @@ warn() {
# shellcheck disable=SC2059
error() {
increase_indent
error_mode=true
printf "$fg_red$*$reset\\n"
error_mode=false
decrease_indent
}
# Intentionally using variables in format string
Expand All @@ -134,17 +139,19 @@ prompt() {

observiq_banner()
{
fg_cyan " 888 8888888 .d88888b.\\n"
fg_cyan " 888 888 d88P\" \"Y88b\\n"
fg_cyan " 888 888 888 888\\n"
fg_cyan " .d88b. 88888b. .d8888b .d88b. 888d888 888 888 888 888 888\\n"
fg_cyan " d88\"\"88b 888 \"88b 88K d8P Y8b 888P\" 888 888 888 888 888\\n"
fg_cyan " 888 888 888 888 \"Y8888b. 88888888 888 Y88 88P 888 888 Y8b 888\\n"
fg_cyan " Y88..88P 888 d88P X88 Y8b. 888 Y8bd8P 888 Y88b.Y8b88P\\n"
fg_cyan " \"Y88P\" 88888P\" 88888P' \"Y8888 888 Y88P 8888888 \"Y888888\"\\n"
fg_cyan " Y8b \\n"

reset
if [ "$non_interactive" = "false" ]; then
fg_cyan " 888 8888888 .d88888b.\\n"
fg_cyan " 888 888 d88P\" \"Y88b\\n"
fg_cyan " 888 888 888 888\\n"
fg_cyan " .d88b. 88888b. .d8888b .d88b. 888d888 888 888 888 888 888\\n"
fg_cyan " d88\"\"88b 888 \"88b 88K d8P Y8b 888P\" 888 888 888 888 888\\n"
fg_cyan " 888 888 888 888 \"Y8888b. 88888888 888 Y88 88P 888 888 Y8b 888\\n"
fg_cyan " Y88..88P 888 d88P X88 Y8b. 888 Y8bd8P 888 Y88b.Y8b88P\\n"
fg_cyan " \"Y88P\" 88888P\" 88888P' \"Y8888 888 Y88P 8888888 \"Y888888\"\\n"
fg_cyan " Y8b \\n"

reset
fi
}

separator() { printf "===================================================\\n" ; }
Expand Down
43 changes: 25 additions & 18 deletions scripts/install/install_unix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ SCRIPT_NAME="$0"
INDENT_WIDTH=' '
indent=""
non_interactive=false
error_mode=false

# out_file_path is the full path to the downloaded package (e.g. "/tmp/observiq-otel-collector_linux_amd64.deb")
out_file_path="unknown"

# Colors
if [ "$non_interactive" = "true" ]; then
if [ "$non_interactive" = "false" ]; then
num_colors=$(tput colors 2>/dev/null)
if test -n "$num_colors" && test "$num_colors" -ge 8; then
bold="$(tput bold)"
Expand Down Expand Up @@ -75,12 +76,14 @@ fi

# Helper Functions
printf() {
if command -v sed >/dev/null; then
command printf -- "$@" | sed -r "$sed_ignore s/^/$indent/g" # Ignore sole reset characters if defined
else
# Ignore $* suggestion as this breaks the output
# shellcheck disable=SC2145
command printf -- "$indent$@"
if [ "$non_interactive" = "false" ] || [ "$error_mode" = "true" ]; then
if command -v sed >/dev/null; then
command printf -- "$@" | sed -r "$sed_ignore s/^/$indent/g" # Ignore sole reset characters if defined
else
# Ignore $* suggestion as this breaks the output
# shellcheck disable=SC2145
command printf -- "$indent$@"
fi
fi
}

Expand Down Expand Up @@ -125,7 +128,9 @@ warn() {
# shellcheck disable=SC2059
error() {
increase_indent
error_mode=true
printf "$fg_red$*$reset\\n"
error_mode=false
decrease_indent
}
# Intentionally using variables in format string
Expand All @@ -143,17 +148,19 @@ prompt() {

observiq_banner()
{
fg_cyan " 888 8888888 .d88888b.\\n"
fg_cyan " 888 888 d88P\" \"Y88b\\n"
fg_cyan " 888 888 888 888\\n"
fg_cyan " .d88b. 88888b. .d8888b .d88b. 888d888 888 888 888 888 888\\n"
fg_cyan " d88\"\"88b 888 \"88b 88K d8P Y8b 888P\" 888 888 888 888 888\\n"
fg_cyan " 888 888 888 888 \"Y8888b. 88888888 888 Y88 88P 888 888 Y8b 888\\n"
fg_cyan " Y88..88P 888 d88P X88 Y8b. 888 Y8bd8P 888 Y88b.Y8b88P\\n"
fg_cyan " \"Y88P\" 88888P\" 88888P' \"Y8888 888 Y88P 8888888 \"Y888888\"\\n"
fg_cyan " Y8b \\n"

reset
if [ "$non_interactive" = "false" ]; then
fg_cyan " 888 8888888 .d88888b.\\n"
fg_cyan " 888 888 d88P\" \"Y88b\\n"
fg_cyan " 888 888 888 888\\n"
fg_cyan " .d88b. 88888b. .d8888b .d88b. 888d888 888 888 888 888 888\\n"
fg_cyan " d88\"\"88b 888 \"88b 88K d8P Y8b 888P\" 888 888 888 888 888\\n"
fg_cyan " 888 888 888 888 \"Y8888b. 88888888 888 Y88 88P 888 888 Y8b 888\\n"
fg_cyan " Y88..88P 888 d88P X88 Y8b. 888 Y8bd8P 888 Y88b.Y8b88P\\n"
fg_cyan " \"Y88P\" 88888P\" 88888P' \"Y8888 888 Y88P 8888888 \"Y888888\"\\n"
fg_cyan " Y8b \\n"

reset
fi
}

separator() { printf "===================================================\\n" ; }
Expand Down

0 comments on commit 9bdc523

Please sign in to comment.