-#!/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
# 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}"
"
## /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
install
clear
remove
+reconfig
default
"
"
readonly salt_minion_service_wrapper=\
-"# Copyright 2021-2023 VMware, Inc.
+"# Copyright 2021-2024 VMware, Inc.
# SPDX-License-Identifier: Apache-2
[Unit]
## 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
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
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=""
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
"${log_dir}/vmware-${SCRIPTNAME}-${LOG_ACTION}-${logdate}.log"
}
+# shellcheck disable=SC2329
_display() {
if [[ ${VERBOSE_FLAG} -eq 1 ]]; then echo "$1"; fi
_log "$*"
fi
}
+# shellcheck disable=SC2329
_yesno() {
read -r -p "Continue (y/n)?" choice
case "$choice" in
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"
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"
# Results:
# Exits with hard-coded value 130
#
+# shellcheck disable=SC2329
_cleanup_int() {
rm -rf "$WORK_DIR"
#
# 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"
}
+
+#
+# _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
#
# 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
#
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"
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
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
"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
}
-#
-# _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<CURL_DOWNLOAD_RETRY_COUNT; i++))
- do
- # ensure minimum version of TLS used is v1.2
- curl -o "${file_name}" --tlsv1.2 -fsSL "${file_url}"
- _retn=$?
- if [[ ${_retn} -ne 0 ]]; then
- _warning_log "$0:${FUNCNAME[0]} failed to download file "\
- "'${file_name}' from '${file_url}' on '${i}' attempt, "\
- "retcode '${_retn}'"
- else
- download_retry_failed=0
- _debug_log "$0:${FUNCNAME[0]} successfully downloaded file "\
- "'${file_name}' from '${file_url}' after '${i}' attempts"
- break
- fi
- done
- if [[ ${download_retry_failed} -ne 0 ]]; then
- _error_log "$0:${FUNCNAME[0]} failed to download file '${file_name}' "\
- "from '${file_url}' after '${CURL_DOWNLOAD_RETRY_COUNT}' attempts"
- fi
-
- _info_log "$0:${FUNCNAME[0]} successfully downloaded file "\
- "'${file_name}' from '${file_url}'"
- return 0
-}
-
-
-#
-# _parse_json_specd_ver
-#
-# Retrieve the salt-minion from Salt repository
-#
-# Results:
-# Echos string containing colon separated version, name and sha512
-# from parsed input repo json file
-# Echos empty '' if 'salt_url_version' is not found in repo json file
-#
-# Note: salt_url_version defaults to 'latest' unless set to a specific
-# Salt minion version, for example: 3004.1-1
-#
-
- _parse_json_specd_ver() {
- local file_name="$1"
- local file_value=""
- local blk_count=0
- local specd_ver_blk_count=0
- local specd_ver_flag=0
- local found_specd_ver_linux=0
-
- local var1=""
- local var2=""
- local machine_arch_chk="${MACHINE_ARCH}"
- declare -A rdict
-
- _info_log "$0:${FUNCNAME[0]} parsing of repo json file '${file_name}'"
-
- if [[ ${POST_3005_FLAG} -eq 0 ]]; then
- machine_arch_chk="amd64" # pre_3006 used amd64
- fi
-
- file_value=$(<"${file_name}")
-
- # limit 80 cols
- var1=$(echo "${file_value}" | sed 's/,/,\n/g' | sed 's/{/\n{\n/g')
- var2=$(echo "${var1}" | sed 's/}/\n}\n/g' | sed 's/,//g' | sed 's/"//g')
-
- while IFS= read -r line
- do
- _debug_log "$0:${FUNCNAME[0]} parsing line '${line}'"
- if [[ -z "${line}" ]]; then
- continue
- fi
- if [[ "${line}" = "{" ]]; then
- (( blk_count++ ))
- elif [[ "${line}" = "}" ]]; then
- # examine directory just read in
- if [[ ${specd_ver_flag} -eq 1 ]]; then
- if [[ "${rdict['os']}" = "linux" \
- && "${rdict['arch']}" = "${machine_arch_chk}" ]]; then
- # have linux values for specd_ver
- _debug_log "$0:${FUNCNAME[0]} parsed following linux for "\
- "specified version '${salt_url_version}' from repo json "\
- "file '${file_name}', os ${rdict['os']}, version "\
- "${rdict['version']}, name ${rdict['name']}, sha512 "\
- "${rdict['SHA512']}"
- found_specd_ver_linux=1
- break
- fi
- fi
-
- if [[ ${blk_count} -eq ${specd_ver_blk_count} ]]; then
- specd_ver_flag=0
- ## break
- fi
- (( blk_count-- ))
- else
- if [[ ${POST_3005_FLAG} -eq 1 \
- && ${POST_3005_MAJOR_VER_FLAG} -eq 1 ]]; then
- # doing major version check
- line_major_key=$(echo "${line}" | cut -d ':' -f 1 | cut -d '-' -f 2 | cut -d '.' -f 1 |xargs)
- line_key=$(echo "${line}" | cut -d ':' -f 1 | xargs)
- line_value=$(echo "${line}" | cut -d ':' -f 2 | xargs)
- _debug_log "$0:${FUNCNAME[0]} check line_major_key "\
- "'${line_major_key}' again salt_url_version "\
- "'${salt_url_version}', line_key '${line_key}', "\
- "line_value '${line_value}'"
- if [[ "${line_major_key}" = "${salt_url_version}" ]]; then
- # blk_count encountered 'specd_ver', closing brace check
- specd_ver_flag=1
- specd_ver_blk_count=${blk_count}
- (( specd_ver_blk_count++ ))
- _debug_log "$0:${FUNCNAME[0]} found specd version, "\
- "version '${salt_url_version}' and line_major_key "\
- "'${line_major_key}', line_key '${line_key}' "\
- "specd_ver_blk_count '${specd_ver_blk_count}'"
- else
- rdict["${line_key}"]="${line_value}"
- _debug_log "$0:${FUNCNAME[0]} updated dictionary for "\
- "major version with line_key '${line_key}' and "\
- "line_value '${line_value}'"
- fi
- else
- line_key=$(echo "${line}" | cut -d ':' -f 1 | xargs)
- line_value=$(echo "${line}" | cut -d ':' -f 2 | xargs)
- _debug_log "$0:${FUNCNAME[0]} check line_key '${line_key}' "\
- "again salt_url_version '${salt_url_version}', "\
- "line_value '${line_value}'"
- if [[ "${line_key}" = "${salt_url_version}" ]]; then
- # blk_count encountered 'specd_ver', closing brace check
- specd_ver_flag=1
- specd_ver_blk_count=${blk_count}
- (( specd_ver_blk_count++ ))
- _debug_log "$0:${FUNCNAME[0]} found specd version, "\
- "version '${salt_url_version}' and line_key "\
- "'${line_key}' and specd_ver_blk_count "\
- "'${specd_ver_blk_count}'"
- else
- rdict["${line_key}"]="${line_value}"
- _debug_log "$0:${FUNCNAME[0]} updated dictionary with "\
- "line_key '${line_key}' and line_value '${line_value}'"
- fi
- fi
- fi
- done <<< "${var2}"
-
- if [[ ${found_specd_ver_linux} -eq 1 ]]; then
- echo "${rdict['version']}:${rdict['name']}:${rdict['SHA512']}"
- else
- _error_log "$0:${FUNCNAME[0]} unable to parse version, name and "\
- "sha512 from repo json file '${file_name}'"
- # echo ""
- fi
- return 0
-}
-
-
#
# _fetch_salt_minion
#
# Retrieve the salt-minion from Salt repository
#
-# Note:
-# pre_3006 The repo.json file only existed in one place (salt/onedir)
-# and contained everything in the directory and sub-directories
-# where the repo.json file resides.
-# post_3005 There are two repo.json files:
-# top level (salt/py3/onedir):
-# repo.json contains 'latest' and 'major versions' only.
-# minor level (salt/py3/onedir/minor):
-# repo.json contains 'latest' and 'minor versions' only.
-#
-# With the 3006 release a breaking change in directory structure was introduced
-# to bring conformity with directory structure used for packages.
+# Note: Only support Salt 3006 and higher with new Broadcom infrastructure
+# salt_url_version is always set with desired version of Salt
+# for example: latest, 3006, 3007, 3006.8, 3007.1
#
# Side Effects:
# CURRENT_STATUS updated
#
_fetch_salt_minion() {
+
# fetch the current salt-minion into specified location
# could check if already there but by always getting it
# ensure we are not using stale versions
local _retn=0
- local calc_sha512sum=1
- local download_retry_failed=1 # assume issues
local salt_pkg_name=""
local salt_url=""
- local json_version_name_sha=""
local local_base_url=""
local local_file_flag=0
- local local_count_repo_json=0
-
- local salt_tarball=""
- local salt_tarball_SHA512=""
- local salt_json_version=""
- local salt_json_name=""
- local salt_json_sha512=""
- local salt_pkg512=""
+ local salt_pkg_sha256_found=0
+ local salt_pkg_shakey=0
+ local salt_pkg_sha256=""
+ local calc_sha256sum=1
local install_onedir_chk=0
local sys_arch=""
- local ver_chk=""
- local ver_chk_major=""
- local ver_chk_minor=""
+ local salt_pkg_metadata=0
- _debug_log "$0:${FUNCNAME[0]} retrieve the salt-minion and check "\
- "its validity"
+ _debug_log "$0:${FUNCNAME[0]} retrieve the salt-minion and check its validity"
CURRENT_STATUS=${STATUS_CODES_ARY[installFailed]}
mkdir -p ${base_salt_location}
- ## cd ${base_salt_location} || return $?
cd "${WORK_DIR}" || return $?
- # check for pre-3006 or post-3005 and adjust base_url
# unless already defined by --source option
if [[ -z "${base_url}" ]]; then
_debug_log "$0:${FUNCNAME[0]} no source option used, determine "\
"version attempting to install, version '${salt_url_version}"
- _set_post_3005_flags_from_version
+ base_url="${bd_3006_base_url}"
else
_debug_log "$0:${FUNCNAME[0]} source url provided, need to scan for "\
- "pre 3006 / post 3005, and local file using base_url '${base_url}'"
+ "local file using base_url '${base_url}'"
# curl on Linux doesn't support file:// support
if echo "${base_url}" | grep -q '^/' ; then
"from '${base_url}'"
else
_debug_log "$0:${FUNCNAME[0]} using non-local source '${base_url}'"
-
- ver_chk=$(echo "${base_url}" | grep 'salt/py3/onedir')
- if [[ -n "${ver_chk}" ]]; then
- POST_3005_FLAG=1
- _set_post_3005_flags_from_version
- fi
fi
fi
+ sys_arch="${MACHINE_ARCH}"
+
if [[ ${local_file_flag} -eq 1 ]]; then
# local absolute path
# and allow for Linux handling multiple slashes
- # need to determine if pre 3005 or post 3006
- local_count_repo_json=$(find "${local_base_url}" -name repo.json|wc -l)
- if [[ ${local_count_repo_json} -eq 2 ]]; then
- POST_3005_FLAG=1
- _set_post_3005_flags_from_version
- else
- _debug_log "$0:${FUNCNAME[0]} pre-3006 local install, for "\
- "'${salt_url_version}' using specified source "\
- "'${local_base_url}'"
- fi
-
- if [[ ${POST_3005_FLAG} -eq 1 ]]; then
- if [[ ${POST_3005_MAJOR_VER_FLAG} -eq 1 ]]; then
- salt_url="${local_base_url}"
- else
- salt_url="${local_base_url}/minor"
- fi
- else
- salt_url="${local_base_url}/${salt_url_version}"
- fi
-
- if [[ -f "${salt_url}/${repo_json_file}" ]]; then
- _debug_log "$0:${FUNCNAME[0]} successfully found file "\
- "'${repo_json_file}' in '${salt_url}/${repo_json_file}'"
-
- cp -a "${salt_url}/${repo_json_file}" .
- _retn=$?
- if [[ ${_retn} -ne 0 ]]; then
- CURRENT_STATUS=${STATUS_CODES_ARY[installFailed]}
- _error_log "$0:${FUNCNAME[0]} failed to find file "\
- "'${repo_json_file}' in specified location ${base_url}, "\
- "error '${_retn}'"
- fi
+ # use defaults
+ # directory with onedir files and retrieve files from it
+ salt_url="${local_base_url}"
+ curr_dir=$(pwd)
+ _debug_log "$0:${FUNCNAME[0]} current directory ${curr_dir}"
+
+ # get desired specific version of Salt
+ _get_desired_salt_version_fn "${salt_url}"
+ cd "${salt_url}" || return 1
+ cd "${salt_specific_version}" || return 1
+ salt_pkg_name=$(ls "${salt_name}-${salt_specific_version}-onedir-linux-${sys_arch}.tar.xz")
+ cd "${curr_dir}" || return 1
+ cp -a "${salt_url}/${salt_specific_version}/${salt_pkg_name}" ${salt_pkg_name}
+ _debug_log "$0:${FUNCNAME[0]} successfully copied tarball from "\
+ "'${salt_url}/${salt_specific_version}' to file '${salt_pkg_name}'"
+ else
+ # assume use curl for local or remote URI
+ # directory with onedir files and retrieve files from it
- # 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
- cp -a "${salt_url}/minor/${salt_json_version}/${salt_pkg_name}" .
- else
- cp -a "${salt_url}/${salt_json_version}/${salt_pkg_name}" .
- fi
- _retn=$?
- if [[ ${_retn} -ne 0 ]]; then
- CURRENT_STATUS=${STATUS_CODES_ARY[installFailed]}
- _error_log "$0:${FUNCNAME[0]} failed to find file "\
- "'${salt_pkg_name}' in specified location "\
- "${salt_url}/${salt_json_version}, error '${_retn}'"
- fi
- _debug_log "$0:${FUNCNAME[0]} successfully copied from "\
- "'${salt_url}/${salt_json_version}' to file '${salt_pkg_name}'"
+ _debug_log "$0:${FUNCNAME[0]} using curl to download from url '${base_url}'"
- 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]} copied file "\
- "'${salt_url}/${salt_json_version}' 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="${local_base_url}/${salt_url_version}"
+ # get dir listing from url, sort and pick highest
+ generic_versions_tmpdir=$(mktemp -d)
+ curr_pwd=$(pwd)
+ cd ${generic_versions_tmpdir} || return 1
+ # leverage the onedir directories since release Windows and Linux
+ wget -r -np -nH --exclude-directories=windows,relenv,macos -x -l 1 "${base_url}/"
+ cd ${curr_pwd} || return 1
- _debug_log "$0:${FUNCNAME[0]} current directory $(pwd)"
+ # get desired specific version of Salt
+ _get_desired_salt_version_fn "${generic_versions_tmpdir}/artifactory/saltproject-generic/onedir"
- cp -a "${salt_url}/${salt_name}"*-linux-*.tar.?z .
- _retn=$?
- if [[ ${_retn} -ne 0 ]]; then
- CURRENT_STATUS=${STATUS_CODES_ARY[installFailed]}
- _error_log "$0:${FUNCNAME[0]} failed to find file "\
- "for Linux in specified location ${salt_url}, "\
- "error '${_retn}'"
- fi
+ # clean up temp dir
+ rm -fR ${generic_versions_tmpdir}
- cp -a "${salt_url}/${salt_name}"*-linux-*.tar.?z.sha512 . 2>/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]}
# 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() {
/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
# 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
#
# 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:
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
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
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
#
}
+#
+# _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
#
#
_install_fn () {
+
# execute install of Salt minion
local _retn=0
local existing_chk=""
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)
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
}
# 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
# 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
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 || {
#
# 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}
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)
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;
VERSION_FLAG=1;
shift;
;;
+ -u | --upgrade )
+ UPGRADE_FLAG=1;
+ shift;
+ ;;
+
-- )
shift;
break;
_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"
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
_status_fn
retn=$?
;;
+ # TBD what will VM TOOLS do for reconfig, upgrade, stop and start ?
*)
;;
esac