From 7d763782944ed7d9dc5d15ea99ccd03676c0be1f Mon Sep 17 00:00:00 2001 From: Dakota Paasman <122491662+dpaasman00@users.noreply.github.com> Date: Thu, 29 Aug 2024 09:23:59 -0400 Subject: [PATCH] feat: Add clean install option to scripts (#1819) * unix script clean install * macos script clean install * add force clean install option * add force dirty install (update) option --- scripts/install/install_macos.sh | 108 ++++++++++++++++++++++--------- scripts/install/install_unix.sh | 103 +++++++++++++++++++++-------- 2 files changed, 155 insertions(+), 56 deletions(-) diff --git a/scripts/install/install_macos.sh b/scripts/install/install_macos.sh index 2fab97da8..45f17f945 100755 --- a/scripts/install/install_macos.sh +++ b/scripts/install/install_macos.sh @@ -204,6 +204,12 @@ Usage: This parameter will have the script check access to BindPlane based on the provided '--endpoint' + $(fg_yellow '-i, --clean-install') + Do a clean install of the agent regardless of if a supervisor.yaml config file is already present. + + $(fg_yellow '-u --dirty-install') + Do a dirty install by not generating a supervisor.yaml. Useful when one already exists and treats the install as an update. + EOF ) info "$USAGE" @@ -367,6 +373,8 @@ setup_installation() { set_opamp_labels set_opamp_secret_key + ask_clean_install + success "Configuration complete!" decrease_indent } @@ -448,6 +456,36 @@ set_opamp_secret_key() { fi } +# If an existing supervisor.yaml is present, ask whether we should do a clean install. +# Want to avoid inadvertanly overwriting endpoint or secret_key values. +ask_clean_install() { + if [ "$clean_install" = "true" ] || [ "$clean_install" = "false" ]; then + # install type already set, so just return + return + fi + + if [ -f "$SUPERVISOR_YML_PATH" ]; then + command printf "${indent}An installation already exists. Would you like to do a clean install? $(prompt n)" + read -r clean_install_response + clean_install_response=$(echo "$clean_install_response" | tr '[:upper:]' '[:lower:]') + case $clean_install_response in + y | yes) + increase_indent + success "Doing clean install!" + decrease_indent + clean_install="true" + ;; + *) + warn "Doing upgrade instead of clean install" + clean_install="false" + ;; + esac + else + warn "Previous supervisor config not found, doing clean install" + clean_install="true" + fi +} + # 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 | @@ -548,36 +586,40 @@ install_package() { 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 + + # Return if we're not doing a clean install + if [ "$clean_install" = "false" ]; then + return fi + + 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 } # This will display the results of an installation @@ -690,6 +732,14 @@ main() { base_url=$2 shift 2 ;; + -i | --clean-install) + clean_install="true" + shift 1 + ;; + -u | --dirty-install) + clean_install="false" + shift 1 + ;; --) shift break diff --git a/scripts/install/install_unix.sh b/scripts/install/install_unix.sh index f5e4c790c..04feac536 100755 --- a/scripts/install/install_unix.sh +++ b/scripts/install/install_unix.sh @@ -221,6 +221,12 @@ Usage: This parameter will have the script check access to BindPlane based on the provided '--endpoint' + $(fg_yellow '-i, --clean-install') + Do a clean install of the agent regardless of if a supervisor.yaml config file is already present. + + $(fg_yellow '-u --dirty-install') + Do a dirty install by not generating a supervisor.yaml. Useful when one already exists and treats the install as an update. + EOF ) info "$USAGE" @@ -300,6 +306,8 @@ setup_installation() { set_opamp_labels set_opamp_secret_key + ask_clean_install + success "Configuration complete!" decrease_indent } @@ -454,6 +462,36 @@ set_opamp_secret_key() { fi } +# If an existing supervisor.yaml is present, ask whether we should do a clean install. +# Want to avoid inadvertanly overwriting endpoint or secret_key values. +ask_clean_install() { + if [ "$clean_install" = "true" ] || [ "$clean_install" = "false" ]; then + # install type already set, so just return + return + fi + + if [ -f "$SUPERVISOR_YML_PATH" ]; then + command printf "${indent}An installation already exists. Would you like to do a clean install? $(prompt n)" + read -r clean_install_response + clean_install_response=$(echo "$clean_install_response" | tr '[:upper:]' '[:lower:]') + case $clean_install_response in + y | yes) + increase_indent + success "Doing clean install!" + decrease_indent + clean_install="true" + ;; + *) + warn "Doing upgrade instead of clean install" + clean_install="false" + ;; + esac + else + warn "Previous supervisor config not found, doing clean install" + clean_install="true" + fi +} + # Test connection to BindPlane if it was specified connection_check() { if [ -n "$check_bp_url" ]; then @@ -558,7 +596,7 @@ dependencies_check() { succeeded } -# This will check to ensure either dpkg or rpm is installedon the system +# This will check to ensure either dpkg or rpm is installed on the system package_type_check() { info "Checking for package manager..." if command -v dpkg >/dev/null 2>&1; then @@ -674,33 +712,36 @@ unpack_package() { # create_supervisor_config creates the supervisor.yml at the specified path, containing opamp information. create_supervisor_config() { supervisor_yml_path="$1" - if [ ! -f "$supervisor_yml_path" ]; then - - # 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/obseriq-otel-collector. - command printf '' >>"$supervisor_yml_path" - chown observiq-otel-collector:observiq-otel-collector "$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" - 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" - 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" + + # Return if we're not doing a clean install + if [ "$clean_install" = "false" ]; then + return fi + + # 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/obseriq-otel-collector. + command printf '' >>"$supervisor_yml_path" + chown observiq-otel-collector:observiq-otel-collector "$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" + 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" + 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" } # This will display the results of an installation @@ -793,6 +834,14 @@ main() { usage exit 0 ;; + -i | --clean-install) + clean_install="true" + shift 1 + ;; + -u | --dirty-install) + clean_install="false" + shift 1 + ;; --) shift break