Skip to content

Commit

Permalink
Add quiet flag to allow use in non-interactive shells
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan-M committed Oct 2, 2024
1 parent 9c2517d commit e5847a8
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 46 deletions.
54 changes: 31 additions & 23 deletions scripts/install/install_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,35 @@ MANAGEMENT_YML_PATH="$INSTALL_DIR/manager.yaml"
SCRIPT_NAME="$0"
INDENT_WIDTH=' '
indent=""
non_interactive=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" = "true" ]; 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 Down Expand Up @@ -204,6 +207,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 @@ -673,6 +679,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
64 changes: 41 additions & 23 deletions scripts/install/install_unix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,37 @@ PREREQS="curl printf $SVC_PRE sed uname cut"
SCRIPT_NAME="$0"
INDENT_WIDTH=' '
indent=""
non_interactive=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" = "true" ]; 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 Down Expand Up @@ -223,6 +226,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 @@ -506,6 +512,7 @@ check_prereqs()
banner "Checking Prerequisites"
increase_indent
root_check
proxy_check
os_check
os_arch_check
package_type_check
Expand All @@ -525,6 +532,15 @@ root_check()
fi
}

proxy_check()
{
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
}

# This will check if the operating system is supported.
os_check()
{
Expand Down Expand Up @@ -823,6 +839,8 @@ main()
if [ $# -ge 1 ]; then
while [ -n "$1" ]; do
case "$1" in
-q|--quiet)
non_interactive="true" ; shift 1 ;;
-v|--version)
version=$2 ; shift 2 ;;
-l|--url)
Expand Down

0 comments on commit e5847a8

Please sign in to comment.