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

Fix errors coming from linters #61

Merged
merged 19 commits into from
Jan 10, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixup! Refactor oneagent installer to pass ctl args safely
hparzych committed Jan 9, 2025
commit 6961574db243815536838ba3415e0179135e5922
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ repos:
additional_dependencies: [mvdan.cc/sh/v3/cmd/[email protected]]
entry: shfmt
language: golang
exclude: gradlew
exclude: roles/oneagent/tests/resources/installers/Dynatrace-OneAgent-Linux.sh
args:
- "-s"
- "-w"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -eu

# This script acts as a self contained installer of the product
# This script acts as a self contained installer of the procuct

set -e

@@ -9,22 +9,20 @@ readonly INSTALLER_VERSION="##VERSION##"
readonly DEPLOYMENT_CONF_PATH="/var/lib/dynatrace/oneagent/agent/config"

readonly UNINSTALL_SCRIPT="uninstall.sh"
UNINSTALL_CODE="$(
cat <<-ENDUNINSTALL
##UNINSTALL_CODE##
ENDUNINSTALL
UNINSTALL_CODE="$(cat <<-ENDUNINSTALL
##UNINSTALL_CODE##
ENDUNINSTALL
)"
readonly UNINSTALL_CODE

readonly ONEAGENTCTL_BIN="oneagentctl"
ONEAGENTCTL_CODE="$(
cat <<-ENDCTL
##ONEAGENTCTL_CODE##
ENDCTL
ONEAGENTCTL_CODE="$(cat <<-ENDCTL
##ONEAGENTCTL_CODE##
ENDCTL
)"
readonly ONEAGENTCTL_CODE

CTL_PARAMS=()
CTL_PARAMS=
INSTALL_DIR="${DEFAULT_INSTALL_DIR}"

parseParams() {
@@ -36,7 +34,7 @@ parseParams() {
elif [ "${param}" = "INSTALL_PATH" ]; then
INSTALL_DIR="$(printf "%s" "${param}" | cut -d "=" -f "2-")"
elif printf "%s" "${param}" | grep -q -- "--set"; then
CTL_PARAMS+=("${1}")
CTL_PARAMS="${CTL_PARAMS} ${1}"
fi
shift
done
@@ -53,19 +51,20 @@ deployOneagentCtl() {
local ONEAGENTCTL_DIR="${INSTALL_DIR}/agent/tools"
mkdir -p "${ONEAGENTCTL_DIR}"
mkdir -p "${DEPLOYMENT_CONF_PATH}"
printf '%s' "${ONEAGENTCTL_CODE}" >"${ONEAGENTCTL_DIR}/${ONEAGENTCTL_BIN}"
printf '%s' "${ONEAGENTCTL_CODE}" > "${ONEAGENTCTL_DIR}/${ONEAGENTCTL_BIN}"
chmod +x "${ONEAGENTCTL_DIR}/${ONEAGENTCTL_BIN}"
}

deployUninstallScript() {
local UNINSTALL_DIR="${INSTALL_DIR}/agent"
mkdir -p "${UNINSTALL_DIR}"
printf '%s' "${UNINSTALL_CODE}" >"${UNINSTALL_DIR}/${UNINSTALL_SCRIPT}"
printf '%s' "${UNINSTALL_CODE}" > "${UNINSTALL_DIR}/${UNINSTALL_SCRIPT}"
chmod +x "${UNINSTALL_DIR}/${UNINSTALL_SCRIPT}"
}

applyConfig() {
"${INSTALL_DIR}/agent/tools/${ONEAGENTCTL_BIN}" "${CTL_PARAMS[@]}"
# shellcheck disable=SC2086
"${INSTALL_DIR}/agent/tools/${ONEAGENTCTL_BIN}" ${CTL_PARAMS}
}

main() {