Skip to content

Commit

Permalink
fix(install-script): support fips package
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Kolberg <[email protected]>
  • Loading branch information
amdprophet committed Nov 27, 2024
1 parent a00bbd2 commit 09f4042
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 54 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.log
tmp/
build/
*.swp

# WiX toolset
*.msi
Expand Down
125 changes: 71 additions & 54 deletions install-script/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -574,34 +574,40 @@ function upgrade() {
}

function upgrade_command_linux() {
local package_name
readonly package_name="${1}"

if [[ -z "${VERSION}" ]]; then
case $(get_package_manager) in
yum | dnf)
echo "yum update otelcol-sumo --quiet -y"
echo "yum update ${package_name} --quiet -y"
;;
apt-get)
echo "apt-get update --quiet && apt-get install otelcol-sumo --quiet -y --only-upgrade"
echo "apt-get update --quiet && apt-get install ${package_name} --quiet -y --only-upgrade"
;;
esac
else
case $(get_package_manager) in
yum | dnf)
echo "yum update \"otelcol-sumo-${VERSION}\" --quiet -y"
echo "yum update \"${package_name}-${VERSION}\" --quiet -y"
;;
apt-get)
echo "apt-get update --quiet && apt-get install \"otelcol-sumo=${VERSION}\" --quiet -y --only-upgrade"
echo "apt-get update --quiet && apt-get install \"${package_name}=${VERSION}\" --quiet -y --only-upgrade"
;;
esac
fi
}

function upgrade_linux() {
local package_name
readonly package_name="${1}"

if [[ -z "${VERSION}" ]]; then
echo "Upgrading to the latest version of otelcol-sumo"
echo "Upgrading to the latest version of ${package_name}"
else
echo "Upgrading to otelcol-sumo version ${VERSION}"
echo "Upgrading to ${package_name} version ${VERSION}"
fi
eval "$(upgrade_command_linux)"
eval "$(upgrade_command_linux "${package_name}")"
}

# uninstall otelcol-sumo on darwin
Expand Down Expand Up @@ -910,10 +916,16 @@ function install_linux_package() {
}

function show_upgrade_instructions_linux() {
echo "Upgrades can be performed using the native package manager: $(upgrade_command_linux)"
local package_name
readonly package_name="${1}"

echo "Upgrades can be performed using the native package manager: $(upgrade_command_linux "${package_name}")"
}

