From: Kruti Pendharkar Date: Tue, 18 Feb 2025 09:13:56 +0000 (-0800) Subject: [componentMgr] salt-minion - update integration script to version 2024.12.05 X-Git-Tag: stable-13.1.0~228 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b29e809bed8be4f3a5e207589674f122f7907c80;p=thirdparty%2Fopen-vm-tools.git [componentMgr] salt-minion - update integration script to version 2024.12.05 svtminion: New release (2024.12.05) of the salt-minion integration script. o Supports the new repository locations at packages.broadcom.com. o Only supports Salt 3006 and higher with new Broadcom infrastructure. o New return code 107 (Installed but Stopped); used when the service is installed but stopped. Added to help with customer case where the service remains 'not running' due to user action. NOTE: Fixed line 31 apostrophe being an unicode homoglyph in svtminion.ps1 validated the downloaded files sha256 before that change. componentMgr: Update component manager to support the new return code 107. return code: 107 string id: INSTALLEDSTOPPED string message: Installed but Stopped. --- diff --git a/open-vm-tools/services/plugins/componentMgr/componentMgrInstallAction.c b/open-vm-tools/services/plugins/componentMgr/componentMgrInstallAction.c index ff8588844..e051f41a4 100644 --- a/open-vm-tools/services/plugins/componentMgr/componentMgrInstallAction.c +++ b/open-vm-tools/services/plugins/componentMgr/componentMgrInstallAction.c @@ -1,5 +1,6 @@ /********************************************************* - * Copyright (c) 2021-2023 VMware, Inc. All rights reserved. + * Copyright (c) 2021-2024 Broadcom. All Rights Reserved. + * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -16,6 +17,7 @@ * *********************************************************/ + /* * componentMgrInstallAction.c -- * @@ -736,7 +738,8 @@ ComponentMgr_ExecuteComponentAction(int componentIndex) // IN } else if((Str_Strcmp(action, COMPONENTMGR_COMPONENTABSENT) == 0) && (components[componentIndex].status == INSTALLED || components[componentIndex].status == INSTALLFAILED || - components[componentIndex].status == REMOVEFAILED)) { + components[componentIndex].status == REMOVEFAILED || + components[componentIndex].status == INSTALLEDSTOPPED)) { installaction = ABSENT; } else { g_debug("%s: Action %s will not be executed for component %s with " @@ -1031,7 +1034,7 @@ ComponentMgrCheckExecuteComponentAction(ToolsAppCtx *ctx, // IN * Add the component to the guest only if it is NOTINSTALLED, * INSTALLFAILED or REMOVEFAILED. * Remove the component on the guest only if it is INSTALLED, - * INSTALLFAILED or REMOVEFAILED. + * INSTALLFAILED, REMOVEFAILED or INSTALLEDSTOPPED. */ if((Str_Strcmp(action, COMPONENTMGR_COMPONENTPRESENT) == 0) && (components[componentIndex].status == NOTINSTALLED || @@ -1041,7 +1044,8 @@ ComponentMgrCheckExecuteComponentAction(ToolsAppCtx *ctx, // IN } else if((Str_Strcmp(action, COMPONENTMGR_COMPONENTABSENT) == 0) && (components[componentIndex].status == INSTALLED || components[componentIndex].status == INSTALLFAILED || - components[componentIndex].status == REMOVEFAILED)) { + components[componentIndex].status == REMOVEFAILED || + components[componentIndex].status == INSTALLEDSTOPPED)) { installaction = ABSENT; } else { components[componentIndex].statuscount -= 1; diff --git a/open-vm-tools/services/plugins/componentMgr/componentMgrPlugin.h b/open-vm-tools/services/plugins/componentMgr/componentMgrPlugin.h index 2454ef450..0d5551bc7 100644 --- a/open-vm-tools/services/plugins/componentMgr/componentMgrPlugin.h +++ b/open-vm-tools/services/plugins/componentMgr/componentMgrPlugin.h @@ -1,5 +1,6 @@ /********************************************************* - * Copyright (c) 2021,2023 VMware, Inc. All rights reserved. + * Copyright (c) 2021-2024 Broadcom. All Rights Reserved. + * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -202,6 +203,9 @@ typedef enum InstallStatus * is not managed (or manageable), through the * component manager plugin. */ + INSTALLEDSTOPPED, /* The component is installed on the guest OS; but + * is stopped. + */ SCRIPTFAILED = 126, /* The component script failed for some reason. */ SCRIPTTERMINATED = 130 /* The component script terminated for some reason. */ diff --git a/open-vm-tools/services/plugins/componentMgr/componentMgrUtil.c b/open-vm-tools/services/plugins/componentMgr/componentMgrUtil.c index 0828cb5c5..c291ace21 100644 --- a/open-vm-tools/services/plugins/componentMgr/componentMgrUtil.c +++ b/open-vm-tools/services/plugins/componentMgr/componentMgrUtil.c @@ -1,5 +1,6 @@ /********************************************************* - * Copyright (c) 2021,2023 VMware, Inc. All rights reserved. + * Copyright (c) 2021-2024 Broadcom. All Rights Reserved. + * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -116,6 +117,7 @@ ComponentMgr_GetComponentInstallStatus(InstallStatus installStatus) // IN case INSTALLFAILED: return "INSTALLFAILED"; case REMOVEFAILED: return "REMOVEFAILED"; case UNMANAGED: return "UNMANAGED"; + case INSTALLEDSTOPPED: return "INSTALLEDSTOPPED"; case SCRIPTFAILED: return "SCRIPTFAILED"; case SCRIPTTERMINATED: return "SCRIPTTERMINATED"; } diff --git a/open-vm-tools/services/plugins/componentMgr/svtminion.sh b/open-vm-tools/services/plugins/componentMgr/svtminion.sh index 7c99a04a4..e0b6bf4fc 100644 --- a/open-vm-tools/services/plugins/componentMgr/svtminion.sh +++ b/open-vm-tools/services/plugins/componentMgr/svtminion.sh @@ -1,6 +1,6 @@ -#!/usr/bin/env bash +#!/bin/bash -# Copyright 2021-2023 VMware, Inc. +# Copyright 2021-2024 Broadcom Inc. # SPDX-License-Identifier: Apache-2 ## Salt VMware Tools Integration script @@ -19,23 +19,23 @@ set -o pipefail # using bash for now # run this script as root, as needed to run Salt -## readonly SCRIPT_VERSION='SCRIPT_VERSION_REPLACE' -readonly SCRIPT_VERSION="1.6" +readonly SCRIPT_VERSION="2024.12.05" # definitions -CURL_DOWNLOAD_RETRY_COUNT=5 - ## Repository locations and naming readonly default_salt_url_version="latest" -readonly salt_name="salt" -readonly repo_json_file="repo.json" salt_url_version="${default_salt_url_version}" -pre_3006_base_url="https://repo.saltproject.io/salt/vmware-tools-onedir" -# Release -post_3005_base_url="https://repo.saltproject.io/salt/py3/onedir" +salt_specific_version="" + +readonly salt_name="salt" base_url="" +# Broadcom infrastructure +bd_3006_base_url="https://packages.broadcom.com/artifactory/saltproject-generic/onedir" +bd_3006_chksum_base_url="https://packages.broadcom.com/artifactory/api/storage/saltproject-generic/onedir" + + # Salt file and directory locations readonly base_salt_location="/opt/saltstack" readonly salt_dir="${base_salt_location}/${salt_name}" @@ -62,15 +62,17 @@ ${list_files_systemd_to_remove} " ## /var/log/vmware-${SCRIPTNAME}-* +# some docker containers don't include 'find' - RHEL 8 equivalents readonly salt_dep_file_list="systemctl curl -sha512sum +sha256sum vmtoolsd grep awk sed cut wget +find " readonly allowed_log_file_action_names="status @@ -78,6 +80,7 @@ depend install clear remove +reconfig default " @@ -86,7 +89,7 @@ call " readonly salt_minion_service_wrapper=\ -"# Copyright 2021-2023 VMware, Inc. +"# Copyright 2021-2024 VMware, Inc. # SPDX-License-Identifier: Apache-2 [Unit] @@ -138,13 +141,14 @@ declare -a m_cfg_values ## Component Manager Installer/Script return/exit status codes # return/exit Status codes -# 100 + 0 => installed +# 100 + 0 => installed (and running) # 100 + 1 => installing # 100 + 2 => notInstalled # 100 + 3 => installFailed # 100 + 4 => removing # 100 + 5 => removeFailed # 100 + 6 => externalInstall +# 100 + 7 => installedStopped # 126 => scriptFailed # 130 => scriptTerminated declare -A STATUS_CODES_ARY @@ -155,6 +159,7 @@ STATUS_CODES_ARY[installFailed]=103 STATUS_CODES_ARY[removing]=104 STATUS_CODES_ARY[removeFailed]=105 STATUS_CODES_ARY[externalInstall]=106 +STATUS_CODES_ARY[installedStopped]=107 STATUS_CODES_ARY[scriptFailed]=126 STATUS_CODES_ARY[scriptTerminated]=130 @@ -184,6 +189,13 @@ INSTALL_PARAMS="" MINION_VERSION_FLAG=0 MINION_VERSION_PARAMS="" +RECONFIG_FLAG=0 +RECONFIG_PARAMS="" + +STOP_FLAG=0 +RESTART_FLAG=0 +UPGRADE_FLAG=0 + LOG_LEVEL_FLAG=0 LOG_LEVEL_PARAMS="" @@ -193,10 +205,6 @@ LOG_LEVEL=${LOG_LEVELS_ARY[warning]} SOURCE_FLAG=0 SOURCE_PARAMS="" -# Flag for pre_3006 and post_3005, 0 => pre_3006, 1 => post_3005 -POST_3005_FLAG=0 -POST_3005_MAJOR_VER_FLAG=0 - # helper functions @@ -209,6 +217,7 @@ _log() { "${log_dir}/vmware-${SCRIPTNAME}-${LOG_ACTION}-${logdate}.log" } +# shellcheck disable=SC2329 _display() { if [[ ${VERBOSE_FLAG} -eq 1 ]]; then echo "$1"; fi _log "$*" @@ -248,6 +257,7 @@ _debug_log() { fi } +# shellcheck disable=SC2329 _yesno() { read -r -p "Continue (y/n)?" choice case "$choice" in @@ -269,7 +279,9 @@ esac echo "usage: ${0}" echo " [-c|--clear] [-d|--depend] [-h|--help] [-i|--install]" echo " [-j|--source] [-l|--loglevel] [-m|--minionversion]" - echo " [-r|--remove] [-s|--status] [-v|--version]" + echo " [-n|--reconfig] [-q|--stop] [-p|--start]" + echo " [-r|--remove] [-s|--status] [-u|--upgrade]" + echo " [-v|--version]" echo "" echo " -c, --clear clear previous minion identifier and keys," echo " and set specified identifier if present" @@ -290,8 +302,12 @@ esac echo " silent error warning debug info" echo " default loglevel is warning" echo " -m, --minionversion install salt-minion version, default[latest]" + echo " -n, --reconfig salt-minion restarts after reading updated config" + echo " -q, --stop stop salt-minion" + echo " -p, --start start salt-minion (restarts salt-minion)" echo " -r, --remove deactivate and remove the salt-minion" echo " -s, --status return status for this script" + echo " -u, --upgrade upgrade when installing, used with --install" echo " -v, --version version of this script" echo "" echo " salt-minion VMTools integration script" @@ -310,6 +326,7 @@ esac # Results: # Exits with hard-coded value 130 # +# shellcheck disable=SC2329 _cleanup_int() { rm -rf "$WORK_DIR" @@ -323,6 +340,7 @@ _cleanup_int() { # # Cleanups any running process and areas on exit # +# shellcheck disable=SC2329 _cleanup_exit() { rm -rf "$WORK_DIR" _debug_log "$0:${FUNCNAME[0]} Deleted temp working directory $WORK_DIR" @@ -382,6 +400,94 @@ _set_log_level() { } + +# +# _get_desired_salt_version_fn +# +# Get the appropriate desirted salt version based on salt_url_version, +# latest or specified input Salt version, 3007, 3006, 3006.x, 3007.1 +# and set salt_specific_version accordinly +# +# Note: typically Salt version includes the release number in addition to +# version number or 'latest' for the most recent release +# +# for example: currently major version 3006 implies 3006.9 +# the latest version of Salt 3006.x +# +# if an unsupported version is input, for example: 3004.2 +# it will default to installing the latest version +# +# Input: +# directory contains directory list of current available +# Salt versions, 3006.x - 3007.1 +# +# Results: +# Returns with exit code +# +_get_desired_salt_version_fn() { + + if [[ "$#" -ne 1 ]]; then + _error_log "$0:${FUNCNAME[0]} error expected one parameter "\ + "specifying the location for directories containing versions Salt" + fi + + _info_log "$0:${FUNCNAME[0]} processing getting desired Salt version "\ + "'$salt_url_version' for salt-minion to install, input directory $1" + + generic_versions_tmpdir="$1" + curr_pwd=$(pwd) + cd ${generic_versions_tmpdir} || return 1 + + # something werid is happening with tail, that does not fail in test + # programs getting failures inside tail hence use bash loop + if [ "$salt_url_version" = "latest" ]; then + # shellcheck disable=SC2010,SC2012 + ## _GENERIC_PKG_VERSION=$(ls ./. | grep -v 'index.html' | sort -V -u | tail -n 1) + test_dir=$(ls ./. | grep -v 'index.html' | sort -V -u) + for idx in $test_dir + do + _GENERIC_PKG_VERSION="$idx" + done + _debug_log "$0:${FUNCNAME[0]} latest found version '${_GENERIC_PKG_VERSION}'" + + elif [ "$(echo "$salt_url_version" | grep -E '^(3006|3007)$')" != "" ]; then + # want major latest version of Salt + # shellcheck disable=SC2010,SC2012 + ## _GENERIC_PKG_VERSION=$(ls ./. | grep -v 'index.html' | sort -V -u | grep -E "$salt_url_version" | tail -n 1) + test_dir=$(ls ./. | grep -v 'index.html' | sort -V -u | grep -E "$salt_url_version") + for idx in $test_dir + do + _GENERIC_PKG_VERSION="$idx" + done + _debug_log "$0:${FUNCNAME[0]} input $salt_url_version found "\ + "version '${_GENERIC_PKG_VERSION}'" + + elif [ "$(echo "$salt_url_version" | grep -E '^([3-9][0-5]{2}[6-9](\.[0-9]*)?)')" != "" ]; then + # Minor version Salt, want specific minor version + # if old style VMTools version 3004.2-1 is used + # defaults to else and install latest + _GENERIC_PKG_VERSION="$salt_url_version" + else + # default to latest version Salt + # shellcheck disable=SC2010,SC2012 + ## _GENERIC_PKG_VERSION=$(ls ./. | grep -v 'index.html' | sort -V -u | tail -n 1) + test_dir=$(ls ./. | grep -v 'index.html' | sort -V -u) + for idx in $test_dir + do + _GENERIC_PKG_VERSION="$idx" + done + _debug_log "$0:${FUNCNAME[0]} default found version '${_GENERIC_PKG_VERSION}'" + + fi + cd ${curr_pwd} || return 1 + + # set specific version of Salt to use + salt_specific_version="${_GENERIC_PKG_VERSION}" + + return 0 +} + + # # _set_install_minion_version_fn # @@ -391,9 +497,11 @@ _set_log_level() { # Note: typically Salt version includes the release number in addition to # version number or 'latest' for the most recent release # -# for example: 3003.3-1 +# for example: 3006.8 # # Results: +# Sets salt_url_version to latest or specified input +# Salt version, 3007, 3006, 3006.x # Returns with exit code # @@ -410,6 +518,7 @@ _set_install_minion_version_fn() { salt_version=$(echo "$1" | cut -d ' ' -f 1) if [[ "latest" = "${salt_version}" ]]; then + # salt_url_version already set to default_salt_url_version _debug_log "$0:${FUNCNAME[0]} input Salt version for salt-minion to "\ "install is 'latest', leaving as default "\ "'${default_salt_url_version}' for now" @@ -426,54 +535,6 @@ _set_install_minion_version_fn() { return 0 } -# -# _set_post_3005_flags_from_version -# -# Sets the POST_3005_FLAG and POST_3005_MAJOR_VER_FLAG -# from the version currently present in salt_url_version -# -# Will also set base_url if not already defined by --source option -# -# Results: -# Returns with exit code -# -_set_post_3005_flags_from_version() { - _info_log "$0:${FUNCNAME[0]} setting POST_3005_FLAG and "\ - "POST_3005_MAJOR_VER_FLAG from Salt version '${salt_url_version}'" - - if [[ "latest" = "${salt_url_version}" ]]; then - POST_3005_FLAG=1 - POST_3005_MAJOR_VER_FLAG=1 - base_url="${post_3005_base_url}" - # done, already have url for latest & major versions - _debug_log "$0:${FUNCNAME[0]} post-3005 install, using latest "\ - "base_url '${base_url}'" - else - ver_chk=$(echo "${salt_url_version}" | cut -d '.' -f 1) - if [[ ${ver_chk} -ge 3006 ]]; then - POST_3005_FLAG=1 - ver_chk_major=$(echo "${salt_url_version}" | cut -d '.' -f 1) - ver_chk_minor=$(echo "${salt_url_version}" | cut -d '.' -f 2) - _debug_log "$0:${FUNCNAME[0]} post-3005 install, checking "\ - "for major version only '${ver_chk_major}', minor "\ - "'${ver_chk_minor}'" - if [[ "${ver_chk_major}" = "${ver_chk_minor}" ]]; then - POST_3005_MAJOR_VER_FLAG=1 - base_url="${post_3005_base_url}" - else - base_url="${post_3005_base_url}/minor" - fi - _debug_log "$0:${FUNCNAME[0]} post-3005 install, for "\ - "'${salt_url_version}' using base_url '${base_url}'" - else - # install pre-3006, use older url - base_url="${pre_3006_base_url}" - _debug_log "$0:${FUNCNAME[0]} pre-3006 install, for "\ - "'${salt_url_version}' using base_url '${base_url}'" - fi - fi -} - # # _update_minion_conf_ary @@ -629,9 +690,9 @@ _fetch_vmtools_salt_minion_conf_guestvars() { cfg_key=$(echo "${idx}" | cut -d '=' -f 1) cfg_value=$(echo "${idx}" | cut -d '=' -f 2) _update_minion_conf_ary "${cfg_key}" "${cfg_value}" || { - _error_log "$0:${FUNCNAME[0]} error updating minion configuration "\ - "array with key '${cfg_key}' and value '${cfg_value}', "\ - "retcode '$?'"; + _error_log "$0:${FUNCNAME[0]} error updating minion "\ + "configuration array with key '${cfg_key}' and value "\ + "'${cfg_value}', retcode '$?'"; } done @@ -766,7 +827,7 @@ _fetch_vmtools_salt_minion_conf() { "configuration parameters for master public signed key" echo "${m_cfg_keys[${chk_idx}]}: True" \ >> "${salt_minion_conf_file}" - mkdir -p "/etc/salt/pki/minion" + mkdir -p "${salt_conf_dir}/pki/minion" cp -f "${m_cfg_values[${chk_idx}]}" \ "${salt_master_sign_dir}/" else @@ -782,196 +843,14 @@ _fetch_vmtools_salt_minion_conf() { } -# -# _curl_download -# -# Retrieve file from specified url to specific file -# -# Results: -# Exits with 0 or error code -# - -_curl_download() { - local file_name="$1" - local file_url="$2" - local download_retry_failed=1 # assume issues - local _retn=0 - - _info_log "$0:${FUNCNAME[0]} attempting download of file '${file_name}'" - - for ((i=0; i/dev/null - cp -a "${salt_url}/${salt_name}"*_SHA512 . - _retn=$? - if [[ ${_retn} -ne 0 ]]; then - CURRENT_STATUS=${STATUS_CODES_ARY[installFailed]} - _error_log "$0:${FUNCNAME[0]} failed to find file "\ - "sha512 in specified location ${salt_url}, "\ - "error '${_retn}'" - fi + salt_pkg_name="${salt_name}-${salt_specific_version}-onedir-linux-${sys_arch}.tar.xz" + salt_url="${base_url}/${salt_specific_version}/${salt_pkg_name}" - ## shellcheck - salt_chksum_file=$(ls "${salt_name}"*_SHA512) - salt_pkg_name=$(ls "${salt_name}"*-linux-amd64.tar.gz 2>/dev/null) - if [[ -z "${salt_pkg_name}" ]]; then - # failed to find pre-3006 linux tarball, - # attempt to find post-3005 with appro. arch - sys_arch="${MACHINE_ARCH}" - salt_chksum_file=$(ls "${salt_name}"*-linux-"${sys_arch}".tar.xz.sha512) - salt_pkg_name=$(ls "${salt_name}"*-linux-"${sys_arch}".tar.xz) - fi - _debug_log "$0:${FUNCNAME[0]} successfully copied tarball from "\ - "'${salt_url}' file '${salt_pkg_name}'" - _debug_log "$0:${FUNCNAME[0]} successfully coped checksum from "\ - "'${salt_url}' file '${salt_chksum_file}'" - calc_sha512sum=$(grep "${salt_pkg_name}" \ - "${salt_chksum_file}" | sha512sum --check --status) - if [[ ${calc_sha512sum} -ne 0 ]]; then - CURRENT_STATUS=${STATUS_CODES_ARY[installFailed]} - _error_log "$0:${FUNCNAME[0]} downloaded file "\ - "'${salt_pkg_name}' failed to match checksum in file "\ - "'${salt_chksum_file}'" - fi + # assume http://, https:// or similar + wget -q -r -l1 -nd -np -A "${salt_pkg_name}" "${salt_url}" + _retn=$? + if [[ ${_retn} -ne 0 ]]; then + CURRENT_STATUS=${STATUS_CODES_ARY[installFailed]} + _error_log "$0:${FUNCNAME[0]} downloaded file "\ + "'${salt_pkg_name}' failed to download, error '${_retn}'" fi - else - # assume use curl for local or remote URI - _curl_download "${repo_json_file}" "${base_url}/${repo_json_file}" - _debug_log "$0:${FUNCNAME[0]} successfully downloaded from "\ - "'${base_url}/${repo_json_file}' into file '${repo_json_file}'" - - if [[ -f "${repo_json_file}" ]]; then - # use latest from repo.json file, (version:name:sha512) - json_version_name_sha=$(_parse_json_specd_ver "${repo_json_file}") - salt_json_version=$(\ - echo "${json_version_name_sha}" | awk -F":" '{print $1}') - salt_json_name=$(\ - echo "${json_version_name_sha}" | awk -F":" '{print $2}') - salt_json_sha512=$(\ - echo "${json_version_name_sha}" | awk -F":" '{print $3}') - _debug_log "$0:${FUNCNAME[0]} using repo.json values version "\ - "'${salt_json_version}', name '${salt_json_name}, sha512 "\ - "'${salt_json_sha512}'"/ - - salt_pkg_name="${salt_json_name}" - if [[ ${POST_3005_FLAG} -eq 1 \ - && ${POST_3005_MAJOR_VER_FLAG} -eq 1 ]]; then - salt_url="${base_url}/minor/${salt_json_version}/${salt_pkg_name}" - else - salt_url="${base_url}/${salt_json_version}/${salt_pkg_name}" - fi - _curl_download "${salt_pkg_name}" "${salt_url}" - _debug_log "$0:${FUNCNAME[0]} successfully downloaded from "\ - "'${salt_url}' into file '${salt_pkg_name}'" - salt_pkg512=$(sha512sum "${salt_pkg_name}" |awk -F" " '{print $1}') - if [[ "${salt_pkg512}" != "${salt_json_sha512}" ]]; then - CURRENT_STATUS=${STATUS_CODES_ARY[installFailed]} - _error_log "$0:${FUNCNAME[0]} downloaded file '${salt_url}' "\ - "failed to match checksum in file '${repo_json_file}'" - fi - else - # use defaults - # repo.json file is missing, look for 'latest' - # directory with onedir files and retrieve files from it - salt_url="${base_url}/${salt_url_version}" - salt_tarball="${salt_name}*-linux-*.tar.?z" - salt_tarball_SHA512="${salt_name}*_SHA512" - - # assume http://, https:// or similar - wget -q -r -l1 -nd -np -A "${salt_tarball}" "${salt_url}" - _retn=$? - if [[ ${_retn} -ne 0 ]]; then - CURRENT_STATUS=${STATUS_CODES_ARY[installFailed]} - _error_log "$0:${FUNCNAME[0]} downloaded file "\ - "'${salt_tarball}' failed to download, error '${_retn}'" - fi - wget -q -r -l1 -nd -np -A "${salt_name}*_SHA512" "${salt_url}" - _retn=$? - if [[ ${_retn} -ne 0 ]]; then - CURRENT_STATUS=${STATUS_CODES_ARY[installFailed]} - _error_log "$0:${FUNCNAME[0]} downloaded file "\ - "'${salt_tarball_SHA512}' failed to download, error '${_retn}'" + salt_pkg_metadata=$(curl "${bd_3006_chksum_base_url}/${salt_specific_version}/${salt_pkg_name}") + salt_pkg_sha=$(echo "${salt_pkg_metadata}" | grep -w "sha256" | sort | uniq) + if [[ -n "${salt_pkg_sha}" ]]; then + # have package metadata to process + salt_pkg_shakey=$(echo "${salt_pkg_sha}" | awk -F ':' '{print $1}' | awk -F '"' '{print $2}') + salt_pkg_sha256=$(echo "${salt_pkg_sha}" | awk -F ':' '{print $2}' | awk -F '"' '{print $2}') + + _debug_log "$0:${FUNCNAME[0]} found information for file "\ + "'${salt_pkg_name}', shakey '${salt_pkg_shakey}', "\ + "sha256value '${salt_pkg_sha256}'" + + if [[ "${salt_pkg_shakey}" = "sha256" ]]; then + # Found sha256 + salt_pkg_sha256_found=1 + _debug_log "$0:${FUNCNAME[0]} successfully found sha256 "\ + "information on file '${salt_pkg_name}'" + else + # sanity check for sha256 key not found + CURRENT_STATUS=${STATUS_CODES_ARY[installing]} + _warning_log "$0:${FUNCNAME[0]} failed to find sha256 "\ + "information for downloaded file '${salt_pkg_name}', "\ + "error '${salt_pkg_sha256}'" fi + fi - ## shellcheck - salt_chksum_file=$(ls "${salt_name}"*_SHA512) - salt_pkg_name=$(ls "${salt_name}"*-linux-amd64.tar.gz) - if [[ -z "${salt_pkg_name}" ]]; then - # failed to find pre-3006 linux tarball, - # attempt to find post-3005 with appro. arch - sys_arch="${MACHINE_ARCH}" - salt_chksum_file=$(ls "${salt_name}"*-linux-"${sys_arch}".tar.xz.sha512) - salt_pkg_name=$(ls "${salt_name}"*-linux-"${sys_arch}".tar.xz) - fi - _debug_log "$0:${FUNCNAME[0]} successfully downloaded tarball "\ - "from '${salt_url}' into file '${salt_pkg_name}'" - _debug_log "$0:${FUNCNAME[0]} successfully downloaded checksum "\ - "from '${salt_url}' into file '${salt_chksum_file}'" - - calc_sha512sum=$(grep "${salt_pkg_name}" \ - "${salt_chksum_file}" | sha512sum --check --status) - if [[ ${calc_sha512sum} -ne 0 ]]; then + if [[ ${salt_pkg_sha256_found} -eq 1 ]]; then + # Have sha256 information to check against + calc_sha256sum=$(sha256sum "${salt_pkg_name}" | awk -F ' ' '{print $1}') + if [[ "${calc_sha256sum}" != "${salt_pkg_sha256}" ]]; then CURRENT_STATUS=${STATUS_CODES_ARY[installFailed]} - _error_log "$0:${FUNCNAME[0]} downloaded file "\ - "'${salt_pkg_name}' failed to match checksum in file "\ - "'${salt_chksum_file}'" + _error_log "$0:${FUNCNAME[0]} generated checksum "\ + "'${calc_sha256sum}' for downloaded file '${salt_pkg_name}' "\ + "does not match that retrieved from repository '${salt_pkg_sha256}'" + else + _debug_log "$0:${FUNCNAME[0]} downloaded file "\ + "'${salt_pkg_name}' matched checksum retrieved from repository" fi fi fi - _debug_log "$0:${FUNCNAME[0]} sha512sum match was successful" - if [[ ${POST_3005_FLAG} -eq 1 ]]; then - # need to setup salt user and group if not already existing - _debug_log "$0:${FUNCNAME[0]} setup salt user and group if not "\ - "already existing" - _SALT_GROUP=salt - _SALT_USER=salt - _SALT_NAME=Salt + # need to setup salt user and group if not already existing + _debug_log "$0:${FUNCNAME[0]} setup salt user and group if not "\ + "already existing" + _SALT_GROUP=salt + _SALT_USER=salt + _SALT_NAME=Salt + # 1. create group if not existing + if getent group "${_SALT_GROUP}" 1>/dev/null; then + _debug_log "$0:${FUNCNAME[0]} already group salt, assume user "\ + "and group setup for Salt" + else + _debug_log "$0:${FUNCNAME[0]} setup group and user salt" + # create user to avoid running server as root # 1. create group if not existing - if getent group "${_SALT_GROUP}" 1>/dev/null; then - _debug_log "$0:${FUNCNAME[0]} already group salt, assume user "\ - "and group setup for Salt" - else - _debug_log "$0:${FUNCNAME[0]} setup group and user salt" - # create user to avoid running server as root - # 1. create group if not existing - groupadd --system "${_SALT_GROUP}" 2>/dev/null - # 2. create homedir if not existing - if [[ ! -d "${salt_dir}" ]]; then - mkdir -p "${salt_dir}" - fi - # 3. create user if not existing - if ! getent passwd | grep -q "^${_SALT_USER}:"; then - useradd --system --no-create-home -s /sbin/nologin -g \ - "${_SALT_GROUP}" "${_SALT_USER}" 2>/dev/null - fi - # 4. adjust passwd entry - usermod -c "${_SALT_NAME}" -d "${salt_dir}" -g "${_SALT_GROUP}" \ - "${_SALT_USER}" 2>/dev/null + groupadd --system "${_SALT_GROUP}" 2>/dev/null + # 2. create homedir if not existing + if [[ ! -d "${salt_dir}" ]]; then + mkdir -p "${salt_dir}" fi - tar xf "${salt_pkg_name}" -C "${base_salt_location}" 1>/dev/null - # 5. adjust file and directory permissions - chown -R "${_SALT_USER}":"${_SALT_GROUP}" "${salt_dir}" - else - tar xf "${salt_pkg_name}" -C "${base_salt_location}" 1>/dev/null + # 3. create user if not existing + if ! getent passwd | grep -q "^${_SALT_USER}:"; then + useradd --system --no-create-home -s /sbin/nologin -g \ + "${_SALT_GROUP}" "${_SALT_USER}" 2>/dev/null + fi + # 4. adjust passwd entry + usermod -c "${_SALT_NAME}" -d "${salt_dir}" -g "${_SALT_GROUP}" \ + "${_SALT_USER}" 2>/dev/null fi + tar xf "${salt_pkg_name}" -C "${base_salt_location}" 1>/dev/null + # 5. adjust file and directory permissions + chown -R "${_SALT_USER}":"${_SALT_GROUP}" "${salt_dir}" _retn=$? if [[ ${_retn} -ne 0 ]]; then CURRENT_STATUS=${STATUS_CODES_ARY[installFailed]} @@ -1359,8 +1099,8 @@ _check_multiple_script_running() { # for example: install salt-minion from rpm or deb package # # Results: -# 0 - No standard install found and empty string output -# !0 - Standard install found and Salt version found output +# 0 - No standard classic install found and empty string output +# !0 - Standard classic install found and Salt version found output # _check_classic_minion_install() { @@ -1376,7 +1116,8 @@ _check_classic_minion_install() { /usr/bin/salt-call /usr/local/bin/salt-call " - _info_log "$0:${FUNCNAME[0]} check if standard salt-minion installed" + _info_log "$0:${FUNCNAME[0]} check if standard classic "\ + "salt-minion installed" for idx in ${list_of_files_check} do @@ -1394,8 +1135,8 @@ _check_classic_minion_install() { # get salt-version local s_ver="" s_ver=$("${idx}" --local test.version |grep -v 'local:' |xargs) - _debug_log "$0:${FUNCNAME[0]} found standard salt-minion, "\ - "Salt version: '${s_ver}'" + _debug_log "$0:${FUNCNAME[0]} found standard classic "\ + "salt-minion, Salt version: '${s_ver}'" echo "${s_ver}" _retn=1 break @@ -1580,13 +1321,14 @@ _create_pre_3006_helper_scripts() { # # discover and return the current status # -# 0 => installed +# 0 => installed (and running) # 1 => installing # 2 => notInstalled # 3 => installFailed # 4 => removing # 5 => removeFailed # 6 => externalInstall +# 7 => installedStopped # 126 => scriptFailed # # Side Effects: @@ -1609,12 +1351,12 @@ _status_fn() { found_salt_ver=$(_check_classic_minion_install) if [[ -n "${found_salt_ver}" ]]; then _debug_log "$0:${FUNCNAME[0]}" \ - "existing Standard Salt Installation detected, "\ + "existing Standard Classic Salt Installation detected, "\ "Salt version: '${found_salt_ver}'" CURRENT_STATUS=${STATUS_CODES_ARY[externalInstall]} _retn_status=${STATUS_CODES_ARY[externalInstall]} else - _debug_log "$0:${FUNCNAME[0]} no standardized install found" + _debug_log "$0:${FUNCNAME[0]} no standardized classic install found" install_onedir_chk=$(_check_onedir_minion_install) if [[ ${install_onedir_chk} -eq 2 ]]; then @@ -1623,11 +1365,11 @@ _status_fn() { svpid=$(_find_salt_pid) if [[ ${install_onedir_chk} -eq 0 && -z ${svpid} ]]; then - # check not installed and no process id + # not installed and no process id CURRENT_STATUS=${STATUS_CODES_ARY[notInstalled]} _retn_status=${STATUS_CODES_ARY[notInstalled]} elif [[ ${install_onedir_chk} -ne 0 ]]; then - # check installed + # installed, check for pid CURRENT_STATUS=${STATUS_CODES_ARY[installed]} _retn_status=${STATUS_CODES_ARY[installed]} # normal case but double-check @@ -1635,23 +1377,197 @@ _status_fn() { if [[ -z ${svpid} ]]; then # Note: someone could have stopped the salt-minion, # so installed but not running, - # status codes don't allow for that case - CURRENT_STATUS=${STATUS_CODES_ARY[installFailed]} - _retn_status=${STATUS_CODES_ARY[installFailed]} + CURRENT_STATUS=${STATUS_CODES_ARY[installedStopped]} + _retn_status=${STATUS_CODES_ARY[installedStopped]} + else + # have running pid for salt-minion + CURRENT_STATUS=${STATUS_CODES_ARY[installed]} + _retn_status=${STATUS_CODES_ARY[installed]} fi elif [[ -z ${svpid} ]]; then - # check no process id and main directory still left, =>removeFailed + # check no process id and + # main directory still left, =>installedStopped if [[ ${install_onedir_chk} -ne 0 ]]; then - CURRENT_STATUS=${STATUS_CODES_ARY[removeFailed]} - _retn_status=${STATUS_CODES_ARY[removeFailed]} + CURRENT_STATUS=${STATUS_CODES_ARY[installedStopped]} + _retn_status=${STATUS_CODES_ARY[installedStopped]} + fi + fi + fi + + return ${_retn_status} +} + + +# +# _stop_fn +# +# stop the salt-minion if running and return the current status +# +# 0 => installed (and running) +# 1 => installing +# 2 => notInstalled +# 3 => installFailed +# 4 => removing +# 5 => removeFailed +# 6 => externalInstall +# 7 => installedStopped +# 126 => scriptFailed +# +# Side Effects: +# CURRENT_STATUS updated +# +# Results: +# Exits numerical status +# + +_stop_fn() { + # return status + local _retn_status=${STATUS_CODES_ARY[notInstalled]} + local install_onedir_chk=0 + local found_salt_ver="" + local systemctl_issue=0 + + _info_log "$0:${FUNCNAME[0]} checking status for script" + + _check_multiple_script_running + + found_salt_ver=$(_check_classic_minion_install) + if [[ -n "${found_salt_ver}" ]]; then + _debug_log "$0:${FUNCNAME[0]}" \ + "existing Standard Classic Salt Installation detected, "\ + "Salt version: '${found_salt_ver}'" + CURRENT_STATUS=${STATUS_CODES_ARY[externalInstall]} + _retn_status=${STATUS_CODES_ARY[externalInstall]} + else + _debug_log "$0:${FUNCNAME[0]} no standardized classic install found" + + install_onedir_chk=$(_check_onedir_minion_install) + if [[ ${install_onedir_chk} -eq 2 ]]; then + POST_3005_FLAG=1 # ensure note 3006 and above + fi + + if [[ ${install_onedir_chk} -eq 0 ]]; then + # not installed + CURRENT_STATUS=${STATUS_CODES_ARY[notInstalled]} + _retn_status=${STATUS_CODES_ARY[notInstalled]} + elif [[ ${install_onedir_chk} -ne 0 ]]; then + # installed, check for pid + CURRENT_STATUS=${STATUS_CODES_ARY[installed]} + _retn_status=${STATUS_CODES_ARY[installed]} + svpid=$(_find_salt_pid) + if [[ -z ${svpid} ]]; then + # Note: someone could have stopped the salt-minion, + # so installed but not running, + CURRENT_STATUS=${STATUS_CODES_ARY[installedStopped]} + _retn_status=${STATUS_CODES_ARY[installedStopped]} + else + # have pid for salt-minion, need to stop + systemctl stop salt-minion || { + _warning_log "$0:${FUNCNAME[0]} stopping existing Salt "\ + "functionality salt-minion encountered difficulties "\ + "using systemctl, retcode '$?'"; + systemctl_issue=1; + } + if [[ "${systemctl_issue}" -eq 0 ]]; then + CURRENT_STATUS=${STATUS_CODES_ARY[installedStopped]} + _retn_status=${STATUS_CODES_ARY[installedStopped]} + else + CURRENT_STATUS=${STATUS_CODES_ARY[installedStopped]} + _retn_status=${STATUS_CODES_ARY[installedStopped]} + _error_log "$0:${FUNCNAME[0]} stopping existing Salt "\ + "functionality salt-minion encountered difficulties "\ + "using systemctl, run 'systemctl status salt-minion'"\ + "to resolve issue'"; + fi fi fi fi + _debug_log "$0:${FUNCNAME[0]} stop returning '${_retn_status}'" return ${_retn_status} } +# +# _restart_fn +# +# restart the salt-minion if not running and return the current status +# +# 0 => installed (and running) +# 1 => installing +# 2 => notInstalled +# 3 => installFailed +# 4 => removing +# 5 => removeFailed +# 6 => externalInstall +# 7 => installedStopped +# 126 => scriptFailed +# +# Side Effects: +# CURRENT_STATUS updated +# +# Results: +# Exits numerical status +# + +_restart_fn() { + + # return status + local _retn_status=${STATUS_CODES_ARY[notInstalled]} + local install_onedir_chk=0 + local found_salt_ver="" + local systemctl_issue=0 + + _info_log "$0:${FUNCNAME[0]} checking status for script" + + _check_multiple_script_running + + found_salt_ver=$(_check_classic_minion_install) + if [[ -n "${found_salt_ver}" ]]; then + _debug_log "$0:${FUNCNAME[0]}" \ + "existing Standard Classic Salt Installation detected, "\ + "Salt version: '${found_salt_ver}'" + CURRENT_STATUS=${STATUS_CODES_ARY[externalInstall]} + _retn_status=${STATUS_CODES_ARY[externalInstall]} + else + _debug_log "$0:${FUNCNAME[0]} no standardized classic install found" + + install_onedir_chk=$(_check_onedir_minion_install) + if [[ ${install_onedir_chk} -eq 2 ]]; then + POST_3005_FLAG=1 # ensure note 3006 and above + fi + + if [[ ${install_onedir_chk} -eq 0 ]]; then + # not installed + CURRENT_STATUS=${STATUS_CODES_ARY[notInstalled]} + _retn_status=${STATUS_CODES_ARY[notInstalled]} + elif [[ ${install_onedir_chk} -ne 0 ]]; then + # installed, check running + systemctl restart salt-minion || { + _warning_log "$0:${FUNCNAME[0]} restarting existing Salt "\ + "functionality salt-minion encountered difficulties "\ + "using systemctl, retcode '$?'"; + systemctl_issue=1; + } + if [[ "${systemctl_issue}" -eq 0 ]]; then + CURRENT_STATUS=${STATUS_CODES_ARY[installed]} + _retn_status=${STATUS_CODES_ARY[installed]} + else + CURRENT_STATUS=${STATUS_CODES_ARY[installed]} + _retn_status=${STATUS_CODES_ARY[installed]} + _error_log "$0:${FUNCNAME[0]} restarting existing Salt "\ + "functionality salt-minion encountered difficulties "\ + "using systemctl, run 'systemctl status salt-minion'"\ + "to resolve issue'"; + fi + fi + fi + _debug_log "$0:${FUNCNAME[0]} restart returning '${_retn_status}'" + return ${_retn_status} +} + + + # # _deps_chk_fn # @@ -1723,6 +1639,78 @@ _find_system_lib_path () { } +# +# _reconfig_fn +# +# Executes scripts to stop the salt-minion, if active +# Re-read the configuration +# Restart the salt-minion, if it had been active +# +# Results: +# Exits with 0 or error code +# +_reconfig_fn () { + local _retn=0 + local minion_was_active="" + + _info_log "$0:${FUNCNAME[0]} processing script install" + + _check_multiple_script_running + + found_salt_ver=$(_check_classic_minion_install) + if [[ -n "${found_salt_ver}" ]]; then + _warning_log "$0:${FUNCNAME[0]} failed to install, "\ + "existing Standard Classic Salt Installation detected, "\ + "Salt version: '${found_salt_ver}'" + CURRENT_STATUS=${STATUS_CODES_ARY[externalInstall]} + exit ${STATUS_CODES_ARY[externalInstall]} + else + _debug_log "$0:${FUNCNAME[0]} no standardized classic install found" + fi + + minion_was_active=$(systemctl is-active salt-minion) || { + _error_log "$0:${FUNCNAME[0]} checking running existing salt-minion "\ + "encountered difficulties using systemctl, retcode '$?'"; + } + + # get configuration for salt-minion + _fetch_vmtools_salt_minion_conf "$@" || { + _error_log "$0:${FUNCNAME[0]} failed, read configuration for "\ + "salt-minion, retcode '$?'"; + } + + # ensure minion id or fqdn for salt-minion + _ensure_id_or_fqdn + + cd "${CURRDIR}" || return $? + + # restart the salt-minion using systemd if it was active at the start + systemctl daemon-reload || { + _error_log "$0:${FUNCNAME[0]} reloading the systemd daemon "\ + "failed , retcode '$?'"; + } + _debug_log "$0:${FUNCNAME[0]} successfully executed systemctl "\ + "daemon-reload" + if [[ "${minion_was_active}" = "active" ]]; then + local name_service="salt-minion.service" + systemctl restart "${name_service}" || { + _error_log "$0:${FUNCNAME[0]} restarting the salt-minion using "\ + "systemctl failed , retcode '$?'"; + } + _debug_log "$0:${FUNCNAME[0]} successfully executed systemctl "\ + "restart '${name_service}'" + systemctl enable "${name_service}" || { + _error_log "$0:${FUNCNAME[0]} enabling the salt-minion using "\ + "systemctl failed , retcode '$?'"; + } + _debug_log "$0:${FUNCNAME[0]} successfully executed systemctl "\ + "enable '${name_service}'" + fi + return ${_retn} +} + + + # # _install_fn # @@ -1734,6 +1722,7 @@ _find_system_lib_path () { # _install_fn () { + # execute install of Salt minion local _retn=0 local existing_chk="" @@ -1747,12 +1736,12 @@ _install_fn () { found_salt_ver=$(_check_classic_minion_install) if [[ -n "${found_salt_ver}" ]]; then _warning_log "$0:${FUNCNAME[0]} failed to install, "\ - "existing Standard Salt Installation detected, "\ + "existing Standard Classic Salt Installation detected, "\ "Salt version: '${found_salt_ver}'" CURRENT_STATUS=${STATUS_CODES_ARY[externalInstall]} exit ${STATUS_CODES_ARY[externalInstall]} else - _debug_log "$0:${FUNCNAME[0]} no standardized install found" + _debug_log "$0:${FUNCNAME[0]} no standardized Classic install found" fi # check if salt-minion or salt-master (salt-cloud etc req master) @@ -1763,9 +1752,17 @@ _install_fn () { do local salt_fn="" salt_fn="$(basename "${idx}")" - _warning_log "$0:${FUNCNAME[0]} existing Salt functionality "\ - "${salt_fn} shall be stopped and replaced when new "\ - "salt-minion is installed" + if [ "${UPGRADE_FLAG}" -eq 0 ]; then + # performing a clean install + _warning_log "$0:${FUNCNAME[0]} existing Salt functionality "\ + "${salt_fn} shall be stopped and replaced when new "\ + "salt-minion is installed" + else + # performing an upgrade, note in logs + _warning_log "$0:${FUNCNAME[0]} existing Salt functionality "\ + "${salt_fn} shall be stopped and upgraded when new "\ + "salt-minion is installed" + fi done fi @@ -1776,10 +1773,17 @@ _install_fn () { } # get configuration for salt-minion - _fetch_vmtools_salt_minion_conf "$@" || { - _error_log "$0:${FUNCNAME[0]} failed, read configuration for "\ - "salt-minion, retcode '$?'"; - } + if [ "${UPGRADE_FLAG}" -eq 0 ]; then + # performing a clean install + _fetch_vmtools_salt_minion_conf "$@" || { + _error_log "$0:${FUNCNAME[0]} failed, read configuration for "\ + "salt-minion, retcode '$?'"; + } + else + # performing an upgrade, note in logs, and leave config alone + _debug_log "$0:${FUNCNAME[0]} performing upgrade, using existing "\ + "read configuration for salt-minion"; + fi if [[ ${_retn} -eq 0 && -f "${onedir_pre_3006_location}" ]]; then # create helper scripts for /usr/bin to ensure they are present @@ -2002,7 +2006,7 @@ _generate_minion_id () { # re-generates new identifier, allows for a VM containing a salt-minion, # to be cloned and not have conflicting id and keys # salt-minion is stopped, id and keys cleared, and restarted -# if it was previously running +# if it was previously running, and not an upgrade # # Input: # Optional specified input ID to be used, default generate randomized value @@ -2058,25 +2062,34 @@ _clear_id_key_fn () { salt_minion_pre_active_flag=1 fi - rm -fR "${salt_conf_dir}/minion_id" - rm -fR "${salt_conf_dir}/pki/${salt_minion_conf_name}" - # always comment out what was there - sed -i 's/^id/# id/g' "${salt_minion_conf_file}" - _debug_log "$0:${FUNCNAME[0]} removed '${salt_conf_dir}/minion_id' "\ - "and '${salt_conf_dir}/pki/${salt_minion_conf_name}', and "\ - "commented out id in '${salt_minion_conf_file}'" + if [ "${UPGRADE_FLAG}" -eq 0 ]; then + # perform a clean install and generate new keys and minion id + rm -fR "${salt_conf_dir}/minion_id" + rm -fR "${salt_conf_dir}/pki/${salt_minion_conf_name}" + # always comment out what was there + sed -i 's/^id/# id/g' "${salt_minion_conf_file}" + _debug_log "$0:${FUNCNAME[0]} removed '${salt_conf_dir}/minion_id' "\ + "and '${salt_conf_dir}/pki/${salt_minion_conf_name}', and "\ + "commented out id in '${salt_minion_conf_file}'" + + if [[ -z "${minion_ip_id}" ]] ;then + minion_id=$(_generate_minion_id) + else + minion_id="${minion_ip_id}" + fi - if [[ -z "${minion_ip_id}" ]] ;then - minion_id=$(_generate_minion_id) + # add new minion id to bottom of minion configuration file + echo "id: ${minion_id}" >> "${salt_minion_conf_file}" + _debug_log "$0:${FUNCNAME[0]} updated salt-minion identifier "\ + "'${minion_id}' in configuration file '${salt_minion_conf_file}'" else + # performing an upgrade, log info minion_id="${minion_ip_id}" + _debug_log "$0:${FUNCNAME[0]} maintaining salt-minion identifier "\ + "'${minion_id}' and keys in configuration file "\ + "'${salt_minion_conf_file}' since performing upgrade" fi - # add new minion id to bottom of minion configuration file - echo "id: ${minion_id}" >> "${salt_minion_conf_file}" - _debug_log "$0:${FUNCNAME[0]} updated salt-minion identifier "\ - "'${minion_id}' in configuration file '${salt_minion_conf_file}'" - if [[ ${salt_minion_pre_active_flag} -eq 1 ]]; then # restart the stopped salt-minion using systemd systemctl restart salt-minion || { @@ -2097,11 +2110,15 @@ _clear_id_key_fn () { # # Removes all Salt files and directories that may be used # +# Note: +# funciton only call when performing an uninstall +# # Results: # Exits with 0 or error code # _remove_installed_files_dirs() { + # performing an uninstall _debug_log "$0:${FUNCNAME[0]} removing directories and files "\ "in '${list_file_dirs_to_remove}'" for idx in ${list_file_dirs_to_remove} @@ -2141,12 +2158,12 @@ _uninstall_fn () { found_salt_ver=$(_check_classic_minion_install) if [[ -n "${found_salt_ver}" ]]; then _warning_log "$0:${FUNCNAME[0]} failed to install, "\ - "existing Standard Salt Installation detected, "\ + "existing Standard Classic Salt Installation detected, "\ "Salt version: '${found_salt_ver}'" CURRENT_STATUS=${STATUS_CODES_ARY[externalInstall]} exit ${STATUS_CODES_ARY[externalInstall]} else - _debug_log "$0:${FUNCNAME[0]} no standardized install found" + _debug_log "$0:${FUNCNAME[0]} no standardized classic install found" fi install_onedir_chk=$(_check_onedir_minion_install) @@ -2349,6 +2366,19 @@ while true; do shift; MINION_VERSION_PARAMS="$*"; ;; + -n | --reconfig ) + RECONFIG_FLAG=1; + shift; + RECONFIG_PARAMS="$*"; + ;; + -q | --stop ) + STOP_FLAG=1; + shift; + ;; + -p | --start ) + RESTART_FLAG=1; + shift; + ;; -r | --remove ) UNINSTALL_FLAG=1; shift; @@ -2361,6 +2391,11 @@ while true; do VERSION_FLAG=1; shift; ;; + -u | --upgrade ) + UPGRADE_FLAG=1; + shift; + ;; + -- ) shift; break; @@ -2413,6 +2448,11 @@ if [[ ${MINION_VERSION_FLAG} -eq 1 ]]; then _set_install_minion_version_fn "${MINION_VERSION_PARAMS}" retn=$? fi +if [[ ${UPGRADE_FLAG} -eq 1 ]]; then + CLI_ACTION=1 + # ensure this is processed before install + retn=$? +fi if [[ ${INSTALL_FLAG} -eq 1 ]]; then CLI_ACTION=1 LOG_ACTION="install" @@ -2436,6 +2476,24 @@ if [[ ${VERSION_FLAG} -eq 1 ]]; then echo "${SCRIPT_VERSION}" retn=0 fi +if [[ ${RECONFIG_FLAG} -eq 1 ]]; then + CLI_ACTION=1 + LOG_ACTION="reconfig" + _reconfig_fn "${RECONFIG_PARAMS}" + retn=$? +fi +if [[ ${STOP_FLAG} -eq 1 ]]; then + CLI_ACTION=1 + LOG_ACTION="default" + _stop_fn + retn=$? +fi +if [[ ${RESTART_FLAG} -eq 1 ]]; then + CLI_ACTION=1 + LOG_ACTION="default" + _restart_fn + retn=$? +fi if [[ ${CLI_ACTION} -eq 0 ]]; then # check if guest variables have an action since none from CLI @@ -2468,6 +2526,7 @@ if [[ ${CLI_ACTION} -eq 0 ]]; then _status_fn retn=$? ;; + # TBD what will VM TOOLS do for reconfig, upgrade, stop and start ? *) ;; esac