Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(install): Add quiet flag to allow use in non-interactive shells #1895

Open
wants to merge 3 commits into
base: release/v1.62.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 67 additions & 40 deletions scripts/install/install_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,36 @@ MANAGEMENT_YML_PATH="$INSTALL_DIR/manager.yaml"
SCRIPT_NAME="$0"
INDENT_WIDTH=' '
indent=""
non_interactive=false
error_mode=false


# Colors
num_colors=$(tput colors 2>/dev/null)
if test -n "$num_colors" && test "$num_colors" -ge 8; then
bold="$(tput bold)"
underline="$(tput smul)"
# standout can be bold or reversed colors dependent on terminal
standout="$(tput smso)"
reset="$(tput sgr0)"
bg_black="$(tput setab 0)"
bg_blue="$(tput setab 4)"
bg_cyan="$(tput setab 6)"
bg_green="$(tput setab 2)"
bg_magenta="$(tput setab 5)"
bg_red="$(tput setab 1)"
bg_white="$(tput setab 7)"
bg_yellow="$(tput setab 3)"
fg_black="$(tput setaf 0)"
fg_blue="$(tput setaf 4)"
fg_cyan="$(tput setaf 6)"
fg_green="$(tput setaf 2)"
fg_magenta="$(tput setaf 5)"
fg_red="$(tput setaf 1)"
fg_white="$(tput setaf 7)"
fg_yellow="$(tput setaf 3)"
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)"
underline="$(tput smul)"
# standout can be bold or reversed colors dependent on terminal
standout="$(tput smso)"
reset="$(tput sgr0)"
bg_black="$(tput setab 0)"
bg_blue="$(tput setab 4)"
bg_cyan="$(tput setab 6)"
bg_green="$(tput setab 2)"
bg_magenta="$(tput setab 5)"
bg_red="$(tput setab 1)"
bg_white="$(tput setab 7)"
bg_yellow="$(tput setab 3)"
fg_black="$(tput setaf 0)"
fg_blue="$(tput setaf 4)"
fg_cyan="$(tput setaf 6)"
fg_green="$(tput setaf 2)"
fg_magenta="$(tput setaf 5)"
fg_red="$(tput setaf 1)"
fg_white="$(tput setaf 7)"
fg_yellow="$(tput setaf 3)"
fi
fi

if [ -z "$reset" ]; then
Expand All @@ -63,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 @@ -113,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 @@ -131,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 Expand Up @@ -204,6 +214,9 @@ Usage:

This parameter will have the script check access to BindPlane based on the provided '--endpoint'

$(fg_yellow '-q, --quiet')
Use quiet (non-interactive) mode to run the script in headless environments

EOF
)
info "$USAGE"
Expand Down Expand Up @@ -279,6 +292,17 @@ check_prereqs()
decrease_indent
}

# Test non-interactive mode compatibility
interactive_check()
{
# Incompatible with checking the BP url since it can be interactive on failed connection
if [ "$non_interactive" = "true" ] && [ "$check_bp_url" = "true" ]
then
failed
error_exit "$LINENO" "The proxy password must be set via the command line argument -P, if called non-interactively!"
fi
}

# Test connection to BindPlane if it was specified
connection_check()
{
Expand Down Expand Up @@ -673,6 +697,8 @@ main()
if [ $# -ge 1 ]; then
while [ -n "$1" ]; do
case "$1" in
-q|--quiet)
non_interactive="true" ; shift 1 ;;
-l|--url)
url=$2 ; shift 2 ;;
-v|--version)
Expand Down Expand Up @@ -706,6 +732,7 @@ main()
done
fi

interactive_check
connection_check
setup_installation
install_package
Expand Down
114 changes: 74 additions & 40 deletions scripts/install/install_unix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,38 @@ PREREQS="curl printf $SVC_PRE sed uname cut"
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
num_colors=$(tput colors 2>/dev/null)
if test -n "$num_colors" && test "$num_colors" -ge 8; then
bold="$(tput bold)"
underline="$(tput smul)"
# standout can be bold or reversed colors dependent on terminal
standout="$(tput smso)"
reset="$(tput sgr0)"
bg_black="$(tput setab 0)"
bg_blue="$(tput setab 4)"
bg_cyan="$(tput setab 6)"
bg_green="$(tput setab 2)"
bg_magenta="$(tput setab 5)"
bg_red="$(tput setab 1)"
bg_white="$(tput setab 7)"
bg_yellow="$(tput setab 3)"
fg_black="$(tput setaf 0)"
fg_blue="$(tput setaf 4)"
fg_cyan="$(tput setaf 6)"
fg_green="$(tput setaf 2)"
fg_magenta="$(tput setaf 5)"
fg_red="$(tput setaf 1)"
fg_white="$(tput setaf 7)"
fg_yellow="$(tput setaf 3)"
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)"
underline="$(tput smul)"
# standout can be bold or reversed colors dependent on terminal
standout="$(tput smso)"
reset="$(tput sgr0)"
bg_black="$(tput setab 0)"
bg_blue="$(tput setab 4)"
bg_cyan="$(tput setab 6)"
bg_green="$(tput setab 2)"
bg_magenta="$(tput setab 5)"
bg_red="$(tput setab 1)"
bg_white="$(tput setab 7)"
bg_yellow="$(tput setab 3)"
fg_black="$(tput setaf 0)"
fg_blue="$(tput setaf 4)"
fg_cyan="$(tput setaf 6)"
fg_green="$(tput setaf 2)"
fg_magenta="$(tput setaf 5)"
fg_red="$(tput setaf 1)"
fg_white="$(tput setaf 7)"
fg_yellow="$(tput setaf 3)"
fi
fi

if [ -z "$reset" ]; then
Expand All @@ -72,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 @@ -122,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 @@ -140,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 Expand Up @@ -223,6 +233,9 @@ Usage:

This parameter will have the script check access to BindPlane based on the provided '--endpoint'

$(fg_yellow '-q, --quiet')
Use quiet (non-interactive) mode to run the script in headless environments

EOF
)
info "$USAGE"
Expand Down Expand Up @@ -525,6 +538,24 @@ root_check()
fi
}

# Test non-interactive mode compatibility
interactive_check()
{
# Incompatible with proxies unless both username and password are passed
if [ "$non_interactive" = "true" ] && [ -z "$proxy_password" ]
then
failed
error_exit "$LINENO" "The proxy password must be set via the command line argument -P, if called non-interactively!"
fi

# Incompatible with checking the BP url since it can be interactive on failed connection
if [ "$non_interactive" = "true" ] && [ "$check_bp_url" = "true" ]
then
failed
error_exit "$LINENO" "The proxy password must be set via the command line argument -P, if called non-interactively!"
fi
}

# This will check if the operating system is supported.
os_check()
{
Expand Down Expand Up @@ -823,6 +854,8 @@ main()
if [ $# -ge 1 ]; then
while [ -n "$1" ]; do
case "$1" in
-q|--quiet)
Dylan-M marked this conversation as resolved.
Show resolved Hide resolved
non_interactive="true" ; shift 1 ;;
-v|--version)
version=$2 ; shift 2 ;;
-l|--url)
Expand Down Expand Up @@ -864,6 +897,7 @@ main()
done
fi

interactive_check
connection_check
setup_installation
install_package
Expand Down
Loading