function check_deprecated_linux_flags() {
local package_name
readonly package_name="${1}"

if [[ -n "${BINARY_BRANCH}" ]]; then
echo "warning: --binary-branch is deprecated"
exit 1
Expand All @@ -929,19 +941,22 @@ function check_deprecated_linux_flags() {

if [[ -n "${DOWNLOAD_ONLY}" ]]; then
echo "--download-only is only supported on darwin"
show_upgrade_instructions_linux "${VERSION}"
show_upgrade_instructions_linux "${package_name}"
exit 1
fi
}

function is_package_installed() {
local package_name
readonly package_name="${1}"

case $(get_package_manager) in
yum | dnf)
# TODO: refine exact command
yum --cacheonly list --installed otelcol-sumo > /dev/null 2>&1
yum --cacheonly list --installed "${package_name}" > /dev/null 2>&1
;;
apt-get)
status="$(dpkg-query -Wf '${db:Status-Status}' otelcol-sumo)"
status="$(dpkg-query -Wf '${db:Status-Status}' "${package_name}")"
if [[ $? != 0 || "${status}" != "installed" ]]; then
false
else
Expand All @@ -955,7 +970,7 @@ function is_package_installed() {
# kind of installation that was performed by downloading artifacts from Github,
# before we moved to using distribution packages.
function has_prepackaging_installation() {
if command -v otelcol-sumo > /dev/null 2>&1 && ! is_package_installed; then
if command -v otelcol-sumo > /dev/null 2>&1 && ! is_package_installed otelcol-sumo && ! is_package_installed otelcol-sumo-fips; then
true
else
false
Expand Down Expand Up @@ -992,37 +1007,6 @@ function uninstall_prepackaging_installation() {
groupdel "${SYSTEM_USER}" 2>/dev/null || true
}

############################ Main code

OS_TYPE="$(get_os_type)"
ARCH_TYPE="$(get_arch_type)"
readonly OS_TYPE ARCH_TYPE

echo -e "Detected OS type:\t${OS_TYPE}"
echo -e "Detected architecture:\t${ARCH_TYPE}"

set_defaults
parse_options "$@"
set_tmpdir
check_dependencies
check_deprecated_linux_flags

readonly SUMOLOGIC_INSTALLATION_TOKEN API_BASE_URL OPAMP_API_URL FIELDS CONTINUE CONFIG_DIRECTORY UNINSTALL
readonly USER_ENV_DIRECTORY CONFIG_DIRECTORY COMMON_CONFIG_PATH
readonly INSTALL_HOSTMETRICS
readonly REMOTELY_MANAGED
readonly CURL_MAX_TIME
readonly LAUNCHD_CONFIG LAUNCHD_ENV_KEY LAUNCHD_TOKEN_KEY

if [[ "${UNINSTALL}" == "true" ]]; then
uninstall
exit 0
fi
if [[ "${UPGRADE}" == "true" ]]; then
upgrade
exit 0
fi

# get_installation_token returns the value of SUMOLOGIC_INSTALLATION_TOKEN
# (set by a flag or environment variable) when it is not empty, otherwise it
# will attempt to fetch the token from an existing installation and return it.
Expand Down Expand Up @@ -1069,6 +1053,47 @@ function get_user_token() {
echo "${token}"
}


############################ Main code

OS_TYPE="$(get_os_type)"
ARCH_TYPE="$(get_arch_type)"
readonly OS_TYPE ARCH_TYPE

echo -e "Detected OS type:\t${OS_TYPE}"
echo -e "Detected architecture:\t${ARCH_TYPE}"

set_defaults
parse_options "$@"
set_tmpdir

package_name=""
if [[ "${FIPS}" == "true" ]]; then
echo "Getting FIPS-compliant binary"
package_name=otelcol-sumo-fips
else
package_name=otelcol-sumo
fi

check_dependencies
check_deprecated_linux_flags "${package_name}"

readonly SUMOLOGIC_INSTALLATION_TOKEN API_BASE_URL OPAMP_API_URL FIELDS CONTINUE CONFIG_DIRECTORY UNINSTALL
readonly USER_ENV_DIRECTORY CONFIG_DIRECTORY COMMON_CONFIG_PATH
readonly INSTALL_HOSTMETRICS
readonly REMOTELY_MANAGED
readonly CURL_MAX_TIME
readonly LAUNCHD_CONFIG LAUNCHD_ENV_KEY LAUNCHD_TOKEN_KEY

if [[ "${UNINSTALL}" == "true" ]]; then
uninstall
exit 0
fi
if [[ "${UPGRADE}" == "true" ]]; then
upgrade
exit 0
fi

# Load & cache user token
USER_TOKEN="$(get_user_token)"

Expand Down Expand Up @@ -1196,14 +1221,6 @@ if [[ "${OS_TYPE}" == "darwin" ]]; then
exit 0
fi

package_name=""
if [[ "${FIPS}" == "true" ]]; then
echo "Getting FIPS-compliant binary"
package_name=otelcol-sumo-fips
else
package_name=otelcol-sumo
fi

if has_prepackaging_installation; then
# Display a warning and information message here?
echo 'Pre-packaging installation detected'
Expand All @@ -1221,9 +1238,9 @@ fi

echo "Version specified: ${VERSION}"

if is_package_installed; then
echo "The otelcol-sumo package is already installed"
show_upgrade_instructions_linux
if is_package_installed "${package_name}"; then
echo "The ${package_name} package is already installed"
show_upgrade_instructions_linux "${package_name}"
exit 1
fi

Expand Down

0 comments on commit 09f4042

Please sign in to comment.