Skip to content

Commit

Permalink
feat: Add clean install option to scripts (observIQ#1819)
Browse files Browse the repository at this point in the history
* unix script clean install

* macos script clean install

* add force clean install option

* add force dirty install (update) option
  • Loading branch information
dpaasman00 authored Aug 29, 2024
1 parent e62087d commit 7d76378
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 56 deletions.
108 changes: 79 additions & 29 deletions scripts/install/install_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -367,6 +373,8 @@ setup_installation() {
set_opamp_labels
set_opamp_secret_key

ask_clean_install

success "Configuration complete!"
decrease_indent
}
Expand Down Expand Up @@ -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 |
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
103 changes: 76 additions & 27 deletions scripts/install/install_unix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -300,6 +306,8 @@ setup_installation() {
set_opamp_labels
set_opamp_secret_key

ask_clean_install

success "Configuration complete!"
decrease_indent
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7d76378

Please sign in to comment.