diff --git a/scripts/install/install_macos.sh b/scripts/install/install_macos.sh index de185ae21..7886d49f4 100755 --- a/scripts/install/install_macos.sh +++ b/scripts/install/install_macos.sh @@ -23,12 +23,11 @@ DOWNLOAD_BASE="https://github.com/observIQ/bindplane-agent/releases/download" PREREQS="printf sed uname tr find grep" TMP_DIR="${TMPDIR:-"/tmp/"}observiq-otel-collector" # Allow this to be overriden by cannonical TMPDIR env var INSTALL_DIR="/opt/observiq-otel-collector" -MANAGEMENT_YML_PATH="$INSTALL_DIR/manager.yaml" +SUPERVISOR_YML_PATH="$INSTALL_DIR/supervisor-config.yaml" SCRIPT_NAME="$0" INDENT_WIDTH=' ' indent="" - # Colors num_colors=$(tput colors 2>/dev/null) if test -n "$num_colors" && test "$num_colors" -ge 8; then @@ -64,7 +63,7 @@ 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 + 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 @@ -72,36 +71,36 @@ printf() { fi } -increase_indent() { indent="$INDENT_WIDTH$indent" ; } -decrease_indent() { indent="${indent#*"$INDENT_WIDTH"}" ; } +increase_indent() { indent="$INDENT_WIDTH$indent"; } +decrease_indent() { indent="${indent#*"$INDENT_WIDTH"}"; } # Color functions reset only when given an argument -bold() { command printf "$bold$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } -underline() { command printf "$underline$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } -standout() { command printf "$standout$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } +bold() { command printf "$bold$*$(if [ -n "$1" ]; then command printf "$reset"; fi)"; } +underline() { command printf "$underline$*$(if [ -n "$1" ]; then command printf "$reset"; fi)"; } +standout() { command printf "$standout$*$(if [ -n "$1" ]; then command printf "$reset"; fi)"; } # Ignore "parameters are never passed" # shellcheck disable=SC2120 -reset() { command printf "$reset$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } -bg_black() { command printf "$bg_black$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } -bg_blue() { command printf "$bg_blue$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } -bg_cyan() { command printf "$bg_cyan$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } -bg_green() { command printf "$bg_green$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } -bg_magenta() { command printf "$bg_magenta$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } -bg_red() { command printf "$bg_red$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } -bg_white() { command printf "$bg_white$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } -bg_yellow() { command printf "$bg_yellow$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } -fg_black() { command printf "$fg_black$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } -fg_blue() { command printf "$fg_blue$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } -fg_cyan() { command printf "$fg_cyan$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } -fg_green() { command printf "$fg_green$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } -fg_magenta() { command printf "$fg_magenta$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } -fg_red() { command printf "$fg_red$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } -fg_white() { command printf "$fg_white$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } -fg_yellow() { command printf "$fg_yellow$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } +reset() { command printf "$reset$*$(if [ -n "$1" ]; then command printf "$reset"; fi)"; } +bg_black() { command printf "$bg_black$*$(if [ -n "$1" ]; then command printf "$reset"; fi)"; } +bg_blue() { command printf "$bg_blue$*$(if [ -n "$1" ]; then command printf "$reset"; fi)"; } +bg_cyan() { command printf "$bg_cyan$*$(if [ -n "$1" ]; then command printf "$reset"; fi)"; } +bg_green() { command printf "$bg_green$*$(if [ -n "$1" ]; then command printf "$reset"; fi)"; } +bg_magenta() { command printf "$bg_magenta$*$(if [ -n "$1" ]; then command printf "$reset"; fi)"; } +bg_red() { command printf "$bg_red$*$(if [ -n "$1" ]; then command printf "$reset"; fi)"; } +bg_white() { command printf "$bg_white$*$(if [ -n "$1" ]; then command printf "$reset"; fi)"; } +bg_yellow() { command printf "$bg_yellow$*$(if [ -n "$1" ]; then command printf "$reset"; fi)"; } +fg_black() { command printf "$fg_black$*$(if [ -n "$1" ]; then command printf "$reset"; fi)"; } +fg_blue() { command printf "$fg_blue$*$(if [ -n "$1" ]; then command printf "$reset"; fi)"; } +fg_cyan() { command printf "$fg_cyan$*$(if [ -n "$1" ]; then command printf "$reset"; fi)"; } +fg_green() { command printf "$fg_green$*$(if [ -n "$1" ]; then command printf "$reset"; fi)"; } +fg_magenta() { command printf "$fg_magenta$*$(if [ -n "$1" ]; then command printf "$reset"; fi)"; } +fg_red() { command printf "$fg_red$*$(if [ -n "$1" ]; then command printf "$reset"; fi)"; } +fg_white() { command printf "$fg_white$*$(if [ -n "$1" ]; then command printf "$reset"; fi)"; } +fg_yellow() { command printf "$fg_yellow$*$(if [ -n "$1" ]; then command printf "$reset"; fi)"; } # Intentionally using variables in format string # shellcheck disable=SC2059 -info() { printf "$*\\n" ; } +info() { printf "$*\\n"; } # Intentionally using variables in format string # shellcheck disable=SC2059 warn() { @@ -118,7 +117,7 @@ error() { } # Intentionally using variables in format string # shellcheck disable=SC2059 -success() { printf "$fg_green$*$reset\\n" ; } +success() { printf "$fg_green$*$reset\\n"; } # Ignore 'arguments are never passed' # shellcheck disable=SC2120 prompt() { @@ -129,8 +128,7 @@ prompt() { fi } -observiq_banner() -{ +observiq_banner() { fg_cyan " 888 8888888 .d88888b.\\n" fg_cyan " 888 888 d88P\" \"Y88b\\n" fg_cyan " 888 888 888 888\\n" @@ -144,20 +142,19 @@ observiq_banner() reset } -separator() { printf "===================================================\\n" ; } +separator() { printf "===================================================\\n"; } -banner() -{ +banner() { printf "\\n" separator - printf "| %s\\n" "$*" ; + printf "| %s\\n" "$*" separator } -usage() -{ +usage() { increase_indent - USAGE=$(cat <&2 shift 2 @@ -232,16 +230,14 @@ error_exit() force_exit } -print_prereq_line() -{ +print_prereq_line() { if [ -n "$2" ]; then command printf "\\n${indent} - " command printf "[$1]: $2" fi } -check_failure() -{ +check_failure() { if [ "$indent" != '' ]; then increase_indent; fi command printf "${indent}${fg_red}ERROR: %s check failed!${reset}" "$1" @@ -255,21 +251,18 @@ check_failure() force_exit } -succeeded() -{ +succeeded() { increase_indent success "Succeeded!" decrease_indent } -failed() -{ +failed() { error "Failed!" } # This will check all prerequisites before running an installation. -check_prereqs() -{ +check_prereqs() { banner "Checking Prerequisites" increase_indent root_check @@ -280,14 +273,13 @@ check_prereqs() } # Test connection to BindPlane if it was specified -connection_check() -{ - if [ "$check_bp_url" = "true" ] ; then +connection_check() { + if [ "$check_bp_url" = "true" ]; then if [ -n "$opamp_endpoint" ]; then HTTP_ENDPOINT="$(echo "${opamp_endpoint}" | sed 's#^ws#http#' | sed 's#/v1/opamp$##')" info "Testing connection to BindPlane: $fg_magenta$HTTP_ENDPOINT$reset..." - if curl --max-time 20 -s "${HTTP_ENDPOINT}" > /dev/null; then + if curl --max-time 20 -s "${HTTP_ENDPOINT}" >/dev/null; then succeeded else failed @@ -309,27 +301,24 @@ connection_check() } # This will check if the operating system is supported. -os_check() -{ +os_check() { info "Checking that the operating system is supported..." os_type=$(uname -s) case "$os_type" in - Darwin) - succeeded - ;; - *) - failed - error_exit "$LINENO" "The operating system $(fg_yellow "$os_type") is not supported by this script." - ;; + Darwin) + succeeded + ;; + *) + failed + error_exit "$LINENO" "The operating system $(fg_yellow "$os_type") is not supported by this script." + ;; esac } # This checks to see if the user who is running the script has root permissions. -root_check() -{ +root_check() { system_user_name=$(id -un) - if [ "${system_user_name}" != 'root' ] - then + if [ "${system_user_name}" != 'root' ]; then failed error_exit "$LINENO" "Script needs to be run as root or with sudo" fi @@ -337,8 +326,7 @@ root_check() # This will check if the current environment has # all required shell dependencies to run the installation. -dependencies_check() -{ +dependencies_check() { info "Checking for script dependencies..." FAILED_PREREQS='' for prerequisite in $PREREQS; do @@ -362,13 +350,19 @@ dependencies_check() # This will set all installation variables # at the beginning of the script. -setup_installation() -{ +setup_installation() { banner "Configuring Installation Variables" increase_indent set_os_arch - set_download_urls + + if [ -z "$package_path" ]; then + set_download_urls + out_file_path="$TMP_DIR/observiq-otel-collector.tar.gz" + else + out_file_path="$package_path" + fi + set_opamp_endpoint set_opamp_labels set_opamp_secret_key @@ -377,44 +371,42 @@ setup_installation() decrease_indent } -set_os_arch() -{ +set_os_arch() { os_arch=$(uname -m) - case "$os_arch" in - # arm64 strings. These are from https://stackoverflow.com/questions/45125516/possible-values-for-uname-m - aarch64|arm64|aarch64_be|armv8b|armv8l) - os_arch="arm64" - ;; - x86_64) - os_arch="amd64" - ;; - *) - # We only support arm64/amd64 architectures for macOS - error_exit "$LINENO" "Unsupported os arch: $os_arch" - ;; + case "$os_arch" in + # arm64 strings. These are from https://stackoverflow.com/questions/45125516/possible-values-for-uname-m + aarch64 | arm64 | aarch64_be | armv8b | armv8l) + os_arch="arm64" + ;; + x86_64) + os_arch="amd64" + ;; + *) + # We only support arm64/amd64 architectures for macOS + error_exit "$LINENO" "Unsupported os arch: $os_arch" + ;; esac } # This will set the urls to use when downloading the agent and its plugins. # These urls are constructed based on the --version flag or COLLECTOR_VERSION env variable. # If not specified, the version defaults to whatever the latest release on github is. -set_download_urls() -{ - if [ -z "$url" ] ; then - if [ -z "$version" ] ; then +set_download_urls() { + if [ -z "$url" ]; then + if [ -z "$version" ]; then # shellcheck disable=SC2153 version=$COLLECTOR_VERSION fi - if [ -z "$version" ] ; then + if [ -z "$version" ]; then version=$(latest_version) fi - if [ -z "$version" ] ; then + if [ -z "$version" ]; then error_exit "$LINENO" "Could not determine version to install" fi - if [ -z "$base_url" ] ; then + if [ -z "$base_url" ]; then base_url=$DOWNLOAD_BASE fi @@ -424,18 +416,16 @@ set_download_urls() fi } -set_opamp_endpoint() -{ - if [ -z "$opamp_endpoint" ] ; then +set_opamp_endpoint() { + if [ -z "$opamp_endpoint" ]; then opamp_endpoint="$ENDPOINT" fi OPAMP_ENDPOINT="$opamp_endpoint" } -set_opamp_labels() -{ - if [ -z "$opamp_labels" ] ; then +set_opamp_labels() { + if [ -z "$opamp_labels" ]; then opamp_labels=$LABELS fi @@ -446,9 +436,8 @@ set_opamp_labels() fi } -set_opamp_secret_key() -{ - if [ -z "$opamp_secret_key" ] ; then +set_opamp_secret_key() { + if [ -z "$opamp_secret_key" ]; then opamp_secret_key=$SECRET_KEY fi @@ -460,31 +449,31 @@ set_opamp_secret_key() } # latest_version gets the tag of the latest release, without the v prefix. -latest_version() -{ - curl -sSL -H"Accept: application/vnd.github.v3+json" https://api.github.com/repos/observIQ/bindplane-agent/releases/latest | \ - grep "\"tag_name\"" | \ +latest_version() { + curl -sSL -H"Accept: application/vnd.github.v3+json" https://api.github.com/repos/observIQ/bindplane-agent/releases/latest | + grep "\"tag_name\"" | sed -E 's/ *"tag_name": "v([0-9]+\.[0-9]+\.[0-9+])",/\1/' } # This will install the package by downloading & unpacking the tarball into the install directory -install_package() -{ +install_package() { banner "Installing BindPlane Agent" - increase_indent + increase_indent # Remove temporary directory, if it exists rm -rf "$TMP_DIR" mkdir -p "$TMP_DIR/artifacts" # Download into tmp dir - info "Downloading tarball into temporary directory..." - curl -L "$collector_download_url" -o "$TMP_DIR/observiq-otel-collector.tar.gz" --progress-bar --fail || error_exit "$LINENO" "Failed to download package" - succeeded + if [ -z "$package_path" ]; then + info "Downloading tarball into temporary directory..." + curl -L "$collector_download_url" -o "$out_file_path" --progress-bar --fail || error_exit "$LINENO" "Failed to download package" + succeeded + fi # unpack info "Unpacking tarball..." - tar -xzf "$TMP_DIR/observiq-otel-collector.tar.gz" -C "$TMP_DIR/artifacts" || error_exit "$LINENO" "Failed to unack archive $TMP_DIR/observiq-otel-collector.tar.gz" + tar -xzf "$out_file_path" -C "$TMP_DIR/artifacts" || error_exit "$LINENO" "Failed to unpack archive $out_file_path" succeeded mkdir -p "$INSTALL_DIR" || error_exit "$LINENO" "Failed to create directory $INSTALL_DIR" @@ -492,12 +481,14 @@ install_package() info "Creating install directory structure..." increase_indent # Find all directorys in the unpackaged tar - DIRS=$(cd "$TMP_DIR/artifacts"; find "." -type d) - for d in $DIRS - do + DIRS=$( + cd "$TMP_DIR/artifacts" + find "." -type d + ) + for d in $DIRS; do mkdir -p "$INSTALL_DIR/$d" || error_exit "$LINENO" "Failed to create directory $INSTALL_DIR/$d" done - + # Create the storage dir; This dir is necessary for filelog based plugins mkdir -p "$INSTALL_DIR/storage" || error_exit "$LINENO" "Failed to create directory $INSTALL_DIR/storage" @@ -507,33 +498,28 @@ install_package() info "Copying artifacts to install directory..." increase_indent - # This find command gets a list of all artifacts paths except config.yaml, logging.yaml, or opentelemetry-java-contrib-jmx-metrics.jar - FILES=$(cd "$TMP_DIR/artifacts"; find "." -type f -not \( -name config.yaml -or -name logging.yaml -or -name opentelemetry-java-contrib-jmx-metrics.jar \)) + # This find command gets a list of all artifacts paths except logging.yaml, or opentelemetry-java-contrib-jmx-metrics.jar + FILES=$( + cd "$TMP_DIR/artifacts" + find "." -type f -not \( -name logging.yaml -or -name opentelemetry-java-contrib-jmx-metrics.jar \) + ) # Move files to install dir - for f in $FILES - do + for f in $FILES; do rm -rf "$INSTALL_DIR/${f:?}" cp "$TMP_DIR/artifacts/${f:?}" "$INSTALL_DIR/${f:?}" || error_exit "$LINENO" "Failed to copy artifact $f to install dir" done decrease_indent succeeded - if [ ! -f "$INSTALL_DIR/config.yaml" ]; then - info "Copying default config.yaml..." - cp "$TMP_DIR/artifacts/config.yaml" "$INSTALL_DIR/config.yaml" || error_exit "$LINENO" "Failed to copy default config.yaml to install dir" - chmod 0600 "$INSTALL_DIR/config.yaml" || error_exit "$LINENO" "Failed to change permissions of config.yaml" - succeeded - fi - if [ ! -f "$INSTALL_DIR/logging.yaml" ]; then info "Copying default logging.yaml..." cp "$TMP_DIR/artifacts/logging.yaml" "$INSTALL_DIR/logging.yaml" || error_exit "$LINENO" "Failed to copy default logging.yaml to install dir" succeeded fi - # If an endpoint was specified, we need to write the manager.yaml + # If an endpoint was specified, we need to write the supervisor-config.yaml if [ -n "$OPAMP_ENDPOINT" ]; then - create_manager_yml "$MANAGEMENT_YML_PATH" + create_supervisor_config "$SUPERVISOR_YML_PATH" fi # Install jmx jar @@ -544,14 +530,14 @@ install_package() if [ -f "/Library/LaunchDaemons/$SERVICE_NAME.plist" ]; then # Existing service file, we should stop & unload first. info "Uninstalling existing service file..." - launchctl unload -w "/Library/LaunchDaemons/$SERVICE_NAME.plist" > /dev/null 2>&1 || error_exit "$LINENO" "Failed to unload service file /Library/LaunchDaemons/$SERVICE_NAME.plist" + launchctl unload -w "/Library/LaunchDaemons/$SERVICE_NAME.plist" >/dev/null 2>&1 || error_exit "$LINENO" "Failed to unload service file /Library/LaunchDaemons/$SERVICE_NAME.plist" succeeded fi # Install service file info "Installing service file..." - sed "s|\\[INSTALLDIR\\]|${INSTALL_DIR}/|g" "$INSTALL_DIR/install/$SERVICE_NAME.plist" | tee "/Library/LaunchDaemons/$SERVICE_NAME.plist" > /dev/null 2>&1 || error_exit "$LINENO" "Failed to install service file" - launchctl load -w "/Library/LaunchDaemons/$SERVICE_NAME.plist" > /dev/null 2>&1 || error_exit "$LINENO" "Failed to load service file /Library/LaunchDaemons/$SERVICE_NAME.plist" + sed "s|\\[INSTALLDIR\\]|${INSTALL_DIR}/|g" "$INSTALL_DIR/install/$SERVICE_NAME.plist" | tee "/Library/LaunchDaemons/$SERVICE_NAME.plist" >/dev/null 2>&1 || error_exit "$LINENO" "Failed to install service file" + launchctl load -w "/Library/LaunchDaemons/$SERVICE_NAME.plist" >/dev/null 2>&1 || error_exit "$LINENO" "Failed to load service file /Library/LaunchDaemons/$SERVICE_NAME.plist" succeeded info "Starting service..." @@ -566,54 +552,65 @@ install_package() decrease_indent } -# create_manager_yml creates the manager.yml at the specified path, containing opamp information. -create_manager_yml() -{ - manager_yml_path="$1" - if [ ! -f "$manager_yml_path" ]; then - info "Creating manager yaml..." - - # Note here: We create the file and change permissions of the file here BEFORE writing info to it - # We do this because the file may contain a secret key, so we want 0 window when the - # file is readable by anyone other than root - command printf '' >> "$manager_yml_path" - chmod 0600 "$manager_yml_path" - - command printf 'endpoint: "%s"\n' "$OPAMP_ENDPOINT" > "$manager_yml_path" - [ -n "$OPAMP_LABELS" ] && command printf 'labels: "%s"\n' "$OPAMP_LABELS" >> "$manager_yml_path" - [ -n "$OPAMP_SECRET_KEY" ] && command printf 'secret_key: "%s"\n' "$OPAMP_SECRET_KEY" >> "$manager_yml_path" +create_supervisor_config() { + supervisor_yml_path="$1" + if [ ! -f "$supervisor_yml_path" ]; then + info "Creating supervisor config..." + + # Note here: We create the file and change permissions of the file here BEFORE writing info to it. + # We do this because the file contains the secret key. + # We do not want the file readable by anyone other than root. + command printf '' >>"$supervisor_yml_path" + chmod 0600 "$supervisor_yml_path" + + command printf 'server:\n' >"$supervisor_yml_path" + command printf ' endpoint: "%s"\n' "$OPAMP_ENDPOINT" >>"$supervisor_yml_path" + command printf ' headers:\n' >>"$supervisor_yml_path" + [ -n "$OPAMP_SECRET_KEY" ] && command printf ' Authorization: "Secret-Key %s"\n' "$OPAMP_SECRET_KEY" >>"$supervisor_yml_path" + # [ -n "$OPAMP_LABELS" ] && command printf ' X-Bindplane-Attribute: "%s"\n' "$OPAMP_LABELS" >> "$supervisor_yml_path" + command printf ' tls:\n' >>"$supervisor_yml_path" + command printf ' insecure: true\n' >>"$supervisor_yml_path" + command printf ' insecure_skip_verify: true\n' >>"$supervisor_yml_path" + command printf 'capabilities:\n' >>"$supervisor_yml_path" + command printf ' accepts_remote_config: true\n' >>"$supervisor_yml_path" + command printf ' reports_remote_config: true\n' >>"$supervisor_yml_path" + command printf 'agent:\n' >>"$supervisor_yml_path" + # TODO(dakota): Add logging config option when supervisor suppports it + command printf ' executable: "%s"\n' "$INSTALL_DIR/observiq-otel-collector" >>"$supervisor_yml_path" + command printf ' description:\n' >>"$supervisor_yml_path" + command printf ' non_identifying_attributes:\n' >>"$supervisor_yml_path" + [ -n "$OPAMP_LABELS" ] && command printf ' service.labels: "%s"\n' "$OPAMP_LABELS" >>"$supervisor_yml_path" + command printf 'storage:\n' >>"$supervisor_yml_path" + command printf ' directory: "%s"\n' "$INSTALL_DIR/supervisor_storage" >>"$supervisor_yml_path" succeeded fi } - # This will display the results of an installation -display_results() -{ - banner 'Information' - increase_indent - info "Agent Home: $(fg_cyan "$INSTALL_DIR")$(reset)" - info "Agent Config: $(fg_cyan "$INSTALL_DIR/config.yaml")$(reset)" - info "Start Command: $(fg_cyan "sudo launchctl load /Library/LaunchDaemons/$SERVICE_NAME.plist")$(reset)" - info "Stop Command: $(fg_cyan "sudo launchctl unload /Library/LaunchDaemons/$SERVICE_NAME.plist")$(reset)" - info "Logs Command: $(fg_cyan "sudo tail -F $INSTALL_DIR/log/collector.log")$(reset)" - decrease_indent +display_results() { + banner 'Information' + increase_indent + info "Agent Home: $(fg_cyan "$INSTALL_DIR")$(reset)" + info "Agent Config: $(fg_cyan "$INSTALL_DIR/supervisor_storage/effective.yaml")$(reset)" + info "Agent Logs Command: $(fg_cyan "sudo tail -F $INSTALL_DIR/supervisor_storage/agent.log")$(reset)" + info "Supervisor Start Command: $(fg_cyan "sudo launchctl load /Library/LaunchDaemons/$SERVICE_NAME.plist")$(reset)" + info "Supervisor Stop Command: $(fg_cyan "sudo launchctl unload /Library/LaunchDaemons/$SERVICE_NAME.plist")$(reset)" + decrease_indent - banner 'Support' - increase_indent - info "For more information on configuring the agent, see the docs:" - increase_indent - info "$(fg_cyan "https://github.com/observIQ/bindplane-agent/tree/main#bindplane-agent")$(reset)" - decrease_indent - info "If you have any other questions please contact us at $(fg_cyan support@observiq.com)$(reset)" - decrease_indent + banner 'Support' + increase_indent + info "For more information on configuring the agent, see the docs:" + increase_indent + info "$(fg_cyan "https://github.com/observIQ/bindplane-agent/tree/main#bindplane-agent")$(reset)" + decrease_indent + info "If you have any other questions please contact us at $(fg_cyan support@observiq.com)$(reset)" + decrease_indent - banner "$(fg_green Installation Complete!)" - return 0 + banner "$(fg_green Installation Complete!)" + return 0 } -uninstall() -{ +uninstall() { banner "Uninstalling BindPlane Agent" increase_indent @@ -631,22 +628,9 @@ uninstall() rm -f "/Library/LaunchDaemons/$SERVICE_NAME.plist" || error_exit "$LINENO" "Failed to remove service file /Library/LaunchDaemons/$SERVICE_NAME.plist" succeeded - info "Backing up config.yaml to config.bak.yaml" - cp "$INSTALL_DIR/config.yaml" "$INSTALL_DIR/config.bak.yaml" || error_exit "$LINENO" "Failed to backup config.yaml to config.bak.yaml" - succeeded - - # Removes the whole install directory, including configs. + # Removes the whole install directory info "Removing installed artifacts..." - # This find command gets a list of all artifacts paths except config.yaml or the root directory. - FILES=$(cd "$INSTALL_DIR"; find "." -not \( -name config.bak.yaml -or -name "." \)) - for f in $FILES - do - rm -rf "${INSTALL_DIR:?}/$f" || error_exit "$LINENO" "Failed to remove artifact ${INSTALL_DIR:?}/$f" - done - - # Copy the old config to a backup. This is similar to how RPM handles this. - # This way, the file is recoverable if the uninstall was somehow accidental, - # but if a new install occurs, the default config will still be used. + rm -rf /opt/observiq-otel-collector || error_exit "$LINENO" "Failed to remove /opt/observiq-otel-collector" succeeded info "Removing any existing log files" @@ -661,8 +645,7 @@ uninstall() banner "$(fg_green Uninstallation Complete!)" } -main() -{ +main() { # We do these checks before we process arguments, because # some of these options bail early, and we'd like to be sure that those commands # (e.g. uninstall) can run @@ -673,30 +656,50 @@ main() if [ $# -ge 1 ]; then while [ -n "$1" ]; do case "$1" in - -l|--url) - url=$2 ; shift 2 ;; - -v|--version) - version=$2 ; shift 2 ;; - -r|--uninstall) - uninstall - exit 0 - ;; - -h|--help) - usage - exit 0 - ;; - -e|--endpoint) - opamp_endpoint=$2 ; shift 2 ;; - -k|--labels) - opamp_labels=$2 ; shift 2 ;; - -s|--secret-key) - opamp_secret_key=$2 ; shift 2 ;; - -c|--check-bp-url) - check_bp_url="true" ; shift 1 ;; - -b|--base-url) - base_url=$2 ; shift 2 ;; + -l | --url) + url=$2 + shift 2 + ;; + -v | --version) + version=$2 + shift 2 + ;; + -f | --file) + package_path=$2 + shift 2 + ;; + -r | --uninstall) + uninstall + exit 0 + ;; + -h | --help) + usage + exit 0 + ;; + -e | --endpoint) + opamp_endpoint=$2 + shift 2 + ;; + -k | --labels) + opamp_labels=$2 + shift 2 + ;; + -s | --secret-key) + opamp_secret_key=$2 + shift 2 + ;; + -c | --check-bp-url) + check_bp_url="true" + shift 1 + ;; + -b | --base-url) + base_url=$2 + shift 2 + ;; --) - shift; break ;; + shift + break + ;; *) error "Invalid argument: $1" usage diff --git a/service/com.observiq.collector.plist b/service/com.observiq.collector.plist index 8dd47803a..edf19c793 100644 --- a/service/com.observiq.collector.plist +++ b/service/com.observiq.collector.plist @@ -13,13 +13,9 @@ ProgramArguments - [INSTALLDIR]observiq-otel-collector + [INSTALLDIR]opampsupervisor --config - [INSTALLDIR]config.yaml - --logging - [INSTALLDIR]logging.yaml - --manager - [INSTALLDIR]manager.yaml + [INSTALLDIR]supervisor-config.yaml RunAtLoad