From 546b549ca114a5db96599487c9566e41e91275dd Mon Sep 17 00:00:00 2001 From: kgbsd <45101782+kgbsd@users.noreply.github.com> Date: Wed, 16 Oct 2019 17:44:15 -0600 Subject: [PATCH 01/64] fix bootstrap-salt.sh for FreeBSD FreeBSD has py36-salt packages which handle all dependencies, etc - simple as pkg install -y py36-salt and then enabling it. Don't need dependencies or git hacks. --- bootstrap-salt.sh | 211 ++++------------------------------------------ 1 file changed, 18 insertions(+), 193 deletions(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 2b41411..3a3eb2a 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -238,7 +238,11 @@ _ECHO_DEBUG=${BS_ECHO_DEBUG:-$BS_FALSE} _CONFIG_ONLY=$BS_FALSE _PIP_ALLOWED=${BS_PIP_ALLOWED:-$BS_FALSE} _PIP_ALL=${BS_PIP_ALL:-$BS_FALSE} -_SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/etc/salt} +if uname -a | grep FreeBSD > /dev/null; then + SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/usr/local/etc/salt} +else + _SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/etc/salt} +fi _SALT_CACHE_DIR=${BS_SALT_CACHE_DIR:-/var/cache/salt} _PKI_DIR=${_SALT_ETC_DIR}/pki _FORCE_OVERWRITE=${BS_FORCE_OVERWRITE:-$BS_FALSE} @@ -5170,48 +5174,7 @@ __freebsd_get_packagesite() { # Using a separate conf step to head for idempotent install... __configure_freebsd_pkg_details() { - ## pkg.conf is deprecated. - ## We use conf files in /usr/local or /etc instead - mkdir -p /usr/local/etc/pkg/repos/ - mkdir -p /etc/pkg/ - - ## Use new JSON-like format for pkg repo configs - ## check if /etc/pkg/FreeBSD.conf is already in place - if [ ! -f /etc/pkg/FreeBSD.conf ]; then - conf_file=/usr/local/etc/pkg/repos/freebsd.conf - { - echo "FreeBSD:{" - echo " url: \"${PKGCONFURL}\"," - echo " mirror_type: \"srv\"," - echo " signature_type: \"fingerprints\"," - echo " fingerprints: \"/usr/share/keys/pkg\"," - echo " enabled: true" - echo "}" - } > $conf_file - __copyfile $conf_file /etc/pkg/FreeBSD.conf - fi - FROM_FREEBSD="-r FreeBSD" - - ##### Workaround : Waiting for SaltStack Repository to be available for FreeBSD 12 #### - if [ "${DISTRO_MAJOR_VERSION}" -ne 12 ]; then - ## add saltstack freebsd repo - salt_conf_file=/usr/local/etc/pkg/repos/saltstack.conf - { - echo "SaltStack:{" - echo " url: \"${SALTPKGCONFURL}\"," - echo " mirror_type: \"http\"," - echo " enabled: true" - echo " priority: 10" - echo "}" - } > $salt_conf_file - FROM_SALTSTACK="-r SaltStack" - fi - ##### End Workaround : Waiting for SaltStack Repository to be available for FreeBSD 12 #### - - ## ensure future ports builds use pkgng - echo "WITH_PKGNG= yes" >> /etc/make.conf - - /usr/local/sbin/pkg update -f || return 1 + echo 'not hijacking pkg repo configurations' } install_freebsd_9_stable_deps() { @@ -5223,36 +5186,9 @@ install_freebsd_9_stable_deps() { __freebsd_get_packagesite if [ ! -x /usr/local/sbin/pkg ]; then - - # install new `pkg` code from its own tarball. - fetch "${_PACKAGESITE}/Latest/pkg.txz" || return 1 - tar xf ./pkg.txz -s ",/.*/,,g" "*/pkg-static" || return 1 - ./pkg-static add ./pkg.txz || return 1 - /usr/local/sbin/pkg2ng || return 1 + pkg install -y pkg fi - - # Configure the pkg repository using new approach - __configure_freebsd_pkg_details || return 1 fi - - # Now install swig30 - # shellcheck disable=SC2086 - /usr/local/sbin/pkg install ${FROM_FREEBSD} -y swig30 || return 1 - - # YAML module is used for generating custom master/minion configs - # shellcheck disable=SC2086 - /usr/local/sbin/pkg install ${FROM_FREEBSD} -y py27-yaml || return 1 - - if [ "${_EXTRA_PACKAGES}" != "" ]; then - echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" - # shellcheck disable=SC2086 - /usr/local/sbin/pkg install ${FROM_FREEBSD} -y ${_EXTRA_PACKAGES} || return 1 - fi - - if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then - pkg upgrade -y || return 1 - fi - return 0 } @@ -5269,136 +5205,32 @@ install_freebsd_12_stable_deps() { } install_freebsd_git_deps() { - install_freebsd_9_stable_deps || return 1 - - # shellcheck disable=SC2086 - SALT_DEPENDENCIES=$(/usr/local/sbin/pkg search ${FROM_FREEBSD} -R -d sysutils/py-salt | grep -i origin | sed -e 's/^[[:space:]]*//' | tail -n +2 | awk -F\" '{print $2}' | tr '\n' ' ') - # shellcheck disable=SC2086 - /usr/local/sbin/pkg install ${FROM_FREEBSD} -y ${SALT_DEPENDENCIES} || return 1 - # install python meta package - /usr/local/sbin/pkg install -y lang/python || return 1 - - if ! __check_command_exists git; then - /usr/local/sbin/pkg install -y git || return 1 - fi - - /usr/local/sbin/pkg install -y www/py-requests || return 1 - - __git_clone_and_checkout || return 1 - - if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then - # We're on the develop branch, install whichever tornado is on the requirements file - __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" - if [ "${__REQUIRED_TORNADO}" != "" ]; then - /usr/local/sbin/pkg install -y www/py-tornado4 || return 1 - fi - fi - - echodebug "Adapting paths to FreeBSD" - # The list of files was taken from Salt's BSD port Makefile - for file in doc/man/salt-key.1 doc/man/salt-cp.1 doc/man/salt-minion.1 \ - doc/man/salt-syndic.1 doc/man/salt-master.1 doc/man/salt-run.1 \ - doc/man/salt.7 doc/man/salt.1 doc/man/salt-call.1; do - [ ! -f $file ] && continue - echodebug "Patching ${file}" - sed -in -e "s|/etc/salt|${_SALT_ETC_DIR}|" \ - -e "s|/srv/salt|${_SALT_ETC_DIR}/states|" \ - -e "s|/srv/pillar|${_SALT_ETC_DIR}/pillar|" ${file} - done - if [ ! -f salt/syspaths.py ]; then - # We still can't provide the system paths, salt 0.16.x - # Let's patch salt's source and adapt paths to what's expected on FreeBSD - echodebug "Replacing occurrences of '/etc/salt' with ${_SALT_ETC_DIR}" - # The list of files was taken from Salt's BSD port Makefile - for file in conf/minion conf/master salt/config.py salt/client.py \ - salt/modules/mysql.py salt/utils/parsers.py salt/modules/tls.py \ - salt/modules/postgres.py salt/utils/migrations.py; do - [ ! -f $file ] && continue - echodebug "Patching ${file}" - sed -in -e "s|/etc/salt|${_SALT_ETC_DIR}|" \ - -e "s|/srv/salt|${_SALT_ETC_DIR}/states|" \ - -e "s|/srv/pillar|${_SALT_ETC_DIR}/pillar|" ${file} - done - fi - echodebug "Finished patching" - - # Let's trigger config_salt() - if [ "$_TEMP_CONFIG_DIR" = "null" ]; then - _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" - CONFIG_SALT_FUNC="config_salt" - - fi - - return 0 + echo 'do not need to git on FreeBSD salt install' } install_freebsd_9_stable() { - # shellcheck disable=SC2086 - /usr/local/sbin/pkg install ${FROM_SALTSTACK} -y sysutils/py-salt || return 1 + pkg install -y py36-salt return 0 } install_freebsd_10_stable() { - # shellcheck disable=SC2086 - /usr/local/sbin/pkg install ${FROM_FREEBSD} -y sysutils/py-salt || return 1 + pkg install -y py36-salt return 0 } install_freebsd_11_stable() { -# -# installing latest version of salt from FreeBSD CURRENT ports repo -# - # shellcheck disable=SC2086 - /usr/local/sbin/pkg install ${FROM_FREEBSD} -y sysutils/py-salt || return 1 - - return 0 + pkg install -y py36-salt + return 0 } install_freebsd_12_stable() { -# -# installing latest version of salt from FreeBSD CURRENT ports repo -# - # shellcheck disable=SC2086 - /usr/local/sbin/pkg install ${FROM_FREEBSD} -y sysutils/py-salt || return 1 - - return 0 + pkg install -y py36-salt + return 0 } install_freebsd_git() { - - # /usr/local/bin/python2 in FreeBSD is a symlink to /usr/local/bin/python2.7 - __PYTHON_PATH=$(readlink -f "$(command -v python2)") - __ESCAPED_PYTHON_PATH=$(echo "${__PYTHON_PATH}" | sed 's/\//\\\//g') - - # Install from git - if [ ! -f salt/syspaths.py ]; then - # We still can't provide the system paths, salt 0.16.x - ${__PYTHON_PATH} setup.py ${SETUP_PY_INSTALL_ARGS} install || return 1 - else - ${__PYTHON_PATH} setup.py \ - --salt-root-dir=/ \ - --salt-config-dir="${_SALT_ETC_DIR}" \ - --salt-cache-dir="${_SALT_CACHE_DIR}" \ - --salt-sock-dir=/var/run/salt \ - --salt-srv-root-dir="${_SALT_ETC_DIR}" \ - --salt-base-file-roots-dir="${_SALT_ETC_DIR}/states" \ - --salt-base-pillar-roots-dir="${_SALT_ETC_DIR}/pillar" \ - --salt-base-master-roots-dir="${_SALT_ETC_DIR}/salt-master" \ - --salt-logs-dir=/var/log/salt \ - --salt-pidfile-dir=/var/run \ - ${SETUP_PY_INSTALL_ARGS} install \ - || return 1 - fi - - for script in salt_api salt_master salt_minion salt_proxy salt_syndic; do - __fetch_url "/usr/local/etc/rc.d/${script}" "https://raw.githubusercontent.com/freebsd/freebsd-ports/master/sysutils/py-salt/files/${script}.in" || return 1 - sed -i '' 's/%%PREFIX%%/\/usr\/local/g' /usr/local/etc/rc.d/${script} - sed -i '' "s/%%PYTHON_CMD%%/${__ESCAPED_PYTHON_PATH}/g" /usr/local/etc/rc.d/${script} - chmod +x /usr/local/etc/rc.d/${script} || return 1 - done - - # And we're good to go - return 0 + echo 'do not need to git on FreeBSD salt install' + return 0 } install_freebsd_9_stable_post() { @@ -5414,11 +5246,6 @@ install_freebsd_9_stable_post() { enable_string="salt_${fname}_enable=\"YES\"" grep "$enable_string" /etc/rc.conf >/dev/null 2>&1 [ $? -eq 1 ] && echo "$enable_string" >> /etc/rc.conf - - if [ $fname = "minion" ] ; then - grep "salt_minion_paths" /etc/rc.conf >/dev/null 2>&1 - [ $? -eq 1 ] && echo "salt_minion_paths=\"/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin\"" >> /etc/rc.conf - fi done } @@ -5435,15 +5262,13 @@ install_freebsd_12_stable_post() { } install_freebsd_git_post() { - if [ -f $salt_conf_file ]; then - rm -f $salt_conf_file - fi - install_freebsd_9_stable_post || return 1 + echo 'no git post for freebsd' return 0 } install_freebsd_restart_daemons() { [ $_START_DAEMONS -eq $BS_FALSE ] && return + /usr/sbin/sysrc salt_minion_enable="YES" for fname in api master minion syndic; do # Skip salt-api since the service should be opt-in and not necessarily started on boot From d647c0a5647d127e940b008063ca2524696e56a8 Mon Sep 17 00:00:00 2001 From: kgbsd <45101782+kgbsd@users.noreply.github.com> Date: Thu, 31 Oct 2019 18:14:19 -0600 Subject: [PATCH 02/64] Update bootstrap-salt.sh --- bootstrap-salt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 3a3eb2a..c232571 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -239,7 +239,7 @@ _CONFIG_ONLY=$BS_FALSE _PIP_ALLOWED=${BS_PIP_ALLOWED:-$BS_FALSE} _PIP_ALL=${BS_PIP_ALL:-$BS_FALSE} if uname -a | grep FreeBSD > /dev/null; then - SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/usr/local/etc/salt} + _SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/usr/local/etc/salt} else _SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/etc/salt} fi From e45aa3fe76893a8cf8056be808075984cc867b1a Mon Sep 17 00:00:00 2001 From: ch3ll Date: Mon, 4 Nov 2019 13:17:23 -0500 Subject: [PATCH 03/64] Add 2019.11.04 sha and tornado warning --- README.rst | 9 + index.html | 7375 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 7384 insertions(+) create mode 100644 index.html diff --git a/README.rst b/README.rst index 776473c..757645a 100644 --- a/README.rst +++ b/README.rst @@ -28,6 +28,7 @@ sum** of the downloaded ``bootstrap-salt.sh`` file. The SHA256 sum of the ``bootstrap-salt.sh`` file, per release, is: +- 2019.11.04: ``905924fccd4ebf168d19ba598bf10af53efe02302b792aeb15433e73fd3ad1d2`` - 2019.10.03: ``34f196f06d586ce9e1b9907660ea6e67caf57abcecfea66e0343697e3fd0d17d`` - 2019.05.20: ``46fb5e4b7815efafd69fd703f033fe86e7b584b6770f7e0b936995bcae1cedd8`` - 2019.02.27: ``23728e4b5e54f564062070e3be53c5602b55c24c9a76671968abbf3d609258cb`` @@ -207,6 +208,14 @@ Installing the latest develop branch of Salt: curl -L https://bootstrap.saltstack.com | sudo sh -s -- git develop +Tornado 5/6 Workaround +---------------------- +Salt does not support tornado>=5.0 currently. This support will not be added until the neon +release. In order to work around this requirement on OSs that no longer have the tornado 4 package +available in their repositories we are pip installing tornado<5.0 in the bootstrap script. This +requires the user to pass -P to the bootstrap script to ensure tornado is pip installed. If a user +does not pass this argument they will be warned that it is required for the tornado 5 workaround. +So far the OSs that are using this workaround are Debian 10, Centos 8 and Fedora 31. Supported Operating Systems --------------------------- diff --git a/index.html b/index.html new file mode 100644 index 0000000..4e197ab --- /dev/null +++ b/index.html @@ -0,0 +1,7375 @@ +#!/bin/sh - + +# WARNING: Changes to this file in the salt repo will be overwritten! +# Please submit pull requests against the salt-bootstrap repo: +# https://github.com/saltstack/salt-bootstrap + +#====================================================================================================================== +# vim: softtabstop=4 shiftwidth=4 expandtab fenc=utf-8 spell spelllang=en cc=120 +#====================================================================================================================== +# +# FILE: bootstrap-salt.sh +# +# DESCRIPTION: Bootstrap Salt installation for various systems/distributions +# +# BUGS: https://github.com/saltstack/salt-bootstrap/issues +# +# COPYRIGHT: (c) 2012-2018 by the SaltStack Team, see AUTHORS.rst for more +# details. +# +# LICENSE: Apache 2.0 +# ORGANIZATION: SaltStack (saltstack.com) +# CREATED: 10/15/2012 09:49:37 PM WEST +#====================================================================================================================== +set -o nounset # Treat unset variables as an error + +__ScriptVersion="2019.11.04" +__ScriptName="bootstrap-salt.sh" + +__ScriptFullName="$0" +__ScriptArgs="$*" + +#====================================================================================================================== +# Environment variables taken into account. +#---------------------------------------------------------------------------------------------------------------------- +# * BS_COLORS: If 0 disables colour support +# * BS_PIP_ALLOWED: If 1 enable pip based installations(if needed) +# * BS_PIP_ALL: If 1 enable all python packages to be installed via pip instead of apt, requires setting virtualenv +# * BS_VIRTUALENV_DIR: The virtualenv to install salt into (shouldn't exist yet) +# * BS_ECHO_DEBUG: If 1 enable debug echo which can also be set by -D +# * BS_SALT_ETC_DIR: Defaults to /etc/salt (Only tweak'able on git based installations) +# * BS_SALT_CACHE_DIR: Defaults to /var/cache/salt (Only tweak'able on git based installations) +# * BS_KEEP_TEMP_FILES: If 1, don't move temporary files, instead copy them +# * BS_FORCE_OVERWRITE: Force overriding copied files(config, init.d, etc) +# * BS_UPGRADE_SYS: If 1 and an option, upgrade system. Default 0. +# * BS_GENTOO_USE_BINHOST: If 1 add `--getbinpkg` to gentoo's emerge +# * BS_SALT_MASTER_ADDRESS: The IP or DNS name of the salt-master the minion should connect to +# * BS_SALT_GIT_CHECKOUT_DIR: The directory where to clone Salt on git installations +#====================================================================================================================== + + +# Bootstrap script truth values +BS_TRUE=1 +BS_FALSE=0 + +# Default sleep time used when waiting for daemons to start, restart and checking for these running +__DEFAULT_SLEEP=3 + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __detect_color_support +# DESCRIPTION: Try to detect color support. +#---------------------------------------------------------------------------------------------------------------------- +_COLORS=${BS_COLORS:-$(tput colors 2>/dev/null || echo 0)} +__detect_color_support() { + # shellcheck disable=SC2181 + if [ $? -eq 0 ] && [ "$_COLORS" -gt 2 ]; then + RC='\033[1;31m' + GC='\033[1;32m' + BC='\033[1;34m' + YC='\033[1;33m' + EC='\033[0m' + else + RC="" + GC="" + BC="" + YC="" + EC="" + fi +} +__detect_color_support + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: echoerr +# DESCRIPTION: Echo errors to stderr. +#---------------------------------------------------------------------------------------------------------------------- +echoerror() { + printf "${RC} * ERROR${EC}: %s\\n" "$@" 1>&2; +} + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: echoinfo +# DESCRIPTION: Echo information to stdout. +#---------------------------------------------------------------------------------------------------------------------- +echoinfo() { + printf "${GC} * INFO${EC}: %s\\n" "$@"; +} + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: echowarn +# DESCRIPTION: Echo warning information to stdout. +#---------------------------------------------------------------------------------------------------------------------- +echowarn() { + printf "${YC} * WARN${EC}: %s\\n" "$@"; +} + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: echodebug +# DESCRIPTION: Echo debug information to stdout. +#---------------------------------------------------------------------------------------------------------------------- +echodebug() { + if [ "$_ECHO_DEBUG" -eq $BS_TRUE ]; then + printf "${BC} * DEBUG${EC}: %s\\n" "$@"; + fi +} + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __check_command_exists +# DESCRIPTION: Check if a command exists. +#---------------------------------------------------------------------------------------------------------------------- +__check_command_exists() { + command -v "$1" > /dev/null 2>&1 +} + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __check_pip_allowed +# DESCRIPTION: Simple function to let the users know that -P needs to be used. +#---------------------------------------------------------------------------------------------------------------------- +__check_pip_allowed() { + if [ $# -eq 1 ]; then + _PIP_ALLOWED_ERROR_MSG=$1 + else + _PIP_ALLOWED_ERROR_MSG="pip based installations were not allowed. Retry using '-P'" + fi + + if [ "$_PIP_ALLOWED" -eq $BS_FALSE ]; then + echoerror "$_PIP_ALLOWED_ERROR_MSG" + __usage + exit 1 + fi +} + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __check_config_dir +# DESCRIPTION: Checks the config directory, retrieves URLs if provided. +#---------------------------------------------------------------------------------------------------------------------- +__check_config_dir() { + CC_DIR_NAME="$1" + CC_DIR_BASE=$(basename "${CC_DIR_NAME}") + + case "$CC_DIR_NAME" in + http://*|https://*) + __fetch_url "/tmp/${CC_DIR_BASE}" "${CC_DIR_NAME}" + CC_DIR_NAME="/tmp/${CC_DIR_BASE}" + ;; + ftp://*) + __fetch_url "/tmp/${CC_DIR_BASE}" "${CC_DIR_NAME}" + CC_DIR_NAME="/tmp/${CC_DIR_BASE}" + ;; + *://*) + echoerror "Unsupported URI scheme for $CC_DIR_NAME" + echo "null" + return + ;; + *) + if [ ! -e "${CC_DIR_NAME}" ]; then + echoerror "The configuration directory or archive $CC_DIR_NAME does not exist." + echo "null" + return + fi + ;; + esac + + case "$CC_DIR_NAME" in + *.tgz|*.tar.gz) + tar -zxf "${CC_DIR_NAME}" -C /tmp + CC_DIR_BASE=$(basename "${CC_DIR_BASE}" ".tgz") + CC_DIR_BASE=$(basename "${CC_DIR_BASE}" ".tar.gz") + CC_DIR_NAME="/tmp/${CC_DIR_BASE}" + ;; + *.tbz|*.tar.bz2) + tar -xjf "${CC_DIR_NAME}" -C /tmp + CC_DIR_BASE=$(basename "${CC_DIR_BASE}" ".tbz") + CC_DIR_BASE=$(basename "${CC_DIR_BASE}" ".tar.bz2") + CC_DIR_NAME="/tmp/${CC_DIR_BASE}" + ;; + *.txz|*.tar.xz) + tar -xJf "${CC_DIR_NAME}" -C /tmp + CC_DIR_BASE=$(basename "${CC_DIR_BASE}" ".txz") + CC_DIR_BASE=$(basename "${CC_DIR_BASE}" ".tar.xz") + CC_DIR_NAME="/tmp/${CC_DIR_BASE}" + ;; + esac + + echo "${CC_DIR_NAME}" +} + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __check_unparsed_options +# DESCRIPTION: Checks the placed after the install arguments +#---------------------------------------------------------------------------------------------------------------------- +__check_unparsed_options() { + shellopts="$1" + # grep alternative for SunOS + if [ -f /usr/xpg4/bin/grep ]; then + grep='/usr/xpg4/bin/grep' + else + grep='grep' + fi + unparsed_options=$( echo "$shellopts" | ${grep} -E '(^|[[:space:]])[-]+[[:alnum:]]' ) + if [ "$unparsed_options" != "" ]; then + __usage + echo + echoerror "options are only allowed before install arguments" + echo + exit 1 + fi +} + + +#---------------------------------------------------------------------------------------------------------------------- +# Handle command line arguments +#---------------------------------------------------------------------------------------------------------------------- +_KEEP_TEMP_FILES=${BS_KEEP_TEMP_FILES:-$BS_FALSE} +_TEMP_CONFIG_DIR="null" +_SALTSTACK_REPO_URL="https://github.com/saltstack/salt.git" +_SALT_REPO_URL=${_SALTSTACK_REPO_URL} +_DOWNSTREAM_PKG_REPO=$BS_FALSE +_TEMP_KEYS_DIR="null" +_SLEEP="${__DEFAULT_SLEEP}" +_INSTALL_MASTER=$BS_FALSE +_INSTALL_SYNDIC=$BS_FALSE +_INSTALL_MINION=$BS_TRUE +_INSTALL_CLOUD=$BS_FALSE +_VIRTUALENV_DIR=${BS_VIRTUALENV_DIR:-"null"} +_START_DAEMONS=$BS_TRUE +_DISABLE_SALT_CHECKS=$BS_FALSE +_ECHO_DEBUG=${BS_ECHO_DEBUG:-$BS_FALSE} +_CONFIG_ONLY=$BS_FALSE +_PIP_ALLOWED=${BS_PIP_ALLOWED:-$BS_FALSE} +_PIP_ALL=${BS_PIP_ALL:-$BS_FALSE} +_SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/etc/salt} +_SALT_CACHE_DIR=${BS_SALT_CACHE_DIR:-/var/cache/salt} +_PKI_DIR=${_SALT_ETC_DIR}/pki +_FORCE_OVERWRITE=${BS_FORCE_OVERWRITE:-$BS_FALSE} +_GENTOO_USE_BINHOST=${BS_GENTOO_USE_BINHOST:-$BS_FALSE} +_EPEL_REPO=${BS_EPEL_REPO:-epel} +_EPEL_REPOS_INSTALLED=$BS_FALSE +_UPGRADE_SYS=${BS_UPGRADE_SYS:-$BS_FALSE} +_INSECURE_DL=${BS_INSECURE_DL:-$BS_FALSE} +_CURL_ARGS=${BS_CURL_ARGS:-} +_FETCH_ARGS=${BS_FETCH_ARGS:-} +_GPG_ARGS=${BS_GPG_ARGS:-} +_WGET_ARGS=${BS_WGET_ARGS:-} +_SALT_MASTER_ADDRESS=${BS_SALT_MASTER_ADDRESS:-null} +_SALT_MINION_ID="null" +# _SIMPLIFY_VERSION is mostly used in Solaris based distributions +_SIMPLIFY_VERSION=$BS_TRUE +_LIBCLOUD_MIN_VERSION="0.14.0" +_EXTRA_PACKAGES="" +_HTTP_PROXY="" +_SALT_GIT_CHECKOUT_DIR=${BS_SALT_GIT_CHECKOUT_DIR:-/tmp/git/salt} +_NO_DEPS=$BS_FALSE +_FORCE_SHALLOW_CLONE=$BS_FALSE +_DISABLE_SSL=$BS_FALSE +_DISABLE_REPOS=$BS_FALSE +_CUSTOM_REPO_URL="null" +_CUSTOM_MASTER_CONFIG="null" +_CUSTOM_MINION_CONFIG="null" +_QUIET_GIT_INSTALLATION=$BS_FALSE +_REPO_URL="repo.saltstack.com" +_PY_EXE="" +_INSTALL_PY="$BS_FALSE" + +# Defaults for install arguments +ITYPE="stable" + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __usage +# DESCRIPTION: Display usage information. +#---------------------------------------------------------------------------------------------------------------------- +__usage() { + cat << EOT + + Usage : ${__ScriptName} [options] [install-type-args] + + Installation types: + - stable Install latest stable release. This is the default + install type + - stable [branch] Install latest version on a branch. Only supported + for packages available at repo.saltstack.com + - stable [version] Install a specific version. Only supported for + packages available at repo.saltstack.com + - testing RHEL-family specific: configure EPEL testing repo + - git Install from the head of the develop branch + - git [ref] Install from any git ref (such as a branch, tag, or + commit) + + Examples: + - ${__ScriptName} + - ${__ScriptName} stable + - ${__ScriptName} stable 2017.7 + - ${__ScriptName} stable 2017.7.2 + - ${__ScriptName} testing + - ${__ScriptName} git + - ${__ScriptName} git 2017.7 + - ${__ScriptName} git v2017.7.2 + - ${__ScriptName} git 06f249901a2e2f1ed310d58ea3921a129f214358 + + Options: + -h Display this message + -v Display script version + -n No colours + -D Show debug output + -c Temporary configuration directory + -g Salt Git repository URL. Default: ${_SALTSTACK_REPO_URL} + -w Install packages from downstream package repository rather than + upstream, saltstack package repository. This is currently only + implemented for SUSE. + -k Temporary directory holding the minion keys which will pre-seed + the master. + -s Sleep time used when waiting for daemons to start, restart and when + checking for the services running. Default: ${__DEFAULT_SLEEP} + -L Also install salt-cloud and required python-libcloud package + -M Also install salt-master + -S Also install salt-syndic + -N Do not install salt-minion + -X Do not start daemons after installation + -d Disables checking if Salt services are enabled to start on system boot. + You can also do this by touching /tmp/disable_salt_checks on the target + host. Default: \${BS_FALSE} + -P Allow pip based installations. On some distributions the required salt + packages or its dependencies are not available as a package for that + distribution. Using this flag allows the script to use pip as a last + resort method. NOTE: This only works for functions which actually + implement pip based installations. + -U If set, fully upgrade the system prior to bootstrapping Salt + -I If set, allow insecure connections while downloading any files. For + example, pass '--no-check-certificate' to 'wget' or '--insecure' to + 'curl'. On Debian and Ubuntu, using this option with -U allows obtaining + GnuPG archive keys insecurely if distro has changed release signatures. + -F Allow copied files to overwrite existing (config, init.d, etc) + -K If set, keep the temporary files in the temporary directories specified + with -c and -k + -C Only run the configuration function. Implies -F (forced overwrite). + To overwrite Master or Syndic configs, -M or -S, respectively, must + also be specified. Salt installation will be ommitted, but some of the + dependencies could be installed to write configuration with -j or -J. + -A Pass the salt-master DNS name or IP. This will be stored under + \${BS_SALT_ETC_DIR}/minion.d/99-master-address.conf + -i Pass the salt-minion id. This will be stored under + \${BS_SALT_ETC_DIR}/minion_id + -p Extra-package to install while installing Salt dependencies. One package + per -p flag. You are responsible for providing the proper package name. + -H Use the specified HTTP proxy for all download URLs (including https://). + For example: http://myproxy.example.com:3128 + -b Assume that dependencies are already installed and software sources are + set up. If git is selected, git tree is still checked out as dependency + step. + -f Force shallow cloning for git installations. + This may result in an "n/a" in the version number. + -l Disable ssl checks. When passed, switches "https" calls to "http" where + possible. + -V Install Salt into virtualenv + (only available for Ubuntu based distributions) + -a Pip install all Python pkg dependencies for Salt. Requires -V to install + all pip pkgs into the virtualenv. + (Only available for Ubuntu based distributions) + -r Disable all repository configuration performed by this script. This + option assumes all necessary repository configuration is already present + on the system. + -R Specify a custom repository URL. Assumes the custom repository URL + points to a repository that mirrors Salt packages located at + repo.saltstack.com. The option passed with -R replaces the + "repo.saltstack.com". If -R is passed, -r is also set. Currently only + works on CentOS/RHEL and Debian based distributions. + -J Replace the Master config file with data passed in as a JSON string. If + a Master config file is found, a reasonable effort will be made to save + the file with a ".bak" extension. If used in conjunction with -C or -F, + no ".bak" file will be created as either of those options will force + a complete overwrite of the file. + -j Replace the Minion config file with data passed in as a JSON string. If + a Minion config file is found, a reasonable effort will be made to save + the file with a ".bak" extension. If used in conjunction with -C or -F, + no ".bak" file will be created as either of those options will force + a complete overwrite of the file. + -q Quiet salt installation from git (setup.py install -q) + -x Changes the Python version used to install Salt. + For CentOS 6 git installations python2.7 is supported. + Fedora git installation, CentOS 7, Debian 9, Ubuntu 16.04 and 18.04 support python3. + -y Installs a different python version on host. Currently this has only been + tested with CentOS 6 and is considered experimental. This will install the + ius repo on the box if disable repo is false. This must be used in conjunction + with -x . For example: + sh bootstrap.sh -P -y -x python2.7 git v2017.7.2 + The above will install python27 and install the git version of salt using the + python2.7 executable. This only works for git and pip installations. + +EOT +} # ---------- end of function __usage ---------- + + +while getopts ':hvnDc:g:Gyx:wk:s:MSNXCPFUKIA:i:Lp:dH:bflV:J:j:rR:aq' opt +do + case "${opt}" in + + h ) __usage; exit 0 ;; + v ) echo "$0 -- Version $__ScriptVersion"; exit 0 ;; + n ) _COLORS=0; __detect_color_support ;; + D ) _ECHO_DEBUG=$BS_TRUE ;; + c ) _TEMP_CONFIG_DIR="$OPTARG" ;; + g ) _SALT_REPO_URL=$OPTARG ;; + + G ) echowarn "The '-G' option is DEPRECATED and will be removed in the future stable release!" + echowarn "Bootstrap will always use 'https' protocol to clone from SaltStack GitHub repo." + echowarn "No need to provide this option anymore, now it is a default behavior." + ;; + + w ) _DOWNSTREAM_PKG_REPO=$BS_TRUE ;; + k ) _TEMP_KEYS_DIR="$OPTARG" ;; + s ) _SLEEP=$OPTARG ;; + M ) _INSTALL_MASTER=$BS_TRUE ;; + S ) _INSTALL_SYNDIC=$BS_TRUE ;; + N ) _INSTALL_MINION=$BS_FALSE ;; + X ) _START_DAEMONS=$BS_FALSE ;; + C ) _CONFIG_ONLY=$BS_TRUE ;; + P ) _PIP_ALLOWED=$BS_TRUE ;; + F ) _FORCE_OVERWRITE=$BS_TRUE ;; + U ) _UPGRADE_SYS=$BS_TRUE ;; + K ) _KEEP_TEMP_FILES=$BS_TRUE ;; + I ) _INSECURE_DL=$BS_TRUE ;; + A ) _SALT_MASTER_ADDRESS=$OPTARG ;; + i ) _SALT_MINION_ID=$OPTARG ;; + L ) _INSTALL_CLOUD=$BS_TRUE ;; + p ) _EXTRA_PACKAGES="$_EXTRA_PACKAGES $OPTARG" ;; + d ) _DISABLE_SALT_CHECKS=$BS_TRUE ;; + H ) _HTTP_PROXY="$OPTARG" ;; + b ) _NO_DEPS=$BS_TRUE ;; + f ) _FORCE_SHALLOW_CLONE=$BS_TRUE ;; + l ) _DISABLE_SSL=$BS_TRUE ;; + V ) _VIRTUALENV_DIR="$OPTARG" ;; + a ) _PIP_ALL=$BS_TRUE ;; + r ) _DISABLE_REPOS=$BS_TRUE ;; + R ) _CUSTOM_REPO_URL=$OPTARG ;; + J ) _CUSTOM_MASTER_CONFIG=$OPTARG ;; + j ) _CUSTOM_MINION_CONFIG=$OPTARG ;; + q ) _QUIET_GIT_INSTALLATION=$BS_TRUE ;; + x ) _PY_EXE="$OPTARG" ;; + y ) _INSTALL_PY="$BS_TRUE" ;; + + \?) echo + echoerror "Option does not exist : $OPTARG" + __usage + exit 1 + ;; + + esac # --- end of case --- +done +shift $((OPTIND-1)) + + +# Define our logging file and pipe paths +LOGFILE="/tmp/$( echo "$__ScriptName" | sed s/.sh/.log/g )" +LOGPIPE="/tmp/$( echo "$__ScriptName" | sed s/.sh/.logpipe/g )" +# Ensure no residual pipe exists +rm "$LOGPIPE" 2>/dev/null + +# Create our logging pipe +# On FreeBSD we have to use mkfifo instead of mknod +if ! (mknod "$LOGPIPE" p >/dev/null 2>&1 || mkfifo "$LOGPIPE" >/dev/null 2>&1); then + echoerror "Failed to create the named pipe required to log" + exit 1 +fi + +# What ever is written to the logpipe gets written to the logfile +tee < "$LOGPIPE" "$LOGFILE" & + +# Close STDOUT, reopen it directing it to the logpipe +exec 1>&- +exec 1>"$LOGPIPE" +# Close STDERR, reopen it directing it to the logpipe +exec 2>&- +exec 2>"$LOGPIPE" + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __exit_cleanup +# DESCRIPTION: Cleanup any leftovers after script has ended +# +# +# http://www.unix.com/man-page/POSIX/1posix/trap/ +# +# Signal Number Signal Name +# 1 SIGHUP +# 2 SIGINT +# 3 SIGQUIT +# 6 SIGABRT +# 9 SIGKILL +# 14 SIGALRM +# 15 SIGTERM +#---------------------------------------------------------------------------------------------------------------------- +APT_ERR=$(mktemp /tmp/apt_error.XXXXXX) +__exit_cleanup() { + EXIT_CODE=$? + + if [ "$ITYPE" = "git" ] && [ -d "${_SALT_GIT_CHECKOUT_DIR}" ]; then + if [ $_KEEP_TEMP_FILES -eq $BS_FALSE ]; then + # Clean up the checked out repository + echodebug "Cleaning up the Salt Temporary Git Repository" + # shellcheck disable=SC2164 + cd "${__SALT_GIT_CHECKOUT_PARENT_DIR}" + rm -rf "${_SALT_GIT_CHECKOUT_DIR}" + else + echowarn "Not cleaning up the Salt Temporary git repository on request" + echowarn "Note that if you intend to re-run this script using the git approach, you might encounter some issues" + fi + fi + + # Remove the logging pipe when the script exits + if [ -p "$LOGPIPE" ]; then + echodebug "Removing the logging pipe $LOGPIPE" + rm -f "$LOGPIPE" + fi + + # Remove the temporary apt error file when the script exits + if [ -f "$APT_ERR" ]; then + echodebug "Removing the temporary apt error file $APT_ERR" + rm -f "$APT_ERR" + fi + + # Kill tee when exiting, CentOS, at least requires this + # shellcheck disable=SC2009 + TEE_PID=$(ps ax | grep tee | grep "$LOGFILE" | awk '{print $1}') + + [ "$TEE_PID" = "" ] && exit $EXIT_CODE + + echodebug "Killing logging pipe tee's with pid(s): $TEE_PID" + + # We need to trap errors since killing tee will cause a 127 errno + # We also do this as late as possible so we don't "mis-catch" other errors + __trap_errors() { + echoinfo "Errors Trapped: $EXIT_CODE" + # Exit with the "original" exit code, not the trapped code + exit $EXIT_CODE + } + trap "__trap_errors" INT ABRT QUIT TERM + + # Now we're "good" to kill tee + kill -s TERM "$TEE_PID" + + # In case the 127 errno is not triggered, exit with the "original" exit code + exit $EXIT_CODE +} +trap "__exit_cleanup" EXIT INT + + +# Let's discover how we're being called +# shellcheck disable=SC2009 +CALLER=$(ps -a -o pid,args | grep $$ | grep -v grep | tr -s ' ' | cut -d ' ' -f 3) + +if [ "${CALLER}x" = "${0}x" ]; then + CALLER="shell pipe" +fi + +echoinfo "Running version: ${__ScriptVersion}" +echoinfo "Executed by: ${CALLER}" +echoinfo "Command line: '${__ScriptFullName} ${__ScriptArgs}'" +#echowarn "Running the unstable version of ${__ScriptName}" + +# Define installation type +if [ "$#" -gt 0 ];then + __check_unparsed_options "$*" + ITYPE=$1 + shift +fi + +# Check installation type +if [ "$(echo "$ITYPE" | grep -E '(stable|testing|git)')" = "" ]; then + echoerror "Installation type \"$ITYPE\" is not known..." + exit 1 +fi + +# If doing a git install, check what branch/tag/sha will be checked out +if [ "$ITYPE" = "git" ]; then + if [ "$#" -eq 0 ];then + GIT_REV="develop" + else + GIT_REV="$1" + shift + fi + + # Disable shell warning about unbound variable during git install + STABLE_REV="latest" + +# If doing stable install, check if version specified +elif [ "$ITYPE" = "stable" ]; then + if [ "$#" -eq 0 ];then + STABLE_REV="latest" + else + if [ "$(echo "$1" | grep -E '^(latest|1\.6|1\.7|2014\.1|2014\.7|2015\.5|2015\.8|2016\.3|2016\.11|2017\.7|2018\.3|2019\.2)$')" != "" ]; then + STABLE_REV="$1" + shift + elif [ "$(echo "$1" | grep -E '^([0-9]*\.[0-9]*\.[0-9]*)$')" != "" ]; then + if [ "$(uname)" = "Darwin" ]; then + STABLE_REV="$1" + else + STABLE_REV="archive/$1" + fi + shift + else + echo "Unknown stable version: $1 (valid: 1.6, 1.7, 2014.1, 2014.7, 2015.5, 2015.8, 2016.3, 2016.11, 2017.7, 2018.3, 2019.2, latest, \$MAJOR.\$MINOR.\$PATCH)" + exit 1 + fi + fi +fi + +# Check for any unparsed arguments. Should be an error. +if [ "$#" -gt 0 ]; then + __usage + echo + echoerror "Too many arguments." + exit 1 +fi + +# whoami alternative for SunOS +if [ -f /usr/xpg4/bin/id ]; then + whoami='/usr/xpg4/bin/id -un' +else + whoami='whoami' +fi + +# Root permissions are required to run this script +if [ "$($whoami)" != "root" ]; then + echoerror "Salt requires root privileges to install. Please re-run this script as root." + exit 1 +fi + +# Check that we're actually installing one of minion/master/syndic +if [ "$_INSTALL_MINION" -eq $BS_FALSE ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then + echowarn "Nothing to install or configure" + exit 1 +fi + +# Check that we're installing a minion if we're being passed a master address +if [ "$_INSTALL_MINION" -eq $BS_FALSE ] && [ "$_SALT_MASTER_ADDRESS" != "null" ]; then + echoerror "Don't pass a master address (-A) if no minion is going to be bootstrapped." + exit 1 +fi + +# Check that we're installing a minion if we're being passed a minion id +if [ "$_INSTALL_MINION" -eq $BS_FALSE ] && [ "$_SALT_MINION_ID" != "null" ]; then + echoerror "Don't pass a minion id (-i) if no minion is going to be bootstrapped." + exit 1 +fi + +# Check that we're installing or configuring a master if we're being passed a master config json dict +if [ "$_CUSTOM_MASTER_CONFIG" != "null" ]; then + if [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then + echoerror "Don't pass a master config JSON dict (-J) if no master is going to be bootstrapped or configured." + exit 1 + fi +fi + +# Check that we're installing or configuring a minion if we're being passed a minion config json dict +if [ "$_CUSTOM_MINION_CONFIG" != "null" ]; then + if [ "$_INSTALL_MINION" -eq $BS_FALSE ] && [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then + echoerror "Don't pass a minion config JSON dict (-j) if no minion is going to be bootstrapped or configured." + exit 1 + fi +fi + +# Check if we're installing via a different Python executable and set major version variables +if [ -n "$_PY_EXE" ]; then + if [ "$(uname)" = "Darwin" ]; then + _PY_PKG_VER=$(echo "$_PY_EXE" | sed "s/\\.//g") + else + _PY_PKG_VER=$(echo "$_PY_EXE" | sed -r "s/\\.//g") + fi + + _PY_MAJOR_VERSION=$(echo "$_PY_PKG_VER" | cut -c 7) + if [ "$_PY_MAJOR_VERSION" != 3 ] && [ "$_PY_MAJOR_VERSION" != 2 ]; then + echoerror "Detected -x option, but Python major version is not 2 or 3." + echoerror "The -x option must be passed as python2, python27, or python2.7 (or use the Python '3' versions of examples)." + exit 1 + fi + + echoinfo "Detected -x option. Using $_PY_EXE to install Salt." +else + _PY_PKG_VER="" +fi + +# If the configuration directory or archive does not exist, error out +if [ "$_TEMP_CONFIG_DIR" != "null" ]; then + _TEMP_CONFIG_DIR="$(__check_config_dir "$_TEMP_CONFIG_DIR")" + [ "$_TEMP_CONFIG_DIR" = "null" ] && exit 1 +fi + +# If the pre-seed keys directory does not exist, error out +if [ "$_TEMP_KEYS_DIR" != "null" ] && [ ! -d "$_TEMP_KEYS_DIR" ]; then + echoerror "The pre-seed keys directory ${_TEMP_KEYS_DIR} does not exist." + exit 1 +fi + +# -a and -V only work from git +if [ "$ITYPE" != "git" ]; then + if [ $_PIP_ALL -eq $BS_TRUE ]; then + echoerror "Pip installing all python packages with -a is only possible when installing Salt via git" + exit 1 + fi + if [ "$_VIRTUALENV_DIR" != "null" ]; then + echoerror "Virtualenv installs via -V is only possible when installing Salt via git" + exit 1 + fi +fi + +# Set the _REPO_URL value based on if -R was passed or not. Defaults to repo.saltstack.com. +if [ "$_CUSTOM_REPO_URL" != "null" ]; then + _REPO_URL="$_CUSTOM_REPO_URL" + + # Check for -r since -R is being passed. Set -r with a warning. + if [ "$_DISABLE_REPOS" -eq $BS_FALSE ]; then + echowarn "Detected -R option. No other repositories will be configured when -R is used. Setting -r option to True." + _DISABLE_REPOS=$BS_TRUE + fi +fi + +# Check the _DISABLE_SSL value and set HTTP or HTTPS. +if [ "$_DISABLE_SSL" -eq $BS_TRUE ]; then + HTTP_VAL="http" +else + HTTP_VAL="https" +fi + +# Check the _QUIET_GIT_INSTALLATION value and set SETUP_PY_INSTALL_ARGS. +if [ "$_QUIET_GIT_INSTALLATION" -eq $BS_TRUE ]; then + SETUP_PY_INSTALL_ARGS="-q" +else + SETUP_PY_INSTALL_ARGS="" +fi + +# Handle the insecure flags +if [ "$_INSECURE_DL" -eq $BS_TRUE ]; then + _CURL_ARGS="${_CURL_ARGS} --insecure" + _FETCH_ARGS="${_FETCH_ARGS} --no-verify-peer" + _GPG_ARGS="${_GPG_ARGS} --keyserver-options no-check-cert" + _WGET_ARGS="${_WGET_ARGS} --no-check-certificate" +else + _GPG_ARGS="${_GPG_ARGS} --keyserver-options ca-cert-file=/etc/ssl/certs/ca-certificates.crt" +fi + +# Export the http_proxy configuration to our current environment +if [ "${_HTTP_PROXY}" != "" ]; then + export http_proxy="${_HTTP_PROXY}" + export https_proxy="${_HTTP_PROXY}" + # Using "deprecated" option here, but that appears the only way to make it work. + # See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=818802 + # and https://bugs.launchpad.net/ubuntu/+source/gnupg2/+bug/1625848 + _GPG_ARGS="${_GPG_ARGS},http-proxy=${_HTTP_PROXY}" +fi + +# Work around for 'Docker + salt-bootstrap failure' https://github.com/saltstack/salt-bootstrap/issues/394 +if [ "${_DISABLE_SALT_CHECKS}" -eq $BS_FALSE ] && [ -f /tmp/disable_salt_checks ]; then + # shellcheck disable=SC2016 + echowarn 'Found file: /tmp/disable_salt_checks, setting _DISABLE_SALT_CHECKS=$BS_TRUE' + _DISABLE_SALT_CHECKS=$BS_TRUE +fi + +# Because -a can only be installed into virtualenv +if [ "${_PIP_ALL}" -eq $BS_TRUE ] && [ "${_VIRTUALENV_DIR}" = "null" ]; then + usage + # Could possibly set up a default virtualenv location when -a flag is passed + echoerror "Using -a requires -V because pip pkgs should be siloed from python system pkgs" + exit 1 +fi + +# Make sure virtualenv directory does not already exist +if [ -d "${_VIRTUALENV_DIR}" ]; then + echoerror "The directory ${_VIRTUALENV_DIR} for virtualenv already exists" + exit 1 +fi + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __fetch_url +# DESCRIPTION: Retrieves a URL and writes it to a given path +#---------------------------------------------------------------------------------------------------------------------- +__fetch_url() { + # shellcheck disable=SC2086 + curl $_CURL_ARGS -L -s -o "$1" "$2" >/dev/null 2>&1 || + wget $_WGET_ARGS -q -O "$1" "$2" >/dev/null 2>&1 || + fetch $_FETCH_ARGS -q -o "$1" "$2" >/dev/null 2>&1 || # FreeBSD + fetch -q -o "$1" "$2" >/dev/null 2>&1 || # Pre FreeBSD 10 + ftp -o "$1" "$2" >/dev/null 2>&1 # OpenBSD +} + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __fetch_verify +# DESCRIPTION: Retrieves a URL, verifies its content and writes it to standard output +#---------------------------------------------------------------------------------------------------------------------- +__fetch_verify() { + fetch_verify_url="$1" + fetch_verify_sum="$2" + fetch_verify_size="$3" + + fetch_verify_tmpf=$(mktemp) && \ + __fetch_url "$fetch_verify_tmpf" "$fetch_verify_url" && \ + test "$(stat --format=%s "$fetch_verify_tmpf")" -eq "$fetch_verify_size" && \ + test "$(md5sum "$fetch_verify_tmpf" | awk '{ print $1 }')" = "$fetch_verify_sum" && \ + cat "$fetch_verify_tmpf" && \ + if rm -f "$fetch_verify_tmpf"; then + return 0 + fi + echo "Failed verification of $fetch_verify_url" + return 1 +} + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __gather_hardware_info +# DESCRIPTION: Discover hardware information +#---------------------------------------------------------------------------------------------------------------------- +__gather_hardware_info() { + if [ -f /proc/cpuinfo ]; then + CPU_VENDOR_ID=$(awk '/vendor_id|Processor/ {sub(/-.*$/,"",$3); print $3; exit}' /proc/cpuinfo ) + elif [ -f /usr/bin/kstat ]; then + # SmartOS. + # Solaris!? + # This has only been tested for a GenuineIntel CPU + CPU_VENDOR_ID=$(/usr/bin/kstat -p cpu_info:0:cpu_info0:vendor_id | awk '{print $2}') + else + CPU_VENDOR_ID=$( sysctl -n hw.model ) + fi + # shellcheck disable=SC2034 + CPU_VENDOR_ID_L=$( echo "$CPU_VENDOR_ID" | tr '[:upper:]' '[:lower:]' ) + CPU_ARCH=$(uname -m 2>/dev/null || uname -p 2>/dev/null || echo "unknown") + CPU_ARCH_L=$( echo "$CPU_ARCH" | tr '[:upper:]' '[:lower:]' ) +} +__gather_hardware_info + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __gather_os_info +# DESCRIPTION: Discover operating system information +#---------------------------------------------------------------------------------------------------------------------- +__gather_os_info() { + OS_NAME=$(uname -s 2>/dev/null) + OS_NAME_L=$( echo "$OS_NAME" | tr '[:upper:]' '[:lower:]' ) + OS_VERSION=$(uname -r) + # shellcheck disable=SC2034 + OS_VERSION_L=$( echo "$OS_VERSION" | tr '[:upper:]' '[:lower:]' ) +} +__gather_os_info + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __parse_version_string +# DESCRIPTION: Parse version strings ignoring the revision. +# MAJOR.MINOR.REVISION becomes MAJOR.MINOR +#---------------------------------------------------------------------------------------------------------------------- +__parse_version_string() { + VERSION_STRING="$1" + PARSED_VERSION=$( + echo "$VERSION_STRING" | + sed -e 's/^/#/' \ + -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\)\(\.[0-9][0-9]*\).*$/\1/' \ + -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \ + -e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \ + -e 's/^#.*$//' + ) + echo "$PARSED_VERSION" +} + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __derive_debian_numeric_version +# DESCRIPTION: Derive the numeric version from a Debian version string. +#---------------------------------------------------------------------------------------------------------------------- +__derive_debian_numeric_version() { + NUMERIC_VERSION="" + INPUT_VERSION="$1" + if echo "$INPUT_VERSION" | grep -q '^[0-9]'; then + NUMERIC_VERSION="$INPUT_VERSION" + elif [ -z "$INPUT_VERSION" ] && [ -f "/etc/debian_version" ]; then + INPUT_VERSION="$(cat /etc/debian_version)" + fi + if [ -z "$NUMERIC_VERSION" ]; then + if [ "$INPUT_VERSION" = "wheezy/sid" ]; then + # I've found an EC2 wheezy image which did not tell its version + NUMERIC_VERSION=$(__parse_version_string "7.0") + elif [ "$INPUT_VERSION" = "jessie/sid" ]; then + NUMERIC_VERSION=$(__parse_version_string "8.0") + elif [ "$INPUT_VERSION" = "stretch/sid" ]; then + NUMERIC_VERSION=$(__parse_version_string "9.0") + elif [ "$INPUT_VERSION" = "buster/sid" ]; then + NUMERIC_VERSION=$(__parse_version_string "10.0") + else + echowarn "Unable to parse the Debian Version (codename: '$INPUT_VERSION')" + fi + fi + echo "$NUMERIC_VERSION" +} + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __unquote_string +# DESCRIPTION: Strip single or double quotes from the provided string. +#---------------------------------------------------------------------------------------------------------------------- +__unquote_string() { + # shellcheck disable=SC1117 + echo "$*" | sed -e "s/^\([\"\']\)\(.*\)\1\$/\2/g" +} + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __camelcase_split +# DESCRIPTION: Convert 'CamelCased' strings to 'Camel Cased' +#---------------------------------------------------------------------------------------------------------------------- +__camelcase_split() { + echo "$*" | sed -e 's/\([^[:upper:][:punct:]]\)\([[:upper:]]\)/\1 \2/g' +} + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __strip_duplicates +# DESCRIPTION: Strip duplicate strings +#---------------------------------------------------------------------------------------------------------------------- +__strip_duplicates() { + echo "$*" | tr -s '[:space:]' '\n' | awk '!x[$0]++' +} + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __sort_release_files +# DESCRIPTION: Custom sort function. Alphabetical or numerical sort is not +# enough. +#---------------------------------------------------------------------------------------------------------------------- +__sort_release_files() { + KNOWN_RELEASE_FILES=$(echo "(arch|alpine|centos|debian|ubuntu|fedora|redhat|suse|\ + mandrake|mandriva|gentoo|slackware|turbolinux|unitedlinux|void|lsb|system|\ + oracle|os)(-|_)(release|version)" | sed -r 's:[[:space:]]::g') + primary_release_files="" + secondary_release_files="" + # Sort know VS un-known files first + for release_file in $(echo "${@}" | sed -r 's:[[:space:]]:\n:g' | sort -f | uniq); do + match=$(echo "$release_file" | grep -E -i "${KNOWN_RELEASE_FILES}") + if [ "${match}" != "" ]; then + primary_release_files="${primary_release_files} ${release_file}" + else + secondary_release_files="${secondary_release_files} ${release_file}" + fi + done + + # Now let's sort by know files importance, max important goes last in the max_prio list + max_prio="redhat-release centos-release oracle-release fedora-release" + for entry in $max_prio; do + if [ "$(echo "${primary_release_files}" | grep "$entry")" != "" ]; then + primary_release_files=$(echo "${primary_release_files}" | sed -e "s:\\(.*\\)\\($entry\\)\\(.*\\):\\2 \\1 \\3:g") + fi + done + # Now, least important goes last in the min_prio list + min_prio="lsb-release" + for entry in $min_prio; do + if [ "$(echo "${primary_release_files}" | grep "$entry")" != "" ]; then + primary_release_files=$(echo "${primary_release_files}" | sed -e "s:\\(.*\\)\\($entry\\)\\(.*\\):\\1 \\3 \\2:g") + fi + done + + # Echo the results collapsing multiple white-space into a single white-space + echo "${primary_release_files} ${secondary_release_files}" | sed -r 's:[[:space:]]+:\n:g' +} + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __gather_linux_system_info +# DESCRIPTION: Discover Linux system information +#---------------------------------------------------------------------------------------------------------------------- +__gather_linux_system_info() { + DISTRO_NAME="" + DISTRO_VERSION="" + + # Let's test if the lsb_release binary is available + rv=$(lsb_release >/dev/null 2>&1) + + # shellcheck disable=SC2181 + if [ $? -eq 0 ]; then + DISTRO_NAME=$(lsb_release -si) + if [ "${DISTRO_NAME}" = "Scientific" ]; then + DISTRO_NAME="Scientific Linux" + elif [ "$(echo "$DISTRO_NAME" | grep ^CloudLinux)" != "" ]; then + DISTRO_NAME="Cloud Linux" + elif [ "$(echo "$DISTRO_NAME" | grep ^RedHat)" != "" ]; then + # Let's convert 'CamelCased' to 'Camel Cased' + n=$(__camelcase_split "$DISTRO_NAME") + # Skip setting DISTRO_NAME this time, splitting CamelCase has failed. + # See https://github.com/saltstack/salt-bootstrap/issues/918 + [ "$n" = "$DISTRO_NAME" ] && DISTRO_NAME="" || DISTRO_NAME="$n" + elif [ "${DISTRO_NAME}" = "openSUSE project" ]; then + # lsb_release -si returns "openSUSE project" on openSUSE 12.3 + # lsb_release -si returns "openSUSE" on openSUSE 15.n + DISTRO_NAME="opensuse" + elif [ "${DISTRO_NAME}" = "SUSE LINUX" ]; then + if [ "$(lsb_release -sd | grep -i opensuse)" != "" ]; then + # openSUSE 12.2 reports SUSE LINUX on lsb_release -si + DISTRO_NAME="opensuse" + else + # lsb_release -si returns "SUSE LINUX" on SLES 11 SP3 + DISTRO_NAME="suse" + fi + elif [ "${DISTRO_NAME}" = "EnterpriseEnterpriseServer" ]; then + # This the Oracle Linux Enterprise ID before ORACLE LINUX 5 UPDATE 3 + DISTRO_NAME="Oracle Linux" + elif [ "${DISTRO_NAME}" = "OracleServer" ]; then + # This the Oracle Linux Server 6.5 + DISTRO_NAME="Oracle Linux" + elif [ "${DISTRO_NAME}" = "AmazonAMI" ] || [ "${DISTRO_NAME}" = "Amazon" ]; then + DISTRO_NAME="Amazon Linux AMI" + elif [ "${DISTRO_NAME}" = "ManjaroLinux" ]; then + DISTRO_NAME="Arch Linux" + elif [ "${DISTRO_NAME}" = "Arch" ]; then + DISTRO_NAME="Arch Linux" + return + fi + rv=$(lsb_release -sr) + [ "${rv}" != "" ] && DISTRO_VERSION=$(__parse_version_string "$rv") + elif [ -f /etc/lsb-release ]; then + # We don't have the lsb_release binary, though, we do have the file it parses + DISTRO_NAME=$(grep DISTRIB_ID /etc/lsb-release | sed -e 's/.*=//') + rv=$(grep DISTRIB_RELEASE /etc/lsb-release | sed -e 's/.*=//') + [ "${rv}" != "" ] && DISTRO_VERSION=$(__parse_version_string "$rv") + fi + + if [ "$DISTRO_NAME" != "" ] && [ "$DISTRO_VERSION" != "" ]; then + # We already have the distribution name and version + return + fi + # shellcheck disable=SC2035,SC2086 + for rsource in $(__sort_release_files "$( + cd /etc && /bin/ls *[_-]release *[_-]version 2>/dev/null | env -i sort | \ + sed -e '/^redhat-release$/d' -e '/^lsb-release$/d'; \ + echo redhat-release lsb-release + )"); do + + [ ! -f "/etc/${rsource}" ] && continue # Does not exist + + n=$(echo "${rsource}" | sed -e 's/[_-]release$//' -e 's/[_-]version$//') + shortname=$(echo "${n}" | tr '[:upper:]' '[:lower:]') + if [ "$shortname" = "debian" ]; then + rv=$(__derive_debian_numeric_version "$(cat /etc/${rsource})") + else + rv=$( (grep VERSION "/etc/${rsource}"; cat "/etc/${rsource}") | grep '[0-9]' | sed -e 'q' ) + fi + [ "${rv}" = "" ] && [ "$shortname" != "arch" ] && continue # There's no version information. Continue to next rsource + v=$(__parse_version_string "$rv") + case $shortname in + redhat ) + if [ "$(grep -E 'CentOS' /etc/${rsource})" != "" ]; then + n="CentOS" + elif [ "$(grep -E 'Scientific' /etc/${rsource})" != "" ]; then + n="Scientific Linux" + elif [ "$(grep -E 'Red Hat Enterprise Linux' /etc/${rsource})" != "" ]; then + n="ed at nterprise inux" + else + n="ed at inux" + fi + ;; + arch ) n="Arch Linux" ;; + alpine ) n="Alpine Linux" ;; + centos ) n="CentOS" ;; + debian ) n="Debian" ;; + ubuntu ) n="Ubuntu" ;; + fedora ) n="Fedora" ;; + suse|opensuse ) n="SUSE" ;; + mandrake*|mandriva ) n="Mandriva" ;; + gentoo ) n="Gentoo" ;; + slackware ) n="Slackware" ;; + turbolinux ) n="TurboLinux" ;; + unitedlinux ) n="UnitedLinux" ;; + void ) n="VoidLinux" ;; + oracle ) n="Oracle Linux" ;; + system ) + while read -r line; do + [ "${n}x" != "systemx" ] && break + case "$line" in + *Amazon*Linux*AMI*) + n="Amazon Linux AMI" + break + esac + done < "/etc/${rsource}" + ;; + os ) + nn="$(__unquote_string "$(grep '^ID=' /etc/os-release | sed -e 's/^ID=\(.*\)$/\1/g')")" + rv="$(__unquote_string "$(grep '^VERSION_ID=' /etc/os-release | sed -e 's/^VERSION_ID=\(.*\)$/\1/g')")" + [ "${rv}" != "" ] && v=$(__parse_version_string "$rv") || v="" + case $(echo "${nn}" | tr '[:upper:]' '[:lower:]') in + alpine ) + n="Alpine Linux" + v="${rv}" + ;; + amzn ) + # Amazon AMI's after 2014.09 match here + n="Amazon Linux AMI" + ;; + arch ) + n="Arch Linux" + v="" # Arch Linux does not provide a version. + ;; + cloudlinux ) + n="Cloud Linux" + ;; + debian ) + n="Debian" + v=$(__derive_debian_numeric_version "$v") + ;; + sles ) + n="SUSE" + v="${rv}" + ;; + opensuse-leap ) + n="opensuse" + v="${rv}" + ;; + * ) + n=${nn} + ;; + esac + ;; + * ) n="${n}" ; + esac + DISTRO_NAME=$n + DISTRO_VERSION=$v + break + done +} + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __install_python() +# DESCRIPTION: Install a different version of python on a host. Currently this has only been tested on CentOS 6 and +# is considered experimental. +#---------------------------------------------------------------------------------------------------------------------- +__install_python() { + if [ "$_PY_EXE" = "" ]; then + echoerror "Must specify -x with -y to install a specific python version" + exit 1 + fi + + __PACKAGES="$_PY_PKG_VER" + + if [ ${_DISABLE_REPOS} -eq ${BS_FALSE} ]; then + echoinfo "Attempting to install a repo to help provide a separate python package" + echoinfo "$DISTRO_NAME_L" + case "$DISTRO_NAME_L" in + "red_hat"|"centos") + __PYTHON_REPO_URL="https://centos${DISTRO_MAJOR_VERSION}.iuscommunity.org/ius-release.rpm" + ;; + *) + echoerror "Installing a repo to provide a python package is only supported on Redhat/CentOS. + If a repo is already available, please try running script with -r." + exit 1 + ;; + esac + + echoinfo "Installing IUS repo" + __yum_install_noinput "${__PYTHON_REPO_URL}" || return 1 + fi + + echoinfo "Installing ${__PACKAGES}" + __yum_install_noinput "${__PACKAGES}" || return 1 +} + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __gather_sunos_system_info +# DESCRIPTION: Discover SunOS system info +#---------------------------------------------------------------------------------------------------------------------- +__gather_sunos_system_info() { + if [ -f /sbin/uname ]; then + DISTRO_VERSION=$(/sbin/uname -X | awk '/[kK][eE][rR][nN][eE][lL][iI][dD]/ { print $3 }') + fi + + DISTRO_NAME="" + if [ -f /etc/release ]; then + while read -r line; do + [ "${DISTRO_NAME}" != "" ] && break + case "$line" in + *OpenIndiana*oi_[0-9]*) + DISTRO_NAME="OpenIndiana" + DISTRO_VERSION=$(echo "$line" | sed -nr "s/OpenIndiana(.*)oi_([[:digit:]]+)(.*)/\\2/p") + break + ;; + *OpenSolaris*snv_[0-9]*) + DISTRO_NAME="OpenSolaris" + DISTRO_VERSION=$(echo "$line" | sed -nr "s/OpenSolaris(.*)snv_([[:digit:]]+)(.*)/\\2/p") + break + ;; + *Oracle*Solaris*[0-9]*) + DISTRO_NAME="Oracle Solaris" + DISTRO_VERSION=$(echo "$line" | sed -nr "s/(Oracle Solaris) ([[:digit:]]+)(.*)/\\2/p") + break + ;; + *Solaris*) + DISTRO_NAME="Solaris" + # Let's make sure we not actually on a Joyent's SmartOS VM since some releases + # don't have SmartOS in `/etc/release`, only `Solaris` + if uname -v | grep joyent >/dev/null 2>&1; then + DISTRO_NAME="SmartOS" + fi + break + ;; + *NexentaCore*) + DISTRO_NAME="Nexenta Core" + break + ;; + *SmartOS*) + DISTRO_NAME="SmartOS" + break + ;; + *OmniOS*) + DISTRO_NAME="OmniOS" + DISTRO_VERSION=$(echo "$line" | awk '{print $3}') + _SIMPLIFY_VERSION=$BS_FALSE + break + ;; + esac + done < /etc/release + fi + + if [ "${DISTRO_NAME}" = "" ]; then + DISTRO_NAME="Solaris" + DISTRO_VERSION=$( + echo "${OS_VERSION}" | + sed -e 's;^4\.;1.;' \ + -e 's;^5\.\([0-6]\)[^0-9]*$;2.\1;' \ + -e 's;^5\.\([0-9][0-9]*\).*;\1;' + ) + fi + + if [ "${DISTRO_NAME}" = "SmartOS" ]; then + VIRTUAL_TYPE="smartmachine" + if [ "$(zonename)" = "global" ]; then + VIRTUAL_TYPE="global" + fi + fi +} + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __gather_bsd_system_info +# DESCRIPTION: Discover OpenBSD, NetBSD and FreeBSD systems information +#---------------------------------------------------------------------------------------------------------------------- +__gather_bsd_system_info() { + DISTRO_NAME=${OS_NAME} + DISTRO_VERSION=$(echo "${OS_VERSION}" | sed -e 's;[()];;' -e 's/-.*$//') +} + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __gather_osx_system_info +# DESCRIPTION: Discover MacOS X +#---------------------------------------------------------------------------------------------------------------------- +__gather_osx_system_info() { + DISTRO_NAME="MacOSX" + DISTRO_VERSION=$(sw_vers -productVersion) +} + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __gather_system_info +# DESCRIPTION: Discover which system and distribution we are running. +#---------------------------------------------------------------------------------------------------------------------- +__gather_system_info() { + case ${OS_NAME_L} in + linux ) + __gather_linux_system_info + ;; + sunos ) + __gather_sunos_system_info + ;; + openbsd|freebsd|netbsd ) + __gather_bsd_system_info + ;; + darwin ) + __gather_osx_system_info + ;; + * ) + echoerror "${OS_NAME} not supported."; + exit 1 + ;; + esac + +} + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __ubuntu_derivatives_translation +# DESCRIPTION: Map Ubuntu derivatives to their Ubuntu base versions. +# If distro has a known Ubuntu base version, use those install +# functions by pretending to be Ubuntu (i.e. change global vars) +#---------------------------------------------------------------------------------------------------------------------- +# shellcheck disable=SC2034 +__ubuntu_derivatives_translation() { + UBUNTU_DERIVATIVES="(trisquel|linuxmint|linaro|elementary_os|neon)" + # Mappings + trisquel_6_ubuntu_base="12.04" + linuxmint_13_ubuntu_base="12.04" + linuxmint_17_ubuntu_base="14.04" + linuxmint_18_ubuntu_base="16.04" + linuxmint_19_ubuntu_base="18.04" + linaro_12_ubuntu_base="12.04" + elementary_os_02_ubuntu_base="12.04" + neon_16_ubuntu_base="16.04" + + # Translate Ubuntu derivatives to their base Ubuntu version + match=$(echo "$DISTRO_NAME_L" | grep -E ${UBUNTU_DERIVATIVES}) + + if [ "${match}" != "" ]; then + case $match in + "elementary_os") + _major=$(echo "$DISTRO_VERSION" | sed 's/\.//g') + ;; + "linuxmint") + export LSB_ETC_LSB_RELEASE=/etc/upstream-release/lsb-release + _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') + ;; + *) + _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') + ;; + esac + + _ubuntu_version=$(eval echo "\$${match}_${_major}_ubuntu_base") + + if [ "$_ubuntu_version" != "" ]; then + echodebug "Detected Ubuntu $_ubuntu_version derivative" + DISTRO_NAME_L="ubuntu" + DISTRO_VERSION="$_ubuntu_version" + fi + fi +} + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __check_dpkg_architecture +# DESCRIPTION: Determine the primary architecture for packages to install on Debian and derivatives +# and issue all necessary error messages. +#---------------------------------------------------------------------------------------------------------------------- +__check_dpkg_architecture() { + if __check_command_exists dpkg; then + DPKG_ARCHITECTURE="$(dpkg --print-architecture)" + else + echoerror "dpkg: command not found." + return 1 + fi + + __REPO_ARCH="$DPKG_ARCHITECTURE" + __REPO_ARCH_DEB='deb' + __return_code=0 + + case $DPKG_ARCHITECTURE in + "i386") + error_msg="$_REPO_URL likely doesn't have all required 32-bit packages for $DISTRO_NAME $DISTRO_MAJOR_VERSION." + # amd64 is just a part of repository URI, 32-bit pkgs are hosted under the same location + __REPO_ARCH="amd64" + ;; + "amd64") + error_msg="" + ;; + "arm64") + if [ "$_CUSTOM_REPO_URL" != "null" ]; then + warn_msg="Support for arm64 is experimental, make sure the custom repository used has the expected structure and contents." + else + # Saltstack official repository does not yet have arm64 metadata, + # use amd64 repositories on arm64, since all pkgs are arch-independent + __REPO_ARCH="amd64" + __REPO_ARCH_DEB="deb [arch=$__REPO_ARCH]" + warn_msg="Support for arm64 packages is experimental and might rely on architecture-independent packages from the amd64 repository." + fi + error_msg="" + ;; + "armhf") + if [ "$DISTRO_NAME_L" = "ubuntu" ] || [ "$DISTRO_MAJOR_VERSION" -lt 8 ]; then + error_msg="Support for armhf packages at $_REPO_URL is limited to Debian/Raspbian 8 platforms." + __return_code=1 + else + error_msg="" + fi + ;; + *) + error_msg="$_REPO_URL doesn't have packages for your system architecture: $DPKG_ARCHITECTURE." + __return_code=1 + ;; + esac + + if [ "${warn_msg:-}" != "" ]; then + # AArch64: Do not fail at this point, but warn the user about experimental support + # See https://github.com/saltstack/salt-bootstrap/issues/1240 + echowarn "${warn_msg}" + fi + if [ "${error_msg}" != "" ]; then + echoerror "${error_msg}" + if [ "$ITYPE" != "git" ]; then + echoerror "You can try git installation mode, i.e.: sh ${__ScriptName} git v2017.7.2." + echoerror "It may be necessary to use git installation mode with pip and disable the SaltStack apt repository." + echoerror "For example:" + echoerror " sh ${__ScriptName} -r -P git v2017.7.2" + fi + fi + + if [ "${__return_code}" -eq 0 ]; then + return 0 + else + return 1 + fi +} + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __ubuntu_codename_translation +# DESCRIPTION: Map Ubuntu major versions to their corresponding codenames +#---------------------------------------------------------------------------------------------------------------------- +# shellcheck disable=SC2034 +__ubuntu_codename_translation() { + case $DISTRO_MINOR_VERSION in + "04") + _april="yes" + ;; + "10") + _april="" + ;; + *) + _april="yes" + ;; + esac + + case $DISTRO_MAJOR_VERSION in + "12") + DISTRO_CODENAME="precise" + ;; + "14") + DISTRO_CODENAME="trusty" + ;; + "16") + DISTRO_CODENAME="xenial" + ;; + "18") + DISTRO_CODENAME="bionic" + ;; + *) + DISTRO_CODENAME="trusty" + ;; + esac +} + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __debian_derivatives_translation +# DESCRIPTION: Map Debian derivatives to their Debian base versions. +# If distro has a known Debian base version, use those install +# functions by pretending to be Debian (i.e. change global vars) +#---------------------------------------------------------------------------------------------------------------------- +# shellcheck disable=SC2034 +__debian_derivatives_translation() { + # If the file does not exist, return + [ ! -f /etc/os-release ] && return + + DEBIAN_DERIVATIVES="(cumulus_.+|devuan|kali|linuxmint|raspbian|bunsenlabs|turnkey)" + # Mappings + cumulus_2_debian_base="7.0" + cumulus_3_debian_base="8.0" + devuan_1_debian_base="8.0" + devuan_2_debian_base="9.0" + kali_1_debian_base="7.0" + linuxmint_1_debian_base="8.0" + raspbian_8_debian_base="8.0" + raspbian_9_debian_base="9.0" + raspbian_10_debian_base="10.0" + bunsenlabs_9_debian_base="9.0" + turnkey_9_debian_base="9.0" + + # Translate Debian derivatives to their base Debian version + match=$(echo "$DISTRO_NAME_L" | grep -E ${DEBIAN_DERIVATIVES}) + + if [ "${match}" != "" ]; then + case $match in + cumulus_*) + _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') + _debian_derivative="cumulus" + ;; + devuan) + _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') + _debian_derivative="devuan" + ;; + kali) + _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') + _debian_derivative="kali" + ;; + linuxmint) + _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') + _debian_derivative="linuxmint" + ;; + raspbian) + _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') + _debian_derivative="raspbian" + ;; + bunsenlabs) + _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') + _debian_derivative="bunsenlabs" + ;; + turnkey) + _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') + _debian_derivative="turnkey" + ;; + esac + + _debian_version=$(eval echo "\$${_debian_derivative}_${_major}_debian_base" 2>/dev/null) + + if [ "$_debian_version" != "" ]; then + echodebug "Detected Debian $_debian_version derivative" + DISTRO_NAME_L="debian" + DISTRO_VERSION="$_debian_version" + DISTRO_MAJOR_VERSION="$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g')" + fi + fi +} + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __debian_codename_translation +# DESCRIPTION: Map Debian major versions to their corresponding code names +#---------------------------------------------------------------------------------------------------------------------- +# shellcheck disable=SC2034 +__debian_codename_translation() { + + case $DISTRO_MAJOR_VERSION in + "7") + DISTRO_CODENAME="wheezy" + ;; + "8") + DISTRO_CODENAME="jessie" + ;; + "9") + DISTRO_CODENAME="stretch" + ;; + "10") + DISTRO_CODENAME="buster" + ;; + *) + DISTRO_CODENAME="jessie" + ;; + esac +} + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __check_end_of_life_versions +# DESCRIPTION: Check for end of life distribution versions +#---------------------------------------------------------------------------------------------------------------------- +__check_end_of_life_versions() { + case "${DISTRO_NAME_L}" in + debian) + # Debian versions below 7 are not supported + if [ "$DISTRO_MAJOR_VERSION" -lt 7 ]; then + echoerror "End of life distributions are not supported." + echoerror "Please consider upgrading to the next stable. See:" + echoerror " https://wiki.debian.org/DebianReleases" + exit 1 + fi + ;; + + ubuntu) + # Ubuntu versions not supported + # + # < 14.04 + # = 14.10 + # = 15.04, 15.10 + # = 16.10 + # = 17.04, 17.10 + if [ "$DISTRO_MAJOR_VERSION" -lt 14 ] || \ + [ "$DISTRO_MAJOR_VERSION" -eq 15 ] || \ + [ "$DISTRO_MAJOR_VERSION" -eq 17 ] || \ + { [ "$DISTRO_MAJOR_VERSION" -eq 16 ] && [ "$DISTRO_MINOR_VERSION" -eq 10 ]; }; then + echoerror "End of life distributions are not supported." + echoerror "Please consider upgrading to the next stable. See:" + echoerror " https://wiki.ubuntu.com/Releases" + exit 1 + fi + ;; + + opensuse) + # openSUSE versions not supported + # + # <= 13.X + # <= 42.2 + if [ "$DISTRO_MAJOR_VERSION" -lt 15 ] || \ + { [ "$DISTRO_MAJOR_VERSION" -eq 42 ] && [ "$DISTRO_MINOR_VERSION" -le 2 ]; }; then + echoerror "End of life distributions are not supported." + echoerror "Please consider upgrading to the next stable. See:" + echoerror " http://en.opensuse.org/Lifetime" + exit 1 + fi + ;; + + suse) + # SuSE versions not supported + # + # < 11 SP4 + # < 12 SP2 + SUSE_PATCHLEVEL=$(awk '/PATCHLEVEL/ {print $3}' /etc/SuSE-release ) + if [ "${SUSE_PATCHLEVEL}" = "" ]; then + SUSE_PATCHLEVEL="00" + fi + if [ "$DISTRO_MAJOR_VERSION" -lt 11 ] || \ + { [ "$DISTRO_MAJOR_VERSION" -eq 11 ] && [ "$SUSE_PATCHLEVEL" -lt 04 ]; } || \ + { [ "$DISTRO_MAJOR_VERSION" -eq 12 ] && [ "$SUSE_PATCHLEVEL" -lt 02 ]; }; then + echoerror "Versions lower than SuSE 11 SP4 or 12 SP2 are not supported." + echoerror "Please consider upgrading to the next stable" + echoerror " https://www.suse.com/lifecycle/" + exit 1 + fi + ;; + + fedora) + # Fedora lower than 27 are no longer supported + if [ "$DISTRO_MAJOR_VERSION" -lt 27 ]; then + echoerror "End of life distributions are not supported." + echoerror "Please consider upgrading to the next stable. See:" + echoerror " https://fedoraproject.org/wiki/Releases" + exit 1 + fi + ;; + + centos) + # CentOS versions lower than 6 are no longer supported + if [ "$DISTRO_MAJOR_VERSION" -lt 6 ]; then + echoerror "End of life distributions are not supported." + echoerror "Please consider upgrading to the next stable. See:" + echoerror " http://wiki.centos.org/Download" + exit 1 + fi + ;; + + red_hat*linux) + # Red Hat (Enterprise) Linux versions lower than 6 are no longer supported + if [ "$DISTRO_MAJOR_VERSION" -lt 6 ]; then + echoerror "End of life distributions are not supported." + echoerror "Please consider upgrading to the next stable. See:" + echoerror " https://access.redhat.com/support/policy/updates/errata/" + exit 1 + fi + ;; + + oracle*linux) + # Oracle Linux versions lower than 6 are no longer supported + if [ "$DISTRO_MAJOR_VERSION" -lt 6 ]; then + echoerror "End of life distributions are not supported." + echoerror "Please consider upgrading to the next stable. See:" + echoerror " http://www.oracle.com/us/support/library/elsp-lifetime-069338.pdf" + exit 1 + fi + ;; + + scientific*linux) + # Scientific Linux versions lower than 6 are no longer supported + if [ "$DISTRO_MAJOR_VERSION" -lt 6 ]; then + echoerror "End of life distributions are not supported." + echoerror "Please consider upgrading to the next stable. See:" + echoerror " https://www.scientificlinux.org/downloads/sl-versions/" + exit 1 + fi + ;; + + cloud*linux) + # Cloud Linux versions lower than 6 are no longer supported + if [ "$DISTRO_MAJOR_VERSION" -lt 6 ]; then + echoerror "End of life distributions are not supported." + echoerror "Please consider upgrading to the next stable. See:" + echoerror " https://docs.cloudlinux.com/index.html?cloudlinux_life-cycle.html" + exit 1 + fi + ;; + + amazon*linux*ami) + # Amazon Linux versions lower than 2012.0X no longer supported + # Except for Amazon Linux 2, which reset the major version counter + if [ "$DISTRO_MAJOR_VERSION" -lt 2012 ] && [ "$DISTRO_MAJOR_VERSION" -gt 10 ]; then + echoerror "End of life distributions are not supported." + echoerror "Please consider upgrading to the next stable. See:" + echoerror " https://aws.amazon.com/amazon-linux-ami/" + exit 1 + fi + ;; + + freebsd) + # FreeBSD versions lower than 9.1 are not supported. + if { [ "$DISTRO_MAJOR_VERSION" -eq 9 ] && [ "$DISTRO_MINOR_VERSION" -lt 01 ]; } || \ + [ "$DISTRO_MAJOR_VERSION" -lt 9 ]; then + echoerror "Versions lower than FreeBSD 9.1 are not supported." + exit 1 + fi + ;; + + *) + ;; + esac +} + + +__gather_system_info + +echo +echoinfo "System Information:" +echoinfo " CPU: ${CPU_VENDOR_ID}" +echoinfo " CPU Arch: ${CPU_ARCH}" +echoinfo " OS Name: ${OS_NAME}" +echoinfo " OS Version: ${OS_VERSION}" +echoinfo " Distribution: ${DISTRO_NAME} ${DISTRO_VERSION}" +echo + +# Simplify distro name naming on functions +DISTRO_NAME_L=$(echo "$DISTRO_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-zA-Z0-9_ ]//g' | sed -re 's/([[:space:]])+/_/g') + +# Simplify version naming on functions +if [ "$DISTRO_VERSION" = "" ] || [ ${_SIMPLIFY_VERSION} -eq $BS_FALSE ]; then + DISTRO_MAJOR_VERSION="" + DISTRO_MINOR_VERSION="" + PREFIXED_DISTRO_MAJOR_VERSION="" + PREFIXED_DISTRO_MINOR_VERSION="" +else + DISTRO_MAJOR_VERSION=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') + DISTRO_MINOR_VERSION=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).\([0-9]*\).*/\2/g') + PREFIXED_DISTRO_MAJOR_VERSION="_${DISTRO_MAJOR_VERSION}" + if [ "${PREFIXED_DISTRO_MAJOR_VERSION}" = "_" ]; then + PREFIXED_DISTRO_MAJOR_VERSION="" + fi + PREFIXED_DISTRO_MINOR_VERSION="_${DISTRO_MINOR_VERSION}" + if [ "${PREFIXED_DISTRO_MINOR_VERSION}" = "_" ]; then + PREFIXED_DISTRO_MINOR_VERSION="" + fi +fi + +# For Ubuntu derivatives, pretend to be their Ubuntu base version +__ubuntu_derivatives_translation + +# For Debian derivates, pretend to be their Debian base version +__debian_derivatives_translation + +# Fail soon for end of life versions +__check_end_of_life_versions + +echodebug "Binaries will be searched using the following \$PATH: ${PATH}" + +# Let users know that we'll use a proxy +if [ "${_HTTP_PROXY}" != "" ]; then + echoinfo "Using http proxy $_HTTP_PROXY" +fi + +# Let users know what's going to be installed/configured +if [ "$_INSTALL_MINION" -eq $BS_TRUE ]; then + if [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then + echoinfo "Installing minion" + else + echoinfo "Configuring minion" + fi +fi + +if [ "$_INSTALL_MASTER" -eq $BS_TRUE ]; then + if [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then + echoinfo "Installing master" + else + echoinfo "Configuring master" + fi +fi + +if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ]; then + if [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then + echoinfo "Installing syndic" + else + echoinfo "Configuring syndic" + fi +fi + +if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ] && [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then + echoinfo "Installing salt-cloud and required python-libcloud package" +fi + +if [ $_START_DAEMONS -eq $BS_FALSE ]; then + echoinfo "Daemons will not be started" +fi + +if [ "${DISTRO_NAME_L}" = "ubuntu" ]; then + # For ubuntu versions, obtain the codename from the release version + __ubuntu_codename_translation +elif [ "${DISTRO_NAME_L}" = "debian" ]; then + # For debian versions, obtain the codename from the release version + __debian_codename_translation +fi + +if [ "$(echo "${DISTRO_NAME_L}" | grep -E '(debian|ubuntu|centos|red_hat|oracle|scientific|amazon|fedora)')" = "" ] && [ "$ITYPE" = "stable" ] && [ "$STABLE_REV" != "latest" ]; then + echoerror "${DISTRO_NAME} does not have major version pegged packages support" + exit 1 +fi + +# Only RedHat based distros have testing support +if [ "${ITYPE}" = "testing" ]; then + if [ "$(echo "${DISTRO_NAME_L}" | grep -E '(centos|red_hat|amazon|oracle)')" = "" ]; then + echoerror "${DISTRO_NAME} does not have testing packages support" + exit 1 + fi + _EPEL_REPO="epel-testing" +fi + +# Only Ubuntu has support for installing to virtualenvs +if [ "${DISTRO_NAME_L}" != "ubuntu" ] && [ "$_VIRTUALENV_DIR" != "null" ]; then + echoerror "${DISTRO_NAME} does not have -V support" + exit 1 +fi + +# Only Ubuntu has support for pip installing all packages +if [ "${DISTRO_NAME_L}" != "ubuntu" ] && [ $_PIP_ALL -eq $BS_TRUE ]; then + echoerror "${DISTRO_NAME} does not have -a support" + exit 1 +fi + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __function_defined +# DESCRIPTION: Checks if a function is defined within this scripts scope +# PARAMETERS: function name +# RETURNS: 0 or 1 as in defined or not defined +#---------------------------------------------------------------------------------------------------------------------- +__function_defined() { + FUNC_NAME=$1 + if [ "$(command -v "$FUNC_NAME")" != "" ]; then + echoinfo "Found function $FUNC_NAME" + return 0 + fi + echodebug "$FUNC_NAME not found...." + return 1 +} + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __wait_for_apt +# DESCRIPTION: Check if any apt, apt-get, aptitude, or dpkg processes are running before +# calling these again. This is useful when these process calls are part of +# a boot process, such as on AWS AMIs. This func will wait until the boot +# process is finished so the script doesn't exit on a locked proc. +#---------------------------------------------------------------------------------------------------------------------- +__wait_for_apt(){ + # Timeout set at 15 minutes + WAIT_TIMEOUT=900 + + # Run our passed in apt command + "${@}" 2>"$APT_ERR" + APT_RETURN=$? + + # Make sure we're not waiting on a lock + while [ $APT_RETURN -ne 0 ] && grep -q '^E: Could not get lock' "$APT_ERR"; do + echoinfo "Aware of the lock. Patiently waiting $WAIT_TIMEOUT more seconds..." + sleep 1 + WAIT_TIMEOUT=$((WAIT_TIMEOUT - 1)) + + if [ "$WAIT_TIMEOUT" -eq 0 ]; then + echoerror "Apt, apt-get, aptitude, or dpkg process is taking too long." + echoerror "Bootstrap script cannot proceed. Aborting." + return 1 + else + "${@}" 2>"$APT_ERR" + APT_RETURN=$? + fi + done + + return $APT_RETURN +} + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __apt_get_install_noinput +# DESCRIPTION: (DRY) apt-get install with noinput options +# PARAMETERS: packages +#---------------------------------------------------------------------------------------------------------------------- +__apt_get_install_noinput() { + __wait_for_apt apt-get install -y -o DPkg::Options::=--force-confold "${@}"; return $? +} # ---------- end of function __apt_get_install_noinput ---------- + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __apt_get_upgrade_noinput +# DESCRIPTION: (DRY) apt-get upgrade with noinput options +#---------------------------------------------------------------------------------------------------------------------- +__apt_get_upgrade_noinput() { + __wait_for_apt apt-get upgrade -y -o DPkg::Options::=--force-confold; return $? +} # ---------- end of function __apt_get_upgrade_noinput ---------- + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __temp_gpg_pub +# DESCRIPTION: Create a temporary file for downloading a GPG public key. +#---------------------------------------------------------------------------------------------------------------------- +__temp_gpg_pub() { + if __check_command_exists mktemp; then + tempfile="$(mktemp /tmp/salt-gpg-XXXXXXXX.pub 2>/dev/null)" + + if [ -z "$tempfile" ]; then + echoerror "Failed to create temporary file in /tmp" + return 1 + fi + else + tempfile="/tmp/salt-gpg-$$.pub" + fi + + echo $tempfile +} # ----------- end of function __temp_gpg_pub ----------- + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __apt_key_fetch +# DESCRIPTION: Download and import GPG public key for "apt-secure" +# PARAMETERS: url +#---------------------------------------------------------------------------------------------------------------------- +__apt_key_fetch() { + url=$1 + + tempfile="$(__temp_gpg_pub)" + + __fetch_url "$tempfile" "$url" || return 1 + apt-key add "$tempfile" || return 1 + rm -f "$tempfile" + + return 0 +} # ---------- end of function __apt_key_fetch ---------- + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __rpm_import_gpg +# DESCRIPTION: Download and import GPG public key to rpm database +# PARAMETERS: url +#---------------------------------------------------------------------------------------------------------------------- +__rpm_import_gpg() { + url=$1 + + tempfile="$(__temp_gpg_pub)" + + __fetch_url "$tempfile" "$url" || return 1 + rpm --import "$tempfile" || return 1 + rm -f "$tempfile" + + return 0 +} # ---------- end of function __rpm_import_gpg ---------- + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __yum_install_noinput +# DESCRIPTION: (DRY) yum install with noinput options +#---------------------------------------------------------------------------------------------------------------------- +__yum_install_noinput() { + + ENABLE_EPEL_CMD="" + # Skip Amazon Linux for the first round, since EPEL is no longer required. + # See issue #724 + if [ $_DISABLE_REPOS -eq $BS_FALSE ] && [ "$DISTRO_NAME_L" != "amazon_linux_ami" ]; then + ENABLE_EPEL_CMD="--enablerepo=${_EPEL_REPO}" + fi + + if [ "$DISTRO_NAME_L" = "oracle_linux" ]; then + # We need to install one package at a time because --enablerepo=X disables ALL OTHER REPOS!!!! + for package in "${@}"; do + yum -y install "${package}" || yum -y install "${package}" ${ENABLE_EPEL_CMD} || return $? + done + else + yum -y install "${@}" ${ENABLE_EPEL_CMD} || return $? + fi +} # ---------- end of function __yum_install_noinput ---------- + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __git_clone_and_checkout +# DESCRIPTION: (DRY) Helper function to clone and checkout salt to a +# specific revision. +#---------------------------------------------------------------------------------------------------------------------- +__git_clone_and_checkout() { + + echodebug "Installed git version: $(git --version | awk '{ print $3 }')" + # Turn off SSL verification if -I flag was set for insecure downloads + if [ "$_INSECURE_DL" -eq $BS_TRUE ]; then + export GIT_SSL_NO_VERIFY=1 + fi + + case ${OS_NAME_L} in + openbsd|freebsd|netbsd ) + __TAG_REGEX_MATCH=$(echo "${GIT_REV}" | sed -E 's/^(v?[0-9]{1,4}\.[0-9]{1,2})(\.[0-9]{1,2})?.*$/MATCH/') + ;; + * ) + __TAG_REGEX_MATCH=$(echo "${GIT_REV}" | sed 's/^.*\(v\?[[:digit:]]\{1,4\}\.[[:digit:]]\{1,2\}\)\(\.[[:digit:]]\{1,2\}\)\?.*$/MATCH/') + ;; + esac + + __SALT_GIT_CHECKOUT_PARENT_DIR=$(dirname "${_SALT_GIT_CHECKOUT_DIR}" 2>/dev/null) + __SALT_GIT_CHECKOUT_PARENT_DIR="${__SALT_GIT_CHECKOUT_PARENT_DIR:-/tmp/git}" + __SALT_CHECKOUT_REPONAME="$(basename "${_SALT_GIT_CHECKOUT_DIR}" 2>/dev/null)" + __SALT_CHECKOUT_REPONAME="${__SALT_CHECKOUT_REPONAME:-salt}" + [ -d "${__SALT_GIT_CHECKOUT_PARENT_DIR}" ] || mkdir "${__SALT_GIT_CHECKOUT_PARENT_DIR}" + # shellcheck disable=SC2164 + cd "${__SALT_GIT_CHECKOUT_PARENT_DIR}" + if [ -d "${_SALT_GIT_CHECKOUT_DIR}" ]; then + echodebug "Found a checked out Salt repository" + # shellcheck disable=SC2164 + cd "${_SALT_GIT_CHECKOUT_DIR}" + echodebug "Fetching git changes" + git fetch || return 1 + # Tags are needed because of salt's versioning, also fetch that + echodebug "Fetching git tags" + git fetch --tags || return 1 + + # If we have the SaltStack remote set as upstream, we also need to fetch the tags from there + if [ "$(git remote -v | grep $_SALTSTACK_REPO_URL)" != "" ]; then + echodebug "Fetching upstream(SaltStack's Salt repository) git tags" + git fetch --tags upstream + else + echoinfo "Adding SaltStack's Salt repository as a remote" + git remote add upstream "$_SALTSTACK_REPO_URL" + echodebug "Fetching upstream(SaltStack's Salt repository) git tags" + git fetch --tags upstream + fi + + echodebug "Hard reseting the cloned repository to ${GIT_REV}" + git reset --hard "$GIT_REV" || return 1 + + # Just calling `git reset --hard $GIT_REV` on a branch name that has + # already been checked out will not update that branch to the upstream + # HEAD; instead it will simply reset to itself. Check the ref to see + # if it is a branch name, check out the branch, and pull in the + # changes. + if git branch -a | grep -q "${GIT_REV}"; then + echodebug "Rebasing the cloned repository branch" + git pull --rebase || return 1 + fi + else + if [ "$_FORCE_SHALLOW_CLONE" -eq "${BS_TRUE}" ]; then + echoinfo "Forced shallow cloning of git repository." + __SHALLOW_CLONE=$BS_TRUE + elif [ "$__TAG_REGEX_MATCH" = "MATCH" ]; then + echoinfo "Git revision matches a Salt version tag, shallow cloning enabled." + __SHALLOW_CLONE=$BS_TRUE + else + echowarn "The git revision being installed does not match a Salt version tag. Shallow cloning disabled" + __SHALLOW_CLONE=$BS_FALSE + fi + + if [ "$__SHALLOW_CLONE" -eq $BS_TRUE ]; then + # Let's try shallow cloning to speed up. + # Test for "--single-branch" option introduced in git 1.7.10, the minimal version of git where the shallow + # cloning we need actually works + if [ "$(git clone 2>&1 | grep 'single-branch')" != "" ]; then + # The "--single-branch" option is supported, attempt shallow cloning + echoinfo "Attempting to shallow clone $GIT_REV from Salt's repository ${_SALT_REPO_URL}" + if git clone --depth 1 --branch "$GIT_REV" "$_SALT_REPO_URL" "$__SALT_CHECKOUT_REPONAME"; then + # shellcheck disable=SC2164 + cd "${_SALT_GIT_CHECKOUT_DIR}" + __SHALLOW_CLONE=$BS_TRUE + else + # Shallow clone above failed(missing upstream tags???), let's resume the old behaviour. + echowarn "Failed to shallow clone." + echoinfo "Resuming regular git clone and remote SaltStack repository addition procedure" + __SHALLOW_CLONE=$BS_FALSE + fi + else + echodebug "Shallow cloning not possible. Required git version not met." + __SHALLOW_CLONE=$BS_FALSE + fi + fi + + if [ "$__SHALLOW_CLONE" -eq $BS_FALSE ]; then + git clone "$_SALT_REPO_URL" "$__SALT_CHECKOUT_REPONAME" || return 1 + # shellcheck disable=SC2164 + cd "${_SALT_GIT_CHECKOUT_DIR}" + + if ! echo "$_SALT_REPO_URL" | grep -q -F -w "${_SALTSTACK_REPO_URL#*://}"; then + # We need to add the saltstack repository as a remote and fetch tags for proper versioning + echoinfo "Adding SaltStack's Salt repository as a remote" + git remote add upstream "$_SALTSTACK_REPO_URL" || return 1 + + echodebug "Fetching upstream (SaltStack's Salt repository) git tags" + git fetch --tags upstream || return 1 + + # Check if GIT_REV is a remote branch or just a commit hash + if git branch -r | grep -q -F -w "origin/$GIT_REV"; then + GIT_REV="origin/$GIT_REV" + fi + fi + + echodebug "Checking out $GIT_REV" + git checkout "$GIT_REV" || return 1 + fi + + fi + + echoinfo "Cloning Salt's git repository succeeded" + return 0 +} + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __copyfile +# DESCRIPTION: Simple function to copy files. Overrides if asked. +#---------------------------------------------------------------------------------------------------------------------- +__copyfile() { + overwrite=$_FORCE_OVERWRITE + if [ $# -eq 2 ]; then + sfile=$1 + dfile=$2 + elif [ $# -eq 3 ]; then + sfile=$1 + dfile=$2 + overwrite=$3 + else + echoerror "Wrong number of arguments for __copyfile()" + echoinfo "USAGE: __copyfile OR __copyfile " + exit 1 + fi + + # Does the source file exist? + if [ ! -f "$sfile" ]; then + echowarn "$sfile does not exist!" + return 1 + fi + + # If the destination is a directory, let's make it a full path so the logic + # below works as expected + if [ -d "$dfile" ]; then + echodebug "The passed destination ($dfile) is a directory" + dfile="${dfile}/$(basename "$sfile")" + echodebug "Full destination path is now: $dfile" + fi + + if [ ! -f "$dfile" ]; then + # The destination file does not exist, copy + echodebug "Copying $sfile to $dfile" + cp "$sfile" "$dfile" || return 1 + elif [ -f "$dfile" ] && [ "$overwrite" -eq $BS_TRUE ]; then + # The destination exist and we're overwriting + echodebug "Overwriting $dfile with $sfile" + cp -f "$sfile" "$dfile" || return 1 + elif [ -f "$dfile" ] && [ "$overwrite" -ne $BS_TRUE ]; then + echodebug "Not overwriting $dfile with $sfile" + fi + return 0 +} + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __movefile +# DESCRIPTION: Simple function to move files. Overrides if asked. +#---------------------------------------------------------------------------------------------------------------------- +__movefile() { + overwrite=$_FORCE_OVERWRITE + if [ $# -eq 2 ]; then + sfile=$1 + dfile=$2 + elif [ $# -eq 3 ]; then + sfile=$1 + dfile=$2 + overwrite=$3 + else + echoerror "Wrong number of arguments for __movefile()" + echoinfo "USAGE: __movefile OR __movefile " + exit 1 + fi + + if [ $_KEEP_TEMP_FILES -eq $BS_TRUE ]; then + # We're being told not to move files, instead copy them so we can keep + # them around + echodebug "Since BS_KEEP_TEMP_FILES=1 we're copying files instead of moving them" + __copyfile "$sfile" "$dfile" "$overwrite" + return $? + fi + + # Does the source file exist? + if [ ! -f "$sfile" ]; then + echowarn "$sfile does not exist!" + return 1 + fi + + # If the destination is a directory, let's make it a full path so the logic + # below works as expected + if [ -d "$dfile" ]; then + echodebug "The passed destination($dfile) is a directory" + dfile="${dfile}/$(basename "$sfile")" + echodebug "Full destination path is now: $dfile" + fi + + if [ ! -f "$dfile" ]; then + # The destination file does not exist, move + echodebug "Moving $sfile to $dfile" + mv "$sfile" "$dfile" || return 1 + elif [ -f "$dfile" ] && [ "$overwrite" -eq $BS_TRUE ]; then + # The destination exist and we're overwriting + echodebug "Overriding $dfile with $sfile" + mv -f "$sfile" "$dfile" || return 1 + elif [ -f "$dfile" ] && [ "$overwrite" -ne $BS_TRUE ]; then + echodebug "Not overriding $dfile with $sfile" + fi + + return 0 +} + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __linkfile +# DESCRIPTION: Simple function to create symlinks. Overrides if asked. Accepts globs. +#---------------------------------------------------------------------------------------------------------------------- +__linkfile() { + overwrite=$_FORCE_OVERWRITE + if [ $# -eq 2 ]; then + target=$1 + linkname=$2 + elif [ $# -eq 3 ]; then + target=$1 + linkname=$2 + overwrite=$3 + else + echoerror "Wrong number of arguments for __linkfile()" + echoinfo "USAGE: __linkfile OR __linkfile " + exit 1 + fi + + for sfile in $target; do + # Does the source file exist? + if [ ! -f "$sfile" ]; then + echowarn "$sfile does not exist!" + return 1 + fi + + # If the destination is a directory, let's make it a full path so the logic + # below works as expected + if [ -d "$linkname" ]; then + echodebug "The passed link name ($linkname) is a directory" + linkname="${linkname}/$(basename "$sfile")" + echodebug "Full destination path is now: $linkname" + fi + + if [ ! -e "$linkname" ]; then + # The destination file does not exist, create link + echodebug "Creating $linkname symlink pointing to $sfile" + ln -s "$sfile" "$linkname" || return 1 + elif [ -e "$linkname" ] && [ "$overwrite" -eq $BS_TRUE ]; then + # The destination exist and we're overwriting + echodebug "Overwriting $linkname symlink to point on $sfile" + ln -sf "$sfile" "$linkname" || return 1 + elif [ -e "$linkname" ] && [ "$overwrite" -ne $BS_TRUE ]; then + echodebug "Not overwriting $linkname symlink to point on $sfile" + fi + done + + return 0 +} + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __overwriteconfig() +# DESCRIPTION: Simple function to overwrite master or minion config files. +#---------------------------------------------------------------------------------------------------------------------- +__overwriteconfig() { + if [ $# -eq 2 ]; then + target=$1 + json=$2 + else + echoerror "Wrong number of arguments for __convert_json_to_yaml_str()" + echoinfo "USAGE: __convert_json_to_yaml_str " + exit 1 + fi + + # Make a tempfile to dump any python errors into. + if __check_command_exists mktemp; then + tempfile="$(mktemp /tmp/salt-config-XXXXXXXX 2>/dev/null)" + + if [ -z "$tempfile" ]; then + echoerror "Failed to create temporary file in /tmp" + return 1 + fi + else + tempfile="/tmp/salt-config-$$" + fi + + if [ -n "$_PY_EXE" ]; then + good_python="$_PY_EXE" + # If python does not have yaml installed we're on Arch and should use python2 + elif python -c "import yaml" 2> /dev/null; then + good_python=python + else + good_python=python2 + fi + + # Convert json string to a yaml string and write it to config file. Output is dumped into tempfile. + "$good_python" -c "import json; import yaml; jsn=json.loads('$json'); yml=yaml.safe_dump(jsn, line_break='\\n', default_flow_style=False); config_file=open('$target', 'w'); config_file.write(yml); config_file.close();" 2>$tempfile + + # No python errors output to the tempfile + if [ ! -s "$tempfile" ]; then + rm -f "$tempfile" + return 0 + fi + + # Errors are present in the tempfile - let's expose them to the user. + fullerror=$(cat "$tempfile") + echodebug "$fullerror" + echoerror "Python error encountered. This is likely due to passing in a malformed JSON string. Please use -D to see stacktrace." + + rm -f "$tempfile" + + return 1 + +} + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __check_services_systemd +# DESCRIPTION: Return 0 or 1 in case the service is enabled or not +# PARAMETERS: servicename +#---------------------------------------------------------------------------------------------------------------------- +__check_services_systemd() { + if [ $# -eq 0 ]; then + echoerror "You need to pass a service name to check!" + exit 1 + elif [ $# -ne 1 ]; then + echoerror "You need to pass a service name to check as the single argument to the function" + fi + + servicename=$1 + echodebug "Checking if service ${servicename} is enabled" + + if [ "$(systemctl is-enabled "${servicename}")" = "enabled" ]; then + echodebug "Service ${servicename} is enabled" + return 0 + else + echodebug "Service ${servicename} is NOT enabled" + return 1 + fi +} # ---------- end of function __check_services_systemd ---------- + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __check_services_upstart +# DESCRIPTION: Return 0 or 1 in case the service is enabled or not +# PARAMETERS: servicename +#---------------------------------------------------------------------------------------------------------------------- +__check_services_upstart() { + if [ $# -eq 0 ]; then + echoerror "You need to pass a service name to check!" + exit 1 + elif [ $# -ne 1 ]; then + echoerror "You need to pass a service name to check as the single argument to the function" + fi + + servicename=$1 + echodebug "Checking if service ${servicename} is enabled" + + # Check if service is enabled to start at boot + if initctl list | grep "${servicename}" > /dev/null 2>&1; then + echodebug "Service ${servicename} is enabled" + return 0 + else + echodebug "Service ${servicename} is NOT enabled" + return 1 + fi +} # ---------- end of function __check_services_upstart ---------- + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __check_services_sysvinit +# DESCRIPTION: Return 0 or 1 in case the service is enabled or not +# PARAMETERS: servicename +#---------------------------------------------------------------------------------------------------------------------- +__check_services_sysvinit() { + if [ $# -eq 0 ]; then + echoerror "You need to pass a service name to check!" + exit 1 + elif [ $# -ne 1 ]; then + echoerror "You need to pass a service name to check as the single argument to the function" + fi + + servicename=$1 + echodebug "Checking if service ${servicename} is enabled" + + if [ "$(LC_ALL=C /sbin/chkconfig --list | grep "\\<${servicename}\\>" | grep '[2-5]:on')" != "" ]; then + echodebug "Service ${servicename} is enabled" + return 0 + else + echodebug "Service ${servicename} is NOT enabled" + return 1 + fi +} # ---------- end of function __check_services_sysvinit ---------- + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __check_services_debian +# DESCRIPTION: Return 0 or 1 in case the service is enabled or not +# PARAMETERS: servicename +#---------------------------------------------------------------------------------------------------------------------- +__check_services_debian() { + if [ $# -eq 0 ]; then + echoerror "You need to pass a service name to check!" + exit 1 + elif [ $# -ne 1 ]; then + echoerror "You need to pass a service name to check as the single argument to the function" + fi + + servicename=$1 + echodebug "Checking if service ${servicename} is enabled" + + # Check if the service is going to be started at any runlevel, fixes bootstrap in container (Docker, LXC) + if ls /etc/rc?.d/S*"${servicename}" >/dev/null 2>&1; then + echodebug "Service ${servicename} is enabled" + return 0 + else + echodebug "Service ${servicename} is NOT enabled" + return 1 + fi +} # ---------- end of function __check_services_debian ---------- + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __check_services_openbsd +# DESCRIPTION: Return 0 or 1 in case the service is enabled or not +# PARAMETERS: servicename +#---------------------------------------------------------------------------------------------------------------------- +__check_services_openbsd() { + if [ $# -eq 0 ]; then + echoerror "You need to pass a service name to check!" + exit 1 + elif [ $# -ne 1 ]; then + echoerror "You need to pass a service name to check as the single argument to the function" + fi + + servicename=$1 + echodebug "Checking if service ${servicename} is enabled" + + # shellcheck disable=SC2086,SC2046,SC2144 + if rcctl get ${servicename} status; then + echodebug "Service ${servicename} is enabled" + return 0 + else + echodebug "Service ${servicename} is NOT enabled" + return 1 + fi +} # ---------- end of function __check_services_openbsd ---------- + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __check_services_alpine +# DESCRIPTION: Return 0 or 1 in case the service is enabled or not +# PARAMETERS: servicename +#---------------------------------------------------------------------------------------------------------------------- +__check_services_alpine() { + if [ $# -eq 0 ]; then + echoerror "You need to pass a service name to check!" + exit 1 + elif [ $# -ne 1 ]; then + echoerror "You need to pass a service name to check as the single argument to the function" + fi + + servicename=$1 + echodebug "Checking if service ${servicename} is enabled" + + # shellcheck disable=SC2086,SC2046,SC2144 + if rc-status $(rc-status -r) | tail -n +2 | grep -q "\\<$servicename\\>"; then + echodebug "Service ${servicename} is enabled" + return 0 + else + echodebug "Service ${servicename} is NOT enabled" + return 1 + fi +} # ---------- end of function __check_services_openbsd ---------- + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __create_virtualenv +# DESCRIPTION: Return 0 or 1 depending on successful creation of virtualenv +#---------------------------------------------------------------------------------------------------------------------- +__create_virtualenv() { + if [ ! -d "$_VIRTUALENV_DIR" ]; then + echoinfo "Creating virtualenv ${_VIRTUALENV_DIR}" + if [ $_PIP_ALL -eq $BS_TRUE ]; then + virtualenv --no-site-packages "${_VIRTUALENV_DIR}" || return 1 + else + virtualenv --system-site-packages "${_VIRTUALENV_DIR}" || return 1 + fi + fi + return 0 +} # ---------- end of function __create_virtualenv ---------- + + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __activate_virtualenv +# DESCRIPTION: Return 0 or 1 depending on successful activation of virtualenv +#---------------------------------------------------------------------------------------------------------------------- +__activate_virtualenv() { + set +o nounset + # Is virtualenv empty + if [ -z "$_VIRTUALENV_DIR" ]; then + __create_virtualenv || return 1 + # shellcheck source=/dev/null + . "${_VIRTUALENV_DIR}/bin/activate" || return 1 + echoinfo "Activated virtualenv ${_VIRTUALENV_DIR}" + fi + set -o nounset + return 0 +} # ---------- end of function __activate_virtualenv ---------- + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __install_pip_pkgs +# DESCRIPTION: Return 0 or 1 if successfully able to install pip packages. Can provide a different python version to +# install pip packages with. If $py_ver is not specified it will use the default python version. +# PARAMETERS: pkgs, py_ver +#---------------------------------------------------------------------------------------------------------------------- + +__install_pip_pkgs() { + _pip_pkgs="$1" + _py_exe="$2" + _py_pkg=$(echo "$_py_exe" | sed -r "s/\\.//g") + _pip_cmd="${_py_exe} -m pip" + + if [ "${_py_exe}" = "" ]; then + _py_exe='python' + fi + + __check_pip_allowed + + # Install pip and pip dependencies + if ! __check_command_exists "${_pip_cmd} --version"; then + __PACKAGES="${_py_pkg}-setuptools ${_py_pkg}-pip gcc" + # shellcheck disable=SC2086 + if [ "$DISTRO_NAME_L" = "debian" ];then + __PACKAGES="${__PACKAGES} ${_py_pkg}-dev" + __apt_get_install_noinput ${__PACKAGES} || return 1 + else + __PACKAGES="${__PACKAGES} ${_py_pkg}-devel" + __yum_install_noinput ${__PACKAGES} || return 1 + fi + + fi + + echoinfo "Installing pip packages: ${_pip_pkgs} using ${_py_exe}" + # shellcheck disable=SC2086 + ${_pip_cmd} install ${_pip_pkgs} || return 1 +} + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __install_tornado_pip +# PARAMETERS: python executable +# DESCRIPTION: Return 0 or 1 if successfully able to install tornado<5.0 +#---------------------------------------------------------------------------------------------------------------------- +__install_tornado_pip() { + # OS needs tornado <5.0 from pip + __check_pip_allowed "You need to allow pip based installations (-P) for Tornado <5.0 in order to install Salt on Python 3" + ## install pip if its not installed and install tornado + __install_pip_pkgs "tornado<5.0" "${1}" || return 1 +} + +#--- FUNCTION ------------------------------------------------------------------------------------------------------- +# NAME: __install_pip_deps +# DESCRIPTION: Return 0 or 1 if successfully able to install pip packages via requirements file +# PARAMETERS: requirements_file +#---------------------------------------------------------------------------------------------------------------------- +__install_pip_deps() { + # Install virtualenv to system pip before activating virtualenv if thats going to be used + # We assume pip pkg is installed since that is distro specific + if [ "$_VIRTUALENV_DIR" != "null" ]; then + if ! __check_command_exists pip; then + echoerror "Pip not installed: required for -a installs" + exit 1 + fi + pip install -U virtualenv + __activate_virtualenv || return 1 + else + echoerror "Must have virtualenv dir specified for -a installs" + fi + + requirements_file=$1 + if [ ! -f "${requirements_file}" ]; then + echoerror "Requirements file: ${requirements_file} cannot be found, needed for -a (pip pkg) installs" + exit 1 + fi + + __PIP_PACKAGES='' + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then + # shellcheck disable=SC2089 + __PIP_PACKAGES="${__PIP_PACKAGES} 'apache-libcloud>=$_LIBCLOUD_MIN_VERSION'" + fi + + # shellcheck disable=SC2086,SC2090 + pip install -U -r ${requirements_file} ${__PIP_PACKAGES} +} # ---------- end of function __install_pip_deps ---------- + + +####################################################################################################################### +# +# Distribution install functions +# +# In order to install salt for a distribution you need to define: +# +# To Install Dependencies, which is required, one of: +# 1. install____deps +# 2. install_____deps +# 3. install___deps +# 4 install____deps +# 5. install___deps +# 6. install__deps +# +# Optionally, define a salt configuration function, which will be called if +# the -c (config-dir) option is passed. One of: +# 1. config____salt +# 2. config_____salt +# 3. config___salt +# 4 config____salt +# 5. config___salt +# 6. config__salt +# 7. config_salt [THIS ONE IS ALREADY DEFINED AS THE DEFAULT] +# +# Optionally, define a salt master pre-seed function, which will be called if +# the -k (pre-seed master keys) option is passed. One of: +# 1. preseed____master +# 2. preseed_____master +# 3. preseed___master +# 4 preseed____master +# 5. preseed___master +# 6. preseed__master +# 7. preseed_master [THIS ONE IS ALREADY DEFINED AS THE DEFAULT] +# +# To install salt, which, of course, is required, one of: +# 1. install___ +# 2. install____ +# 3. install__ +# +# Optionally, define a post install function, one of: +# 1. install____post +# 2. install_____post +# 3. install___post +# 4 install____post +# 5. install___post +# 6. install__post +# +# Optionally, define a start daemons function, one of: +# 1. install____restart_daemons +# 2. install_____restart_daemons +# 3. install___restart_daemons +# 4 install____restart_daemons +# 5. install___restart_daemons +# 6. install__restart_daemons +# +# NOTE: The start daemons function should be able to restart any daemons +# which are running, or start if they're not running. +# +# Optionally, define a daemons running function, one of: +# 1. daemons_running___ +# 2. daemons_running____ +# 3. daemons_running__ +# 4 daemons_running___ +# 5. daemons_running__ +# 6. daemons_running_ +# 7. daemons_running [THIS ONE IS ALREADY DEFINED AS THE DEFAULT] +# +# Optionally, check enabled Services: +# 1. install____check_services +# 2. install_____check_services +# 3. install___check_services +# 4 install____check_services +# 5. install___check_services +# 6. install__check_services +# +####################################################################################################################### + + +####################################################################################################################### +# +# Ubuntu Install Functions +# +__enable_universe_repository() { + if [ "$(grep -R universe /etc/apt/sources.list /etc/apt/sources.list.d/ | grep -v '#')" != "" ]; then + # The universe repository is already enabled + return 0 + fi + + echodebug "Enabling the universe repository" + + add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) universe" || return 1 + + return 0 +} + +__install_saltstack_ubuntu_repository() { + # Workaround for latest non-LTS ubuntu + if [ "$DISTRO_MAJOR_VERSION" -gt 18 ] || \ + { [ "$DISTRO_MAJOR_VERSION" -eq 18 ] && [ "$DISTRO_MINOR_VERSION" -eq 10 ]; }; then + echowarn "Non-LTS Ubuntu detected, but stable packages requested. Trying packages for latest LTS release. You may experience problems." + UBUNTU_VERSION=18.04 + UBUNTU_CODENAME="bionic" + else + UBUNTU_VERSION=${DISTRO_VERSION} + UBUNTU_CODENAME=${DISTRO_CODENAME} + fi + + # Install downloader backend for GPG keys fetching + __PACKAGES='wget' + + # Required as it is not installed by default on Ubuntu 18+ + if [ "$DISTRO_MAJOR_VERSION" -ge 18 ]; then + __PACKAGES="${__PACKAGES} gnupg" + fi + + # Make sure https transport is available + if [ "$HTTP_VAL" = "https" ] ; then + __PACKAGES="${__PACKAGES} apt-transport-https ca-certificates" + fi + + # shellcheck disable=SC2086,SC2090 + __apt_get_install_noinput ${__PACKAGES} || return 1 + + __PY_VERSION_REPO="apt" + if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then + __PY_VERSION_REPO="py3" + fi + + # SaltStack's stable Ubuntu repository: + SALTSTACK_UBUNTU_URL="${HTTP_VAL}://${_REPO_URL}/${__PY_VERSION_REPO}/ubuntu/${UBUNTU_VERSION}/${__REPO_ARCH}/${STABLE_REV}" + echo "$__REPO_ARCH_DEB $SALTSTACK_UBUNTU_URL $UBUNTU_CODENAME main" > /etc/apt/sources.list.d/saltstack.list + + __apt_key_fetch "$SALTSTACK_UBUNTU_URL/SALTSTACK-GPG-KEY.pub" || return 1 + + __wait_for_apt apt-get update || return 1 +} + +install_ubuntu_deps() { + if [ $_DISABLE_REPOS -eq $BS_FALSE ]; then + # Install add-apt-repository + if ! __check_command_exists add-apt-repository; then + __apt_get_install_noinput software-properties-common || return 1 + fi + + __enable_universe_repository || return 1 + + __wait_for_apt apt-get update || return 1 + fi + + __PACKAGES='' + + if [ "$DISTRO_MAJOR_VERSION" -lt 16 ]; then + # Minimal systems might not have upstart installed, install it + __PACKAGES="upstart" + fi + + if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then + PY_PKG_VER=3 + else + PY_PKG_VER="" + fi + + if [ "$DISTRO_MAJOR_VERSION" -ge 16 ] && [ -z "$_PY_EXE" ]; then + __PACKAGES="${__PACKAGES} python2.7" + fi + + if [ "$_VIRTUALENV_DIR" != "null" ]; then + __PACKAGES="${__PACKAGES} python-virtualenv" + fi + # Need python-apt for managing packages via Salt + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-apt" + + # requests is still used by many salt modules + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-requests" + + # YAML module is used for generating custom master/minion configs + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-yaml" + + # Additionally install procps and pciutils which allows for Docker bootstraps. See 366#issuecomment-39666813 + __PACKAGES="${__PACKAGES} procps pciutils" + + # shellcheck disable=SC2086,SC2090 + __apt_get_install_noinput ${__PACKAGES} || return 1 + + if [ "${_EXTRA_PACKAGES}" != "" ]; then + echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" + # shellcheck disable=SC2086 + __apt_get_install_noinput ${_EXTRA_PACKAGES} || return 1 + fi + + return 0 +} + +install_ubuntu_stable_deps() { + if [ "${_SLEEP}" -eq "${__DEFAULT_SLEEP}" ] && [ "$DISTRO_MAJOR_VERSION" -lt 16 ]; then + # The user did not pass a custom sleep value as an argument, let's increase the default value + echodebug "On Ubuntu systems we increase the default sleep value to 10." + echodebug "See https://github.com/saltstack/salt/issues/12248 for more info." + _SLEEP=10 + fi + + if [ $_START_DAEMONS -eq $BS_FALSE ]; then + echowarn "Not starting daemons on Debian based distributions is not working mostly because starting them is the default behaviour." + fi + + # No user interaction, libc6 restart services for example + export DEBIAN_FRONTEND=noninteractive + + __wait_for_apt apt-get update || return 1 + + if [ "${_UPGRADE_SYS}" -eq $BS_TRUE ]; then + if [ "${_INSECURE_DL}" -eq $BS_TRUE ]; then + __apt_get_install_noinput --allow-unauthenticated debian-archive-keyring && + apt-key update && apt-get update || return 1 + fi + + __apt_get_upgrade_noinput || return 1 + fi + + if [ "$_DISABLE_REPOS" -eq "$BS_FALSE" ] || [ "$_CUSTOM_REPO_URL" != "null" ]; then + __check_dpkg_architecture || return 1 + __install_saltstack_ubuntu_repository || return 1 + fi + + install_ubuntu_deps || return 1 +} + +install_ubuntu_git_deps() { + __wait_for_apt apt-get update || return 1 + + if ! __check_command_exists git; then + __apt_get_install_noinput git-core || return 1 + fi + + if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then + __apt_get_install_noinput ca-certificates + fi + + __git_clone_and_checkout || return 1 + + __PACKAGES="" + + # See how we are installing packages + if [ "${_PIP_ALL}" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} python-dev swig libssl-dev libzmq3 libzmq3-dev" + + if ! __check_command_exists pip; then + __PACKAGES="${__PACKAGES} python-setuptools python-pip" + fi + + # Get just the apt packages that are required to build all the pythons + # shellcheck disable=SC2086 + __apt_get_install_noinput ${__PACKAGES} || return 1 + # Install the pythons from requirements (only zmq for now) + __install_pip_deps "${_SALT_GIT_CHECKOUT_DIR}/requirements/zeromq.txt" || return 1 + else + install_ubuntu_stable_deps || return 1 + + if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then + PY_PKG_VER=3 + + __PACKAGES="${__PACKAGES} python3-setuptools" + else + PY_PKG_VER="" + + # There is no m2crypto package for Py3 at this time - only install for Py2 + __PACKAGES="${__PACKAGES} python-m2crypto" + fi + + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-crypto python${PY_PKG_VER}-jinja2" + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-msgpack python${PY_PKG_VER}-requests" + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-tornado python${PY_PKG_VER}-yaml" + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-zmq" + __PACKAGES="${__PACKAGES} python-concurrent.futures" + + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then + # Install python-libcloud if asked to + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-libcloud" + fi + + # shellcheck disable=SC2086 + __apt_get_install_noinput ${__PACKAGES} || return 1 + fi + + # Let's trigger config_salt() + if [ "$_TEMP_CONFIG_DIR" = "null" ]; then + _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" + CONFIG_SALT_FUNC="config_salt" + fi + + return 0 +} + +install_ubuntu_stable() { + __PACKAGES="" + + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ];then + __PACKAGES="${__PACKAGES} salt-cloud" + fi + if [ "$_INSTALL_MASTER" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} salt-master" + fi + if [ "$_INSTALL_MINION" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} salt-minion" + fi + if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} salt-syndic" + fi + + # shellcheck disable=SC2086 + __apt_get_install_noinput ${__PACKAGES} || return 1 + + return 0 +} + +install_ubuntu_git() { + # Activate virtualenv before install + if [ "${_VIRTUALENV_DIR}" != "null" ]; then + __activate_virtualenv || return 1 + fi + + if [ -n "$_PY_EXE" ]; then + _PYEXE=${_PY_EXE} + else + _PYEXE=python2.7 + fi + + if [ -f "${_SALT_GIT_CHECKOUT_DIR}/salt/syspaths.py" ]; then + ${_PYEXE} setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install --install-layout=deb || return 1 + else + ${_PYEXE} setup.py ${SETUP_PY_INSTALL_ARGS} install --install-layout=deb || return 1 + fi + + return 0 +} + +install_ubuntu_stable_post() { + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + if [ -f /bin/systemctl ]; then + # Using systemd + /bin/systemctl is-enabled salt-$fname.service > /dev/null 2>&1 || ( + /bin/systemctl preset salt-$fname.service > /dev/null 2>&1 && + /bin/systemctl enable salt-$fname.service > /dev/null 2>&1 + ) + sleep 1 + /bin/systemctl daemon-reload + elif [ -f /etc/init.d/salt-$fname ]; then + update-rc.d salt-$fname defaults + fi + done + + return 0 +} + +install_ubuntu_git_post() { + for fname in api master minion syndic; do + # Skip if not meant to be installed + [ $fname = "api" ] && \ + ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + if [ -f /bin/systemctl ] && [ "$DISTRO_MAJOR_VERSION" -ge 16 ]; then + __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.service" "/lib/systemd/system/salt-${fname}.service" + + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + systemctl is-enabled salt-$fname.service || (systemctl preset salt-$fname.service && systemctl enable salt-$fname.service) + sleep 1 + systemctl daemon-reload + elif [ -f /sbin/initctl ]; then + _upstart_conf="/etc/init/salt-$fname.conf" + # We have upstart support + echodebug "There's upstart support" + if [ ! -f $_upstart_conf ]; then + # upstart does not know about our service, let's copy the proper file + echowarn "Upstart does not appear to know about salt-$fname" + echodebug "Copying ${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-$fname.upstart to $_upstart_conf" + __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.upstart" "$_upstart_conf" + # Set service to know about virtualenv + if [ "${_VIRTUALENV_DIR}" != "null" ]; then + echo "SALT_USE_VIRTUALENV=${_VIRTUALENV_DIR}" > /etc/default/salt-${fname} + fi + /sbin/initctl reload-configuration || return 1 + fi + # No upstart support in Ubuntu!? + elif [ -f "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.init" ]; then + echodebug "There's NO upstart support!?" + echodebug "Copying ${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.init to /etc/init.d/salt-$fname" + __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.init" "/etc/init.d/salt-$fname" + chmod +x /etc/init.d/salt-$fname + + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + update-rc.d salt-$fname defaults + else + echoerror "Neither upstart nor init.d was setup for salt-$fname" + fi + done + + return 0 +} + +install_ubuntu_restart_daemons() { + [ $_START_DAEMONS -eq $BS_FALSE ] && return + + # Ensure upstart configs / systemd units are loaded + if [ -f /bin/systemctl ] && [ "$DISTRO_MAJOR_VERSION" -ge 16 ]; then + systemctl daemon-reload + elif [ -f /sbin/initctl ]; then + /sbin/initctl reload-configuration + fi + + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + if [ -f /bin/systemctl ] && [ "$DISTRO_MAJOR_VERSION" -ge 16 ]; then + echodebug "There's systemd support while checking salt-$fname" + systemctl stop salt-$fname > /dev/null 2>&1 + systemctl start salt-$fname.service && continue + # We failed to start the service, let's test the SysV code below + echodebug "Failed to start salt-$fname using systemd" + fi + + if [ -f /sbin/initctl ]; then + echodebug "There's upstart support while checking salt-$fname" + + if status salt-$fname 2>/dev/null | grep -q running; then + stop salt-$fname || (echodebug "Failed to stop salt-$fname" && return 1) + fi + + start salt-$fname && continue + # We failed to start the service, let's test the SysV code below + echodebug "Failed to start salt-$fname using Upstart" + fi + + if [ ! -f /etc/init.d/salt-$fname ]; then + echoerror "No init.d support for salt-$fname was found" + return 1 + fi + + /etc/init.d/salt-$fname stop > /dev/null 2>&1 + /etc/init.d/salt-$fname start + done + + return 0 +} + +install_ubuntu_check_services() { + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + if [ -f /bin/systemctl ] && [ "$DISTRO_MAJOR_VERSION" -ge 16 ]; then + __check_services_systemd salt-$fname || return 1 + elif [ -f /sbin/initctl ] && [ -f /etc/init/salt-${fname}.conf ]; then + __check_services_upstart salt-$fname || return 1 + elif [ -f /etc/init.d/salt-$fname ]; then + __check_services_debian salt-$fname || return 1 + fi + done + + return 0 +} +# +# End of Ubuntu Install Functions +# +####################################################################################################################### + +####################################################################################################################### +# +# Debian Install Functions +# +__install_saltstack_debian_repository() { + DEBIAN_RELEASE="$DISTRO_MAJOR_VERSION" + DEBIAN_CODENAME="$DISTRO_CODENAME" + + __PY_VERSION_REPO="apt" + if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then + __PY_VERSION_REPO="py3" + fi + + # Install downloader backend for GPG keys fetching + __PACKAGES='wget' + + # Required as it is not installed by default on Debian 9+ + if [ "$DISTRO_MAJOR_VERSION" -ge 9 ]; then + __PACKAGES="${__PACKAGES} gnupg2" + fi + + # Make sure https transport is available + if [ "$HTTP_VAL" = "https" ] ; then + __PACKAGES="${__PACKAGES} apt-transport-https ca-certificates" + fi + + # shellcheck disable=SC2086,SC2090 + __apt_get_install_noinput ${__PACKAGES} || return 1 + + # amd64 is just a part of repository URI, 32-bit pkgs are hosted under the same location + SALTSTACK_DEBIAN_URL="${HTTP_VAL}://${_REPO_URL}/${__PY_VERSION_REPO}/debian/${DEBIAN_RELEASE}/${__REPO_ARCH}/${STABLE_REV}" + echo "$__REPO_ARCH_DEB $SALTSTACK_DEBIAN_URL $DEBIAN_CODENAME main" > "/etc/apt/sources.list.d/saltstack.list" + + __apt_key_fetch "$SALTSTACK_DEBIAN_URL/SALTSTACK-GPG-KEY.pub" || return 1 + + __wait_for_apt apt-get update || return 1 +} + +install_debian_deps() { + if [ $_START_DAEMONS -eq $BS_FALSE ]; then + echowarn "Not starting daemons on Debian based distributions is not working mostly because starting them is the default behaviour." + fi + + # No user interaction, libc6 restart services for example + export DEBIAN_FRONTEND=noninteractive + + __wait_for_apt apt-get update || return 1 + + if [ "${_UPGRADE_SYS}" -eq $BS_TRUE ]; then + # Try to update GPG keys first if allowed + if [ "${_INSECURE_DL}" -eq $BS_TRUE ]; then + __apt_get_install_noinput --allow-unauthenticated debian-archive-keyring && + apt-key update && apt-get update || return 1 + fi + + __apt_get_upgrade_noinput || return 1 + fi + + if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then + PY_PKG_VER=3 + else + PY_PKG_VER="" + fi + + # Additionally install procps and pciutils which allows for Docker bootstraps. See 366#issuecomment-39666813 + __PACKAGES='procps pciutils' + + # YAML module is used for generating custom master/minion configs + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-yaml" + + # shellcheck disable=SC2086 + __apt_get_install_noinput ${__PACKAGES} || return 1 + + if [ "$_DISABLE_REPOS" -eq "$BS_FALSE" ] || [ "$_CUSTOM_REPO_URL" != "null" ]; then + __check_dpkg_architecture || return 1 + __install_saltstack_debian_repository || return 1 + fi + + if [ "${_EXTRA_PACKAGES}" != "" ]; then + echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" + # shellcheck disable=SC2086 + __apt_get_install_noinput ${_EXTRA_PACKAGES} || return 1 + fi + + return 0 +} + +install_debian_git_pre() { + if ! __check_command_exists git; then + __apt_get_install_noinput git || return 1 + fi + + if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then + __apt_get_install_noinput ca-certificates + fi + + __git_clone_and_checkout || return 1 + + # Let's trigger config_salt() + if [ "$_TEMP_CONFIG_DIR" = "null" ]; then + _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" + CONFIG_SALT_FUNC="config_salt" + fi +} + +install_debian_git_deps() { + if ! __check_command_exists git; then + __apt_get_install_noinput git || return 1 + fi + + if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then + __apt_get_install_noinput ca-certificates + fi + + __git_clone_and_checkout || return 1 + + __PACKAGES="libzmq3 libzmq3-dev lsb-release python-apt python-backports.ssl-match-hostname" + __PACKAGES="${__PACKAGES} python-crypto python-jinja2 python-msgpack python-m2crypto" + __PACKAGES="${__PACKAGES} python-requests python-tornado python-yaml python-zmq" + + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then + # Install python-libcloud if asked to + __PACKAGES="${__PACKAGES} python-libcloud" + fi + + # shellcheck disable=SC2086 + __apt_get_install_noinput ${__PACKAGES} || return 1 + + # Let's trigger config_salt() + if [ "$_TEMP_CONFIG_DIR" = "null" ]; then + _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" + CONFIG_SALT_FUNC="config_salt" + fi + + return 0 +} + +install_debian_7_git_deps() { + install_debian_deps || return 1 + install_debian_git_deps || return 1 + + return 0 +} + +install_debian_8_git_deps() { + install_debian_deps || return 1 + + if ! __check_command_exists git; then + __apt_get_install_noinput git || return 1 + fi + + if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then + __apt_get_install_noinput ca-certificates + fi + + __git_clone_and_checkout || return 1 + + __PACKAGES="libzmq3 libzmq3-dev lsb-release python-apt python-crypto python-jinja2" + __PACKAGES="${__PACKAGES} python-m2crypto python-msgpack python-requests python-systemd" + __PACKAGES="${__PACKAGES} python-yaml python-zmq python-concurrent.futures" + + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then + # Install python-libcloud if asked to + __PACKAGES="${__PACKAGES} python-libcloud" + fi + + __PIP_PACKAGES='' + if (__check_pip_allowed >/dev/null 2>&1); then + __PIP_PACKAGES='tornado<5.0' + # Install development environment for building tornado Python module + __PACKAGES="${__PACKAGES} build-essential python-dev" + + if ! __check_command_exists pip; then + __PACKAGES="${__PACKAGES} python-pip" + fi + # Attempt to configure backports repo on non-x86_64 system + elif [ $_DISABLE_REPOS -eq $BS_FALSE ] && [ "$DPKG_ARCHITECTURE" != "amd64" ]; then + # Check if Debian Backports repo already configured + if ! apt-cache policy | grep -q 'Debian Backports'; then + echo 'deb http://httpredir.debian.org/debian jessie-backports main' > \ + /etc/apt/sources.list.d/backports.list + fi + + __wait_for_apt apt-get update || return 1 + + # python-tornado package should be installed from backports repo + __PACKAGES="${__PACKAGES} python-backports.ssl-match-hostname python-tornado/jessie-backports" + else + __PACKAGES="${__PACKAGES} python-backports.ssl-match-hostname python-tornado" + fi + + # shellcheck disable=SC2086 + __apt_get_install_noinput ${__PACKAGES} || return 1 + + if [ "${__PIP_PACKAGES}" != "" ]; then + # shellcheck disable=SC2086,SC2090 + pip install -U ${__PIP_PACKAGES} || return 1 + fi + + # Let's trigger config_salt() + if [ "$_TEMP_CONFIG_DIR" = "null" ]; then + _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" + CONFIG_SALT_FUNC="config_salt" + fi + + return 0 +} + +install_debian_9_git_deps() { + install_debian_deps || return 1 + + if ! __check_command_exists git; then + __apt_get_install_noinput git || return 1 + fi + + if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then + __apt_get_install_noinput ca-certificates + fi + + __git_clone_and_checkout || return 1 + + __PACKAGES="libzmq5 lsb-release" + + if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then + PY_PKG_VER=3 + else + PY_PKG_VER="" + + # These packages are PY2-ONLY + __PACKAGES="${__PACKAGES} python-backports-abc python-m2crypto python-concurrent.futures" + fi + + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-apt python${PY_PKG_VER}-crypto python${PY_PKG_VER}-jinja2" + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-msgpack python${PY_PKG_VER}-requests python${PY_PKG_VER}-systemd" + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-tornado python${PY_PKG_VER}-yaml python${PY_PKG_VER}-zmq" + + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then + # Install python-libcloud if asked to + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-libcloud" + fi + + # shellcheck disable=SC2086 + __apt_get_install_noinput ${__PACKAGES} || return 1 + + # Let's trigger config_salt() + if [ "$_TEMP_CONFIG_DIR" = "null" ]; then + _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" + CONFIG_SALT_FUNC="config_salt" + fi + + return 0 +} + +install_debian_10_git_deps() { + install_debian_git_pre || return 1 + + if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then + _py=${_PY_EXE} + PY_PKG_VER=3 + __PACKAGES="python${PY_PKG_VER}-distutils" + else + _py="python" + PY_PKG_VER="" + __PACKAGES="" + fi + + __install_tornado_pip ${_py}|| return 1 + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-msgpack python${PY_PKG_VER}-jinja2" + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-tornado python${PY_PKG_VER}-yaml python${PY_PKG_VER}-zmq" + + # shellcheck disable=SC2086 + __apt_get_install_noinput ${__PACKAGES} || return 1 + + return 0 +} + +install_debian_stable() { + __PACKAGES="" + + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ];then + __PACKAGES="${__PACKAGES} salt-cloud" + fi + if [ "$_INSTALL_MASTER" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} salt-master" + fi + if [ "$_INSTALL_MINION" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} salt-minion" + fi + if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} salt-syndic" + fi + + # shellcheck disable=SC2086 + __apt_get_install_noinput ${__PACKAGES} || return 1 + + return 0 +} + +install_debian_7_stable() { + install_debian_stable || return 1 + return 0 +} + +install_debian_8_stable() { + install_debian_stable || return 1 + return 0 +} + +install_debian_9_stable() { + install_debian_stable || return 1 + return 0 +} + +install_debian_git() { + if [ -n "$_PY_EXE" ]; then + _PYEXE=${_PY_EXE} + else + _PYEXE=python + fi + + if [ -f "${_SALT_GIT_CHECKOUT_DIR}/salt/syspaths.py" ]; then + ${_PYEXE} setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install --install-layout=deb || return 1 + else + ${_PYEXE} setup.py ${SETUP_PY_INSTALL_ARGS} install --install-layout=deb || return 1 + fi +} + +install_debian_7_git() { + install_debian_git || return 1 + return 0 +} + +install_debian_8_git() { + install_debian_git || return 1 + return 0 +} + +install_debian_9_git() { + install_debian_git || return 1 + return 0 +} + +install_debian_git_post() { + for fname in api master minion syndic; do + # Skip if not meant to be installed + [ "$fname" = "api" ] && \ + ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue + [ "$fname" = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ "$fname" = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ "$fname" = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + # Configure SystemD for Debian 8 "Jessie" and later + if [ -f /bin/systemctl ]; then + if [ ! -f /lib/systemd/system/salt-${fname}.service ] || \ + { [ -f /lib/systemd/system/salt-${fname}.service ] && [ $_FORCE_OVERWRITE -eq $BS_TRUE ]; }; then + if [ -f "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.service" ]; then + __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.service" /lib/systemd/system + __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.environment" "/etc/default/salt-${fname}" + else + # workaround before adding Debian-specific unit files to the Salt main repo + __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.service" /lib/systemd/system + sed -i -e '/^Type/ s/notify/simple/' /lib/systemd/system/salt-${fname}.service + fi + fi + + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ "$fname" = "api" ] && continue + + /bin/systemctl enable "salt-${fname}.service" + SYSTEMD_RELOAD=$BS_TRUE + + # Install initscripts for Debian 7 "Wheezy" + elif [ ! -f "/etc/init.d/salt-$fname" ] || \ + { [ -f "/etc/init.d/salt-$fname" ] && [ "$_FORCE_OVERWRITE" -eq $BS_TRUE ]; }; then + __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/deb/salt-${fname}.init" "/etc/init.d/salt-${fname}" + __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/deb/salt-${fname}.environment" "/etc/default/salt-${fname}" + + if [ ! -f "/etc/init.d/salt-${fname}" ]; then + echowarn "The init script for salt-${fname} was not found, skipping it..." + continue + fi + + chmod +x "/etc/init.d/salt-${fname}" + + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ "$fname" = "api" ] && continue + + update-rc.d "salt-${fname}" defaults + fi + done +} + +install_debian_restart_daemons() { + [ "$_START_DAEMONS" -eq $BS_FALSE ] && return 0 + + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + if [ -f /bin/systemctl ]; then + # Debian 8 uses systemd + /bin/systemctl stop salt-$fname > /dev/null 2>&1 + /bin/systemctl start salt-$fname.service + elif [ -f /etc/init.d/salt-$fname ]; then + # Still in SysV init + /etc/init.d/salt-$fname stop > /dev/null 2>&1 + /etc/init.d/salt-$fname start + fi + done +} + +install_debian_check_services() { + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + if [ -f /bin/systemctl ]; then + __check_services_systemd salt-$fname || return 1 + elif [ -f /etc/init.d/salt-$fname ]; then + __check_services_debian salt-$fname || return 1 + fi + done + return 0 +} +# +# Ended Debian Install Functions +# +####################################################################################################################### + +####################################################################################################################### +# +# Fedora Install Functions +# + +install_fedora_deps() { + if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then + dnf -y update || return 1 + fi + + __PACKAGES="${__PACKAGES:=}" + if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then + # Packages are named python3- + PY_PKG_VER=3 + __PACKAGES="${__PACKAGES} python3-m2crypto python3-PyYAML" + else + PY_PKG_VER=2 + __PACKAGES="${__PACKAGES} m2crypto" + if [ "$DISTRO_MAJOR_VERSION" -ge 28 ]; then + __PACKAGES="${__PACKAGES} python2-pyyaml" + else + __PACKAGES="${__PACKAGES} PyYAML" + fi + fi + __PACKAGES="${__PACKAGES} dnf-utils libyaml procps-ng python${PY_PKG_VER}-crypto python${PY_PKG_VER}-jinja2" + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-msgpack python${PY_PKG_VER}-requests python${PY_PKG_VER}-zmq" + if [ "${_EXTRA_PACKAGES}" != "" ]; then + echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" + fi + + # shellcheck disable=SC2086 + dnf install -y ${__PACKAGES} ${_EXTRA_PACKAGES} || return 1 + + return 0 +} + +install_fedora_stable() { + __PACKAGES="" + + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ];then + __PACKAGES="${__PACKAGES} salt-cloud" + fi + if [ "$_INSTALL_MASTER" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} salt-master" + fi + if [ "$_INSTALL_MINION" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} salt-minion" + fi + if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} salt-syndic" + fi + + # shellcheck disable=SC2086 + dnf install -y ${__PACKAGES} || return 1 + + return 0 +} + +install_fedora_stable_post() { + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + systemctl is-enabled salt-$fname.service || (systemctl preset salt-$fname.service && systemctl enable salt-$fname.service) + sleep 1 + systemctl daemon-reload + done +} + +install_fedora_git_deps() { + if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then + # Packages are named python3- + PY_PKG_VER=3 + else + PY_PKG_VER=2 + fi + + __PACKAGES="${__PACKAGES:=}" + if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then + __PACKAGES="${__PACKAGES} ca-certificates" + fi + if ! __check_command_exists git; then + __PACKAGES="${__PACKAGES} git" + fi + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-libcloud python${PY_PKG_VER}-netaddr" + fi + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-systemd" + + # Fedora 28+ ships with tornado 5.0+ which is broken for salt on py3 + # https://github.com/saltstack/salt-bootstrap/issues/1220 + if [ "${PY_PKG_VER}" -lt 3 ] || [ "$DISTRO_MAJOR_VERSION" -lt 28 ]; then + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-tornado" + fi + + install_fedora_deps || return 1 + + __git_clone_and_checkout || return 1 + + # Fedora 28+ needs tornado <5.0 from pip + # https://github.com/saltstack/salt-bootstrap/issues/1220 + if [ "${PY_PKG_VER}" -eq 3 ] && [ "$DISTRO_MAJOR_VERSION" -ge 28 ]; then + __check_pip_allowed "You need to allow pip based installations (-P) for Tornado <5.0 in order to install Salt on Python 3" + grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" | while IFS=' +' read -r dep; do + "${_PY_EXE}" -m pip install "${dep}" || return 1 + done + fi + + # Let's trigger config_salt() + if [ "$_TEMP_CONFIG_DIR" = "null" ]; then + _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" + CONFIG_SALT_FUNC="config_salt" + fi + + return 0 +} + +install_fedora_git() { + if [ "${_PY_EXE}" != "" ]; then + _PYEXE=${_PY_EXE} + echoinfo "Using the following python version: ${_PY_EXE} to install salt" + else + _PYEXE='python2' + fi + + if [ -f "${_SALT_GIT_CHECKOUT_DIR}/salt/syspaths.py" ]; then + ${_PYEXE} setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install --prefix=/usr || return 1 + else + ${_PYEXE} setup.py ${SETUP_PY_INSTALL_ARGS} install --prefix=/usr || return 1 + fi + return 0 +} + +install_fedora_git_post() { + for fname in api master minion syndic; do + # Skip if not meant to be installed + [ $fname = "api" ] && \ + ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-${fname}.service" "/lib/systemd/system/salt-${fname}.service" + + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + systemctl is-enabled salt-$fname.service || (systemctl preset salt-$fname.service && systemctl enable salt-$fname.service) + sleep 1 + systemctl daemon-reload + done +} + +install_fedora_restart_daemons() { + [ $_START_DAEMONS -eq $BS_FALSE ] && return + + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + systemctl stop salt-$fname > /dev/null 2>&1 + systemctl start salt-$fname.service + done +} + +install_fedora_check_services() { + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + __check_services_systemd salt-$fname || return 1 + done + + return 0 +} +# +# Ended Fedora Install Functions +# +####################################################################################################################### + +####################################################################################################################### +# +# CentOS Install Functions +# +__install_epel_repository() { + if [ ${_EPEL_REPOS_INSTALLED} -eq $BS_TRUE ]; then + return 0 + fi + + # Check if epel repo is already enabled and flag it accordingly + if yum repolist | grep -q "^[!]\\?${_EPEL_REPO}/"; then + _EPEL_REPOS_INSTALLED=$BS_TRUE + return 0 + fi + + # Download latest 'epel-release' package for the distro version directly + epel_repo_url="${HTTP_VAL}://dl.fedoraproject.org/pub/epel/epel-release-latest-${DISTRO_MAJOR_VERSION}.noarch.rpm" + rpm -Uvh --force "$epel_repo_url" || return 1 + + _EPEL_REPOS_INSTALLED=$BS_TRUE + + return 0 +} + +__install_saltstack_rhel_repository() { + if [ "$ITYPE" = "stable" ]; then + repo_rev="$STABLE_REV" + else + repo_rev="latest" + fi + + __PY_VERSION_REPO="yum" + if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then + __PY_VERSION_REPO="py3" + fi + + # Avoid using '$releasever' variable for yum. + # Instead, this should work correctly on all RHEL variants. + base_url="${HTTP_VAL}://${_REPO_URL}/${__PY_VERSION_REPO}/redhat/${DISTRO_MAJOR_VERSION}/\$basearch/${repo_rev}/" + gpg_key="SALTSTACK-GPG-KEY.pub" + repo_file="/etc/yum.repos.d/saltstack.repo" + + if [ ! -s "$repo_file" ] || [ "$_FORCE_OVERWRITE" -eq $BS_TRUE ]; then + cat <<_eof > "$repo_file" +[saltstack] +name=SaltStack ${repo_rev} Release Channel for RHEL/CentOS \$releasever +baseurl=${base_url} +skip_if_unavailable=True +gpgcheck=1 +gpgkey=${base_url}${gpg_key} +enabled=1 +enabled_metadata=1 +_eof + + fetch_url="${HTTP_VAL}://${_REPO_URL}/${__PY_VERSION_REPO}/redhat/${DISTRO_MAJOR_VERSION}/${CPU_ARCH_L}/${repo_rev}/" + __rpm_import_gpg "${fetch_url}${gpg_key}" || return 1 + yum clean metadata || return 1 + elif [ "$repo_rev" != "latest" ]; then + echowarn "saltstack.repo already exists, ignoring salt version argument." + echowarn "Use -F (forced overwrite) to install $repo_rev." + fi + + return 0 +} + +install_centos_stable_deps() { + if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then + yum -y update || return 1 + fi + + if [ "$_DISABLE_REPOS" -eq "$BS_TRUE" ] && [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then + echoerror "Detected -r or -R option while installing Salt packages for Python 3." + echoerror "Python 3 packages for Salt require the EPEL repository to be installed." + echoerror "The -r and -R options are incompatible with -x and Python 3 bootstrap installs." + return 1 + fi + + if [ "$_DISABLE_REPOS" -eq "$BS_FALSE" ]; then + __install_epel_repository || return 1 + __install_saltstack_rhel_repository || return 1 + fi + + # If -R was passed, we need to configure custom repo url with rsync-ed packages + # Which is still handled in __install_saltstack_rhel_repository. This call has + # its own check in case -r was passed without -R. + if [ "$_CUSTOM_REPO_URL" != "null" ]; then + __install_saltstack_rhel_repository || return 1 + fi + + if [ "$DISTRO_MAJOR_VERSION" -ge 8 ]; then + __PACKAGES="dnf-utils chkconfig" + else + __PACKAGES="yum-utils chkconfig" + fi + + if [ "$DISTRO_MAJOR_VERSION" -ge 8 ]; then + # YAML module is used for generating custom master/minion configs + if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then + __PACKAGES="${__PACKAGES} python3-pyyaml" + else + __PACKAGES="${__PACKAGES} python2-pyyaml" + fi + elif [ "$DISTRO_MAJOR_VERSION" -eq 7 ]; then + # YAML module is used for generating custom master/minion configs + if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then + __PACKAGES="${__PACKAGES} python36-PyYAML" + else + __PACKAGES="${__PACKAGES} PyYAML" + fi + else + # YAML module is used for generating custom master/minion configs + if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then + __PACKAGES="${__PACKAGES} python34-PyYAML" + else + __PACKAGES="${__PACKAGES} PyYAML" + fi + fi + + # shellcheck disable=SC2086 + __yum_install_noinput ${__PACKAGES} || return 1 + + if [ "${_EXTRA_PACKAGES}" != "" ]; then + echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" + # shellcheck disable=SC2086 + __yum_install_noinput ${_EXTRA_PACKAGES} || return 1 + fi + + + return 0 +} + +install_centos_stable() { + __PACKAGES="" + + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ];then + __PACKAGES="${__PACKAGES} salt-cloud" + fi + if [ "$_INSTALL_MASTER" -eq $BS_TRUE ];then + __PACKAGES="${__PACKAGES} salt-master" + fi + if [ "$_INSTALL_MINION" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} salt-minion" + fi + if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ];then + __PACKAGES="${__PACKAGES} salt-syndic" + fi + + # shellcheck disable=SC2086 + __yum_install_noinput ${__PACKAGES} || return 1 + + return 0 +} + +install_centos_stable_post() { + SYSTEMD_RELOAD=$BS_FALSE + + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + if [ -f /bin/systemctl ]; then + /bin/systemctl is-enabled salt-${fname}.service > /dev/null 2>&1 || ( + /bin/systemctl preset salt-${fname}.service > /dev/null 2>&1 && + /bin/systemctl enable salt-${fname}.service > /dev/null 2>&1 + ) + + SYSTEMD_RELOAD=$BS_TRUE + elif [ -f "/etc/init.d/salt-${fname}" ]; then + /sbin/chkconfig salt-${fname} on + fi + done + + if [ "$SYSTEMD_RELOAD" -eq $BS_TRUE ]; then + /bin/systemctl daemon-reload + fi + + return 0 +} + +install_centos_git_deps() { + install_centos_stable_deps || return 1 + + if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then + __yum_install_noinput ca-certificates || return 1 + fi + + if ! __check_command_exists git; then + __yum_install_noinput git || return 1 + fi + + __git_clone_and_checkout || return 1 + + + __PACKAGES="" + _install_m2crypto_req=false + if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then + _py=${_PY_EXE} + if [ "$DISTRO_MAJOR_VERSION" -gt 6 ]; then + _install_m2crypto_req=true + fi + if [ "$DISTRO_MAJOR_VERSION" -ge 8 ]; then + # Packages are named python3- + PY_PKG_VER=3 + else + # Packages are named python36- + PY_PKG_VER=36 + fi + else + if [ "$DISTRO_MAJOR_VERSION" -eq 6 ]; then + _install_m2crypto_req=true + fi + _py="python" + PY_PKG_VER="" + + # Only Py2 needs python-futures + __PACKAGES="${__PACKAGES} python-futures" + + # There is no systemd-python3 package as of this writing + if [ "$DISTRO_MAJOR_VERSION" -ge 7 ]; then + __PACKAGES="${__PACKAGES} systemd-python" + fi + fi + + if [ "$DISTRO_MAJOR_VERSION" -ge 8 ]; then + __install_tornado_pip ${_py} || return 1 + __PACKAGES="${__PACKAGES} python3-m2crypto" + else + __PACKAGES="${__PACKAGES} m2crypto python${PY_PKG_VER}-crypto" + fi + + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-jinja2" + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-msgpack python${PY_PKG_VER}-requests" + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-tornado python${PY_PKG_VER}-zmq" + + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-libcloud" + fi + + if [ "${_INSTALL_PY}" -eq "${BS_TRUE}" ]; then + # Install Python if "-y" was passed in. + __install_python || return 1 + fi + + if [ "${_PY_EXE}" != "" ] && [ "$_PIP_ALLOWED" -eq "$BS_TRUE" ]; then + # If "-x" is defined, install dependencies with pip based on the Python version given. + _PIP_PACKAGES="m2crypto!=0.33.0 jinja2 msgpack-python pycrypto PyYAML tornado<5.0 zmq futures>=2.0" + + # install swig and openssl on cent6 + if $_install_m2crypto_req; then + __yum_install_noinput openssl-devel swig || return 1 + fi + + if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then + # Filter out any commented lines from the requirements file + _REQ_LINES="$(grep '^[^#]' "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" + for SINGLE_PACKAGE in ${_PIP_PACKAGES}; do + __REQUIRED_VERSION="$(grep "${SINGLE_PACKAGE}" "${_REQ_LINES}")" + if [ "${__REQUIRED_VERSION}" != "" ]; then + _PIP_PACKAGES=$(echo "$_PIP_PACKAGES" | sed "s/${SINGLE_PACKAGE}/${__REQUIRED_VERSION}/") + fi + done + fi + + if [ "$_INSTALL_CLOUD" -eq "${BS_TRUE}" ]; then + _PIP_PACKAGES="${_PIP_PACKAGES} apache-libcloud" + fi + + __install_pip_pkgs "${_PIP_PACKAGES}" "${_PY_EXE}" || return 1 + else + # shellcheck disable=SC2086 + __yum_install_noinput ${__PACKAGES} || return 1 + fi + + # Let's trigger config_salt() + if [ "$_TEMP_CONFIG_DIR" = "null" ]; then + _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" + CONFIG_SALT_FUNC="config_salt" + fi + + return 0 +} + +install_centos_git() { + if [ "${_PY_EXE}" != "" ]; then + _PYEXE=${_PY_EXE} + echoinfo "Using the following python version: ${_PY_EXE} to install salt" + else + _PYEXE='python2' + fi + + if [ -f "${_SALT_GIT_CHECKOUT_DIR}/salt/syspaths.py" ]; then + $_PYEXE setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install --prefix=/usr || return 1 + else + $_PYEXE setup.py ${SETUP_PY_INSTALL_ARGS} install --prefix=/usr || return 1 + fi + + return 0 +} + +install_centos_git_post() { + SYSTEMD_RELOAD=$BS_FALSE + + for fname in api master minion syndic; do + # Skip if not meant to be installed + [ $fname = "api" ] && \ + ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + if [ -f /bin/systemctl ]; then + if [ ! -f "/usr/lib/systemd/system/salt-${fname}.service" ] || \ + { [ -f "/usr/lib/systemd/system/salt-${fname}.service" ] && [ "$_FORCE_OVERWRITE" -eq $BS_TRUE ]; }; then + __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-${fname}.service" /usr/lib/systemd/system + fi + + SYSTEMD_RELOAD=$BS_TRUE + elif [ ! -f "/etc/init.d/salt-$fname" ] || \ + { [ -f "/etc/init.d/salt-$fname" ] && [ "$_FORCE_OVERWRITE" -eq $BS_TRUE ]; }; then + __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-${fname}" /etc/init.d + chmod +x /etc/init.d/salt-${fname} + fi + done + + if [ "$SYSTEMD_RELOAD" -eq $BS_TRUE ]; then + /bin/systemctl daemon-reload + fi + + install_centos_stable_post || return 1 + + return 0 +} + +install_centos_restart_daemons() { + [ $_START_DAEMONS -eq $BS_FALSE ] && return + + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + if [ -f /sbin/initctl ] && [ -f /etc/init/salt-${fname}.conf ]; then + # We have upstart support and upstart knows about our service + if ! /sbin/initctl status salt-$fname > /dev/null 2>&1; then + # Everything is in place and upstart gave us an error code? Fail! + return 1 + fi + + # upstart knows about this service. + # Let's try to stop it, and then start it + /sbin/initctl stop salt-$fname > /dev/null 2>&1 + # Restart service + if ! /sbin/initctl start salt-$fname > /dev/null 2>&1; then + # Failed the restart?! + return 1 + fi + elif [ -f /etc/init.d/salt-$fname ]; then + # Disable stdin to fix shell session hang on killing tee pipe + service salt-$fname stop < /dev/null > /dev/null 2>&1 + service salt-$fname start < /dev/null + elif [ -f /usr/bin/systemctl ]; then + # CentOS 7 uses systemd + /usr/bin/systemctl stop salt-$fname > /dev/null 2>&1 + /usr/bin/systemctl start salt-$fname.service + fi + done +} + +install_centos_testing_deps() { + install_centos_stable_deps || return 1 + return 0 +} + +install_centos_testing() { + install_centos_stable || return 1 + return 0 +} + +install_centos_testing_post() { + install_centos_stable_post || return 1 + return 0 +} + +install_centos_check_services() { + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + if [ -f /sbin/initctl ] && [ -f /etc/init/salt-${fname}.conf ]; then + __check_services_upstart salt-$fname || return 1 + elif [ -f /etc/init.d/salt-$fname ]; then + __check_services_sysvinit salt-$fname || return 1 + elif [ -f /usr/bin/systemctl ]; then + __check_services_systemd salt-$fname || return 1 + fi + done + + return 0 +} +# +# Ended CentOS Install Functions +# +####################################################################################################################### + +####################################################################################################################### +# +# RedHat Install Functions +# +install_red_hat_linux_stable_deps() { + install_centos_stable_deps || return 1 + return 0 +} + +install_red_hat_linux_git_deps() { + install_centos_git_deps || return 1 + return 0 +} + +install_red_hat_enterprise_linux_stable_deps() { + install_red_hat_linux_stable_deps || return 1 + return 0 +} + +install_red_hat_enterprise_linux_git_deps() { + install_red_hat_linux_git_deps || return 1 + return 0 +} + +install_red_hat_enterprise_server_stable_deps() { + install_red_hat_linux_stable_deps || return 1 + return 0 +} + +install_red_hat_enterprise_server_git_deps() { + install_red_hat_linux_git_deps || return 1 + return 0 +} + +install_red_hat_enterprise_workstation_stable_deps() { + install_red_hat_linux_stable_deps || return 1 + return 0 +} + +install_red_hat_enterprise_workstation_git_deps() { + install_red_hat_linux_git_deps || return 1 + return 0 +} + +install_red_hat_linux_stable() { + install_centos_stable || return 1 + return 0 +} + +install_red_hat_linux_git() { + install_centos_git || return 1 + return 0 +} + +install_red_hat_enterprise_linux_stable() { + install_red_hat_linux_stable || return 1 + return 0 +} + +install_red_hat_enterprise_linux_git() { + install_red_hat_linux_git || return 1 + return 0 +} + +install_red_hat_enterprise_server_stable() { + install_red_hat_linux_stable || return 1 + return 0 +} + +install_red_hat_enterprise_server_git() { + install_red_hat_linux_git || return 1 + return 0 +} + +install_red_hat_enterprise_workstation_stable() { + install_red_hat_linux_stable || return 1 + return 0 +} + +install_red_hat_enterprise_workstation_git() { + install_red_hat_linux_git || return 1 + return 0 +} + +install_red_hat_linux_stable_post() { + install_centos_stable_post || return 1 + return 0 +} + +install_red_hat_linux_restart_daemons() { + install_centos_restart_daemons || return 1 + return 0 +} + +install_red_hat_linux_git_post() { + install_centos_git_post || return 1 + return 0 +} + +install_red_hat_enterprise_linux_stable_post() { + install_red_hat_linux_stable_post || return 1 + return 0 +} + +install_red_hat_enterprise_linux_restart_daemons() { + install_red_hat_linux_restart_daemons || return 1 + return 0 +} + +install_red_hat_enterprise_linux_git_post() { + install_red_hat_linux_git_post || return 1 + return 0 +} + +install_red_hat_enterprise_server_stable_post() { + install_red_hat_linux_stable_post || return 1 + return 0 +} + +install_red_hat_enterprise_server_restart_daemons() { + install_red_hat_linux_restart_daemons || return 1 + return 0 +} + +install_red_hat_enterprise_server_git_post() { + install_red_hat_linux_git_post || return 1 + return 0 +} + +install_red_hat_enterprise_workstation_stable_post() { + install_red_hat_linux_stable_post || return 1 + return 0 +} + +install_red_hat_enterprise_workstation_restart_daemons() { + install_red_hat_linux_restart_daemons || return 1 + return 0 +} + +install_red_hat_enterprise_workstation_git_post() { + install_red_hat_linux_git_post || return 1 + return 0 +} + +install_red_hat_linux_testing_deps() { + install_centos_testing_deps || return 1 + return 0 +} + +install_red_hat_linux_testing() { + install_centos_testing || return 1 + return 0 +} + +install_red_hat_linux_testing_post() { + install_centos_testing_post || return 1 + return 0 +} + +install_red_hat_enterprise_server_testing_deps() { + install_centos_testing_deps || return 1 + return 0 +} + +install_red_hat_enterprise_server_testing() { + install_centos_testing || return 1 + return 0 +} + +install_red_hat_enterprise_server_testing_post() { + install_centos_testing_post || return 1 + return 0 +} + +install_red_hat_enterprise_workstation_testing_deps() { + install_centos_testing_deps || return 1 + return 0 +} + +install_red_hat_enterprise_workstation_testing() { + install_centos_testing || return 1 + return 0 +} + +install_red_hat_enterprise_workstation_testing_post() { + install_centos_testing_post || return 1 + return 0 +} +# +# Ended RedHat Install Functions +# +####################################################################################################################### + +####################################################################################################################### +# +# Oracle Linux Install Functions +# +install_oracle_linux_stable_deps() { + install_centos_stable_deps || return 1 + return 0 +} + +install_oracle_linux_git_deps() { + install_centos_git_deps || return 1 + return 0 +} + +install_oracle_linux_testing_deps() { + install_centos_testing_deps || return 1 + return 0 +} + +install_oracle_linux_stable() { + install_centos_stable || return 1 + return 0 +} + +install_oracle_linux_git() { + install_centos_git || return 1 + return 0 +} + +install_oracle_linux_testing() { + install_centos_testing || return 1 + return 0 +} + +install_oracle_linux_stable_post() { + install_centos_stable_post || return 1 + return 0 +} + +install_oracle_linux_git_post() { + install_centos_git_post || return 1 + return 0 +} + +install_oracle_linux_testing_post() { + install_centos_testing_post || return 1 + return 0 +} + +install_oracle_linux_restart_daemons() { + install_centos_restart_daemons || return 1 + return 0 +} + +install_oracle_linux_check_services() { + install_centos_check_services || return 1 + return 0 +} +# +# Ended Oracle Linux Install Functions +# +####################################################################################################################### + +####################################################################################################################### +# +# Scientific Linux Install Functions +# +install_scientific_linux_stable_deps() { + install_centos_stable_deps || return 1 + return 0 +} + +install_scientific_linux_git_deps() { + install_centos_git_deps || return 1 + return 0 +} + +install_scientific_linux_testing_deps() { + install_centos_testing_deps || return 1 + return 0 +} + +install_scientific_linux_stable() { + install_centos_stable || return 1 + return 0 +} + +install_scientific_linux_git() { + install_centos_git || return 1 + return 0 +} + +install_scientific_linux_testing() { + install_centos_testing || return 1 + return 0 +} + +install_scientific_linux_stable_post() { + install_centos_stable_post || return 1 + return 0 +} + +install_scientific_linux_git_post() { + install_centos_git_post || return 1 + return 0 +} + +install_scientific_linux_testing_post() { + install_centos_testing_post || return 1 + return 0 +} + +install_scientific_linux_restart_daemons() { + install_centos_restart_daemons || return 1 + return 0 +} + +install_scientific_linux_check_services() { + install_centos_check_services || return 1 + return 0 +} +# +# Ended Scientific Linux Install Functions +# +####################################################################################################################### + +####################################################################################################################### +# +# CloudLinux Install Functions +# +install_cloud_linux_stable_deps() { + install_centos_stable_deps || return 1 + return 0 +} + +install_cloud_linux_git_deps() { + install_centos_git_deps || return 1 + return 0 +} + +install_cloud_linux_testing_deps() { + install_centos_testing_deps || return 1 + return 0 +} + +install_cloud_linux_stable() { + install_centos_stable || return 1 + return 0 +} + +install_cloud_linux_git() { + install_centos_git || return 1 + return 0 +} + +install_cloud_linux_testing() { + install_centos_testing || return 1 + return 0 +} + +install_cloud_linux_stable_post() { + install_centos_stable_post || return 1 + return 0 +} + +install_cloud_linux_git_post() { + install_centos_git_post || return 1 + return 0 +} + +install_cloud_linux_testing_post() { + install_centos_testing_post || return 1 + return 0 +} + +install_cloud_linux_restart_daemons() { + install_centos_restart_daemons || return 1 + return 0 +} + +install_cloud_linux_check_services() { + install_centos_check_services || return 1 + return 0 +} +# +# End of CloudLinux Install Functions +# +####################################################################################################################### + +####################################################################################################################### +# +# Alpine Linux Install Functions +# +install_alpine_linux_stable_deps() { + if ! grep -q '^[^#].\+alpine/.\+/community' /etc/apk/repositories; then + # Add community repository entry based on the "main" repo URL + __REPO=$(grep '^[^#].\+alpine/.\+/main\>' /etc/apk/repositories) + echo "${__REPO}" | sed -e 's/main/community/' >> /etc/apk/repositories + fi + + apk update + + # Get latest root CA certs + apk -U add ca-certificates + + if ! __check_command_exists openssl; then + # Install OpenSSL to be able to pull from https:// URLs + apk -U add openssl + fi +} + +install_alpine_linux_git_deps() { + install_alpine_linux_stable_deps || return 1 + + apk -U add python2 py-virtualenv py2-crypto py2-m2crypto py2-setuptools \ + py2-jinja2 py2-yaml py2-markupsafe py2-msgpack py2-psutil \ + py2-zmq zeromq py2-requests || return 1 + + if ! __check_command_exists git; then + apk -U add git || return 1 + fi + + __git_clone_and_checkout || return 1 + + if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then + # We're on the develop branch, install whichever tornado is on the requirements file + __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" + if [ "${__REQUIRED_TORNADO}" != "" ]; then + apk -U add py2-tornado || return 1 + fi + fi + + # Let's trigger config_salt() + if [ "$_TEMP_CONFIG_DIR" = "null" ]; then + _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" + CONFIG_SALT_FUNC="config_salt" + fi +} + +install_alpine_linux_stable() { + __PACKAGES="salt" + + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ];then + __PACKAGES="${__PACKAGES} salt-cloud" + fi + if [ "$_INSTALL_MASTER" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} salt-master" + fi + if [ "$_INSTALL_MINION" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} salt-minion" + fi + if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} salt-syndic" + fi + + # shellcheck disable=SC2086 + apk -U add ${__PACKAGES} || return 1 + return 0 +} + +install_alpine_linux_git() { + if [ -f "${_SALT_GIT_CHECKOUT_DIR}/salt/syspaths.py" ]; then + python2 setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install || return 1 + else + python2 setup.py ${SETUP_PY_INSTALL_ARGS} install || return 1 + fi +} + +install_alpine_linux_post() { + for fname in api master minion syndic; do + # Skip if not meant to be installed + [ $fname = "api" ] && \ + ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + if [ -f /sbin/rc-update ]; then + script_url="${_SALTSTACK_REPO_URL%.git}/raw/develop/pkg/alpine/salt-$fname" + [ -f "/etc/init.d/salt-$fname" ] || __fetch_url "/etc/init.d/salt-$fname" "$script_url" + + # shellcheck disable=SC2181 + if [ $? -eq 0 ]; then + chmod +x "/etc/init.d/salt-$fname" + else + echoerror "Failed to get OpenRC init script for $OS_NAME from $script_url." + return 1 + fi + + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + /sbin/rc-update add "salt-$fname" > /dev/null 2>&1 || return 1 + fi + done +} + +install_alpine_linux_restart_daemons() { + [ "${_START_DAEMONS}" -eq $BS_FALSE ] && return + + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + # Disable stdin to fix shell session hang on killing tee pipe + /sbin/rc-service salt-$fname stop < /dev/null > /dev/null 2>&1 + /sbin/rc-service salt-$fname start < /dev/null || return 1 + done +} + +install_alpine_linux_check_services() { + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + __check_services_alpine salt-$fname || return 1 + done + + return 0 +} + +daemons_running_alpine_linux() { + [ "${_START_DAEMONS}" -eq $BS_FALSE ] && return + + FAILED_DAEMONS=0 + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + # shellcheck disable=SC2009 + if [ "$(ps wwwaux | grep -v grep | grep salt-$fname)" = "" ]; then + echoerror "salt-$fname was not found running" + FAILED_DAEMONS=$((FAILED_DAEMONS + 1)) + fi + done + + return $FAILED_DAEMONS +} + +# +# Ended Alpine Linux Install Functions +# +####################################################################################################################### + + +####################################################################################################################### +# +# Amazon Linux AMI Install Functions +# + +install_amazon_linux_ami_deps() { + # Shim to figure out if we're using old (rhel) or new (aws) rpms. + _USEAWS=$BS_FALSE + pkg_append="python" + + if [ "$ITYPE" = "stable" ]; then + repo_rev="$STABLE_REV" + else + repo_rev="latest" + fi + + if echo $repo_rev | grep -E -q '^archive'; then + year=$(echo "$repo_rev" | cut -d '/' -f 2 | cut -c1-4) + else + year=$(echo "$repo_rev" | cut -c1-4) + fi + + if echo "$repo_rev" | grep -E -q '^(latest|2016\.11)$' || \ + [ "$year" -gt 2016 ]; then + _USEAWS=$BS_TRUE + pkg_append="python27" + fi + + # We need to install yum-utils before doing anything else when installing on + # Amazon Linux ECS-optimized images. See issue #974. + __yum_install_noinput yum-utils + + # Do upgrade early + if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then + yum -y update || return 1 + fi + + if [ $_DISABLE_REPOS -eq $BS_FALSE ] || [ "$_CUSTOM_REPO_URL" != "null" ]; then + __REPO_FILENAME="saltstack-repo.repo" + + # Set a few vars to make life easier. + if [ $_USEAWS -eq $BS_TRUE ]; then + base_url="$HTTP_VAL://${_REPO_URL}/yum/amazon/latest/\$basearch/$repo_rev/" + gpg_key="${base_url}SALTSTACK-GPG-KEY.pub" + repo_name="SaltStack repo for Amazon Linux" + else + base_url="$HTTP_VAL://${_REPO_URL}/yum/redhat/6/\$basearch/$repo_rev/" + gpg_key="${base_url}SALTSTACK-GPG-KEY.pub" + repo_name="SaltStack repo for RHEL/CentOS 6" + fi + + # This should prob be refactored to use __install_saltstack_rhel_repository() + # With args passed in to do the right thing. Reformatted to be more like the + # amazon linux yum file. + if [ ! -s "/etc/yum.repos.d/${__REPO_FILENAME}" ]; then + cat <<_eof > "/etc/yum.repos.d/${__REPO_FILENAME}" +[saltstack-repo] +name=$repo_name +failovermethod=priority +priority=10 +gpgcheck=1 +gpgkey=$gpg_key +baseurl=$base_url +_eof + fi + + fi + + # Package python-ordereddict-1.1-2.el6.noarch is obsoleted by python26-2.6.9-2.88.amzn1.x86_64 + # which is already installed + __PACKAGES="m2crypto ${pkg_append}-crypto ${pkg_append}-jinja2 ${pkg_append}-PyYAML" + __PACKAGES="${__PACKAGES} ${pkg_append}-msgpack ${pkg_append}-requests ${pkg_append}-zmq" + __PACKAGES="${__PACKAGES} ${pkg_append}-futures" + + # shellcheck disable=SC2086 + __yum_install_noinput ${__PACKAGES} || return 1 + + if [ "${_EXTRA_PACKAGES}" != "" ]; then + echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" + # shellcheck disable=SC2086 + __yum_install_noinput ${_EXTRA_PACKAGES} || return 1 + fi +} + +install_amazon_linux_ami_git_deps() { + if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then + yum -y install ca-certificates || return 1 + fi + + PIP_EXE='pip' + if __check_command_exists python2.7; then + if ! __check_command_exists pip2.7; then + if ! __check_command_exists easy_install-2.7; then + __yum_install_noinput python27-setuptools + fi + /usr/bin/easy_install-2.7 pip || return 1 + fi + PIP_EXE='/usr/local/bin/pip2.7' + _PY_EXE='python2.7' + fi + + install_amazon_linux_ami_deps || return 1 + + if ! __check_command_exists git; then + __yum_install_noinput git || return 1 + fi + + __git_clone_and_checkout || return 1 + + __PACKAGES="" + __PIP_PACKAGES="" + + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then + __check_pip_allowed "You need to allow pip based installations (-P) in order to install apache-libcloud" + __PACKAGES="${__PACKAGES} python27-pip" + __PIP_PACKAGES="${__PIP_PACKAGES} apache-libcloud>=$_LIBCLOUD_MIN_VERSION" + fi + + if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then + # We're on the develop branch, install whichever tornado is on the requirements file + __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" + if [ "${__REQUIRED_TORNADO}" != "" ]; then + __PACKAGES="${__PACKAGES} ${pkg_append}-tornado" + fi + fi + + if [ "${__PACKAGES}" != "" ]; then + # shellcheck disable=SC2086 + __yum_install_noinput ${__PACKAGES} || return 1 + fi + + if [ "${__PIP_PACKAGES}" != "" ]; then + # shellcheck disable=SC2086 + ${PIP_EXE} install ${__PIP_PACKAGES} || return 1 + fi + + # Let's trigger config_salt() + if [ "$_TEMP_CONFIG_DIR" = "null" ]; then + _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" + CONFIG_SALT_FUNC="config_salt" + fi + + return 0 +} + +install_amazon_linux_ami_2_git_deps() { + if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then + yum -y install ca-certificates || return 1 + fi + + PIP_EXE='pip' + if __check_command_exists python2.7; then + if ! __check_command_exists pip2.7; then + __yum_install_noinput python2-pip + fi + PIP_EXE='/bin/pip' + _PY_EXE='python2.7' + fi + + install_amazon_linux_ami_2_deps || return 1 + + if ! __check_command_exists git; then + __yum_install_noinput git || return 1 + fi + + __git_clone_and_checkout || return 1 + + __PACKAGES="" + __PIP_PACKAGES="" + + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then + __check_pip_allowed "You need to allow pip based installations (-P) in order to install apache-libcloud" + __PACKAGES="${__PACKAGES} python27-pip" + __PIP_PACKAGES="${__PIP_PACKAGES} apache-libcloud>=$_LIBCLOUD_MIN_VERSION" + fi + + if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then + # We're on the develop branch, install whichever tornado is on the requirements file + __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" + if [ "${__REQUIRED_TORNADO}" != "" ]; then + __PACKAGES="${__PACKAGES} ${pkg_append}-tornado" + fi + fi + + if [ "${__PACKAGES}" != "" ]; then + # shellcheck disable=SC2086 + __yum_install_noinput ${__PACKAGES} || return 1 + fi + + if [ "${__PIP_PACKAGES}" != "" ]; then + # shellcheck disable=SC2086 + ${PIP_EXE} install ${__PIP_PACKAGES} || return 1 + fi + + # Let's trigger config_salt() + if [ "$_TEMP_CONFIG_DIR" = "null" ]; then + _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" + CONFIG_SALT_FUNC="config_salt" + fi + + return 0 +} + +install_amazon_linux_ami_2_deps() { + # Shim to figure out if we're using old (rhel) or new (aws) rpms. + _USEAWS=$BS_FALSE + pkg_append="python" + + if [ "$ITYPE" = "stable" ]; then + repo_rev="$STABLE_REV" + else + repo_rev="latest" + fi + + if echo $repo_rev | grep -E -q '^archive'; then + year=$(echo "$repo_rev" | cut -d '/' -f 2 | cut -c1-4) + else + year=$(echo "$repo_rev" | cut -c1-4) + fi + + if echo "$repo_rev" | grep -E -q '^(latest|2016\.11)$' || \ + [ "$year" -gt 2016 ]; then + _USEAWS=$BS_TRUE + pkg_append="python" + fi + + # We need to install yum-utils before doing anything else when installing on + # Amazon Linux ECS-optimized images. See issue #974. + __yum_install_noinput yum-utils + + # Do upgrade early + if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then + yum -y update || return 1 + fi + + if [ $_DISABLE_REPOS -eq $BS_FALSE ] || [ "$_CUSTOM_REPO_URL" != "null" ]; then + __REPO_FILENAME="saltstack-repo.repo" + + base_url="$HTTP_VAL://${_REPO_URL}/yum/amazon/2/\$basearch/$repo_rev/" + gpg_key="${base_url}SALTSTACK-GPG-KEY.pub + ${base_url}base/RPM-GPG-KEY-CentOS-7" + repo_name="SaltStack repo for Amazon Linux 2.0" + + # This should prob be refactored to use __install_saltstack_rhel_repository() + # With args passed in to do the right thing. Reformatted to be more like the + # amazon linux yum file. + if [ ! -s "/etc/yum.repos.d/${__REPO_FILENAME}" ]; then + cat <<_eof > "/etc/yum.repos.d/${__REPO_FILENAME}" +[saltstack-repo] +name=$repo_name +failovermethod=priority +priority=10 +gpgcheck=1 +gpgkey=$gpg_key +baseurl=$base_url +_eof + fi + + fi + + # Package python-ordereddict-1.1-2.el6.noarch is obsoleted by python26-2.6.9-2.88.amzn1.x86_64 + # which is already installed + __PACKAGES="m2crypto ${pkg_append}-crypto ${pkg_append}-jinja2 PyYAML procps-ng" + __PACKAGES="${__PACKAGES} ${pkg_append}-msgpack ${pkg_append}-requests ${pkg_append}-zmq" + __PACKAGES="${__PACKAGES} ${pkg_append}-futures" + + # shellcheck disable=SC2086 + __yum_install_noinput ${__PACKAGES} || return 1 + + if [ "${_EXTRA_PACKAGES}" != "" ]; then + echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" + # shellcheck disable=SC2086 + __yum_install_noinput ${_EXTRA_PACKAGES} || return 1 + fi +} + +install_amazon_linux_ami_stable() { + install_centos_stable || return 1 + return 0 +} + +install_amazon_linux_ami_stable_post() { + install_centos_stable_post || return 1 + return 0 +} + +install_amazon_linux_ami_restart_daemons() { + install_centos_restart_daemons || return 1 + return 0 +} + +install_amazon_linux_ami_git() { + install_centos_git || return 1 + return 0 +} + +install_amazon_linux_ami_git_post() { + install_centos_git_post || return 1 + return 0 +} + +install_amazon_linux_ami_testing() { + install_centos_testing || return 1 + return 0 +} + +install_amazon_linux_ami_testing_post() { + install_centos_testing_post || return 1 + return 0 +} + +install_amazon_linux_ami_2_stable() { + install_centos_stable || return 1 + return 0 +} + +install_amazon_linux_ami_2_stable_post() { + install_centos_stable_post || return 1 + return 0 +} + +install_amazon_linux_ami_2_restart_daemons() { + install_centos_restart_daemons || return 1 + return 0 +} + +install_amazon_linux_ami_2_git() { + install_centos_git || return 1 + return 0 +} + +install_amazon_linux_ami_2_git_post() { + install_centos_git_post || return 1 + return 0 +} + +install_amazon_linux_ami_2_testing() { + install_centos_testing || return 1 + return 0 +} + +install_amazon_linux_ami_2_testing_post() { + install_centos_testing_post || return 1 + return 0 +} +# +# Ended Amazon Linux AMI Install Functions +# +####################################################################################################################### + +####################################################################################################################### +# +# Arch Install Functions +# +install_arch_linux_stable_deps() { + if [ ! -f /etc/pacman.d/gnupg ]; then + pacman-key --init && pacman-key --populate archlinux || return 1 + fi + + # Pacman does not resolve dependencies on outdated versions + # They always need to be updated + pacman -Syy --noconfirm + + pacman -S --noconfirm --needed archlinux-keyring || return 1 + + pacman -Su --noconfirm --needed pacman || return 1 + + if __check_command_exists pacman-db-upgrade; then + pacman-db-upgrade || return 1 + fi + + # YAML module is used for generating custom master/minion configs + pacman -Su --noconfirm --needed python2-yaml + + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then + pacman -Su --noconfirm --needed python2-apache-libcloud || return 1 + fi + + if [ "${_EXTRA_PACKAGES}" != "" ]; then + echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" + # shellcheck disable=SC2086 + pacman -Su --noconfirm --needed ${_EXTRA_PACKAGES} || return 1 + fi +} + +install_arch_linux_git_deps() { + install_arch_linux_stable_deps + + # Don't fail if un-installing python2-distribute threw an error + if ! __check_command_exists git; then + pacman -Sy --noconfirm --needed git || return 1 + fi + pacman -R --noconfirm python2-distribute + pacman -Su --noconfirm --needed python2-crypto python2-setuptools python2-jinja \ + python2-m2crypto python2-futures python2-markupsafe python2-msgpack python2-psutil \ + python2-pyzmq zeromq python2-requests python2-systemd || return 1 + + __git_clone_and_checkout || return 1 + + if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then + # We're on the develop branch, install whichever tornado is on the requirements file + __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" + if [ "${__REQUIRED_TORNADO}" != "" ]; then + pacman -Su --noconfirm --needed python2-tornado + fi + fi + + + # Let's trigger config_salt() + if [ "$_TEMP_CONFIG_DIR" = "null" ]; then + _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" + CONFIG_SALT_FUNC="config_salt" + fi + + return 0 +} + +install_arch_linux_stable() { + # Pacman does not resolve dependencies on outdated versions + # They always need to be updated + pacman -Syy --noconfirm + + pacman -Su --noconfirm --needed pacman || return 1 + # See https://mailman.archlinux.org/pipermail/arch-dev-public/2013-June/025043.html + # to know why we're ignoring below. + pacman -Syu --noconfirm --ignore filesystem,bash || return 1 + pacman -S --noconfirm --needed bash || return 1 + pacman -Su --noconfirm || return 1 + # We can now resume regular salt update + pacman -Syu --noconfirm salt python2-futures || return 1 + return 0 +} + +install_arch_linux_git() { + if [ -f "${_SALT_GIT_CHECKOUT_DIR}/salt/syspaths.py" ]; then + python2 setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install || return 1 + else + python2 setup.py ${SETUP_PY_INSTALL_ARGS} install || return 1 + fi + return 0 +} + +install_arch_linux_post() { + for fname in api master minion syndic; do + # Skip if not meant to be installed + [ $fname = "api" ] && \ + ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + # Since Arch's pacman renames configuration files + if [ "$_TEMP_CONFIG_DIR" != "null" ] && [ -f "$_SALT_ETC_DIR/$fname.pacorig" ]; then + # Since a configuration directory was provided, it also means that any + # configuration file copied was renamed by Arch, see: + # https://wiki.archlinux.org/index.php/Pacnew_and_Pacsave_Files#.pacorig + __copyfile "$_SALT_ETC_DIR/$fname.pacorig" "$_SALT_ETC_DIR/$fname" $BS_TRUE + fi + + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + if [ -f /usr/bin/systemctl ]; then + # Using systemd + /usr/bin/systemctl is-enabled salt-$fname.service > /dev/null 2>&1 || ( + /usr/bin/systemctl preset salt-$fname.service > /dev/null 2>&1 && + /usr/bin/systemctl enable salt-$fname.service > /dev/null 2>&1 + ) + sleep 1 + /usr/bin/systemctl daemon-reload + continue + fi + + # XXX: How do we enable old Arch init.d scripts? + done +} + +install_arch_linux_git_post() { + for fname in api master minion syndic; do + # Skip if not meant to be installed + [ $fname = "api" ] && \ + ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + if [ -f /usr/bin/systemctl ]; then + __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-${fname}.service" "/lib/systemd/system/salt-${fname}.service" + + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + /usr/bin/systemctl is-enabled salt-${fname}.service > /dev/null 2>&1 || ( + /usr/bin/systemctl preset salt-${fname}.service > /dev/null 2>&1 && + /usr/bin/systemctl enable salt-${fname}.service > /dev/null 2>&1 + ) + sleep 1 + /usr/bin/systemctl daemon-reload + continue + fi + + # SysV init!? + __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-$fname" "/etc/rc.d/init.d/salt-$fname" + chmod +x /etc/rc.d/init.d/salt-$fname + done +} + +install_arch_linux_restart_daemons() { + [ $_START_DAEMONS -eq $BS_FALSE ] && return + + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + if [ -f /usr/bin/systemctl ]; then + /usr/bin/systemctl stop salt-$fname.service > /dev/null 2>&1 + /usr/bin/systemctl start salt-$fname.service + continue + fi + + /etc/rc.d/salt-$fname stop > /dev/null 2>&1 + /etc/rc.d/salt-$fname start + done +} + +install_arch_check_services() { + if [ ! -f /usr/bin/systemctl ]; then + # Not running systemd!? Don't check! + return 0 + fi + + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + __check_services_systemd salt-$fname || return 1 + done + + return 0 +} +# +# Ended Arch Install Functions +# +####################################################################################################################### + +####################################################################################################################### +# +# FreeBSD Install Functions +# + +__freebsd_get_packagesite() { + if [ "$CPU_ARCH_L" = "amd64" ]; then + BSD_ARCH="x86:64" + elif [ "$CPU_ARCH_L" = "x86_64" ]; then + BSD_ARCH="x86:64" + elif [ "$CPU_ARCH_L" = "i386" ]; then + BSD_ARCH="x86:32" + elif [ "$CPU_ARCH_L" = "i686" ]; then + BSD_ARCH="x86:32" + fi + + # Since the variable might not be set, don't, momentarily treat it as a + # failure + set +o nounset + + # ABI is a std format for identifying release / architecture combos + ABI="freebsd:${DISTRO_MAJOR_VERSION}:${BSD_ARCH}" + _PACKAGESITE="http://pkg.freebsd.org/${ABI}/latest" + # Awkwardly, we want the `${ABI}` to be in conf file without escaping + PKGCONFURL="pkg+http://pkg.freebsd.org/\${ABI}/latest" + SALTPKGCONFURL="http://repo.saltstack.com/freebsd/\${ABI}/" + + # Treat unset variables as errors once more + set -o nounset +} + +# Using a separate conf step to head for idempotent install... +__configure_freebsd_pkg_details() { + ## pkg.conf is deprecated. + ## We use conf files in /usr/local or /etc instead + mkdir -p /usr/local/etc/pkg/repos/ + mkdir -p /etc/pkg/ + + ## Use new JSON-like format for pkg repo configs + ## check if /etc/pkg/FreeBSD.conf is already in place + if [ ! -f /etc/pkg/FreeBSD.conf ]; then + conf_file=/usr/local/etc/pkg/repos/freebsd.conf + { + echo "FreeBSD:{" + echo " url: \"${PKGCONFURL}\"," + echo " mirror_type: \"srv\"," + echo " signature_type: \"fingerprints\"," + echo " fingerprints: \"/usr/share/keys/pkg\"," + echo " enabled: true" + echo "}" + } > $conf_file + __copyfile $conf_file /etc/pkg/FreeBSD.conf + fi + FROM_FREEBSD="-r FreeBSD" + + ##### Workaround : Waiting for SaltStack Repository to be available for FreeBSD 12 #### + if [ "${DISTRO_MAJOR_VERSION}" -ne 12 ]; then + ## add saltstack freebsd repo + salt_conf_file=/usr/local/etc/pkg/repos/saltstack.conf + { + echo "SaltStack:{" + echo " url: \"${SALTPKGCONFURL}\"," + echo " mirror_type: \"http\"," + echo " enabled: true" + echo " priority: 10" + echo "}" + } > $salt_conf_file + FROM_SALTSTACK="-r SaltStack" + fi + ##### End Workaround : Waiting for SaltStack Repository to be available for FreeBSD 12 #### + + ## ensure future ports builds use pkgng + echo "WITH_PKGNG= yes" >> /etc/make.conf + + /usr/local/sbin/pkg update -f || return 1 +} + +install_freebsd_9_stable_deps() { + _SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/usr/local/etc/salt} + _PKI_DIR=${_SALT_ETC_DIR}/pki + + if [ $_DISABLE_REPOS -eq $BS_FALSE ]; then + #make variables available even if pkg already installed + __freebsd_get_packagesite + + if [ ! -x /usr/local/sbin/pkg ]; then + + # install new `pkg` code from its own tarball. + fetch "${_PACKAGESITE}/Latest/pkg.txz" || return 1 + tar xf ./pkg.txz -s ",/.*/,,g" "*/pkg-static" || return 1 + ./pkg-static add ./pkg.txz || return 1 + /usr/local/sbin/pkg2ng || return 1 + fi + + # Configure the pkg repository using new approach + __configure_freebsd_pkg_details || return 1 + fi + + # Now install swig30 + # shellcheck disable=SC2086 + /usr/local/sbin/pkg install ${FROM_FREEBSD} -y swig30 || return 1 + + # YAML module is used for generating custom master/minion configs + # shellcheck disable=SC2086 + /usr/local/sbin/pkg install ${FROM_FREEBSD} -y py27-yaml || return 1 + + if [ "${_EXTRA_PACKAGES}" != "" ]; then + echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" + # shellcheck disable=SC2086 + /usr/local/sbin/pkg install ${FROM_FREEBSD} -y ${_EXTRA_PACKAGES} || return 1 + fi + + if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then + pkg upgrade -y || return 1 + fi + + return 0 +} + +install_freebsd_10_stable_deps() { + install_freebsd_9_stable_deps +} + +install_freebsd_11_stable_deps() { + install_freebsd_9_stable_deps +} + +install_freebsd_12_stable_deps() { + install_freebsd_9_stable_deps +} + +install_freebsd_git_deps() { + install_freebsd_9_stable_deps || return 1 + + # shellcheck disable=SC2086 + SALT_DEPENDENCIES=$(/usr/local/sbin/pkg search ${FROM_FREEBSD} -R -d sysutils/py-salt | grep -i origin | sed -e 's/^[[:space:]]*//' | tail -n +2 | awk -F\" '{print $2}' | tr '\n' ' ') + # shellcheck disable=SC2086 + /usr/local/sbin/pkg install ${FROM_FREEBSD} -y ${SALT_DEPENDENCIES} || return 1 + # install python meta package + /usr/local/sbin/pkg install -y lang/python || return 1 + + if ! __check_command_exists git; then + /usr/local/sbin/pkg install -y git || return 1 + fi + + /usr/local/sbin/pkg install -y www/py-requests || return 1 + + __git_clone_and_checkout || return 1 + + if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then + # We're on the develop branch, install whichever tornado is on the requirements file + __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" + if [ "${__REQUIRED_TORNADO}" != "" ]; then + /usr/local/sbin/pkg install -y www/py-tornado4 || return 1 + fi + fi + + echodebug "Adapting paths to FreeBSD" + # The list of files was taken from Salt's BSD port Makefile + for file in doc/man/salt-key.1 doc/man/salt-cp.1 doc/man/salt-minion.1 \ + doc/man/salt-syndic.1 doc/man/salt-master.1 doc/man/salt-run.1 \ + doc/man/salt.7 doc/man/salt.1 doc/man/salt-call.1; do + [ ! -f $file ] && continue + echodebug "Patching ${file}" + sed -in -e "s|/etc/salt|${_SALT_ETC_DIR}|" \ + -e "s|/srv/salt|${_SALT_ETC_DIR}/states|" \ + -e "s|/srv/pillar|${_SALT_ETC_DIR}/pillar|" ${file} + done + if [ ! -f salt/syspaths.py ]; then + # We still can't provide the system paths, salt 0.16.x + # Let's patch salt's source and adapt paths to what's expected on FreeBSD + echodebug "Replacing occurrences of '/etc/salt' with ${_SALT_ETC_DIR}" + # The list of files was taken from Salt's BSD port Makefile + for file in conf/minion conf/master salt/config.py salt/client.py \ + salt/modules/mysql.py salt/utils/parsers.py salt/modules/tls.py \ + salt/modules/postgres.py salt/utils/migrations.py; do + [ ! -f $file ] && continue + echodebug "Patching ${file}" + sed -in -e "s|/etc/salt|${_SALT_ETC_DIR}|" \ + -e "s|/srv/salt|${_SALT_ETC_DIR}/states|" \ + -e "s|/srv/pillar|${_SALT_ETC_DIR}/pillar|" ${file} + done + fi + echodebug "Finished patching" + + # Let's trigger config_salt() + if [ "$_TEMP_CONFIG_DIR" = "null" ]; then + _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" + CONFIG_SALT_FUNC="config_salt" + + fi + + return 0 +} + +install_freebsd_9_stable() { + # shellcheck disable=SC2086 + /usr/local/sbin/pkg install ${FROM_SALTSTACK} -y sysutils/py-salt || return 1 + return 0 +} + +install_freebsd_10_stable() { + # shellcheck disable=SC2086 + /usr/local/sbin/pkg install ${FROM_FREEBSD} -y sysutils/py-salt || return 1 + return 0 +} + +install_freebsd_11_stable() { +# +# installing latest version of salt from FreeBSD CURRENT ports repo +# + # shellcheck disable=SC2086 + /usr/local/sbin/pkg install ${FROM_FREEBSD} -y sysutils/py-salt || return 1 + + return 0 +} + +install_freebsd_12_stable() { +# +# installing latest version of salt from FreeBSD CURRENT ports repo +# + # shellcheck disable=SC2086 + /usr/local/sbin/pkg install ${FROM_FREEBSD} -y sysutils/py-salt || return 1 + + return 0 +} + +install_freebsd_git() { + + # /usr/local/bin/python2 in FreeBSD is a symlink to /usr/local/bin/python2.7 + __PYTHON_PATH=$(readlink -f "$(command -v python2)") + __ESCAPED_PYTHON_PATH=$(echo "${__PYTHON_PATH}" | sed 's/\//\\\//g') + + # Install from git + if [ ! -f salt/syspaths.py ]; then + # We still can't provide the system paths, salt 0.16.x + ${__PYTHON_PATH} setup.py ${SETUP_PY_INSTALL_ARGS} install || return 1 + else + ${__PYTHON_PATH} setup.py \ + --salt-root-dir=/ \ + --salt-config-dir="${_SALT_ETC_DIR}" \ + --salt-cache-dir="${_SALT_CACHE_DIR}" \ + --salt-sock-dir=/var/run/salt \ + --salt-srv-root-dir="${_SALT_ETC_DIR}" \ + --salt-base-file-roots-dir="${_SALT_ETC_DIR}/states" \ + --salt-base-pillar-roots-dir="${_SALT_ETC_DIR}/pillar" \ + --salt-base-master-roots-dir="${_SALT_ETC_DIR}/salt-master" \ + --salt-logs-dir=/var/log/salt \ + --salt-pidfile-dir=/var/run \ + ${SETUP_PY_INSTALL_ARGS} install \ + || return 1 + fi + + for script in salt_api salt_master salt_minion salt_proxy salt_syndic; do + __fetch_url "/usr/local/etc/rc.d/${script}" "https://raw.githubusercontent.com/freebsd/freebsd-ports/master/sysutils/py-salt/files/${script}.in" || return 1 + sed -i '' 's/%%PREFIX%%/\/usr\/local/g' /usr/local/etc/rc.d/${script} + sed -i '' "s/%%PYTHON_CMD%%/${__ESCAPED_PYTHON_PATH}/g" /usr/local/etc/rc.d/${script} + chmod +x /usr/local/etc/rc.d/${script} || return 1 + done + + # And we're good to go + return 0 +} + +install_freebsd_9_stable_post() { + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + enable_string="salt_${fname}_enable=\"YES\"" + grep "$enable_string" /etc/rc.conf >/dev/null 2>&1 + [ $? -eq 1 ] && echo "$enable_string" >> /etc/rc.conf + + if [ $fname = "minion" ] ; then + grep "salt_minion_paths" /etc/rc.conf >/dev/null 2>&1 + [ $? -eq 1 ] && echo "salt_minion_paths=\"/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin\"" >> /etc/rc.conf + fi + done +} + +install_freebsd_10_stable_post() { + install_freebsd_9_stable_post +} + +install_freebsd_11_stable_post() { + install_freebsd_9_stable_post +} + +install_freebsd_12_stable_post() { + install_freebsd_9_stable_post +} + +install_freebsd_git_post() { + if [ -f $salt_conf_file ]; then + rm -f $salt_conf_file + fi + install_freebsd_9_stable_post || return 1 + return 0 +} + +install_freebsd_restart_daemons() { + [ $_START_DAEMONS -eq $BS_FALSE ] && return + + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + service salt_$fname stop > /dev/null 2>&1 + service salt_$fname start + done +} +# +# Ended FreeBSD Install Functions +# +####################################################################################################################### + +####################################################################################################################### +# +# OpenBSD Install Functions +# + +install_openbsd_deps() { + if [ $_DISABLE_REPOS -eq $BS_FALSE ]; then + OPENBSD_REPO='https://cdn.openbsd.org/pub/OpenBSD' + echoinfo "setting package repository to $OPENBSD_REPO" + echo "${OPENBSD_REPO}" >/etc/installurl || return 1 + fi + + if [ "${_EXTRA_PACKAGES}" != "" ]; then + echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" + # shellcheck disable=SC2086 + pkg_add -I -v ${_EXTRA_PACKAGES} || return 1 + fi + return 0 +} + +install_openbsd_git_deps() { + install_openbsd_deps || return 1 + pkg_add -I -v git || return 1 + __git_clone_and_checkout || return 1 + # + # Let's trigger config_salt() + # + if [ "$_TEMP_CONFIG_DIR" = "null" ]; then + _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" + CONFIG_SALT_FUNC="config_salt" + fi + return 0 +} + +install_openbsd_git() { + # + # Install from git + # + if [ ! -f salt/syspaths.py ]; then + # We still can't provide the system paths, salt 0.16.x + /usr/local/bin/python2.7 setup.py ${SETUP_PY_INSTALL_ARGS} install || return 1 + fi + return 0 +} + +install_openbsd_stable() { + pkg_add -r -I -v salt || return 1 + return 0 +} + +install_openbsd_post() { + for fname in api master minion syndic; do + [ $fname = "api" ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + rcctl enable salt_$fname + done + + return 0 +} + +install_openbsd_check_services() { + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && continue + + if [ -f /etc/rc.d/salt_${fname} ]; then + __check_services_openbsd salt_${fname} || return 1 + fi + done + + return 0 +} + +install_openbsd_restart_daemons() { + [ $_START_DAEMONS -eq $BS_FALSE ] && return + + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + rcctl restart salt_${fname} + done + + return 0 +} + +# +# Ended OpenBSD Install Functions +# +####################################################################################################################### + +####################################################################################################################### +# +# SmartOS Install Functions +# +install_smartos_deps() { + smartos_deps="$(pkgin show-deps salt | grep '^\s' | grep -v '\snot' | xargs) py27-m2crypto" + pkgin -y install "${smartos_deps}" || return 1 + + # Set _SALT_ETC_DIR to SmartOS default if they didn't specify + _SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/opt/local/etc/salt} + # We also need to redefine the PKI directory + _PKI_DIR=${_SALT_ETC_DIR}/pki + + # Let's trigger config_salt() + if [ "$_TEMP_CONFIG_DIR" = "null" ]; then + # Let's set the configuration directory to /tmp + _TEMP_CONFIG_DIR="/tmp" + CONFIG_SALT_FUNC="config_salt" + + # Let's download, since they were not provided, the default configuration files + if [ ! -f "$_SALT_ETC_DIR/minion" ] && [ ! -f "$_TEMP_CONFIG_DIR/minion" ]; then + # shellcheck disable=SC2086 + curl $_CURL_ARGS -s -o "$_TEMP_CONFIG_DIR/minion" -L \ + https://raw.githubusercontent.com/saltstack/salt/develop/conf/minion || return 1 + fi + if [ ! -f "$_SALT_ETC_DIR/master" ] && [ ! -f $_TEMP_CONFIG_DIR/master ]; then + # shellcheck disable=SC2086 + curl $_CURL_ARGS -s -o "$_TEMP_CONFIG_DIR/master" -L \ + https://raw.githubusercontent.com/saltstack/salt/develop/conf/master || return 1 + fi + fi + + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then + pkgin -y install py27-apache-libcloud || return 1 + fi + + if [ "${_EXTRA_PACKAGES}" != "" ]; then + echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" + # shellcheck disable=SC2086 + pkgin -y install ${_EXTRA_PACKAGES} || return 1 + fi + + return 0 +} + +install_smartos_git_deps() { + install_smartos_deps || return 1 + + if ! __check_command_exists git; then + pkgin -y install git || return 1 + fi + + if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then + # Install whichever tornado is in the requirements file + __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" + __check_pip_allowed "You need to allow pip based installations (-P) in order to install the python package '${__REQUIRED_TORNADO}'" + + # Install whichever futures is in the requirements file + __REQUIRED_FUTURES="$(grep futures "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" + __check_pip_allowed "You need to allow pip based installations (-P) in order to install the python package '${__REQUIRED_FUTURES}'" + + if [ "${__REQUIRED_TORNADO}" != "" ]; then + if ! __check_command_exists pip; then + pkgin -y install py27-pip + fi + pip install -U "${__REQUIRED_TORNADO}" + fi + + if [ "${__REQUIRED_FUTURES}" != "" ]; then + if ! __check_command_exists pip; then + pkgin -y install py27-pip + fi + pip install -U "${__REQUIRED_FUTURES}" + fi + fi + + __git_clone_and_checkout || return 1 + # Let's trigger config_salt() + if [ "$_TEMP_CONFIG_DIR" = "null" ]; then + _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" + CONFIG_SALT_FUNC="config_salt" + fi + + return 0 +} + +install_smartos_stable() { + pkgin -y install salt || return 1 + return 0 +} + +install_smartos_git() { + # Use setuptools in order to also install dependencies + # lets force our config path on the setup for now, since salt/syspaths.py only got fixed in 2015.5.0 + USE_SETUPTOOLS=1 /opt/local/bin/python setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install || return 1 + return 0 +} + +install_smartos_post() { + smf_dir="/opt/custom/smf" + + # Install manifest files if needed. + for fname in api master minion syndic; do + # Skip if not meant to be installed + [ $fname = "api" ] && \ + ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + svcs network/salt-$fname > /dev/null 2>&1 + if [ $? -eq 1 ]; then + if [ ! -f "$_TEMP_CONFIG_DIR/salt-$fname.xml" ]; then + # shellcheck disable=SC2086 + curl $_CURL_ARGS -s -o "$_TEMP_CONFIG_DIR/salt-$fname.xml" -L \ + "https://raw.githubusercontent.com/saltstack/salt/develop/pkg/smartos/salt-$fname.xml" + fi + svccfg import "$_TEMP_CONFIG_DIR/salt-$fname.xml" + if [ "${VIRTUAL_TYPE}" = "global" ]; then + if [ ! -d "$smf_dir" ]; then + mkdir -p "$smf_dir" || return 1 + fi + if [ ! -f "$smf_dir/salt-$fname.xml" ]; then + __copyfile "$_TEMP_CONFIG_DIR/salt-$fname.xml" "$smf_dir/" || return 1 + fi + fi + fi + done + + return 0 +} + +install_smartos_git_post() { + smf_dir="/opt/custom/smf" + + # Install manifest files if needed. + for fname in api master minion syndic; do + # Skip if not meant to be installed + [ $fname = "api" ] && \ + ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + svcs "network/salt-$fname" > /dev/null 2>&1 + if [ $? -eq 1 ]; then + svccfg import "${_SALT_GIT_CHECKOUT_DIR}/pkg/smartos/salt-$fname.xml" + if [ "${VIRTUAL_TYPE}" = "global" ]; then + if [ ! -d $smf_dir ]; then + mkdir -p "$smf_dir" + fi + if [ ! -f "$smf_dir/salt-$fname.xml" ]; then + __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/smartos/salt-$fname.xml" "$smf_dir/" + fi + fi + fi + done + + return 0 +} + +install_smartos_restart_daemons() { + [ $_START_DAEMONS -eq $BS_FALSE ] && return + + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + # Stop if running && Start service + svcadm disable salt-$fname > /dev/null 2>&1 + svcadm enable salt-$fname + done + + return 0 +} +# +# Ended SmartOS Install Functions +# +####################################################################################################################### + +####################################################################################################################### +# +# openSUSE Install Functions. +# +__ZYPPER_REQUIRES_REPLACE_FILES=-1 + +__set_suse_pkg_repo() { + + # Set distro repo variable + if [ "${DISTRO_MAJOR_VERSION}" -gt 2015 ]; then + DISTRO_REPO="openSUSE_Tumbleweed" + elif [ "${DISTRO_MAJOR_VERSION}" -ge 42 ] || [ "${DISTRO_MAJOR_VERSION}" -eq 15 ]; then + DISTRO_REPO="openSUSE_Leap_${DISTRO_MAJOR_VERSION}.${DISTRO_MINOR_VERSION}" + else + DISTRO_REPO="SLE_${DISTRO_MAJOR_VERSION}_SP${SUSE_PATCHLEVEL}" + fi + + if [ "$_DOWNSTREAM_PKG_REPO" -eq $BS_TRUE ]; then + suse_pkg_url_base="https://download.opensuse.org/repositories/systemsmanagement:/saltstack" + suse_pkg_url_path="${DISTRO_REPO}/systemsmanagement:saltstack.repo" + else + suse_pkg_url_base="${HTTP_VAL}://repo.saltstack.com/opensuse" + suse_pkg_url_path="${DISTRO_REPO}/systemsmanagement:saltstack:products.repo" + fi + SUSE_PKG_URL="$suse_pkg_url_base/$suse_pkg_url_path" +} + +__check_and_refresh_suse_pkg_repo() { + # Check to see if systemsmanagement_saltstack exists + __zypper repos | grep -q systemsmanagement_saltstack + + if [ $? -eq 1 ]; then + # zypper does not yet know anything about systemsmanagement_saltstack + __zypper addrepo --refresh "${SUSE_PKG_URL}" || return 1 + fi +} + +__version_lte() { + if ! __check_command_exists python; then + zypper zypper --non-interactive install --replacefiles --auto-agree-with-licenses python || \ + zypper zypper --non-interactive install --auto-agree-with-licenses python || return 1 + fi + + if [ "$(python -c 'import sys; V1=tuple([int(i) for i in sys.argv[1].split(".")]); V2=tuple([int(i) for i in sys.argv[2].split(".")]); print V1<=V2' "$1" "$2")" = "True" ]; then + __ZYPPER_REQUIRES_REPLACE_FILES=${BS_TRUE} + else + __ZYPPER_REQUIRES_REPLACE_FILES=${BS_FALSE} + fi +} + +__zypper() { + # Check if any zypper process is running before calling zypper again. + # This is useful when a zypper call is part of a boot process and will + # wait until the zypper process is finished, such as on AWS AMIs. + while pgrep -l zypper; do + sleep 1 + done + + zypper --non-interactive "${@}"; return $? +} + +__zypper_install() { + if [ "${__ZYPPER_REQUIRES_REPLACE_FILES}" = "-1" ]; then + __version_lte "1.10.4" "$(zypper --version | awk '{ print $2 }')" + fi + if [ "${__ZYPPER_REQUIRES_REPLACE_FILES}" = "${BS_TRUE}" ]; then + # In case of file conflicts replace old files. + # Option present in zypper 1.10.4 and newer: + # https://github.com/openSUSE/zypper/blob/95655728d26d6d5aef7796b675f4cc69bc0c05c0/package/zypper.changes#L253 + __zypper install --auto-agree-with-licenses --replacefiles "${@}"; return $? + else + __zypper install --auto-agree-with-licenses "${@}"; return $? + fi +} + +__opensuse_prep_install() { + # DRY function for common installation preparatory steps for SUSE + if [ $_DISABLE_REPOS -eq $BS_FALSE ]; then + # Is the repository already known + __set_suse_pkg_repo + # Check zypper repos and refresh if necessary + __check_and_refresh_suse_pkg_repo + fi + + __zypper --gpg-auto-import-keys refresh + + # shellcheck disable=SC2181 + if [ $? -ne 0 ] && [ $? -ne 4 ]; then + # If the exit code is not 0, and it's not 4 (failed to update a + # repository) return a failure. Otherwise continue. + return 1 + fi + + if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then + __zypper --gpg-auto-import-keys update || return 1 + fi +} + +install_opensuse_stable_deps() { + __opensuse_prep_install || return 1 + + if [ "$DISTRO_MAJOR_VERSION" -eq 12 ] && [ "$DISTRO_MINOR_VERSION" -eq 3 ]; then + # Because patterns-openSUSE-minimal_base-conflicts conflicts with python, lets remove the first one + __zypper remove patterns-openSUSE-minimal_base-conflicts + fi + + # YAML module is used for generating custom master/minion configs + # requests is still used by many salt modules + # Salt needs python-zypp installed in order to use the zypper module + __PACKAGES="python-PyYAML python-requests python-zypp" + + # shellcheck disable=SC2086 + __zypper_install ${__PACKAGES} || return 1 + + if [ "${_EXTRA_PACKAGES}" != "" ]; then + echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" + # shellcheck disable=SC2086 + __zypper_install ${_EXTRA_PACKAGES} || return 1 + fi + + return 0 +} + +install_opensuse_git_deps() { + if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ] && ! __check_command_exists update-ca-certificates; then + __zypper_install ca-certificates || return 1 + fi + + install_opensuse_stable_deps || return 1 + + if ! __check_command_exists git; then + __zypper_install git || return 1 + fi + + __zypper_install patch || return 1 + + __git_clone_and_checkout || return 1 + + __PACKAGES="libzmq5 python-Jinja2 python-m2crypto python-msgpack-python python-pycrypto python-pyzmq python-xml python-futures" + + if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then + # We're on the develop branch, install whichever tornado is on the requirements file + __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" + if [ "${__REQUIRED_TORNADO}" != "" ]; then + __PACKAGES="${__PACKAGES} python-tornado" + fi + fi + + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} python-apache-libcloud" + fi + + # shellcheck disable=SC2086 + __zypper_install ${__PACKAGES} || return 1 + + # Let's trigger config_salt() + if [ "$_TEMP_CONFIG_DIR" = "null" ]; then + _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" + CONFIG_SALT_FUNC="config_salt" + fi + + return 0 +} + +install_opensuse_stable() { + __PACKAGES="" + + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ];then + __PACKAGES="${__PACKAGES} salt-cloud" + fi + if [ "$_INSTALL_MASTER" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} salt-master" + fi + if [ "$_INSTALL_MINION" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} salt-minion" + fi + if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} salt-syndic" + fi + + # shellcheck disable=SC2086 + __zypper_install $__PACKAGES || return 1 + + return 0 +} + +install_opensuse_git() { + python setup.py ${SETUP_PY_INSTALL_ARGS} install --prefix=/usr || return 1 + return 0 +} + +install_opensuse_stable_post() { + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + if [ -f /bin/systemctl ]; then + systemctl is-enabled salt-$fname.service || (systemctl preset salt-$fname.service && systemctl enable salt-$fname.service) + sleep 1 + systemctl daemon-reload + continue + fi + + /sbin/chkconfig --add salt-$fname + /sbin/chkconfig salt-$fname on + done + + return 0 +} + +install_opensuse_git_post() { + for fname in api master minion syndic; do + # Skip if not meant to be installed + [ $fname = "api" ] && \ + ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + if [ -f /bin/systemctl ]; then + use_usr_lib=$BS_FALSE + + if [ "${DISTRO_MAJOR_VERSION}" -ge 15 ]; then + use_usr_lib=$BS_TRUE + fi + + if [ "${DISTRO_MAJOR_VERSION}" -eq 12 ] && [ -d "/usr/lib/systemd/" ]; then + use_usr_lib=$BS_TRUE + fi + + if [ "${use_usr_lib}" -eq $BS_TRUE ]; then + __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.service" "/usr/lib/systemd/system/salt-${fname}.service" + else + __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.service" "/lib/systemd/system/salt-${fname}.service" + fi + + continue + fi + + __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-$fname" "/etc/init.d/salt-$fname" + chmod +x /etc/init.d/salt-$fname + done + + install_opensuse_stable_post || return 1 + + return 0 +} + +install_opensuse_restart_daemons() { + [ $_START_DAEMONS -eq $BS_FALSE ] && return + + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + if [ -f /bin/systemctl ]; then + systemctl stop salt-$fname > /dev/null 2>&1 + systemctl start salt-$fname.service + continue + fi + + service salt-$fname stop > /dev/null 2>&1 + service salt-$fname start + done +} + +install_opensuse_check_services() { + if [ ! -f /bin/systemctl ]; then + # Not running systemd!? Don't check! + return 0 + fi + + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + __check_services_systemd salt-$fname > /dev/null 2>&1 || __check_services_systemd salt-$fname.service > /dev/null 2>&1 || return 1 + done + + return 0 +} +# +# End of openSUSE Install Functions. +# +####################################################################################################################### + +####################################################################################################################### +# +# openSUSE Leap 15 +# + +install_opensuse_15_stable_deps() { + __opensuse_prep_install || return 1 + + # SUSE only packages Salt for Python 3 on Leap 15 + # Py3 is the default bootstrap install for Leap 15 + # However, git installs might specify "-x python2" + if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 2 ]; then + PY_PKG_VER=2 + else + PY_PKG_VER=3 + fi + + # YAML module is used for generating custom master/minion configs + # requests is still used by many salt modules + __PACKAGES="python${PY_PKG_VER}-PyYAML python${PY_PKG_VER}-requests" + + # shellcheck disable=SC2086 + __zypper_install ${__PACKAGES} || return 1 + + if [ "${_EXTRA_PACKAGES}" != "" ]; then + echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" + # shellcheck disable=SC2086 + __zypper_install ${_EXTRA_PACKAGES} || return 1 + fi + + return 0 +} + +install_opensuse_15_git_deps() { + install_opensuse_15_stable_deps || return 1 + + if ! __check_command_exists git; then + __zypper_install git || return 1 + fi + + __git_clone_and_checkout || return 1 + + # Py3 is the default bootstrap install for Leap 15 + # However, git installs might specify "-x python2" + if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 2 ]; then + PY_PKG_VER=2 + + # This is required by some of the python2 packages below + __PACKAGES="libpython2_7-1_0 python2-futures python-ipaddress" + else + PY_PKG_VER=3 + __PACKAGES="" + fi + + __PACKAGES="${__PACKAGES} libzmq5 python${PY_PKG_VER}-Jinja2 python${PY_PKG_VER}-msgpack" + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-pycrypto python${PY_PKG_VER}-pyzmq" + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-xml" + + if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then + # We're on the develop branch, install whichever tornado is on the requirements file + __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" + if [ "${__REQUIRED_TORNADO}" != "" ]; then + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-tornado" + fi + fi + + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-apache-libcloud" + fi + + # shellcheck disable=SC2086 + __zypper_install ${__PACKAGES} || return 1 + + # Let's trigger config_salt() + if [ "$_TEMP_CONFIG_DIR" = "null" ]; then + _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" + CONFIG_SALT_FUNC="config_salt" + fi + + return 0 +} + +install_opensuse_15_git() { + + # Py3 is the default bootstrap install for Leap 15 + if [ -n "$_PY_EXE" ]; then + _PYEXE=${_PY_EXE} + else + _PYEXE=python3 + fi + + ${_PYEXE} setup.py ${SETUP_PY_INSTALL_ARGS} install --prefix=/usr || return 1 + return 0 +} + +# +# End of openSUSE Leap 15 +# +####################################################################################################################### + +####################################################################################################################### +# +# SUSE Enterprise 12 +# + +install_suse_12_stable_deps() { + __opensuse_prep_install || return 1 + + # YAML module is used for generating custom master/minion configs + # requests is still used by many salt modules + # Salt needs python-zypp installed in order to use the zypper module + __PACKAGES="python-PyYAML python-requests python-zypp" + + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} python-apache-libcloud" + fi + + # shellcheck disable=SC2086,SC2090 + __zypper_install ${__PACKAGES} || return 1 + + # SLES 11 SP3 ships with both python-M2Crypto-0.22.* and python-m2crypto-0.21 and we will be asked which + # we want to install, even with --non-interactive. + # Let's try to install the higher version first and then the lower one in case of failure + __zypper_install 'python-M2Crypto>=0.22' || __zypper_install 'python-M2Crypto>=0.21' || return 1 + + if [ "${_EXTRA_PACKAGES}" != "" ]; then + echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" + # shellcheck disable=SC2086 + __zypper_install ${_EXTRA_PACKAGES} || return 1 + fi + + return 0 +} + +install_suse_12_git_deps() { + install_suse_12_stable_deps || return 1 + + if ! __check_command_exists git; then + __zypper_install git-core || return 1 + fi + + __git_clone_and_checkout || return 1 + + __PACKAGES="" + # shellcheck disable=SC2089 + __PACKAGES="${__PACKAGES} libzmq4 python-Jinja2 python-msgpack-python python-pycrypto" + __PACKAGES="${__PACKAGES} python-pyzmq python-xml" + + if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then + # We're on the develop branch, install whichever tornado is on the requirements file + __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" + if [ "${__REQUIRED_TORNADO}" != "" ]; then + __PACKAGES="${__PACKAGES} python-tornado" + fi + fi + + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} python-apache-libcloud" + fi + + # shellcheck disable=SC2086 + __zypper_install ${__PACKAGES} || return 1 + + # Let's trigger config_salt() + if [ "$_TEMP_CONFIG_DIR" = "null" ]; then + _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" + CONFIG_SALT_FUNC="config_salt" + fi + + return 0 +} + +install_suse_12_stable() { + install_opensuse_stable || return 1 + return 0 +} + +install_suse_12_git() { + install_opensuse_git || return 1 + return 0 +} + +install_suse_12_stable_post() { + install_opensuse_stable_post || return 1 + return 0 +} + +install_suse_12_git_post() { + install_opensuse_git_post || return 1 + return 0 +} + +install_suse_12_restart_daemons() { + install_opensuse_restart_daemons || return 1 + return 0 +} + +# +# End of SUSE Enterprise 12 +# +####################################################################################################################### + +####################################################################################################################### +# +# SUSE Enterprise 11 +# + +install_suse_11_stable_deps() { + __opensuse_prep_install || return 1 + + # YAML module is used for generating custom master/minion configs + __PACKAGES="python-PyYAML" + + # shellcheck disable=SC2086,SC2090 + __zypper_install ${__PACKAGES} || return 1 + + # SLES 11 SP3 ships with both python-M2Crypto-0.22.* and python-m2crypto-0.21 and we will be asked which + # we want to install, even with --non-interactive. + # Let's try to install the higher version first and then the lower one in case of failure + __zypper_install 'python-M2Crypto>=0.22' || __zypper_install 'python-M2Crypto>=0.21' || return 1 + + if [ "${_EXTRA_PACKAGES}" != "" ]; then + echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" + # shellcheck disable=SC2086 + __zypper_install ${_EXTRA_PACKAGES} || return 1 + fi + + return 0 +} + +install_suse_11_git_deps() { + install_suse_11_stable_deps || return 1 + + if ! __check_command_exists git; then + __zypper_install git || return 1 + fi + + __git_clone_and_checkout || return 1 + + __PACKAGES="" + # shellcheck disable=SC2089 + __PACKAGES="${__PACKAGES} libzmq4 python-Jinja2 python-msgpack-python python-pycrypto" + __PACKAGES="${__PACKAGES} python-pyzmq python-xml python-zypp" + + if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then + # We're on the develop branch, install whichever tornado is on the requirements file + __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" + if [ "${__REQUIRED_TORNADO}" != "" ]; then + __PACKAGES="${__PACKAGES} python-tornado" + fi + fi + + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then + __PACKAGES="${__PACKAGES} python-apache-libcloud" + fi + + # shellcheck disable=SC2086 + __zypper_install ${__PACKAGES} || return 1 + + # Let's trigger config_salt() + if [ "$_TEMP_CONFIG_DIR" = "null" ]; then + _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" + CONFIG_SALT_FUNC="config_salt" + fi + + return 0 +} + +install_suse_11_stable() { + install_opensuse_stable || return 1 + return 0 +} + +install_suse_11_git() { + install_opensuse_git || return 1 + return 0 +} + +install_suse_11_stable_post() { + install_opensuse_stable_post || return 1 + return 0 +} + +install_suse_11_git_post() { + install_opensuse_git_post || return 1 + return 0 +} + +install_suse_11_restart_daemons() { + install_opensuse_restart_daemons || return 1 + return 0 +} + + +# +# End of SUSE Enterprise 11 +# +####################################################################################################################### + +####################################################################################################################### +# +# SUSE Enterprise General Functions +# + +# Used for both SLE 11 and 12 +install_suse_check_services() { + if [ ! -f /bin/systemctl ]; then + # Not running systemd!? Don't check! + return 0 + fi + + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + __check_services_systemd salt-$fname || return 1 + done + + return 0 +} + +# +# End of SUSE Enterprise General Functions +# +####################################################################################################################### + +####################################################################################################################### +# +# Gentoo Install Functions. +# +__autounmask() { + emerge --autounmask-write --autounmask-only "${@}"; return $? +} + +__emerge() { + if [ "$_GENTOO_USE_BINHOST" -eq $BS_TRUE ]; then + emerge --getbinpkg "${@}"; return $? + fi + emerge "${@}"; return $? +} + +__gentoo_config_protection() { + # usually it's a good thing to have config files protected by portage, but + # in this case this would require to interrupt the bootstrapping script at + # this point, manually merge the changes using etc-update/dispatch-conf/ + # cfg-update and then restart the bootstrapping script, so instead we allow + # at this point to modify certain config files directly + export CONFIG_PROTECT_MASK="${CONFIG_PROTECT_MASK:-} /etc/portage/package.accept_keywords /etc/portage/package.keywords /etc/portage/package.license /etc/portage/package.unmask /etc/portage/package.use" + + # emerge currently won't write to files that aren't there, so we need to ensure their presence + touch /etc/portage/package.accept_keywords /etc/portage/package.keywords /etc/portage/package.license /etc/portage/package.unmask /etc/portage/package.use +} + +__gentoo_pre_dep() { + if [ "$_ECHO_DEBUG" -eq $BS_TRUE ]; then + if __check_command_exists eix; then + eix-sync + else + emerge --sync + fi + else + if __check_command_exists eix; then + eix-sync -q + else + emerge --sync --quiet + fi + fi + if [ ! -d /etc/portage ]; then + mkdir /etc/portage + fi +} + +__gentoo_post_dep() { + # ensures dev-lib/crypto++ compiles happily + __emerge --oneshot 'sys-devel/libtool' + # the -o option asks it to emerge the deps but not the package. + __gentoo_config_protection + + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then + __autounmask 'dev-python/libcloud' + __emerge -v 'dev-python/libcloud' + fi + + __autounmask 'dev-python/requests' + __autounmask 'app-admin/salt' + + __emerge -vo 'dev-python/requests' + __emerge -vo 'app-admin/salt' + + if [ "${_EXTRA_PACKAGES}" != "" ]; then + echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" + # shellcheck disable=SC2086 + __autounmask ${_EXTRA_PACKAGES} || return 1 + # shellcheck disable=SC2086 + __emerge -v ${_EXTRA_PACKAGES} || return 1 + fi +} + +install_gentoo_deps() { + __gentoo_pre_dep || return 1 + __gentoo_post_dep || return 1 +} + +install_gentoo_git_deps() { + __gentoo_pre_dep || return 1 + __gentoo_post_dep || return 1 +} + +install_gentoo_stable() { + __gentoo_config_protection + __emerge -v 'app-admin/salt' || return 1 +} + +install_gentoo_git() { + __gentoo_config_protection + __emerge -v '=app-admin/salt-9999' || return 1 +} + +install_gentoo_post() { + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + if [ -d "/run/systemd/system" ]; then + systemctl enable salt-$fname.service + systemctl start salt-$fname.service + else + rc-update add salt-$fname default + /etc/init.d/salt-$fname start + fi + done +} + +install_gentoo_restart_daemons() { + [ $_START_DAEMONS -eq $BS_FALSE ] && return + + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + if [ -d "/run/systemd/system" ]; then + systemctl stop salt-$fname > /dev/null 2>&1 + systemctl start salt-$fname.service + else + /etc/init.d/salt-$fname stop > /dev/null 2>&1 + /etc/init.d/salt-$fname start + fi + done +} + +install_gentoo_check_services() { + if [ ! -d "/run/systemd/system" ]; then + # Not running systemd!? Don't check! + return 0 + fi + + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + __check_services_systemd salt-$fname || return 1 + done + + return 0 +} +# +# End of Gentoo Install Functions. +# +####################################################################################################################### + +####################################################################################################################### +# +# VoidLinux Install Functions +# +install_voidlinux_stable_deps() { + if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then + xbps-install -Suy || return 1 + fi + + if [ "${_EXTRA_PACKAGES}" != "" ]; then + echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" + xbps-install -Suy "${_EXTRA_PACKAGES}" || return 1 + fi + + return 0 +} + +install_voidlinux_stable() { + xbps-install -Suy salt || return 1 + return 0 +} + +install_voidlinux_stable_post() { + for fname in master minion syndic; do + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + ln -s /etc/sv/salt-$fname /var/service/. + done +} + +install_voidlinux_restart_daemons() { + [ $_START_DAEMONS -eq $BS_FALSE ] && return + + for fname in master minion syndic; do + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + sv restart salt-$fname + done +} + +install_voidlinux_check_services() { + for fname in master minion syndic; do + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + [ -e /var/service/salt-$fname ] || return 1 + done + + return 0 +} + +daemons_running_voidlinux() { + [ "$_START_DAEMONS" -eq $BS_FALSE ] && return 0 + + FAILED_DAEMONS=0 + for fname in master minion syndic; do + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + if [ "$(sv status salt-$fname | grep run)" = "" ]; then + echoerror "salt-$fname was not found running" + FAILED_DAEMONS=$((FAILED_DAEMONS + 1)) + fi + done + + return $FAILED_DAEMONS +} +# +# Ended VoidLinux Install Functions +# +####################################################################################################################### + +####################################################################################################################### +# +# OS X / Darwin Install Functions +# + +__macosx_get_packagesite() { + DARWIN_ARCH="x86_64" + + __PY_VERSION_REPO="py2" + if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then + __PY_VERSION_REPO="py3" + fi + + PKG="salt-${STABLE_REV}-${__PY_VERSION_REPO}-${DARWIN_ARCH}.pkg" + SALTPKGCONFURL="https://repo.saltstack.com/osx/${PKG}" +} + +# Using a separate conf step to head for idempotent install... +__configure_macosx_pkg_details() { + __macosx_get_packagesite || return 1 + return 0 +} + +install_macosx_stable_deps() { + __configure_macosx_pkg_details || return 1 + return 0 +} + +install_macosx_git_deps() { + install_macosx_stable_deps || return 1 + + __fetch_url "/tmp/get-pip.py" "https://bootstrap.pypa.io/get-pip.py" || return 1 + + if [ -n "$_PY_EXE" ]; then + _PYEXE=${_PY_EXE} + else + _PYEXE=python2.7 + fi + + # Install PIP + $_PYEXE /tmp/get-pip.py || return 1 + + __git_clone_and_checkout || return 1 + + __PIP_REQUIREMENTS="dev_python27.txt" + if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then + __PIP_REQUIREMENTS="dev_python34.txt" + fi + + requirements_file="${_SALT_GIT_CHECKOUT_DIR}/requirements/${__PIP_REQUIREMENTS}" + pip install -U -r "${requirements_file}" --install-option="--prefix=/opt/salt" || return 1 + + return 0 +} + +install_macosx_stable() { + install_macosx_stable_deps || return 1 + + /usr/bin/curl "${SALTPKGCONFURL}" > "/tmp/${PKG}" || return 1 + + /usr/sbin/installer -pkg "/tmp/${PKG}" -target / || return 1 + + return 0 +} + +install_macosx_git() { + + if [ -n "$_PY_EXE" ]; then + _PYEXE=${_PY_EXE} + else + _PYEXE=python2.7 + fi + + if [ -f "${_SALT_GIT_CHECKOUT_DIR}/salt/syspaths.py" ]; then + $_PYEXE setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install --prefix=/opt/salt || return 1 + else + $_PYEXE setup.py ${SETUP_PY_INSTALL_ARGS} install --prefix=/opt/salt || return 1 + fi + + return 0 +} + +install_macosx_stable_post() { + if [ ! -f /etc/paths.d/salt ]; then + print "%s\n" "/opt/salt/bin" "/usr/local/sbin" > /etc/paths.d/salt + fi + + # shellcheck disable=SC1091 + . /etc/profile + + return 0 +} + +install_macosx_git_post() { + install_macosx_stable_post || return 1 + return 0 +} + +install_macosx_restart_daemons() { + [ $_START_DAEMONS -eq $BS_FALSE ] && return + + /bin/launchctl unload -w /Library/LaunchDaemons/com.saltstack.salt.minion.plist || return 1 + /bin/launchctl load -w /Library/LaunchDaemons/com.saltstack.salt.minion.plist || return 1 + + return 0 +} +# +# Ended OS X / Darwin Install Functions +# +####################################################################################################################### + +####################################################################################################################### +# +# Default minion configuration function. Matches ANY distribution as long as +# the -c options is passed. +# +config_salt() { + # If the configuration directory is not passed, return + [ "$_TEMP_CONFIG_DIR" = "null" ] && return + + if [ "$_CONFIG_ONLY" -eq $BS_TRUE ]; then + echowarn "Passing -C (config only) option implies -F (forced overwrite)." + + if [ "$_FORCE_OVERWRITE" -ne $BS_TRUE ]; then + echowarn "Overwriting configs in 11 seconds!" + sleep 11 + _FORCE_OVERWRITE=$BS_TRUE + fi + fi + + # Let's create the necessary directories + [ -d "$_SALT_ETC_DIR" ] || mkdir "$_SALT_ETC_DIR" || return 1 + [ -d "$_PKI_DIR" ] || (mkdir -p "$_PKI_DIR" && chmod 700 "$_PKI_DIR") || return 1 + + # If -C or -F was passed, we don't need a .bak file for the config we're updating + # This is used in the custom master/minion config file checks below + CREATE_BAK=$BS_TRUE + if [ "$_FORCE_OVERWRITE" -eq $BS_TRUE ]; then + CREATE_BAK=$BS_FALSE + fi + + CONFIGURED_ANYTHING=$BS_FALSE + + # Copy the grains file if found + if [ -f "$_TEMP_CONFIG_DIR/grains" ]; then + echodebug "Moving provided grains file from $_TEMP_CONFIG_DIR/grains to $_SALT_ETC_DIR/grains" + __movefile "$_TEMP_CONFIG_DIR/grains" "$_SALT_ETC_DIR/grains" || return 1 + CONFIGURED_ANYTHING=$BS_TRUE + fi + + if [ "$_INSTALL_MINION" -eq $BS_TRUE ] || \ + [ "$_CONFIG_ONLY" -eq $BS_TRUE ] || [ "$_CUSTOM_MINION_CONFIG" != "null" ]; then + # Create the PKI directory + [ -d "$_PKI_DIR/minion" ] || (mkdir -p "$_PKI_DIR/minion" && chmod 700 "$_PKI_DIR/minion") || return 1 + + # Check to see if a custom minion config json dict was provided + if [ "$_CUSTOM_MINION_CONFIG" != "null" ]; then + + # Check if a minion config file already exists and move to .bak if needed + if [ -f "$_SALT_ETC_DIR/minion" ] && [ "$CREATE_BAK" -eq "$BS_TRUE" ]; then + __movefile "$_SALT_ETC_DIR/minion" "$_SALT_ETC_DIR/minion.bak" $BS_TRUE || return 1 + CONFIGURED_ANYTHING=$BS_TRUE + fi + + # Overwrite/create the config file with the yaml string + __overwriteconfig "$_SALT_ETC_DIR/minion" "$_CUSTOM_MINION_CONFIG" || return 1 + CONFIGURED_ANYTHING=$BS_TRUE + + # Copy the minions configuration if found + # Explicitly check for custom master config to avoid moving the minion config + elif [ -f "$_TEMP_CONFIG_DIR/minion" ] && [ "$_CUSTOM_MASTER_CONFIG" = "null" ]; then + __movefile "$_TEMP_CONFIG_DIR/minion" "$_SALT_ETC_DIR" "$_FORCE_OVERWRITE" || return 1 + CONFIGURED_ANYTHING=$BS_TRUE + fi + + # Copy the minion's keys if found + if [ -f "$_TEMP_CONFIG_DIR/minion.pem" ]; then + __movefile "$_TEMP_CONFIG_DIR/minion.pem" "$_PKI_DIR/minion/" "$_FORCE_OVERWRITE" || return 1 + chmod 400 "$_PKI_DIR/minion/minion.pem" || return 1 + CONFIGURED_ANYTHING=$BS_TRUE + fi + if [ -f "$_TEMP_CONFIG_DIR/minion.pub" ]; then + __movefile "$_TEMP_CONFIG_DIR/minion.pub" "$_PKI_DIR/minion/" "$_FORCE_OVERWRITE" || return 1 + chmod 664 "$_PKI_DIR/minion/minion.pub" || return 1 + CONFIGURED_ANYTHING=$BS_TRUE + fi + # For multi-master-pki, copy the master_sign public key if found + if [ -f "$_TEMP_CONFIG_DIR/master_sign.pub" ]; then + __movefile "$_TEMP_CONFIG_DIR/master_sign.pub" "$_PKI_DIR/minion/" || return 1 + chmod 664 "$_PKI_DIR/minion/master_sign.pub" || return 1 + CONFIGURED_ANYTHING=$BS_TRUE + fi + fi + + # only (re)place master or syndic configs if -M (install master) or -S + # (install syndic) specified + OVERWRITE_MASTER_CONFIGS=$BS_FALSE + if [ "$_INSTALL_MASTER" -eq $BS_TRUE ] && [ "$_CONFIG_ONLY" -eq $BS_TRUE ]; then + OVERWRITE_MASTER_CONFIGS=$BS_TRUE + fi + if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ] && [ "$_CONFIG_ONLY" -eq $BS_TRUE ]; then + OVERWRITE_MASTER_CONFIGS=$BS_TRUE + fi + + if [ "$_INSTALL_MASTER" -eq $BS_TRUE ] || [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ] || [ "$OVERWRITE_MASTER_CONFIGS" -eq $BS_TRUE ] || [ "$_CUSTOM_MASTER_CONFIG" != "null" ]; then + # Create the PKI directory + [ -d "$_PKI_DIR/master" ] || (mkdir -p "$_PKI_DIR/master" && chmod 700 "$_PKI_DIR/master") || return 1 + + # Check to see if a custom master config json dict was provided + if [ "$_CUSTOM_MASTER_CONFIG" != "null" ]; then + + # Check if a master config file already exists and move to .bak if needed + if [ -f "$_SALT_ETC_DIR/master" ] && [ "$CREATE_BAK" -eq "$BS_TRUE" ]; then + __movefile "$_SALT_ETC_DIR/master" "$_SALT_ETC_DIR/master.bak" $BS_TRUE || return 1 + CONFIGURED_ANYTHING=$BS_TRUE + fi + + # Overwrite/create the config file with the yaml string + __overwriteconfig "$_SALT_ETC_DIR/master" "$_CUSTOM_MASTER_CONFIG" || return 1 + CONFIGURED_ANYTHING=$BS_TRUE + + # Copy the masters configuration if found + elif [ -f "$_TEMP_CONFIG_DIR/master" ]; then + __movefile "$_TEMP_CONFIG_DIR/master" "$_SALT_ETC_DIR" || return 1 + CONFIGURED_ANYTHING=$BS_TRUE + fi + + # Copy the master's keys if found + if [ -f "$_TEMP_CONFIG_DIR/master.pem" ]; then + __movefile "$_TEMP_CONFIG_DIR/master.pem" "$_PKI_DIR/master/" || return 1 + chmod 400 "$_PKI_DIR/master/master.pem" || return 1 + CONFIGURED_ANYTHING=$BS_TRUE + fi + if [ -f "$_TEMP_CONFIG_DIR/master.pub" ]; then + __movefile "$_TEMP_CONFIG_DIR/master.pub" "$_PKI_DIR/master/" || return 1 + chmod 664 "$_PKI_DIR/master/master.pub" || return 1 + CONFIGURED_ANYTHING=$BS_TRUE + fi + fi + + if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then + # Recursively copy salt-cloud configs with overwriting if necessary + for file in "$_TEMP_CONFIG_DIR"/cloud*; do + if [ -f "$file" ]; then + __copyfile "$file" "$_SALT_ETC_DIR" || return 1 + elif [ -d "$file" ]; then + subdir="$(basename "$file")" + mkdir -p "$_SALT_ETC_DIR/$subdir" + for file_d in "$_TEMP_CONFIG_DIR/$subdir"/*; do + if [ -f "$file_d" ]; then + __copyfile "$file_d" "$_SALT_ETC_DIR/$subdir" || return 1 + fi + done + fi + done + fi + + if [ "$_CONFIG_ONLY" -eq $BS_TRUE ] && [ $CONFIGURED_ANYTHING -eq $BS_FALSE ]; then + echowarn "No configuration or keys were copied over. No configuration was done!" + exit 0 + fi + + return 0 +} +# +# Ended Default Configuration function +# +####################################################################################################################### + +####################################################################################################################### +# +# Default salt master minion keys pre-seed function. Matches ANY distribution +# as long as the -k option is passed. +# +preseed_master() { + # Create the PKI directory + + if [ "$(find "$_TEMP_KEYS_DIR" -maxdepth 1 -type f | wc -l)" -lt 1 ]; then + echoerror "No minion keys were uploaded. Unable to pre-seed master" + return 1 + fi + + SEED_DEST="$_PKI_DIR/master/minions" + [ -d "$SEED_DEST" ] || (mkdir -p "$SEED_DEST" && chmod 700 "$SEED_DEST") || return 1 + + for keyfile in "$_TEMP_KEYS_DIR"/*; do + keyfile=$(basename "${keyfile}") + src_keyfile="${_TEMP_KEYS_DIR}/${keyfile}" + dst_keyfile="${SEED_DEST}/${keyfile}" + + # If it's not a file, skip to the next + [ ! -f "$src_keyfile" ] && continue + + __movefile "$src_keyfile" "$dst_keyfile" || return 1 + chmod 664 "$dst_keyfile" || return 1 + done + + return 0 +} +# +# Ended Default Salt Master Pre-Seed minion keys function +# +####################################################################################################################### + +####################################################################################################################### +# +# This function checks if all of the installed daemons are running or not. +# +daemons_running() { + [ "$_START_DAEMONS" -eq $BS_FALSE ] && return 0 + + FAILED_DAEMONS=0 + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + # shellcheck disable=SC2009 + if [ "${DISTRO_NAME}" = "SmartOS" ]; then + if [ "$(svcs -Ho STA salt-$fname)" != "ON" ]; then + echoerror "salt-$fname was not found running" + FAILED_DAEMONS=$((FAILED_DAEMONS + 1)) + fi + elif [ "$(ps wwwaux | grep -v grep | grep salt-$fname)" = "" ]; then + echoerror "salt-$fname was not found running" + FAILED_DAEMONS=$((FAILED_DAEMONS + 1)) + fi + done + + return $FAILED_DAEMONS +} +# +# Ended daemons running check function +# +####################################################################################################################### + +#====================================================================================================================== +# LET'S PROCEED WITH OUR INSTALLATION +#====================================================================================================================== + +# Let's get the dependencies install function +DEP_FUNC_NAMES="" +if [ ${_NO_DEPS} -eq $BS_FALSE ]; then + DEP_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_deps" + DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_deps" + DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_deps" + DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_deps" + DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}_deps" + DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}_deps" +fi + +DEPS_INSTALL_FUNC="null" +for FUNC_NAME in $(__strip_duplicates "$DEP_FUNC_NAMES"); do + if __function_defined "$FUNC_NAME"; then + DEPS_INSTALL_FUNC="$FUNC_NAME" + break + fi +done +echodebug "DEPS_INSTALL_FUNC=${DEPS_INSTALL_FUNC}" + +# Let's get the Salt config function +CONFIG_FUNC_NAMES="config_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_salt" +CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_salt" +CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_salt" +CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_salt" +CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}_${ITYPE}_salt" +CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}_salt" +CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_salt" + +CONFIG_SALT_FUNC="null" +for FUNC_NAME in $(__strip_duplicates "$CONFIG_FUNC_NAMES"); do + if __function_defined "$FUNC_NAME"; then + CONFIG_SALT_FUNC="$FUNC_NAME" + break + fi +done +echodebug "CONFIG_SALT_FUNC=${CONFIG_SALT_FUNC}" + +# Let's get the pre-seed master function +PRESEED_FUNC_NAMES="preseed_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_master" +PRESEED_FUNC_NAMES="$PRESEED_FUNC_NAMES preseed_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_master" +PRESEED_FUNC_NAMES="$PRESEED_FUNC_NAMES preseed_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_master" +PRESEED_FUNC_NAMES="$PRESEED_FUNC_NAMES preseed_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_master" +PRESEED_FUNC_NAMES="$PRESEED_FUNC_NAMES preseed_${DISTRO_NAME_L}_${ITYPE}_master" +PRESEED_FUNC_NAMES="$PRESEED_FUNC_NAMES preseed_${DISTRO_NAME_L}_master" +PRESEED_FUNC_NAMES="$PRESEED_FUNC_NAMES preseed_master" + +PRESEED_MASTER_FUNC="null" +for FUNC_NAME in $(__strip_duplicates "$PRESEED_FUNC_NAMES"); do + if __function_defined "$FUNC_NAME"; then + PRESEED_MASTER_FUNC="$FUNC_NAME" + break + fi +done +echodebug "PRESEED_MASTER_FUNC=${PRESEED_MASTER_FUNC}" + +# Let's get the install function +INSTALL_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}" +INSTALL_FUNC_NAMES="$INSTALL_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}" +INSTALL_FUNC_NAMES="$INSTALL_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}" + +INSTALL_FUNC="null" +for FUNC_NAME in $(__strip_duplicates "$INSTALL_FUNC_NAMES"); do + if __function_defined "$FUNC_NAME"; then + INSTALL_FUNC="$FUNC_NAME" + break + fi +done +echodebug "INSTALL_FUNC=${INSTALL_FUNC}" + +# Let's get the post install function +POST_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_post" +POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_post" +POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_post" +POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_post" +POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}_post" +POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}_post" + +POST_INSTALL_FUNC="null" +for FUNC_NAME in $(__strip_duplicates "$POST_FUNC_NAMES"); do + if __function_defined "$FUNC_NAME"; then + POST_INSTALL_FUNC="$FUNC_NAME" + break + fi +done +echodebug "POST_INSTALL_FUNC=${POST_INSTALL_FUNC}" + +# Let's get the start daemons install function +STARTDAEMONS_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_restart_daemons" +STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_restart_daemons" +STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_restart_daemons" +STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_restart_daemons" +STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}_restart_daemons" +STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}_restart_daemons" + +STARTDAEMONS_INSTALL_FUNC="null" +for FUNC_NAME in $(__strip_duplicates "$STARTDAEMONS_FUNC_NAMES"); do + if __function_defined "$FUNC_NAME"; then + STARTDAEMONS_INSTALL_FUNC="$FUNC_NAME" + break + fi +done +echodebug "STARTDAEMONS_INSTALL_FUNC=${STARTDAEMONS_INSTALL_FUNC}" + +# Let's get the daemons running check function. +DAEMONS_RUNNING_FUNC_NAMES="daemons_running_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}" +DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}" +DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}" +DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}" +DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running_${DISTRO_NAME_L}_${ITYPE}" +DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running_${DISTRO_NAME_L}" +DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running" + +DAEMONS_RUNNING_FUNC="null" +for FUNC_NAME in $(__strip_duplicates "$DAEMONS_RUNNING_FUNC_NAMES"); do + if __function_defined "$FUNC_NAME"; then + DAEMONS_RUNNING_FUNC="$FUNC_NAME" + break + fi +done +echodebug "DAEMONS_RUNNING_FUNC=${DAEMONS_RUNNING_FUNC}" + +# Let's get the check services function +if [ ${_DISABLE_SALT_CHECKS} -eq $BS_FALSE ]; then + CHECK_SERVICES_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_check_services" + CHECK_SERVICES_FUNC_NAMES="$CHECK_SERVICES_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_check_services" + CHECK_SERVICES_FUNC_NAMES="$CHECK_SERVICES_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_check_services" + CHECK_SERVICES_FUNC_NAMES="$CHECK_SERVICES_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_check_services" + CHECK_SERVICES_FUNC_NAMES="$CHECK_SERVICES_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}_check_services" + CHECK_SERVICES_FUNC_NAMES="$CHECK_SERVICES_FUNC_NAMES install_${DISTRO_NAME_L}_check_services" +else + CHECK_SERVICES_FUNC_NAMES="" +fi + +CHECK_SERVICES_FUNC="null" +for FUNC_NAME in $(__strip_duplicates "$CHECK_SERVICES_FUNC_NAMES"); do + if __function_defined "$FUNC_NAME"; then + CHECK_SERVICES_FUNC="$FUNC_NAME" + break + fi +done +echodebug "CHECK_SERVICES_FUNC=${CHECK_SERVICES_FUNC}" + +if [ ${_NO_DEPS} -eq $BS_FALSE ] && [ "$DEPS_INSTALL_FUNC" = "null" ]; then + echoerror "No dependencies installation function found. Exiting..." + exit 1 +fi + +if [ "$INSTALL_FUNC" = "null" ]; then + echoerror "No installation function found. Exiting..." + exit 1 +fi + + +# Install dependencies +if [ ${_NO_DEPS} -eq $BS_FALSE ] && [ $_CONFIG_ONLY -eq $BS_FALSE ]; then + # Only execute function is not in config mode only + echoinfo "Running ${DEPS_INSTALL_FUNC}()" + if ! ${DEPS_INSTALL_FUNC}; then + echoerror "Failed to run ${DEPS_INSTALL_FUNC}()!!!" + exit 1 + fi +fi + + +if [ "${ITYPE}" = "git" ] && [ ${_NO_DEPS} -eq ${BS_TRUE} ]; then + if ! __git_clone_and_checkout; then + echo "Failed to clone and checkout git repository." + exit 1 + fi +fi + + +# Triggering config_salt() if overwriting master or minion configs +if [ "$_CUSTOM_MASTER_CONFIG" != "null" ] || [ "$_CUSTOM_MINION_CONFIG" != "null" ]; then + if [ "$_TEMP_CONFIG_DIR" = "null" ]; then + _TEMP_CONFIG_DIR="$_SALT_ETC_DIR" + fi + + if [ ${_NO_DEPS} -eq $BS_FALSE ] && [ $_CONFIG_ONLY -eq $BS_TRUE ]; then + # Execute function to satisfy dependencies for configuration step + echoinfo "Running ${DEPS_INSTALL_FUNC}()" + if ! ${DEPS_INSTALL_FUNC}; then + echoerror "Failed to run ${DEPS_INSTALL_FUNC}()!!!" + exit 1 + fi + fi +fi + +# Configure Salt +if [ "$CONFIG_SALT_FUNC" != "null" ] && [ "$_TEMP_CONFIG_DIR" != "null" ]; then + echoinfo "Running ${CONFIG_SALT_FUNC}()" + if ! ${CONFIG_SALT_FUNC}; then + echoerror "Failed to run ${CONFIG_SALT_FUNC}()!!!" + exit 1 + fi +fi + +# Drop the master address if passed +if [ "$_SALT_MASTER_ADDRESS" != "null" ]; then + [ ! -d "$_SALT_ETC_DIR/minion.d" ] && mkdir -p "$_SALT_ETC_DIR/minion.d" + cat <<_eof > "$_SALT_ETC_DIR/minion.d/99-master-address.conf" +master: $_SALT_MASTER_ADDRESS +_eof +fi + +# Drop the minion id if passed +if [ "$_SALT_MINION_ID" != "null" ]; then + [ ! -d "$_SALT_ETC_DIR" ] && mkdir -p "$_SALT_ETC_DIR" + echo "$_SALT_MINION_ID" > "$_SALT_ETC_DIR/minion_id" +fi + +# Pre-seed master keys +if [ "$PRESEED_MASTER_FUNC" != "null" ] && [ "$_TEMP_KEYS_DIR" != "null" ]; then + echoinfo "Running ${PRESEED_MASTER_FUNC}()" + if ! ${PRESEED_MASTER_FUNC}; then + echoerror "Failed to run ${PRESEED_MASTER_FUNC}()!!!" + exit 1 + fi +fi + +# Install Salt +if [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then + # Only execute function is not in config mode only + echoinfo "Running ${INSTALL_FUNC}()" + if ! ${INSTALL_FUNC}; then + echoerror "Failed to run ${INSTALL_FUNC}()!!!" + exit 1 + fi +fi + +# Run any post install function. Only execute function if not in config mode only +if [ "$POST_INSTALL_FUNC" != "null" ] && [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then + echoinfo "Running ${POST_INSTALL_FUNC}()" + if ! ${POST_INSTALL_FUNC}; then + echoerror "Failed to run ${POST_INSTALL_FUNC}()!!!" + exit 1 + fi +fi + +# Run any check services function, Only execute function if not in config mode only +if [ "$CHECK_SERVICES_FUNC" != "null" ] && [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then + echoinfo "Running ${CHECK_SERVICES_FUNC}()" + if ! ${CHECK_SERVICES_FUNC}; then + echoerror "Failed to run ${CHECK_SERVICES_FUNC}()!!!" + exit 1 + fi +fi + +# Run any start daemons function +if [ "$STARTDAEMONS_INSTALL_FUNC" != "null" ] && [ ${_START_DAEMONS} -eq $BS_TRUE ]; then + echoinfo "Running ${STARTDAEMONS_INSTALL_FUNC}()" + echodebug "Waiting ${_SLEEP} seconds for processes to settle before checking for them" + sleep ${_SLEEP} + if ! ${STARTDAEMONS_INSTALL_FUNC}; then + echoerror "Failed to run ${STARTDAEMONS_INSTALL_FUNC}()!!!" + exit 1 + fi +fi + +# Check if the installed daemons are running or not +if [ "$DAEMONS_RUNNING_FUNC" != "null" ] && [ ${_START_DAEMONS} -eq $BS_TRUE ]; then + echoinfo "Running ${DAEMONS_RUNNING_FUNC}()" + echodebug "Waiting ${_SLEEP} seconds for processes to settle before checking for them" + sleep ${_SLEEP} # Sleep a little bit to let daemons start + if ! ${DAEMONS_RUNNING_FUNC}; then + echoerror "Failed to run ${DAEMONS_RUNNING_FUNC}()!!!" + + for fname in api master minion syndic; do + # Skip salt-api since the service should be opt-in and not necessarily started on boot + [ $fname = "api" ] && continue + + # Skip if not meant to be installed + [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue + [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue + [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue + + if [ "$_ECHO_DEBUG" -eq $BS_FALSE ]; then + echoerror "salt-$fname was not found running. Pass '-D' to ${__ScriptName} when bootstrapping for additional debugging information..." + continue + fi + + [ ! -f "$_SALT_ETC_DIR/$fname" ] && [ $fname != "syndic" ] && echodebug "$_SALT_ETC_DIR/$fname does not exist" + + echodebug "Running salt-$fname by hand outputs: $(nohup salt-$fname -l debug)" + + [ ! -f /var/log/salt/$fname ] && echodebug "/var/log/salt/$fname does not exist. Can't cat its contents!" && continue + + echodebug "DAEMON LOGS for $fname:" + echodebug "$(cat /var/log/salt/$fname)" + echo + done + + echodebug "Running Processes:" + echodebug "$(ps auxwww)" + + exit 1 + fi +fi + +# Done! +if [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then + echoinfo "Salt installed!" +else + echoinfo "Salt configured!" +fi + +exit 0 + +# vim: set sts=4 ts=4 et From f2a250b9d97dbb186f083f433eb3e951e367dc39 Mon Sep 17 00:00:00 2001 From: ch3ll Date: Mon, 4 Nov 2019 13:18:28 -0500 Subject: [PATCH 04/64] Remove unnecessary file --- index.html | 7375 ---------------------------------------------------- 1 file changed, 7375 deletions(-) delete mode 100644 index.html diff --git a/index.html b/index.html deleted file mode 100644 index 4e197ab..0000000 --- a/index.html +++ /dev/null @@ -1,7375 +0,0 @@ -#!/bin/sh - - -# WARNING: Changes to this file in the salt repo will be overwritten! -# Please submit pull requests against the salt-bootstrap repo: -# https://github.com/saltstack/salt-bootstrap - -#====================================================================================================================== -# vim: softtabstop=4 shiftwidth=4 expandtab fenc=utf-8 spell spelllang=en cc=120 -#====================================================================================================================== -# -# FILE: bootstrap-salt.sh -# -# DESCRIPTION: Bootstrap Salt installation for various systems/distributions -# -# BUGS: https://github.com/saltstack/salt-bootstrap/issues -# -# COPYRIGHT: (c) 2012-2018 by the SaltStack Team, see AUTHORS.rst for more -# details. -# -# LICENSE: Apache 2.0 -# ORGANIZATION: SaltStack (saltstack.com) -# CREATED: 10/15/2012 09:49:37 PM WEST -#====================================================================================================================== -set -o nounset # Treat unset variables as an error - -__ScriptVersion="2019.11.04" -__ScriptName="bootstrap-salt.sh" - -__ScriptFullName="$0" -__ScriptArgs="$*" - -#====================================================================================================================== -# Environment variables taken into account. -#---------------------------------------------------------------------------------------------------------------------- -# * BS_COLORS: If 0 disables colour support -# * BS_PIP_ALLOWED: If 1 enable pip based installations(if needed) -# * BS_PIP_ALL: If 1 enable all python packages to be installed via pip instead of apt, requires setting virtualenv -# * BS_VIRTUALENV_DIR: The virtualenv to install salt into (shouldn't exist yet) -# * BS_ECHO_DEBUG: If 1 enable debug echo which can also be set by -D -# * BS_SALT_ETC_DIR: Defaults to /etc/salt (Only tweak'able on git based installations) -# * BS_SALT_CACHE_DIR: Defaults to /var/cache/salt (Only tweak'able on git based installations) -# * BS_KEEP_TEMP_FILES: If 1, don't move temporary files, instead copy them -# * BS_FORCE_OVERWRITE: Force overriding copied files(config, init.d, etc) -# * BS_UPGRADE_SYS: If 1 and an option, upgrade system. Default 0. -# * BS_GENTOO_USE_BINHOST: If 1 add `--getbinpkg` to gentoo's emerge -# * BS_SALT_MASTER_ADDRESS: The IP or DNS name of the salt-master the minion should connect to -# * BS_SALT_GIT_CHECKOUT_DIR: The directory where to clone Salt on git installations -#====================================================================================================================== - - -# Bootstrap script truth values -BS_TRUE=1 -BS_FALSE=0 - -# Default sleep time used when waiting for daemons to start, restart and checking for these running -__DEFAULT_SLEEP=3 - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __detect_color_support -# DESCRIPTION: Try to detect color support. -#---------------------------------------------------------------------------------------------------------------------- -_COLORS=${BS_COLORS:-$(tput colors 2>/dev/null || echo 0)} -__detect_color_support() { - # shellcheck disable=SC2181 - if [ $? -eq 0 ] && [ "$_COLORS" -gt 2 ]; then - RC='\033[1;31m' - GC='\033[1;32m' - BC='\033[1;34m' - YC='\033[1;33m' - EC='\033[0m' - else - RC="" - GC="" - BC="" - YC="" - EC="" - fi -} -__detect_color_support - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: echoerr -# DESCRIPTION: Echo errors to stderr. -#---------------------------------------------------------------------------------------------------------------------- -echoerror() { - printf "${RC} * ERROR${EC}: %s\\n" "$@" 1>&2; -} - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: echoinfo -# DESCRIPTION: Echo information to stdout. -#---------------------------------------------------------------------------------------------------------------------- -echoinfo() { - printf "${GC} * INFO${EC}: %s\\n" "$@"; -} - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: echowarn -# DESCRIPTION: Echo warning information to stdout. -#---------------------------------------------------------------------------------------------------------------------- -echowarn() { - printf "${YC} * WARN${EC}: %s\\n" "$@"; -} - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: echodebug -# DESCRIPTION: Echo debug information to stdout. -#---------------------------------------------------------------------------------------------------------------------- -echodebug() { - if [ "$_ECHO_DEBUG" -eq $BS_TRUE ]; then - printf "${BC} * DEBUG${EC}: %s\\n" "$@"; - fi -} - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __check_command_exists -# DESCRIPTION: Check if a command exists. -#---------------------------------------------------------------------------------------------------------------------- -__check_command_exists() { - command -v "$1" > /dev/null 2>&1 -} - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __check_pip_allowed -# DESCRIPTION: Simple function to let the users know that -P needs to be used. -#---------------------------------------------------------------------------------------------------------------------- -__check_pip_allowed() { - if [ $# -eq 1 ]; then - _PIP_ALLOWED_ERROR_MSG=$1 - else - _PIP_ALLOWED_ERROR_MSG="pip based installations were not allowed. Retry using '-P'" - fi - - if [ "$_PIP_ALLOWED" -eq $BS_FALSE ]; then - echoerror "$_PIP_ALLOWED_ERROR_MSG" - __usage - exit 1 - fi -} - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __check_config_dir -# DESCRIPTION: Checks the config directory, retrieves URLs if provided. -#---------------------------------------------------------------------------------------------------------------------- -__check_config_dir() { - CC_DIR_NAME="$1" - CC_DIR_BASE=$(basename "${CC_DIR_NAME}") - - case "$CC_DIR_NAME" in - http://*|https://*) - __fetch_url "/tmp/${CC_DIR_BASE}" "${CC_DIR_NAME}" - CC_DIR_NAME="/tmp/${CC_DIR_BASE}" - ;; - ftp://*) - __fetch_url "/tmp/${CC_DIR_BASE}" "${CC_DIR_NAME}" - CC_DIR_NAME="/tmp/${CC_DIR_BASE}" - ;; - *://*) - echoerror "Unsupported URI scheme for $CC_DIR_NAME" - echo "null" - return - ;; - *) - if [ ! -e "${CC_DIR_NAME}" ]; then - echoerror "The configuration directory or archive $CC_DIR_NAME does not exist." - echo "null" - return - fi - ;; - esac - - case "$CC_DIR_NAME" in - *.tgz|*.tar.gz) - tar -zxf "${CC_DIR_NAME}" -C /tmp - CC_DIR_BASE=$(basename "${CC_DIR_BASE}" ".tgz") - CC_DIR_BASE=$(basename "${CC_DIR_BASE}" ".tar.gz") - CC_DIR_NAME="/tmp/${CC_DIR_BASE}" - ;; - *.tbz|*.tar.bz2) - tar -xjf "${CC_DIR_NAME}" -C /tmp - CC_DIR_BASE=$(basename "${CC_DIR_BASE}" ".tbz") - CC_DIR_BASE=$(basename "${CC_DIR_BASE}" ".tar.bz2") - CC_DIR_NAME="/tmp/${CC_DIR_BASE}" - ;; - *.txz|*.tar.xz) - tar -xJf "${CC_DIR_NAME}" -C /tmp - CC_DIR_BASE=$(basename "${CC_DIR_BASE}" ".txz") - CC_DIR_BASE=$(basename "${CC_DIR_BASE}" ".tar.xz") - CC_DIR_NAME="/tmp/${CC_DIR_BASE}" - ;; - esac - - echo "${CC_DIR_NAME}" -} - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __check_unparsed_options -# DESCRIPTION: Checks the placed after the install arguments -#---------------------------------------------------------------------------------------------------------------------- -__check_unparsed_options() { - shellopts="$1" - # grep alternative for SunOS - if [ -f /usr/xpg4/bin/grep ]; then - grep='/usr/xpg4/bin/grep' - else - grep='grep' - fi - unparsed_options=$( echo "$shellopts" | ${grep} -E '(^|[[:space:]])[-]+[[:alnum:]]' ) - if [ "$unparsed_options" != "" ]; then - __usage - echo - echoerror "options are only allowed before install arguments" - echo - exit 1 - fi -} - - -#---------------------------------------------------------------------------------------------------------------------- -# Handle command line arguments -#---------------------------------------------------------------------------------------------------------------------- -_KEEP_TEMP_FILES=${BS_KEEP_TEMP_FILES:-$BS_FALSE} -_TEMP_CONFIG_DIR="null" -_SALTSTACK_REPO_URL="https://github.com/saltstack/salt.git" -_SALT_REPO_URL=${_SALTSTACK_REPO_URL} -_DOWNSTREAM_PKG_REPO=$BS_FALSE -_TEMP_KEYS_DIR="null" -_SLEEP="${__DEFAULT_SLEEP}" -_INSTALL_MASTER=$BS_FALSE -_INSTALL_SYNDIC=$BS_FALSE -_INSTALL_MINION=$BS_TRUE -_INSTALL_CLOUD=$BS_FALSE -_VIRTUALENV_DIR=${BS_VIRTUALENV_DIR:-"null"} -_START_DAEMONS=$BS_TRUE -_DISABLE_SALT_CHECKS=$BS_FALSE -_ECHO_DEBUG=${BS_ECHO_DEBUG:-$BS_FALSE} -_CONFIG_ONLY=$BS_FALSE -_PIP_ALLOWED=${BS_PIP_ALLOWED:-$BS_FALSE} -_PIP_ALL=${BS_PIP_ALL:-$BS_FALSE} -_SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/etc/salt} -_SALT_CACHE_DIR=${BS_SALT_CACHE_DIR:-/var/cache/salt} -_PKI_DIR=${_SALT_ETC_DIR}/pki -_FORCE_OVERWRITE=${BS_FORCE_OVERWRITE:-$BS_FALSE} -_GENTOO_USE_BINHOST=${BS_GENTOO_USE_BINHOST:-$BS_FALSE} -_EPEL_REPO=${BS_EPEL_REPO:-epel} -_EPEL_REPOS_INSTALLED=$BS_FALSE -_UPGRADE_SYS=${BS_UPGRADE_SYS:-$BS_FALSE} -_INSECURE_DL=${BS_INSECURE_DL:-$BS_FALSE} -_CURL_ARGS=${BS_CURL_ARGS:-} -_FETCH_ARGS=${BS_FETCH_ARGS:-} -_GPG_ARGS=${BS_GPG_ARGS:-} -_WGET_ARGS=${BS_WGET_ARGS:-} -_SALT_MASTER_ADDRESS=${BS_SALT_MASTER_ADDRESS:-null} -_SALT_MINION_ID="null" -# _SIMPLIFY_VERSION is mostly used in Solaris based distributions -_SIMPLIFY_VERSION=$BS_TRUE -_LIBCLOUD_MIN_VERSION="0.14.0" -_EXTRA_PACKAGES="" -_HTTP_PROXY="" -_SALT_GIT_CHECKOUT_DIR=${BS_SALT_GIT_CHECKOUT_DIR:-/tmp/git/salt} -_NO_DEPS=$BS_FALSE -_FORCE_SHALLOW_CLONE=$BS_FALSE -_DISABLE_SSL=$BS_FALSE -_DISABLE_REPOS=$BS_FALSE -_CUSTOM_REPO_URL="null" -_CUSTOM_MASTER_CONFIG="null" -_CUSTOM_MINION_CONFIG="null" -_QUIET_GIT_INSTALLATION=$BS_FALSE -_REPO_URL="repo.saltstack.com" -_PY_EXE="" -_INSTALL_PY="$BS_FALSE" - -# Defaults for install arguments -ITYPE="stable" - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __usage -# DESCRIPTION: Display usage information. -#---------------------------------------------------------------------------------------------------------------------- -__usage() { - cat << EOT - - Usage : ${__ScriptName} [options] [install-type-args] - - Installation types: - - stable Install latest stable release. This is the default - install type - - stable [branch] Install latest version on a branch. Only supported - for packages available at repo.saltstack.com - - stable [version] Install a specific version. Only supported for - packages available at repo.saltstack.com - - testing RHEL-family specific: configure EPEL testing repo - - git Install from the head of the develop branch - - git [ref] Install from any git ref (such as a branch, tag, or - commit) - - Examples: - - ${__ScriptName} - - ${__ScriptName} stable - - ${__ScriptName} stable 2017.7 - - ${__ScriptName} stable 2017.7.2 - - ${__ScriptName} testing - - ${__ScriptName} git - - ${__ScriptName} git 2017.7 - - ${__ScriptName} git v2017.7.2 - - ${__ScriptName} git 06f249901a2e2f1ed310d58ea3921a129f214358 - - Options: - -h Display this message - -v Display script version - -n No colours - -D Show debug output - -c Temporary configuration directory - -g Salt Git repository URL. Default: ${_SALTSTACK_REPO_URL} - -w Install packages from downstream package repository rather than - upstream, saltstack package repository. This is currently only - implemented for SUSE. - -k Temporary directory holding the minion keys which will pre-seed - the master. - -s Sleep time used when waiting for daemons to start, restart and when - checking for the services running. Default: ${__DEFAULT_SLEEP} - -L Also install salt-cloud and required python-libcloud package - -M Also install salt-master - -S Also install salt-syndic - -N Do not install salt-minion - -X Do not start daemons after installation - -d Disables checking if Salt services are enabled to start on system boot. - You can also do this by touching /tmp/disable_salt_checks on the target - host. Default: \${BS_FALSE} - -P Allow pip based installations. On some distributions the required salt - packages or its dependencies are not available as a package for that - distribution. Using this flag allows the script to use pip as a last - resort method. NOTE: This only works for functions which actually - implement pip based installations. - -U If set, fully upgrade the system prior to bootstrapping Salt - -I If set, allow insecure connections while downloading any files. For - example, pass '--no-check-certificate' to 'wget' or '--insecure' to - 'curl'. On Debian and Ubuntu, using this option with -U allows obtaining - GnuPG archive keys insecurely if distro has changed release signatures. - -F Allow copied files to overwrite existing (config, init.d, etc) - -K If set, keep the temporary files in the temporary directories specified - with -c and -k - -C Only run the configuration function. Implies -F (forced overwrite). - To overwrite Master or Syndic configs, -M or -S, respectively, must - also be specified. Salt installation will be ommitted, but some of the - dependencies could be installed to write configuration with -j or -J. - -A Pass the salt-master DNS name or IP. This will be stored under - \${BS_SALT_ETC_DIR}/minion.d/99-master-address.conf - -i Pass the salt-minion id. This will be stored under - \${BS_SALT_ETC_DIR}/minion_id - -p Extra-package to install while installing Salt dependencies. One package - per -p flag. You are responsible for providing the proper package name. - -H Use the specified HTTP proxy for all download URLs (including https://). - For example: http://myproxy.example.com:3128 - -b Assume that dependencies are already installed and software sources are - set up. If git is selected, git tree is still checked out as dependency - step. - -f Force shallow cloning for git installations. - This may result in an "n/a" in the version number. - -l Disable ssl checks. When passed, switches "https" calls to "http" where - possible. - -V Install Salt into virtualenv - (only available for Ubuntu based distributions) - -a Pip install all Python pkg dependencies for Salt. Requires -V to install - all pip pkgs into the virtualenv. - (Only available for Ubuntu based distributions) - -r Disable all repository configuration performed by this script. This - option assumes all necessary repository configuration is already present - on the system. - -R Specify a custom repository URL. Assumes the custom repository URL - points to a repository that mirrors Salt packages located at - repo.saltstack.com. The option passed with -R replaces the - "repo.saltstack.com". If -R is passed, -r is also set. Currently only - works on CentOS/RHEL and Debian based distributions. - -J Replace the Master config file with data passed in as a JSON string. If - a Master config file is found, a reasonable effort will be made to save - the file with a ".bak" extension. If used in conjunction with -C or -F, - no ".bak" file will be created as either of those options will force - a complete overwrite of the file. - -j Replace the Minion config file with data passed in as a JSON string. If - a Minion config file is found, a reasonable effort will be made to save - the file with a ".bak" extension. If used in conjunction with -C or -F, - no ".bak" file will be created as either of those options will force - a complete overwrite of the file. - -q Quiet salt installation from git (setup.py install -q) - -x Changes the Python version used to install Salt. - For CentOS 6 git installations python2.7 is supported. - Fedora git installation, CentOS 7, Debian 9, Ubuntu 16.04 and 18.04 support python3. - -y Installs a different python version on host. Currently this has only been - tested with CentOS 6 and is considered experimental. This will install the - ius repo on the box if disable repo is false. This must be used in conjunction - with -x . For example: - sh bootstrap.sh -P -y -x python2.7 git v2017.7.2 - The above will install python27 and install the git version of salt using the - python2.7 executable. This only works for git and pip installations. - -EOT -} # ---------- end of function __usage ---------- - - -while getopts ':hvnDc:g:Gyx:wk:s:MSNXCPFUKIA:i:Lp:dH:bflV:J:j:rR:aq' opt -do - case "${opt}" in - - h ) __usage; exit 0 ;; - v ) echo "$0 -- Version $__ScriptVersion"; exit 0 ;; - n ) _COLORS=0; __detect_color_support ;; - D ) _ECHO_DEBUG=$BS_TRUE ;; - c ) _TEMP_CONFIG_DIR="$OPTARG" ;; - g ) _SALT_REPO_URL=$OPTARG ;; - - G ) echowarn "The '-G' option is DEPRECATED and will be removed in the future stable release!" - echowarn "Bootstrap will always use 'https' protocol to clone from SaltStack GitHub repo." - echowarn "No need to provide this option anymore, now it is a default behavior." - ;; - - w ) _DOWNSTREAM_PKG_REPO=$BS_TRUE ;; - k ) _TEMP_KEYS_DIR="$OPTARG" ;; - s ) _SLEEP=$OPTARG ;; - M ) _INSTALL_MASTER=$BS_TRUE ;; - S ) _INSTALL_SYNDIC=$BS_TRUE ;; - N ) _INSTALL_MINION=$BS_FALSE ;; - X ) _START_DAEMONS=$BS_FALSE ;; - C ) _CONFIG_ONLY=$BS_TRUE ;; - P ) _PIP_ALLOWED=$BS_TRUE ;; - F ) _FORCE_OVERWRITE=$BS_TRUE ;; - U ) _UPGRADE_SYS=$BS_TRUE ;; - K ) _KEEP_TEMP_FILES=$BS_TRUE ;; - I ) _INSECURE_DL=$BS_TRUE ;; - A ) _SALT_MASTER_ADDRESS=$OPTARG ;; - i ) _SALT_MINION_ID=$OPTARG ;; - L ) _INSTALL_CLOUD=$BS_TRUE ;; - p ) _EXTRA_PACKAGES="$_EXTRA_PACKAGES $OPTARG" ;; - d ) _DISABLE_SALT_CHECKS=$BS_TRUE ;; - H ) _HTTP_PROXY="$OPTARG" ;; - b ) _NO_DEPS=$BS_TRUE ;; - f ) _FORCE_SHALLOW_CLONE=$BS_TRUE ;; - l ) _DISABLE_SSL=$BS_TRUE ;; - V ) _VIRTUALENV_DIR="$OPTARG" ;; - a ) _PIP_ALL=$BS_TRUE ;; - r ) _DISABLE_REPOS=$BS_TRUE ;; - R ) _CUSTOM_REPO_URL=$OPTARG ;; - J ) _CUSTOM_MASTER_CONFIG=$OPTARG ;; - j ) _CUSTOM_MINION_CONFIG=$OPTARG ;; - q ) _QUIET_GIT_INSTALLATION=$BS_TRUE ;; - x ) _PY_EXE="$OPTARG" ;; - y ) _INSTALL_PY="$BS_TRUE" ;; - - \?) echo - echoerror "Option does not exist : $OPTARG" - __usage - exit 1 - ;; - - esac # --- end of case --- -done -shift $((OPTIND-1)) - - -# Define our logging file and pipe paths -LOGFILE="/tmp/$( echo "$__ScriptName" | sed s/.sh/.log/g )" -LOGPIPE="/tmp/$( echo "$__ScriptName" | sed s/.sh/.logpipe/g )" -# Ensure no residual pipe exists -rm "$LOGPIPE" 2>/dev/null - -# Create our logging pipe -# On FreeBSD we have to use mkfifo instead of mknod -if ! (mknod "$LOGPIPE" p >/dev/null 2>&1 || mkfifo "$LOGPIPE" >/dev/null 2>&1); then - echoerror "Failed to create the named pipe required to log" - exit 1 -fi - -# What ever is written to the logpipe gets written to the logfile -tee < "$LOGPIPE" "$LOGFILE" & - -# Close STDOUT, reopen it directing it to the logpipe -exec 1>&- -exec 1>"$LOGPIPE" -# Close STDERR, reopen it directing it to the logpipe -exec 2>&- -exec 2>"$LOGPIPE" - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __exit_cleanup -# DESCRIPTION: Cleanup any leftovers after script has ended -# -# -# http://www.unix.com/man-page/POSIX/1posix/trap/ -# -# Signal Number Signal Name -# 1 SIGHUP -# 2 SIGINT -# 3 SIGQUIT -# 6 SIGABRT -# 9 SIGKILL -# 14 SIGALRM -# 15 SIGTERM -#---------------------------------------------------------------------------------------------------------------------- -APT_ERR=$(mktemp /tmp/apt_error.XXXXXX) -__exit_cleanup() { - EXIT_CODE=$? - - if [ "$ITYPE" = "git" ] && [ -d "${_SALT_GIT_CHECKOUT_DIR}" ]; then - if [ $_KEEP_TEMP_FILES -eq $BS_FALSE ]; then - # Clean up the checked out repository - echodebug "Cleaning up the Salt Temporary Git Repository" - # shellcheck disable=SC2164 - cd "${__SALT_GIT_CHECKOUT_PARENT_DIR}" - rm -rf "${_SALT_GIT_CHECKOUT_DIR}" - else - echowarn "Not cleaning up the Salt Temporary git repository on request" - echowarn "Note that if you intend to re-run this script using the git approach, you might encounter some issues" - fi - fi - - # Remove the logging pipe when the script exits - if [ -p "$LOGPIPE" ]; then - echodebug "Removing the logging pipe $LOGPIPE" - rm -f "$LOGPIPE" - fi - - # Remove the temporary apt error file when the script exits - if [ -f "$APT_ERR" ]; then - echodebug "Removing the temporary apt error file $APT_ERR" - rm -f "$APT_ERR" - fi - - # Kill tee when exiting, CentOS, at least requires this - # shellcheck disable=SC2009 - TEE_PID=$(ps ax | grep tee | grep "$LOGFILE" | awk '{print $1}') - - [ "$TEE_PID" = "" ] && exit $EXIT_CODE - - echodebug "Killing logging pipe tee's with pid(s): $TEE_PID" - - # We need to trap errors since killing tee will cause a 127 errno - # We also do this as late as possible so we don't "mis-catch" other errors - __trap_errors() { - echoinfo "Errors Trapped: $EXIT_CODE" - # Exit with the "original" exit code, not the trapped code - exit $EXIT_CODE - } - trap "__trap_errors" INT ABRT QUIT TERM - - # Now we're "good" to kill tee - kill -s TERM "$TEE_PID" - - # In case the 127 errno is not triggered, exit with the "original" exit code - exit $EXIT_CODE -} -trap "__exit_cleanup" EXIT INT - - -# Let's discover how we're being called -# shellcheck disable=SC2009 -CALLER=$(ps -a -o pid,args | grep $$ | grep -v grep | tr -s ' ' | cut -d ' ' -f 3) - -if [ "${CALLER}x" = "${0}x" ]; then - CALLER="shell pipe" -fi - -echoinfo "Running version: ${__ScriptVersion}" -echoinfo "Executed by: ${CALLER}" -echoinfo "Command line: '${__ScriptFullName} ${__ScriptArgs}'" -#echowarn "Running the unstable version of ${__ScriptName}" - -# Define installation type -if [ "$#" -gt 0 ];then - __check_unparsed_options "$*" - ITYPE=$1 - shift -fi - -# Check installation type -if [ "$(echo "$ITYPE" | grep -E '(stable|testing|git)')" = "" ]; then - echoerror "Installation type \"$ITYPE\" is not known..." - exit 1 -fi - -# If doing a git install, check what branch/tag/sha will be checked out -if [ "$ITYPE" = "git" ]; then - if [ "$#" -eq 0 ];then - GIT_REV="develop" - else - GIT_REV="$1" - shift - fi - - # Disable shell warning about unbound variable during git install - STABLE_REV="latest" - -# If doing stable install, check if version specified -elif [ "$ITYPE" = "stable" ]; then - if [ "$#" -eq 0 ];then - STABLE_REV="latest" - else - if [ "$(echo "$1" | grep -E '^(latest|1\.6|1\.7|2014\.1|2014\.7|2015\.5|2015\.8|2016\.3|2016\.11|2017\.7|2018\.3|2019\.2)$')" != "" ]; then - STABLE_REV="$1" - shift - elif [ "$(echo "$1" | grep -E '^([0-9]*\.[0-9]*\.[0-9]*)$')" != "" ]; then - if [ "$(uname)" = "Darwin" ]; then - STABLE_REV="$1" - else - STABLE_REV="archive/$1" - fi - shift - else - echo "Unknown stable version: $1 (valid: 1.6, 1.7, 2014.1, 2014.7, 2015.5, 2015.8, 2016.3, 2016.11, 2017.7, 2018.3, 2019.2, latest, \$MAJOR.\$MINOR.\$PATCH)" - exit 1 - fi - fi -fi - -# Check for any unparsed arguments. Should be an error. -if [ "$#" -gt 0 ]; then - __usage - echo - echoerror "Too many arguments." - exit 1 -fi - -# whoami alternative for SunOS -if [ -f /usr/xpg4/bin/id ]; then - whoami='/usr/xpg4/bin/id -un' -else - whoami='whoami' -fi - -# Root permissions are required to run this script -if [ "$($whoami)" != "root" ]; then - echoerror "Salt requires root privileges to install. Please re-run this script as root." - exit 1 -fi - -# Check that we're actually installing one of minion/master/syndic -if [ "$_INSTALL_MINION" -eq $BS_FALSE ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then - echowarn "Nothing to install or configure" - exit 1 -fi - -# Check that we're installing a minion if we're being passed a master address -if [ "$_INSTALL_MINION" -eq $BS_FALSE ] && [ "$_SALT_MASTER_ADDRESS" != "null" ]; then - echoerror "Don't pass a master address (-A) if no minion is going to be bootstrapped." - exit 1 -fi - -# Check that we're installing a minion if we're being passed a minion id -if [ "$_INSTALL_MINION" -eq $BS_FALSE ] && [ "$_SALT_MINION_ID" != "null" ]; then - echoerror "Don't pass a minion id (-i) if no minion is going to be bootstrapped." - exit 1 -fi - -# Check that we're installing or configuring a master if we're being passed a master config json dict -if [ "$_CUSTOM_MASTER_CONFIG" != "null" ]; then - if [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then - echoerror "Don't pass a master config JSON dict (-J) if no master is going to be bootstrapped or configured." - exit 1 - fi -fi - -# Check that we're installing or configuring a minion if we're being passed a minion config json dict -if [ "$_CUSTOM_MINION_CONFIG" != "null" ]; then - if [ "$_INSTALL_MINION" -eq $BS_FALSE ] && [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then - echoerror "Don't pass a minion config JSON dict (-j) if no minion is going to be bootstrapped or configured." - exit 1 - fi -fi - -# Check if we're installing via a different Python executable and set major version variables -if [ -n "$_PY_EXE" ]; then - if [ "$(uname)" = "Darwin" ]; then - _PY_PKG_VER=$(echo "$_PY_EXE" | sed "s/\\.//g") - else - _PY_PKG_VER=$(echo "$_PY_EXE" | sed -r "s/\\.//g") - fi - - _PY_MAJOR_VERSION=$(echo "$_PY_PKG_VER" | cut -c 7) - if [ "$_PY_MAJOR_VERSION" != 3 ] && [ "$_PY_MAJOR_VERSION" != 2 ]; then - echoerror "Detected -x option, but Python major version is not 2 or 3." - echoerror "The -x option must be passed as python2, python27, or python2.7 (or use the Python '3' versions of examples)." - exit 1 - fi - - echoinfo "Detected -x option. Using $_PY_EXE to install Salt." -else - _PY_PKG_VER="" -fi - -# If the configuration directory or archive does not exist, error out -if [ "$_TEMP_CONFIG_DIR" != "null" ]; then - _TEMP_CONFIG_DIR="$(__check_config_dir "$_TEMP_CONFIG_DIR")" - [ "$_TEMP_CONFIG_DIR" = "null" ] && exit 1 -fi - -# If the pre-seed keys directory does not exist, error out -if [ "$_TEMP_KEYS_DIR" != "null" ] && [ ! -d "$_TEMP_KEYS_DIR" ]; then - echoerror "The pre-seed keys directory ${_TEMP_KEYS_DIR} does not exist." - exit 1 -fi - -# -a and -V only work from git -if [ "$ITYPE" != "git" ]; then - if [ $_PIP_ALL -eq $BS_TRUE ]; then - echoerror "Pip installing all python packages with -a is only possible when installing Salt via git" - exit 1 - fi - if [ "$_VIRTUALENV_DIR" != "null" ]; then - echoerror "Virtualenv installs via -V is only possible when installing Salt via git" - exit 1 - fi -fi - -# Set the _REPO_URL value based on if -R was passed or not. Defaults to repo.saltstack.com. -if [ "$_CUSTOM_REPO_URL" != "null" ]; then - _REPO_URL="$_CUSTOM_REPO_URL" - - # Check for -r since -R is being passed. Set -r with a warning. - if [ "$_DISABLE_REPOS" -eq $BS_FALSE ]; then - echowarn "Detected -R option. No other repositories will be configured when -R is used. Setting -r option to True." - _DISABLE_REPOS=$BS_TRUE - fi -fi - -# Check the _DISABLE_SSL value and set HTTP or HTTPS. -if [ "$_DISABLE_SSL" -eq $BS_TRUE ]; then - HTTP_VAL="http" -else - HTTP_VAL="https" -fi - -# Check the _QUIET_GIT_INSTALLATION value and set SETUP_PY_INSTALL_ARGS. -if [ "$_QUIET_GIT_INSTALLATION" -eq $BS_TRUE ]; then - SETUP_PY_INSTALL_ARGS="-q" -else - SETUP_PY_INSTALL_ARGS="" -fi - -# Handle the insecure flags -if [ "$_INSECURE_DL" -eq $BS_TRUE ]; then - _CURL_ARGS="${_CURL_ARGS} --insecure" - _FETCH_ARGS="${_FETCH_ARGS} --no-verify-peer" - _GPG_ARGS="${_GPG_ARGS} --keyserver-options no-check-cert" - _WGET_ARGS="${_WGET_ARGS} --no-check-certificate" -else - _GPG_ARGS="${_GPG_ARGS} --keyserver-options ca-cert-file=/etc/ssl/certs/ca-certificates.crt" -fi - -# Export the http_proxy configuration to our current environment -if [ "${_HTTP_PROXY}" != "" ]; then - export http_proxy="${_HTTP_PROXY}" - export https_proxy="${_HTTP_PROXY}" - # Using "deprecated" option here, but that appears the only way to make it work. - # See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=818802 - # and https://bugs.launchpad.net/ubuntu/+source/gnupg2/+bug/1625848 - _GPG_ARGS="${_GPG_ARGS},http-proxy=${_HTTP_PROXY}" -fi - -# Work around for 'Docker + salt-bootstrap failure' https://github.com/saltstack/salt-bootstrap/issues/394 -if [ "${_DISABLE_SALT_CHECKS}" -eq $BS_FALSE ] && [ -f /tmp/disable_salt_checks ]; then - # shellcheck disable=SC2016 - echowarn 'Found file: /tmp/disable_salt_checks, setting _DISABLE_SALT_CHECKS=$BS_TRUE' - _DISABLE_SALT_CHECKS=$BS_TRUE -fi - -# Because -a can only be installed into virtualenv -if [ "${_PIP_ALL}" -eq $BS_TRUE ] && [ "${_VIRTUALENV_DIR}" = "null" ]; then - usage - # Could possibly set up a default virtualenv location when -a flag is passed - echoerror "Using -a requires -V because pip pkgs should be siloed from python system pkgs" - exit 1 -fi - -# Make sure virtualenv directory does not already exist -if [ -d "${_VIRTUALENV_DIR}" ]; then - echoerror "The directory ${_VIRTUALENV_DIR} for virtualenv already exists" - exit 1 -fi - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __fetch_url -# DESCRIPTION: Retrieves a URL and writes it to a given path -#---------------------------------------------------------------------------------------------------------------------- -__fetch_url() { - # shellcheck disable=SC2086 - curl $_CURL_ARGS -L -s -o "$1" "$2" >/dev/null 2>&1 || - wget $_WGET_ARGS -q -O "$1" "$2" >/dev/null 2>&1 || - fetch $_FETCH_ARGS -q -o "$1" "$2" >/dev/null 2>&1 || # FreeBSD - fetch -q -o "$1" "$2" >/dev/null 2>&1 || # Pre FreeBSD 10 - ftp -o "$1" "$2" >/dev/null 2>&1 # OpenBSD -} - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __fetch_verify -# DESCRIPTION: Retrieves a URL, verifies its content and writes it to standard output -#---------------------------------------------------------------------------------------------------------------------- -__fetch_verify() { - fetch_verify_url="$1" - fetch_verify_sum="$2" - fetch_verify_size="$3" - - fetch_verify_tmpf=$(mktemp) && \ - __fetch_url "$fetch_verify_tmpf" "$fetch_verify_url" && \ - test "$(stat --format=%s "$fetch_verify_tmpf")" -eq "$fetch_verify_size" && \ - test "$(md5sum "$fetch_verify_tmpf" | awk '{ print $1 }')" = "$fetch_verify_sum" && \ - cat "$fetch_verify_tmpf" && \ - if rm -f "$fetch_verify_tmpf"; then - return 0 - fi - echo "Failed verification of $fetch_verify_url" - return 1 -} - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __gather_hardware_info -# DESCRIPTION: Discover hardware information -#---------------------------------------------------------------------------------------------------------------------- -__gather_hardware_info() { - if [ -f /proc/cpuinfo ]; then - CPU_VENDOR_ID=$(awk '/vendor_id|Processor/ {sub(/-.*$/,"",$3); print $3; exit}' /proc/cpuinfo ) - elif [ -f /usr/bin/kstat ]; then - # SmartOS. - # Solaris!? - # This has only been tested for a GenuineIntel CPU - CPU_VENDOR_ID=$(/usr/bin/kstat -p cpu_info:0:cpu_info0:vendor_id | awk '{print $2}') - else - CPU_VENDOR_ID=$( sysctl -n hw.model ) - fi - # shellcheck disable=SC2034 - CPU_VENDOR_ID_L=$( echo "$CPU_VENDOR_ID" | tr '[:upper:]' '[:lower:]' ) - CPU_ARCH=$(uname -m 2>/dev/null || uname -p 2>/dev/null || echo "unknown") - CPU_ARCH_L=$( echo "$CPU_ARCH" | tr '[:upper:]' '[:lower:]' ) -} -__gather_hardware_info - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __gather_os_info -# DESCRIPTION: Discover operating system information -#---------------------------------------------------------------------------------------------------------------------- -__gather_os_info() { - OS_NAME=$(uname -s 2>/dev/null) - OS_NAME_L=$( echo "$OS_NAME" | tr '[:upper:]' '[:lower:]' ) - OS_VERSION=$(uname -r) - # shellcheck disable=SC2034 - OS_VERSION_L=$( echo "$OS_VERSION" | tr '[:upper:]' '[:lower:]' ) -} -__gather_os_info - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __parse_version_string -# DESCRIPTION: Parse version strings ignoring the revision. -# MAJOR.MINOR.REVISION becomes MAJOR.MINOR -#---------------------------------------------------------------------------------------------------------------------- -__parse_version_string() { - VERSION_STRING="$1" - PARSED_VERSION=$( - echo "$VERSION_STRING" | - sed -e 's/^/#/' \ - -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\)\(\.[0-9][0-9]*\).*$/\1/' \ - -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \ - -e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \ - -e 's/^#.*$//' - ) - echo "$PARSED_VERSION" -} - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __derive_debian_numeric_version -# DESCRIPTION: Derive the numeric version from a Debian version string. -#---------------------------------------------------------------------------------------------------------------------- -__derive_debian_numeric_version() { - NUMERIC_VERSION="" - INPUT_VERSION="$1" - if echo "$INPUT_VERSION" | grep -q '^[0-9]'; then - NUMERIC_VERSION="$INPUT_VERSION" - elif [ -z "$INPUT_VERSION" ] && [ -f "/etc/debian_version" ]; then - INPUT_VERSION="$(cat /etc/debian_version)" - fi - if [ -z "$NUMERIC_VERSION" ]; then - if [ "$INPUT_VERSION" = "wheezy/sid" ]; then - # I've found an EC2 wheezy image which did not tell its version - NUMERIC_VERSION=$(__parse_version_string "7.0") - elif [ "$INPUT_VERSION" = "jessie/sid" ]; then - NUMERIC_VERSION=$(__parse_version_string "8.0") - elif [ "$INPUT_VERSION" = "stretch/sid" ]; then - NUMERIC_VERSION=$(__parse_version_string "9.0") - elif [ "$INPUT_VERSION" = "buster/sid" ]; then - NUMERIC_VERSION=$(__parse_version_string "10.0") - else - echowarn "Unable to parse the Debian Version (codename: '$INPUT_VERSION')" - fi - fi - echo "$NUMERIC_VERSION" -} - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __unquote_string -# DESCRIPTION: Strip single or double quotes from the provided string. -#---------------------------------------------------------------------------------------------------------------------- -__unquote_string() { - # shellcheck disable=SC1117 - echo "$*" | sed -e "s/^\([\"\']\)\(.*\)\1\$/\2/g" -} - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __camelcase_split -# DESCRIPTION: Convert 'CamelCased' strings to 'Camel Cased' -#---------------------------------------------------------------------------------------------------------------------- -__camelcase_split() { - echo "$*" | sed -e 's/\([^[:upper:][:punct:]]\)\([[:upper:]]\)/\1 \2/g' -} - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __strip_duplicates -# DESCRIPTION: Strip duplicate strings -#---------------------------------------------------------------------------------------------------------------------- -__strip_duplicates() { - echo "$*" | tr -s '[:space:]' '\n' | awk '!x[$0]++' -} - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __sort_release_files -# DESCRIPTION: Custom sort function. Alphabetical or numerical sort is not -# enough. -#---------------------------------------------------------------------------------------------------------------------- -__sort_release_files() { - KNOWN_RELEASE_FILES=$(echo "(arch|alpine|centos|debian|ubuntu|fedora|redhat|suse|\ - mandrake|mandriva|gentoo|slackware|turbolinux|unitedlinux|void|lsb|system|\ - oracle|os)(-|_)(release|version)" | sed -r 's:[[:space:]]::g') - primary_release_files="" - secondary_release_files="" - # Sort know VS un-known files first - for release_file in $(echo "${@}" | sed -r 's:[[:space:]]:\n:g' | sort -f | uniq); do - match=$(echo "$release_file" | grep -E -i "${KNOWN_RELEASE_FILES}") - if [ "${match}" != "" ]; then - primary_release_files="${primary_release_files} ${release_file}" - else - secondary_release_files="${secondary_release_files} ${release_file}" - fi - done - - # Now let's sort by know files importance, max important goes last in the max_prio list - max_prio="redhat-release centos-release oracle-release fedora-release" - for entry in $max_prio; do - if [ "$(echo "${primary_release_files}" | grep "$entry")" != "" ]; then - primary_release_files=$(echo "${primary_release_files}" | sed -e "s:\\(.*\\)\\($entry\\)\\(.*\\):\\2 \\1 \\3:g") - fi - done - # Now, least important goes last in the min_prio list - min_prio="lsb-release" - for entry in $min_prio; do - if [ "$(echo "${primary_release_files}" | grep "$entry")" != "" ]; then - primary_release_files=$(echo "${primary_release_files}" | sed -e "s:\\(.*\\)\\($entry\\)\\(.*\\):\\1 \\3 \\2:g") - fi - done - - # Echo the results collapsing multiple white-space into a single white-space - echo "${primary_release_files} ${secondary_release_files}" | sed -r 's:[[:space:]]+:\n:g' -} - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __gather_linux_system_info -# DESCRIPTION: Discover Linux system information -#---------------------------------------------------------------------------------------------------------------------- -__gather_linux_system_info() { - DISTRO_NAME="" - DISTRO_VERSION="" - - # Let's test if the lsb_release binary is available - rv=$(lsb_release >/dev/null 2>&1) - - # shellcheck disable=SC2181 - if [ $? -eq 0 ]; then - DISTRO_NAME=$(lsb_release -si) - if [ "${DISTRO_NAME}" = "Scientific" ]; then - DISTRO_NAME="Scientific Linux" - elif [ "$(echo "$DISTRO_NAME" | grep ^CloudLinux)" != "" ]; then - DISTRO_NAME="Cloud Linux" - elif [ "$(echo "$DISTRO_NAME" | grep ^RedHat)" != "" ]; then - # Let's convert 'CamelCased' to 'Camel Cased' - n=$(__camelcase_split "$DISTRO_NAME") - # Skip setting DISTRO_NAME this time, splitting CamelCase has failed. - # See https://github.com/saltstack/salt-bootstrap/issues/918 - [ "$n" = "$DISTRO_NAME" ] && DISTRO_NAME="" || DISTRO_NAME="$n" - elif [ "${DISTRO_NAME}" = "openSUSE project" ]; then - # lsb_release -si returns "openSUSE project" on openSUSE 12.3 - # lsb_release -si returns "openSUSE" on openSUSE 15.n - DISTRO_NAME="opensuse" - elif [ "${DISTRO_NAME}" = "SUSE LINUX" ]; then - if [ "$(lsb_release -sd | grep -i opensuse)" != "" ]; then - # openSUSE 12.2 reports SUSE LINUX on lsb_release -si - DISTRO_NAME="opensuse" - else - # lsb_release -si returns "SUSE LINUX" on SLES 11 SP3 - DISTRO_NAME="suse" - fi - elif [ "${DISTRO_NAME}" = "EnterpriseEnterpriseServer" ]; then - # This the Oracle Linux Enterprise ID before ORACLE LINUX 5 UPDATE 3 - DISTRO_NAME="Oracle Linux" - elif [ "${DISTRO_NAME}" = "OracleServer" ]; then - # This the Oracle Linux Server 6.5 - DISTRO_NAME="Oracle Linux" - elif [ "${DISTRO_NAME}" = "AmazonAMI" ] || [ "${DISTRO_NAME}" = "Amazon" ]; then - DISTRO_NAME="Amazon Linux AMI" - elif [ "${DISTRO_NAME}" = "ManjaroLinux" ]; then - DISTRO_NAME="Arch Linux" - elif [ "${DISTRO_NAME}" = "Arch" ]; then - DISTRO_NAME="Arch Linux" - return - fi - rv=$(lsb_release -sr) - [ "${rv}" != "" ] && DISTRO_VERSION=$(__parse_version_string "$rv") - elif [ -f /etc/lsb-release ]; then - # We don't have the lsb_release binary, though, we do have the file it parses - DISTRO_NAME=$(grep DISTRIB_ID /etc/lsb-release | sed -e 's/.*=//') - rv=$(grep DISTRIB_RELEASE /etc/lsb-release | sed -e 's/.*=//') - [ "${rv}" != "" ] && DISTRO_VERSION=$(__parse_version_string "$rv") - fi - - if [ "$DISTRO_NAME" != "" ] && [ "$DISTRO_VERSION" != "" ]; then - # We already have the distribution name and version - return - fi - # shellcheck disable=SC2035,SC2086 - for rsource in $(__sort_release_files "$( - cd /etc && /bin/ls *[_-]release *[_-]version 2>/dev/null | env -i sort | \ - sed -e '/^redhat-release$/d' -e '/^lsb-release$/d'; \ - echo redhat-release lsb-release - )"); do - - [ ! -f "/etc/${rsource}" ] && continue # Does not exist - - n=$(echo "${rsource}" | sed -e 's/[_-]release$//' -e 's/[_-]version$//') - shortname=$(echo "${n}" | tr '[:upper:]' '[:lower:]') - if [ "$shortname" = "debian" ]; then - rv=$(__derive_debian_numeric_version "$(cat /etc/${rsource})") - else - rv=$( (grep VERSION "/etc/${rsource}"; cat "/etc/${rsource}") | grep '[0-9]' | sed -e 'q' ) - fi - [ "${rv}" = "" ] && [ "$shortname" != "arch" ] && continue # There's no version information. Continue to next rsource - v=$(__parse_version_string "$rv") - case $shortname in - redhat ) - if [ "$(grep -E 'CentOS' /etc/${rsource})" != "" ]; then - n="CentOS" - elif [ "$(grep -E 'Scientific' /etc/${rsource})" != "" ]; then - n="Scientific Linux" - elif [ "$(grep -E 'Red Hat Enterprise Linux' /etc/${rsource})" != "" ]; then - n="ed at nterprise inux" - else - n="ed at inux" - fi - ;; - arch ) n="Arch Linux" ;; - alpine ) n="Alpine Linux" ;; - centos ) n="CentOS" ;; - debian ) n="Debian" ;; - ubuntu ) n="Ubuntu" ;; - fedora ) n="Fedora" ;; - suse|opensuse ) n="SUSE" ;; - mandrake*|mandriva ) n="Mandriva" ;; - gentoo ) n="Gentoo" ;; - slackware ) n="Slackware" ;; - turbolinux ) n="TurboLinux" ;; - unitedlinux ) n="UnitedLinux" ;; - void ) n="VoidLinux" ;; - oracle ) n="Oracle Linux" ;; - system ) - while read -r line; do - [ "${n}x" != "systemx" ] && break - case "$line" in - *Amazon*Linux*AMI*) - n="Amazon Linux AMI" - break - esac - done < "/etc/${rsource}" - ;; - os ) - nn="$(__unquote_string "$(grep '^ID=' /etc/os-release | sed -e 's/^ID=\(.*\)$/\1/g')")" - rv="$(__unquote_string "$(grep '^VERSION_ID=' /etc/os-release | sed -e 's/^VERSION_ID=\(.*\)$/\1/g')")" - [ "${rv}" != "" ] && v=$(__parse_version_string "$rv") || v="" - case $(echo "${nn}" | tr '[:upper:]' '[:lower:]') in - alpine ) - n="Alpine Linux" - v="${rv}" - ;; - amzn ) - # Amazon AMI's after 2014.09 match here - n="Amazon Linux AMI" - ;; - arch ) - n="Arch Linux" - v="" # Arch Linux does not provide a version. - ;; - cloudlinux ) - n="Cloud Linux" - ;; - debian ) - n="Debian" - v=$(__derive_debian_numeric_version "$v") - ;; - sles ) - n="SUSE" - v="${rv}" - ;; - opensuse-leap ) - n="opensuse" - v="${rv}" - ;; - * ) - n=${nn} - ;; - esac - ;; - * ) n="${n}" ; - esac - DISTRO_NAME=$n - DISTRO_VERSION=$v - break - done -} - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __install_python() -# DESCRIPTION: Install a different version of python on a host. Currently this has only been tested on CentOS 6 and -# is considered experimental. -#---------------------------------------------------------------------------------------------------------------------- -__install_python() { - if [ "$_PY_EXE" = "" ]; then - echoerror "Must specify -x with -y to install a specific python version" - exit 1 - fi - - __PACKAGES="$_PY_PKG_VER" - - if [ ${_DISABLE_REPOS} -eq ${BS_FALSE} ]; then - echoinfo "Attempting to install a repo to help provide a separate python package" - echoinfo "$DISTRO_NAME_L" - case "$DISTRO_NAME_L" in - "red_hat"|"centos") - __PYTHON_REPO_URL="https://centos${DISTRO_MAJOR_VERSION}.iuscommunity.org/ius-release.rpm" - ;; - *) - echoerror "Installing a repo to provide a python package is only supported on Redhat/CentOS. - If a repo is already available, please try running script with -r." - exit 1 - ;; - esac - - echoinfo "Installing IUS repo" - __yum_install_noinput "${__PYTHON_REPO_URL}" || return 1 - fi - - echoinfo "Installing ${__PACKAGES}" - __yum_install_noinput "${__PACKAGES}" || return 1 -} - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __gather_sunos_system_info -# DESCRIPTION: Discover SunOS system info -#---------------------------------------------------------------------------------------------------------------------- -__gather_sunos_system_info() { - if [ -f /sbin/uname ]; then - DISTRO_VERSION=$(/sbin/uname -X | awk '/[kK][eE][rR][nN][eE][lL][iI][dD]/ { print $3 }') - fi - - DISTRO_NAME="" - if [ -f /etc/release ]; then - while read -r line; do - [ "${DISTRO_NAME}" != "" ] && break - case "$line" in - *OpenIndiana*oi_[0-9]*) - DISTRO_NAME="OpenIndiana" - DISTRO_VERSION=$(echo "$line" | sed -nr "s/OpenIndiana(.*)oi_([[:digit:]]+)(.*)/\\2/p") - break - ;; - *OpenSolaris*snv_[0-9]*) - DISTRO_NAME="OpenSolaris" - DISTRO_VERSION=$(echo "$line" | sed -nr "s/OpenSolaris(.*)snv_([[:digit:]]+)(.*)/\\2/p") - break - ;; - *Oracle*Solaris*[0-9]*) - DISTRO_NAME="Oracle Solaris" - DISTRO_VERSION=$(echo "$line" | sed -nr "s/(Oracle Solaris) ([[:digit:]]+)(.*)/\\2/p") - break - ;; - *Solaris*) - DISTRO_NAME="Solaris" - # Let's make sure we not actually on a Joyent's SmartOS VM since some releases - # don't have SmartOS in `/etc/release`, only `Solaris` - if uname -v | grep joyent >/dev/null 2>&1; then - DISTRO_NAME="SmartOS" - fi - break - ;; - *NexentaCore*) - DISTRO_NAME="Nexenta Core" - break - ;; - *SmartOS*) - DISTRO_NAME="SmartOS" - break - ;; - *OmniOS*) - DISTRO_NAME="OmniOS" - DISTRO_VERSION=$(echo "$line" | awk '{print $3}') - _SIMPLIFY_VERSION=$BS_FALSE - break - ;; - esac - done < /etc/release - fi - - if [ "${DISTRO_NAME}" = "" ]; then - DISTRO_NAME="Solaris" - DISTRO_VERSION=$( - echo "${OS_VERSION}" | - sed -e 's;^4\.;1.;' \ - -e 's;^5\.\([0-6]\)[^0-9]*$;2.\1;' \ - -e 's;^5\.\([0-9][0-9]*\).*;\1;' - ) - fi - - if [ "${DISTRO_NAME}" = "SmartOS" ]; then - VIRTUAL_TYPE="smartmachine" - if [ "$(zonename)" = "global" ]; then - VIRTUAL_TYPE="global" - fi - fi -} - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __gather_bsd_system_info -# DESCRIPTION: Discover OpenBSD, NetBSD and FreeBSD systems information -#---------------------------------------------------------------------------------------------------------------------- -__gather_bsd_system_info() { - DISTRO_NAME=${OS_NAME} - DISTRO_VERSION=$(echo "${OS_VERSION}" | sed -e 's;[()];;' -e 's/-.*$//') -} - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __gather_osx_system_info -# DESCRIPTION: Discover MacOS X -#---------------------------------------------------------------------------------------------------------------------- -__gather_osx_system_info() { - DISTRO_NAME="MacOSX" - DISTRO_VERSION=$(sw_vers -productVersion) -} - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __gather_system_info -# DESCRIPTION: Discover which system and distribution we are running. -#---------------------------------------------------------------------------------------------------------------------- -__gather_system_info() { - case ${OS_NAME_L} in - linux ) - __gather_linux_system_info - ;; - sunos ) - __gather_sunos_system_info - ;; - openbsd|freebsd|netbsd ) - __gather_bsd_system_info - ;; - darwin ) - __gather_osx_system_info - ;; - * ) - echoerror "${OS_NAME} not supported."; - exit 1 - ;; - esac - -} - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __ubuntu_derivatives_translation -# DESCRIPTION: Map Ubuntu derivatives to their Ubuntu base versions. -# If distro has a known Ubuntu base version, use those install -# functions by pretending to be Ubuntu (i.e. change global vars) -#---------------------------------------------------------------------------------------------------------------------- -# shellcheck disable=SC2034 -__ubuntu_derivatives_translation() { - UBUNTU_DERIVATIVES="(trisquel|linuxmint|linaro|elementary_os|neon)" - # Mappings - trisquel_6_ubuntu_base="12.04" - linuxmint_13_ubuntu_base="12.04" - linuxmint_17_ubuntu_base="14.04" - linuxmint_18_ubuntu_base="16.04" - linuxmint_19_ubuntu_base="18.04" - linaro_12_ubuntu_base="12.04" - elementary_os_02_ubuntu_base="12.04" - neon_16_ubuntu_base="16.04" - - # Translate Ubuntu derivatives to their base Ubuntu version - match=$(echo "$DISTRO_NAME_L" | grep -E ${UBUNTU_DERIVATIVES}) - - if [ "${match}" != "" ]; then - case $match in - "elementary_os") - _major=$(echo "$DISTRO_VERSION" | sed 's/\.//g') - ;; - "linuxmint") - export LSB_ETC_LSB_RELEASE=/etc/upstream-release/lsb-release - _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') - ;; - *) - _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') - ;; - esac - - _ubuntu_version=$(eval echo "\$${match}_${_major}_ubuntu_base") - - if [ "$_ubuntu_version" != "" ]; then - echodebug "Detected Ubuntu $_ubuntu_version derivative" - DISTRO_NAME_L="ubuntu" - DISTRO_VERSION="$_ubuntu_version" - fi - fi -} - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __check_dpkg_architecture -# DESCRIPTION: Determine the primary architecture for packages to install on Debian and derivatives -# and issue all necessary error messages. -#---------------------------------------------------------------------------------------------------------------------- -__check_dpkg_architecture() { - if __check_command_exists dpkg; then - DPKG_ARCHITECTURE="$(dpkg --print-architecture)" - else - echoerror "dpkg: command not found." - return 1 - fi - - __REPO_ARCH="$DPKG_ARCHITECTURE" - __REPO_ARCH_DEB='deb' - __return_code=0 - - case $DPKG_ARCHITECTURE in - "i386") - error_msg="$_REPO_URL likely doesn't have all required 32-bit packages for $DISTRO_NAME $DISTRO_MAJOR_VERSION." - # amd64 is just a part of repository URI, 32-bit pkgs are hosted under the same location - __REPO_ARCH="amd64" - ;; - "amd64") - error_msg="" - ;; - "arm64") - if [ "$_CUSTOM_REPO_URL" != "null" ]; then - warn_msg="Support for arm64 is experimental, make sure the custom repository used has the expected structure and contents." - else - # Saltstack official repository does not yet have arm64 metadata, - # use amd64 repositories on arm64, since all pkgs are arch-independent - __REPO_ARCH="amd64" - __REPO_ARCH_DEB="deb [arch=$__REPO_ARCH]" - warn_msg="Support for arm64 packages is experimental and might rely on architecture-independent packages from the amd64 repository." - fi - error_msg="" - ;; - "armhf") - if [ "$DISTRO_NAME_L" = "ubuntu" ] || [ "$DISTRO_MAJOR_VERSION" -lt 8 ]; then - error_msg="Support for armhf packages at $_REPO_URL is limited to Debian/Raspbian 8 platforms." - __return_code=1 - else - error_msg="" - fi - ;; - *) - error_msg="$_REPO_URL doesn't have packages for your system architecture: $DPKG_ARCHITECTURE." - __return_code=1 - ;; - esac - - if [ "${warn_msg:-}" != "" ]; then - # AArch64: Do not fail at this point, but warn the user about experimental support - # See https://github.com/saltstack/salt-bootstrap/issues/1240 - echowarn "${warn_msg}" - fi - if [ "${error_msg}" != "" ]; then - echoerror "${error_msg}" - if [ "$ITYPE" != "git" ]; then - echoerror "You can try git installation mode, i.e.: sh ${__ScriptName} git v2017.7.2." - echoerror "It may be necessary to use git installation mode with pip and disable the SaltStack apt repository." - echoerror "For example:" - echoerror " sh ${__ScriptName} -r -P git v2017.7.2" - fi - fi - - if [ "${__return_code}" -eq 0 ]; then - return 0 - else - return 1 - fi -} - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __ubuntu_codename_translation -# DESCRIPTION: Map Ubuntu major versions to their corresponding codenames -#---------------------------------------------------------------------------------------------------------------------- -# shellcheck disable=SC2034 -__ubuntu_codename_translation() { - case $DISTRO_MINOR_VERSION in - "04") - _april="yes" - ;; - "10") - _april="" - ;; - *) - _april="yes" - ;; - esac - - case $DISTRO_MAJOR_VERSION in - "12") - DISTRO_CODENAME="precise" - ;; - "14") - DISTRO_CODENAME="trusty" - ;; - "16") - DISTRO_CODENAME="xenial" - ;; - "18") - DISTRO_CODENAME="bionic" - ;; - *) - DISTRO_CODENAME="trusty" - ;; - esac -} - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __debian_derivatives_translation -# DESCRIPTION: Map Debian derivatives to their Debian base versions. -# If distro has a known Debian base version, use those install -# functions by pretending to be Debian (i.e. change global vars) -#---------------------------------------------------------------------------------------------------------------------- -# shellcheck disable=SC2034 -__debian_derivatives_translation() { - # If the file does not exist, return - [ ! -f /etc/os-release ] && return - - DEBIAN_DERIVATIVES="(cumulus_.+|devuan|kali|linuxmint|raspbian|bunsenlabs|turnkey)" - # Mappings - cumulus_2_debian_base="7.0" - cumulus_3_debian_base="8.0" - devuan_1_debian_base="8.0" - devuan_2_debian_base="9.0" - kali_1_debian_base="7.0" - linuxmint_1_debian_base="8.0" - raspbian_8_debian_base="8.0" - raspbian_9_debian_base="9.0" - raspbian_10_debian_base="10.0" - bunsenlabs_9_debian_base="9.0" - turnkey_9_debian_base="9.0" - - # Translate Debian derivatives to their base Debian version - match=$(echo "$DISTRO_NAME_L" | grep -E ${DEBIAN_DERIVATIVES}) - - if [ "${match}" != "" ]; then - case $match in - cumulus_*) - _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') - _debian_derivative="cumulus" - ;; - devuan) - _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') - _debian_derivative="devuan" - ;; - kali) - _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') - _debian_derivative="kali" - ;; - linuxmint) - _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') - _debian_derivative="linuxmint" - ;; - raspbian) - _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') - _debian_derivative="raspbian" - ;; - bunsenlabs) - _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') - _debian_derivative="bunsenlabs" - ;; - turnkey) - _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') - _debian_derivative="turnkey" - ;; - esac - - _debian_version=$(eval echo "\$${_debian_derivative}_${_major}_debian_base" 2>/dev/null) - - if [ "$_debian_version" != "" ]; then - echodebug "Detected Debian $_debian_version derivative" - DISTRO_NAME_L="debian" - DISTRO_VERSION="$_debian_version" - DISTRO_MAJOR_VERSION="$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g')" - fi - fi -} - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __debian_codename_translation -# DESCRIPTION: Map Debian major versions to their corresponding code names -#---------------------------------------------------------------------------------------------------------------------- -# shellcheck disable=SC2034 -__debian_codename_translation() { - - case $DISTRO_MAJOR_VERSION in - "7") - DISTRO_CODENAME="wheezy" - ;; - "8") - DISTRO_CODENAME="jessie" - ;; - "9") - DISTRO_CODENAME="stretch" - ;; - "10") - DISTRO_CODENAME="buster" - ;; - *) - DISTRO_CODENAME="jessie" - ;; - esac -} - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __check_end_of_life_versions -# DESCRIPTION: Check for end of life distribution versions -#---------------------------------------------------------------------------------------------------------------------- -__check_end_of_life_versions() { - case "${DISTRO_NAME_L}" in - debian) - # Debian versions below 7 are not supported - if [ "$DISTRO_MAJOR_VERSION" -lt 7 ]; then - echoerror "End of life distributions are not supported." - echoerror "Please consider upgrading to the next stable. See:" - echoerror " https://wiki.debian.org/DebianReleases" - exit 1 - fi - ;; - - ubuntu) - # Ubuntu versions not supported - # - # < 14.04 - # = 14.10 - # = 15.04, 15.10 - # = 16.10 - # = 17.04, 17.10 - if [ "$DISTRO_MAJOR_VERSION" -lt 14 ] || \ - [ "$DISTRO_MAJOR_VERSION" -eq 15 ] || \ - [ "$DISTRO_MAJOR_VERSION" -eq 17 ] || \ - { [ "$DISTRO_MAJOR_VERSION" -eq 16 ] && [ "$DISTRO_MINOR_VERSION" -eq 10 ]; }; then - echoerror "End of life distributions are not supported." - echoerror "Please consider upgrading to the next stable. See:" - echoerror " https://wiki.ubuntu.com/Releases" - exit 1 - fi - ;; - - opensuse) - # openSUSE versions not supported - # - # <= 13.X - # <= 42.2 - if [ "$DISTRO_MAJOR_VERSION" -lt 15 ] || \ - { [ "$DISTRO_MAJOR_VERSION" -eq 42 ] && [ "$DISTRO_MINOR_VERSION" -le 2 ]; }; then - echoerror "End of life distributions are not supported." - echoerror "Please consider upgrading to the next stable. See:" - echoerror " http://en.opensuse.org/Lifetime" - exit 1 - fi - ;; - - suse) - # SuSE versions not supported - # - # < 11 SP4 - # < 12 SP2 - SUSE_PATCHLEVEL=$(awk '/PATCHLEVEL/ {print $3}' /etc/SuSE-release ) - if [ "${SUSE_PATCHLEVEL}" = "" ]; then - SUSE_PATCHLEVEL="00" - fi - if [ "$DISTRO_MAJOR_VERSION" -lt 11 ] || \ - { [ "$DISTRO_MAJOR_VERSION" -eq 11 ] && [ "$SUSE_PATCHLEVEL" -lt 04 ]; } || \ - { [ "$DISTRO_MAJOR_VERSION" -eq 12 ] && [ "$SUSE_PATCHLEVEL" -lt 02 ]; }; then - echoerror "Versions lower than SuSE 11 SP4 or 12 SP2 are not supported." - echoerror "Please consider upgrading to the next stable" - echoerror " https://www.suse.com/lifecycle/" - exit 1 - fi - ;; - - fedora) - # Fedora lower than 27 are no longer supported - if [ "$DISTRO_MAJOR_VERSION" -lt 27 ]; then - echoerror "End of life distributions are not supported." - echoerror "Please consider upgrading to the next stable. See:" - echoerror " https://fedoraproject.org/wiki/Releases" - exit 1 - fi - ;; - - centos) - # CentOS versions lower than 6 are no longer supported - if [ "$DISTRO_MAJOR_VERSION" -lt 6 ]; then - echoerror "End of life distributions are not supported." - echoerror "Please consider upgrading to the next stable. See:" - echoerror " http://wiki.centos.org/Download" - exit 1 - fi - ;; - - red_hat*linux) - # Red Hat (Enterprise) Linux versions lower than 6 are no longer supported - if [ "$DISTRO_MAJOR_VERSION" -lt 6 ]; then - echoerror "End of life distributions are not supported." - echoerror "Please consider upgrading to the next stable. See:" - echoerror " https://access.redhat.com/support/policy/updates/errata/" - exit 1 - fi - ;; - - oracle*linux) - # Oracle Linux versions lower than 6 are no longer supported - if [ "$DISTRO_MAJOR_VERSION" -lt 6 ]; then - echoerror "End of life distributions are not supported." - echoerror "Please consider upgrading to the next stable. See:" - echoerror " http://www.oracle.com/us/support/library/elsp-lifetime-069338.pdf" - exit 1 - fi - ;; - - scientific*linux) - # Scientific Linux versions lower than 6 are no longer supported - if [ "$DISTRO_MAJOR_VERSION" -lt 6 ]; then - echoerror "End of life distributions are not supported." - echoerror "Please consider upgrading to the next stable. See:" - echoerror " https://www.scientificlinux.org/downloads/sl-versions/" - exit 1 - fi - ;; - - cloud*linux) - # Cloud Linux versions lower than 6 are no longer supported - if [ "$DISTRO_MAJOR_VERSION" -lt 6 ]; then - echoerror "End of life distributions are not supported." - echoerror "Please consider upgrading to the next stable. See:" - echoerror " https://docs.cloudlinux.com/index.html?cloudlinux_life-cycle.html" - exit 1 - fi - ;; - - amazon*linux*ami) - # Amazon Linux versions lower than 2012.0X no longer supported - # Except for Amazon Linux 2, which reset the major version counter - if [ "$DISTRO_MAJOR_VERSION" -lt 2012 ] && [ "$DISTRO_MAJOR_VERSION" -gt 10 ]; then - echoerror "End of life distributions are not supported." - echoerror "Please consider upgrading to the next stable. See:" - echoerror " https://aws.amazon.com/amazon-linux-ami/" - exit 1 - fi - ;; - - freebsd) - # FreeBSD versions lower than 9.1 are not supported. - if { [ "$DISTRO_MAJOR_VERSION" -eq 9 ] && [ "$DISTRO_MINOR_VERSION" -lt 01 ]; } || \ - [ "$DISTRO_MAJOR_VERSION" -lt 9 ]; then - echoerror "Versions lower than FreeBSD 9.1 are not supported." - exit 1 - fi - ;; - - *) - ;; - esac -} - - -__gather_system_info - -echo -echoinfo "System Information:" -echoinfo " CPU: ${CPU_VENDOR_ID}" -echoinfo " CPU Arch: ${CPU_ARCH}" -echoinfo " OS Name: ${OS_NAME}" -echoinfo " OS Version: ${OS_VERSION}" -echoinfo " Distribution: ${DISTRO_NAME} ${DISTRO_VERSION}" -echo - -# Simplify distro name naming on functions -DISTRO_NAME_L=$(echo "$DISTRO_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-zA-Z0-9_ ]//g' | sed -re 's/([[:space:]])+/_/g') - -# Simplify version naming on functions -if [ "$DISTRO_VERSION" = "" ] || [ ${_SIMPLIFY_VERSION} -eq $BS_FALSE ]; then - DISTRO_MAJOR_VERSION="" - DISTRO_MINOR_VERSION="" - PREFIXED_DISTRO_MAJOR_VERSION="" - PREFIXED_DISTRO_MINOR_VERSION="" -else - DISTRO_MAJOR_VERSION=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') - DISTRO_MINOR_VERSION=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).\([0-9]*\).*/\2/g') - PREFIXED_DISTRO_MAJOR_VERSION="_${DISTRO_MAJOR_VERSION}" - if [ "${PREFIXED_DISTRO_MAJOR_VERSION}" = "_" ]; then - PREFIXED_DISTRO_MAJOR_VERSION="" - fi - PREFIXED_DISTRO_MINOR_VERSION="_${DISTRO_MINOR_VERSION}" - if [ "${PREFIXED_DISTRO_MINOR_VERSION}" = "_" ]; then - PREFIXED_DISTRO_MINOR_VERSION="" - fi -fi - -# For Ubuntu derivatives, pretend to be their Ubuntu base version -__ubuntu_derivatives_translation - -# For Debian derivates, pretend to be their Debian base version -__debian_derivatives_translation - -# Fail soon for end of life versions -__check_end_of_life_versions - -echodebug "Binaries will be searched using the following \$PATH: ${PATH}" - -# Let users know that we'll use a proxy -if [ "${_HTTP_PROXY}" != "" ]; then - echoinfo "Using http proxy $_HTTP_PROXY" -fi - -# Let users know what's going to be installed/configured -if [ "$_INSTALL_MINION" -eq $BS_TRUE ]; then - if [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then - echoinfo "Installing minion" - else - echoinfo "Configuring minion" - fi -fi - -if [ "$_INSTALL_MASTER" -eq $BS_TRUE ]; then - if [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then - echoinfo "Installing master" - else - echoinfo "Configuring master" - fi -fi - -if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ]; then - if [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then - echoinfo "Installing syndic" - else - echoinfo "Configuring syndic" - fi -fi - -if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ] && [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then - echoinfo "Installing salt-cloud and required python-libcloud package" -fi - -if [ $_START_DAEMONS -eq $BS_FALSE ]; then - echoinfo "Daemons will not be started" -fi - -if [ "${DISTRO_NAME_L}" = "ubuntu" ]; then - # For ubuntu versions, obtain the codename from the release version - __ubuntu_codename_translation -elif [ "${DISTRO_NAME_L}" = "debian" ]; then - # For debian versions, obtain the codename from the release version - __debian_codename_translation -fi - -if [ "$(echo "${DISTRO_NAME_L}" | grep -E '(debian|ubuntu|centos|red_hat|oracle|scientific|amazon|fedora)')" = "" ] && [ "$ITYPE" = "stable" ] && [ "$STABLE_REV" != "latest" ]; then - echoerror "${DISTRO_NAME} does not have major version pegged packages support" - exit 1 -fi - -# Only RedHat based distros have testing support -if [ "${ITYPE}" = "testing" ]; then - if [ "$(echo "${DISTRO_NAME_L}" | grep -E '(centos|red_hat|amazon|oracle)')" = "" ]; then - echoerror "${DISTRO_NAME} does not have testing packages support" - exit 1 - fi - _EPEL_REPO="epel-testing" -fi - -# Only Ubuntu has support for installing to virtualenvs -if [ "${DISTRO_NAME_L}" != "ubuntu" ] && [ "$_VIRTUALENV_DIR" != "null" ]; then - echoerror "${DISTRO_NAME} does not have -V support" - exit 1 -fi - -# Only Ubuntu has support for pip installing all packages -if [ "${DISTRO_NAME_L}" != "ubuntu" ] && [ $_PIP_ALL -eq $BS_TRUE ]; then - echoerror "${DISTRO_NAME} does not have -a support" - exit 1 -fi - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __function_defined -# DESCRIPTION: Checks if a function is defined within this scripts scope -# PARAMETERS: function name -# RETURNS: 0 or 1 as in defined or not defined -#---------------------------------------------------------------------------------------------------------------------- -__function_defined() { - FUNC_NAME=$1 - if [ "$(command -v "$FUNC_NAME")" != "" ]; then - echoinfo "Found function $FUNC_NAME" - return 0 - fi - echodebug "$FUNC_NAME not found...." - return 1 -} - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __wait_for_apt -# DESCRIPTION: Check if any apt, apt-get, aptitude, or dpkg processes are running before -# calling these again. This is useful when these process calls are part of -# a boot process, such as on AWS AMIs. This func will wait until the boot -# process is finished so the script doesn't exit on a locked proc. -#---------------------------------------------------------------------------------------------------------------------- -__wait_for_apt(){ - # Timeout set at 15 minutes - WAIT_TIMEOUT=900 - - # Run our passed in apt command - "${@}" 2>"$APT_ERR" - APT_RETURN=$? - - # Make sure we're not waiting on a lock - while [ $APT_RETURN -ne 0 ] && grep -q '^E: Could not get lock' "$APT_ERR"; do - echoinfo "Aware of the lock. Patiently waiting $WAIT_TIMEOUT more seconds..." - sleep 1 - WAIT_TIMEOUT=$((WAIT_TIMEOUT - 1)) - - if [ "$WAIT_TIMEOUT" -eq 0 ]; then - echoerror "Apt, apt-get, aptitude, or dpkg process is taking too long." - echoerror "Bootstrap script cannot proceed. Aborting." - return 1 - else - "${@}" 2>"$APT_ERR" - APT_RETURN=$? - fi - done - - return $APT_RETURN -} - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __apt_get_install_noinput -# DESCRIPTION: (DRY) apt-get install with noinput options -# PARAMETERS: packages -#---------------------------------------------------------------------------------------------------------------------- -__apt_get_install_noinput() { - __wait_for_apt apt-get install -y -o DPkg::Options::=--force-confold "${@}"; return $? -} # ---------- end of function __apt_get_install_noinput ---------- - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __apt_get_upgrade_noinput -# DESCRIPTION: (DRY) apt-get upgrade with noinput options -#---------------------------------------------------------------------------------------------------------------------- -__apt_get_upgrade_noinput() { - __wait_for_apt apt-get upgrade -y -o DPkg::Options::=--force-confold; return $? -} # ---------- end of function __apt_get_upgrade_noinput ---------- - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __temp_gpg_pub -# DESCRIPTION: Create a temporary file for downloading a GPG public key. -#---------------------------------------------------------------------------------------------------------------------- -__temp_gpg_pub() { - if __check_command_exists mktemp; then - tempfile="$(mktemp /tmp/salt-gpg-XXXXXXXX.pub 2>/dev/null)" - - if [ -z "$tempfile" ]; then - echoerror "Failed to create temporary file in /tmp" - return 1 - fi - else - tempfile="/tmp/salt-gpg-$$.pub" - fi - - echo $tempfile -} # ----------- end of function __temp_gpg_pub ----------- - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __apt_key_fetch -# DESCRIPTION: Download and import GPG public key for "apt-secure" -# PARAMETERS: url -#---------------------------------------------------------------------------------------------------------------------- -__apt_key_fetch() { - url=$1 - - tempfile="$(__temp_gpg_pub)" - - __fetch_url "$tempfile" "$url" || return 1 - apt-key add "$tempfile" || return 1 - rm -f "$tempfile" - - return 0 -} # ---------- end of function __apt_key_fetch ---------- - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __rpm_import_gpg -# DESCRIPTION: Download and import GPG public key to rpm database -# PARAMETERS: url -#---------------------------------------------------------------------------------------------------------------------- -__rpm_import_gpg() { - url=$1 - - tempfile="$(__temp_gpg_pub)" - - __fetch_url "$tempfile" "$url" || return 1 - rpm --import "$tempfile" || return 1 - rm -f "$tempfile" - - return 0 -} # ---------- end of function __rpm_import_gpg ---------- - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __yum_install_noinput -# DESCRIPTION: (DRY) yum install with noinput options -#---------------------------------------------------------------------------------------------------------------------- -__yum_install_noinput() { - - ENABLE_EPEL_CMD="" - # Skip Amazon Linux for the first round, since EPEL is no longer required. - # See issue #724 - if [ $_DISABLE_REPOS -eq $BS_FALSE ] && [ "$DISTRO_NAME_L" != "amazon_linux_ami" ]; then - ENABLE_EPEL_CMD="--enablerepo=${_EPEL_REPO}" - fi - - if [ "$DISTRO_NAME_L" = "oracle_linux" ]; then - # We need to install one package at a time because --enablerepo=X disables ALL OTHER REPOS!!!! - for package in "${@}"; do - yum -y install "${package}" || yum -y install "${package}" ${ENABLE_EPEL_CMD} || return $? - done - else - yum -y install "${@}" ${ENABLE_EPEL_CMD} || return $? - fi -} # ---------- end of function __yum_install_noinput ---------- - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __git_clone_and_checkout -# DESCRIPTION: (DRY) Helper function to clone and checkout salt to a -# specific revision. -#---------------------------------------------------------------------------------------------------------------------- -__git_clone_and_checkout() { - - echodebug "Installed git version: $(git --version | awk '{ print $3 }')" - # Turn off SSL verification if -I flag was set for insecure downloads - if [ "$_INSECURE_DL" -eq $BS_TRUE ]; then - export GIT_SSL_NO_VERIFY=1 - fi - - case ${OS_NAME_L} in - openbsd|freebsd|netbsd ) - __TAG_REGEX_MATCH=$(echo "${GIT_REV}" | sed -E 's/^(v?[0-9]{1,4}\.[0-9]{1,2})(\.[0-9]{1,2})?.*$/MATCH/') - ;; - * ) - __TAG_REGEX_MATCH=$(echo "${GIT_REV}" | sed 's/^.*\(v\?[[:digit:]]\{1,4\}\.[[:digit:]]\{1,2\}\)\(\.[[:digit:]]\{1,2\}\)\?.*$/MATCH/') - ;; - esac - - __SALT_GIT_CHECKOUT_PARENT_DIR=$(dirname "${_SALT_GIT_CHECKOUT_DIR}" 2>/dev/null) - __SALT_GIT_CHECKOUT_PARENT_DIR="${__SALT_GIT_CHECKOUT_PARENT_DIR:-/tmp/git}" - __SALT_CHECKOUT_REPONAME="$(basename "${_SALT_GIT_CHECKOUT_DIR}" 2>/dev/null)" - __SALT_CHECKOUT_REPONAME="${__SALT_CHECKOUT_REPONAME:-salt}" - [ -d "${__SALT_GIT_CHECKOUT_PARENT_DIR}" ] || mkdir "${__SALT_GIT_CHECKOUT_PARENT_DIR}" - # shellcheck disable=SC2164 - cd "${__SALT_GIT_CHECKOUT_PARENT_DIR}" - if [ -d "${_SALT_GIT_CHECKOUT_DIR}" ]; then - echodebug "Found a checked out Salt repository" - # shellcheck disable=SC2164 - cd "${_SALT_GIT_CHECKOUT_DIR}" - echodebug "Fetching git changes" - git fetch || return 1 - # Tags are needed because of salt's versioning, also fetch that - echodebug "Fetching git tags" - git fetch --tags || return 1 - - # If we have the SaltStack remote set as upstream, we also need to fetch the tags from there - if [ "$(git remote -v | grep $_SALTSTACK_REPO_URL)" != "" ]; then - echodebug "Fetching upstream(SaltStack's Salt repository) git tags" - git fetch --tags upstream - else - echoinfo "Adding SaltStack's Salt repository as a remote" - git remote add upstream "$_SALTSTACK_REPO_URL" - echodebug "Fetching upstream(SaltStack's Salt repository) git tags" - git fetch --tags upstream - fi - - echodebug "Hard reseting the cloned repository to ${GIT_REV}" - git reset --hard "$GIT_REV" || return 1 - - # Just calling `git reset --hard $GIT_REV` on a branch name that has - # already been checked out will not update that branch to the upstream - # HEAD; instead it will simply reset to itself. Check the ref to see - # if it is a branch name, check out the branch, and pull in the - # changes. - if git branch -a | grep -q "${GIT_REV}"; then - echodebug "Rebasing the cloned repository branch" - git pull --rebase || return 1 - fi - else - if [ "$_FORCE_SHALLOW_CLONE" -eq "${BS_TRUE}" ]; then - echoinfo "Forced shallow cloning of git repository." - __SHALLOW_CLONE=$BS_TRUE - elif [ "$__TAG_REGEX_MATCH" = "MATCH" ]; then - echoinfo "Git revision matches a Salt version tag, shallow cloning enabled." - __SHALLOW_CLONE=$BS_TRUE - else - echowarn "The git revision being installed does not match a Salt version tag. Shallow cloning disabled" - __SHALLOW_CLONE=$BS_FALSE - fi - - if [ "$__SHALLOW_CLONE" -eq $BS_TRUE ]; then - # Let's try shallow cloning to speed up. - # Test for "--single-branch" option introduced in git 1.7.10, the minimal version of git where the shallow - # cloning we need actually works - if [ "$(git clone 2>&1 | grep 'single-branch')" != "" ]; then - # The "--single-branch" option is supported, attempt shallow cloning - echoinfo "Attempting to shallow clone $GIT_REV from Salt's repository ${_SALT_REPO_URL}" - if git clone --depth 1 --branch "$GIT_REV" "$_SALT_REPO_URL" "$__SALT_CHECKOUT_REPONAME"; then - # shellcheck disable=SC2164 - cd "${_SALT_GIT_CHECKOUT_DIR}" - __SHALLOW_CLONE=$BS_TRUE - else - # Shallow clone above failed(missing upstream tags???), let's resume the old behaviour. - echowarn "Failed to shallow clone." - echoinfo "Resuming regular git clone and remote SaltStack repository addition procedure" - __SHALLOW_CLONE=$BS_FALSE - fi - else - echodebug "Shallow cloning not possible. Required git version not met." - __SHALLOW_CLONE=$BS_FALSE - fi - fi - - if [ "$__SHALLOW_CLONE" -eq $BS_FALSE ]; then - git clone "$_SALT_REPO_URL" "$__SALT_CHECKOUT_REPONAME" || return 1 - # shellcheck disable=SC2164 - cd "${_SALT_GIT_CHECKOUT_DIR}" - - if ! echo "$_SALT_REPO_URL" | grep -q -F -w "${_SALTSTACK_REPO_URL#*://}"; then - # We need to add the saltstack repository as a remote and fetch tags for proper versioning - echoinfo "Adding SaltStack's Salt repository as a remote" - git remote add upstream "$_SALTSTACK_REPO_URL" || return 1 - - echodebug "Fetching upstream (SaltStack's Salt repository) git tags" - git fetch --tags upstream || return 1 - - # Check if GIT_REV is a remote branch or just a commit hash - if git branch -r | grep -q -F -w "origin/$GIT_REV"; then - GIT_REV="origin/$GIT_REV" - fi - fi - - echodebug "Checking out $GIT_REV" - git checkout "$GIT_REV" || return 1 - fi - - fi - - echoinfo "Cloning Salt's git repository succeeded" - return 0 -} - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __copyfile -# DESCRIPTION: Simple function to copy files. Overrides if asked. -#---------------------------------------------------------------------------------------------------------------------- -__copyfile() { - overwrite=$_FORCE_OVERWRITE - if [ $# -eq 2 ]; then - sfile=$1 - dfile=$2 - elif [ $# -eq 3 ]; then - sfile=$1 - dfile=$2 - overwrite=$3 - else - echoerror "Wrong number of arguments for __copyfile()" - echoinfo "USAGE: __copyfile OR __copyfile " - exit 1 - fi - - # Does the source file exist? - if [ ! -f "$sfile" ]; then - echowarn "$sfile does not exist!" - return 1 - fi - - # If the destination is a directory, let's make it a full path so the logic - # below works as expected - if [ -d "$dfile" ]; then - echodebug "The passed destination ($dfile) is a directory" - dfile="${dfile}/$(basename "$sfile")" - echodebug "Full destination path is now: $dfile" - fi - - if [ ! -f "$dfile" ]; then - # The destination file does not exist, copy - echodebug "Copying $sfile to $dfile" - cp "$sfile" "$dfile" || return 1 - elif [ -f "$dfile" ] && [ "$overwrite" -eq $BS_TRUE ]; then - # The destination exist and we're overwriting - echodebug "Overwriting $dfile with $sfile" - cp -f "$sfile" "$dfile" || return 1 - elif [ -f "$dfile" ] && [ "$overwrite" -ne $BS_TRUE ]; then - echodebug "Not overwriting $dfile with $sfile" - fi - return 0 -} - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __movefile -# DESCRIPTION: Simple function to move files. Overrides if asked. -#---------------------------------------------------------------------------------------------------------------------- -__movefile() { - overwrite=$_FORCE_OVERWRITE - if [ $# -eq 2 ]; then - sfile=$1 - dfile=$2 - elif [ $# -eq 3 ]; then - sfile=$1 - dfile=$2 - overwrite=$3 - else - echoerror "Wrong number of arguments for __movefile()" - echoinfo "USAGE: __movefile OR __movefile " - exit 1 - fi - - if [ $_KEEP_TEMP_FILES -eq $BS_TRUE ]; then - # We're being told not to move files, instead copy them so we can keep - # them around - echodebug "Since BS_KEEP_TEMP_FILES=1 we're copying files instead of moving them" - __copyfile "$sfile" "$dfile" "$overwrite" - return $? - fi - - # Does the source file exist? - if [ ! -f "$sfile" ]; then - echowarn "$sfile does not exist!" - return 1 - fi - - # If the destination is a directory, let's make it a full path so the logic - # below works as expected - if [ -d "$dfile" ]; then - echodebug "The passed destination($dfile) is a directory" - dfile="${dfile}/$(basename "$sfile")" - echodebug "Full destination path is now: $dfile" - fi - - if [ ! -f "$dfile" ]; then - # The destination file does not exist, move - echodebug "Moving $sfile to $dfile" - mv "$sfile" "$dfile" || return 1 - elif [ -f "$dfile" ] && [ "$overwrite" -eq $BS_TRUE ]; then - # The destination exist and we're overwriting - echodebug "Overriding $dfile with $sfile" - mv -f "$sfile" "$dfile" || return 1 - elif [ -f "$dfile" ] && [ "$overwrite" -ne $BS_TRUE ]; then - echodebug "Not overriding $dfile with $sfile" - fi - - return 0 -} - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __linkfile -# DESCRIPTION: Simple function to create symlinks. Overrides if asked. Accepts globs. -#---------------------------------------------------------------------------------------------------------------------- -__linkfile() { - overwrite=$_FORCE_OVERWRITE - if [ $# -eq 2 ]; then - target=$1 - linkname=$2 - elif [ $# -eq 3 ]; then - target=$1 - linkname=$2 - overwrite=$3 - else - echoerror "Wrong number of arguments for __linkfile()" - echoinfo "USAGE: __linkfile OR __linkfile " - exit 1 - fi - - for sfile in $target; do - # Does the source file exist? - if [ ! -f "$sfile" ]; then - echowarn "$sfile does not exist!" - return 1 - fi - - # If the destination is a directory, let's make it a full path so the logic - # below works as expected - if [ -d "$linkname" ]; then - echodebug "The passed link name ($linkname) is a directory" - linkname="${linkname}/$(basename "$sfile")" - echodebug "Full destination path is now: $linkname" - fi - - if [ ! -e "$linkname" ]; then - # The destination file does not exist, create link - echodebug "Creating $linkname symlink pointing to $sfile" - ln -s "$sfile" "$linkname" || return 1 - elif [ -e "$linkname" ] && [ "$overwrite" -eq $BS_TRUE ]; then - # The destination exist and we're overwriting - echodebug "Overwriting $linkname symlink to point on $sfile" - ln -sf "$sfile" "$linkname" || return 1 - elif [ -e "$linkname" ] && [ "$overwrite" -ne $BS_TRUE ]; then - echodebug "Not overwriting $linkname symlink to point on $sfile" - fi - done - - return 0 -} - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __overwriteconfig() -# DESCRIPTION: Simple function to overwrite master or minion config files. -#---------------------------------------------------------------------------------------------------------------------- -__overwriteconfig() { - if [ $# -eq 2 ]; then - target=$1 - json=$2 - else - echoerror "Wrong number of arguments for __convert_json_to_yaml_str()" - echoinfo "USAGE: __convert_json_to_yaml_str " - exit 1 - fi - - # Make a tempfile to dump any python errors into. - if __check_command_exists mktemp; then - tempfile="$(mktemp /tmp/salt-config-XXXXXXXX 2>/dev/null)" - - if [ -z "$tempfile" ]; then - echoerror "Failed to create temporary file in /tmp" - return 1 - fi - else - tempfile="/tmp/salt-config-$$" - fi - - if [ -n "$_PY_EXE" ]; then - good_python="$_PY_EXE" - # If python does not have yaml installed we're on Arch and should use python2 - elif python -c "import yaml" 2> /dev/null; then - good_python=python - else - good_python=python2 - fi - - # Convert json string to a yaml string and write it to config file. Output is dumped into tempfile. - "$good_python" -c "import json; import yaml; jsn=json.loads('$json'); yml=yaml.safe_dump(jsn, line_break='\\n', default_flow_style=False); config_file=open('$target', 'w'); config_file.write(yml); config_file.close();" 2>$tempfile - - # No python errors output to the tempfile - if [ ! -s "$tempfile" ]; then - rm -f "$tempfile" - return 0 - fi - - # Errors are present in the tempfile - let's expose them to the user. - fullerror=$(cat "$tempfile") - echodebug "$fullerror" - echoerror "Python error encountered. This is likely due to passing in a malformed JSON string. Please use -D to see stacktrace." - - rm -f "$tempfile" - - return 1 - -} - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __check_services_systemd -# DESCRIPTION: Return 0 or 1 in case the service is enabled or not -# PARAMETERS: servicename -#---------------------------------------------------------------------------------------------------------------------- -__check_services_systemd() { - if [ $# -eq 0 ]; then - echoerror "You need to pass a service name to check!" - exit 1 - elif [ $# -ne 1 ]; then - echoerror "You need to pass a service name to check as the single argument to the function" - fi - - servicename=$1 - echodebug "Checking if service ${servicename} is enabled" - - if [ "$(systemctl is-enabled "${servicename}")" = "enabled" ]; then - echodebug "Service ${servicename} is enabled" - return 0 - else - echodebug "Service ${servicename} is NOT enabled" - return 1 - fi -} # ---------- end of function __check_services_systemd ---------- - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __check_services_upstart -# DESCRIPTION: Return 0 or 1 in case the service is enabled or not -# PARAMETERS: servicename -#---------------------------------------------------------------------------------------------------------------------- -__check_services_upstart() { - if [ $# -eq 0 ]; then - echoerror "You need to pass a service name to check!" - exit 1 - elif [ $# -ne 1 ]; then - echoerror "You need to pass a service name to check as the single argument to the function" - fi - - servicename=$1 - echodebug "Checking if service ${servicename} is enabled" - - # Check if service is enabled to start at boot - if initctl list | grep "${servicename}" > /dev/null 2>&1; then - echodebug "Service ${servicename} is enabled" - return 0 - else - echodebug "Service ${servicename} is NOT enabled" - return 1 - fi -} # ---------- end of function __check_services_upstart ---------- - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __check_services_sysvinit -# DESCRIPTION: Return 0 or 1 in case the service is enabled or not -# PARAMETERS: servicename -#---------------------------------------------------------------------------------------------------------------------- -__check_services_sysvinit() { - if [ $# -eq 0 ]; then - echoerror "You need to pass a service name to check!" - exit 1 - elif [ $# -ne 1 ]; then - echoerror "You need to pass a service name to check as the single argument to the function" - fi - - servicename=$1 - echodebug "Checking if service ${servicename} is enabled" - - if [ "$(LC_ALL=C /sbin/chkconfig --list | grep "\\<${servicename}\\>" | grep '[2-5]:on')" != "" ]; then - echodebug "Service ${servicename} is enabled" - return 0 - else - echodebug "Service ${servicename} is NOT enabled" - return 1 - fi -} # ---------- end of function __check_services_sysvinit ---------- - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __check_services_debian -# DESCRIPTION: Return 0 or 1 in case the service is enabled or not -# PARAMETERS: servicename -#---------------------------------------------------------------------------------------------------------------------- -__check_services_debian() { - if [ $# -eq 0 ]; then - echoerror "You need to pass a service name to check!" - exit 1 - elif [ $# -ne 1 ]; then - echoerror "You need to pass a service name to check as the single argument to the function" - fi - - servicename=$1 - echodebug "Checking if service ${servicename} is enabled" - - # Check if the service is going to be started at any runlevel, fixes bootstrap in container (Docker, LXC) - if ls /etc/rc?.d/S*"${servicename}" >/dev/null 2>&1; then - echodebug "Service ${servicename} is enabled" - return 0 - else - echodebug "Service ${servicename} is NOT enabled" - return 1 - fi -} # ---------- end of function __check_services_debian ---------- - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __check_services_openbsd -# DESCRIPTION: Return 0 or 1 in case the service is enabled or not -# PARAMETERS: servicename -#---------------------------------------------------------------------------------------------------------------------- -__check_services_openbsd() { - if [ $# -eq 0 ]; then - echoerror "You need to pass a service name to check!" - exit 1 - elif [ $# -ne 1 ]; then - echoerror "You need to pass a service name to check as the single argument to the function" - fi - - servicename=$1 - echodebug "Checking if service ${servicename} is enabled" - - # shellcheck disable=SC2086,SC2046,SC2144 - if rcctl get ${servicename} status; then - echodebug "Service ${servicename} is enabled" - return 0 - else - echodebug "Service ${servicename} is NOT enabled" - return 1 - fi -} # ---------- end of function __check_services_openbsd ---------- - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __check_services_alpine -# DESCRIPTION: Return 0 or 1 in case the service is enabled or not -# PARAMETERS: servicename -#---------------------------------------------------------------------------------------------------------------------- -__check_services_alpine() { - if [ $# -eq 0 ]; then - echoerror "You need to pass a service name to check!" - exit 1 - elif [ $# -ne 1 ]; then - echoerror "You need to pass a service name to check as the single argument to the function" - fi - - servicename=$1 - echodebug "Checking if service ${servicename} is enabled" - - # shellcheck disable=SC2086,SC2046,SC2144 - if rc-status $(rc-status -r) | tail -n +2 | grep -q "\\<$servicename\\>"; then - echodebug "Service ${servicename} is enabled" - return 0 - else - echodebug "Service ${servicename} is NOT enabled" - return 1 - fi -} # ---------- end of function __check_services_openbsd ---------- - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __create_virtualenv -# DESCRIPTION: Return 0 or 1 depending on successful creation of virtualenv -#---------------------------------------------------------------------------------------------------------------------- -__create_virtualenv() { - if [ ! -d "$_VIRTUALENV_DIR" ]; then - echoinfo "Creating virtualenv ${_VIRTUALENV_DIR}" - if [ $_PIP_ALL -eq $BS_TRUE ]; then - virtualenv --no-site-packages "${_VIRTUALENV_DIR}" || return 1 - else - virtualenv --system-site-packages "${_VIRTUALENV_DIR}" || return 1 - fi - fi - return 0 -} # ---------- end of function __create_virtualenv ---------- - - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __activate_virtualenv -# DESCRIPTION: Return 0 or 1 depending on successful activation of virtualenv -#---------------------------------------------------------------------------------------------------------------------- -__activate_virtualenv() { - set +o nounset - # Is virtualenv empty - if [ -z "$_VIRTUALENV_DIR" ]; then - __create_virtualenv || return 1 - # shellcheck source=/dev/null - . "${_VIRTUALENV_DIR}/bin/activate" || return 1 - echoinfo "Activated virtualenv ${_VIRTUALENV_DIR}" - fi - set -o nounset - return 0 -} # ---------- end of function __activate_virtualenv ---------- - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __install_pip_pkgs -# DESCRIPTION: Return 0 or 1 if successfully able to install pip packages. Can provide a different python version to -# install pip packages with. If $py_ver is not specified it will use the default python version. -# PARAMETERS: pkgs, py_ver -#---------------------------------------------------------------------------------------------------------------------- - -__install_pip_pkgs() { - _pip_pkgs="$1" - _py_exe="$2" - _py_pkg=$(echo "$_py_exe" | sed -r "s/\\.//g") - _pip_cmd="${_py_exe} -m pip" - - if [ "${_py_exe}" = "" ]; then - _py_exe='python' - fi - - __check_pip_allowed - - # Install pip and pip dependencies - if ! __check_command_exists "${_pip_cmd} --version"; then - __PACKAGES="${_py_pkg}-setuptools ${_py_pkg}-pip gcc" - # shellcheck disable=SC2086 - if [ "$DISTRO_NAME_L" = "debian" ];then - __PACKAGES="${__PACKAGES} ${_py_pkg}-dev" - __apt_get_install_noinput ${__PACKAGES} || return 1 - else - __PACKAGES="${__PACKAGES} ${_py_pkg}-devel" - __yum_install_noinput ${__PACKAGES} || return 1 - fi - - fi - - echoinfo "Installing pip packages: ${_pip_pkgs} using ${_py_exe}" - # shellcheck disable=SC2086 - ${_pip_cmd} install ${_pip_pkgs} || return 1 -} - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __install_tornado_pip -# PARAMETERS: python executable -# DESCRIPTION: Return 0 or 1 if successfully able to install tornado<5.0 -#---------------------------------------------------------------------------------------------------------------------- -__install_tornado_pip() { - # OS needs tornado <5.0 from pip - __check_pip_allowed "You need to allow pip based installations (-P) for Tornado <5.0 in order to install Salt on Python 3" - ## install pip if its not installed and install tornado - __install_pip_pkgs "tornado<5.0" "${1}" || return 1 -} - -#--- FUNCTION ------------------------------------------------------------------------------------------------------- -# NAME: __install_pip_deps -# DESCRIPTION: Return 0 or 1 if successfully able to install pip packages via requirements file -# PARAMETERS: requirements_file -#---------------------------------------------------------------------------------------------------------------------- -__install_pip_deps() { - # Install virtualenv to system pip before activating virtualenv if thats going to be used - # We assume pip pkg is installed since that is distro specific - if [ "$_VIRTUALENV_DIR" != "null" ]; then - if ! __check_command_exists pip; then - echoerror "Pip not installed: required for -a installs" - exit 1 - fi - pip install -U virtualenv - __activate_virtualenv || return 1 - else - echoerror "Must have virtualenv dir specified for -a installs" - fi - - requirements_file=$1 - if [ ! -f "${requirements_file}" ]; then - echoerror "Requirements file: ${requirements_file} cannot be found, needed for -a (pip pkg) installs" - exit 1 - fi - - __PIP_PACKAGES='' - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then - # shellcheck disable=SC2089 - __PIP_PACKAGES="${__PIP_PACKAGES} 'apache-libcloud>=$_LIBCLOUD_MIN_VERSION'" - fi - - # shellcheck disable=SC2086,SC2090 - pip install -U -r ${requirements_file} ${__PIP_PACKAGES} -} # ---------- end of function __install_pip_deps ---------- - - -####################################################################################################################### -# -# Distribution install functions -# -# In order to install salt for a distribution you need to define: -# -# To Install Dependencies, which is required, one of: -# 1. install____deps -# 2. install_____deps -# 3. install___deps -# 4 install____deps -# 5. install___deps -# 6. install__deps -# -# Optionally, define a salt configuration function, which will be called if -# the -c (config-dir) option is passed. One of: -# 1. config____salt -# 2. config_____salt -# 3. config___salt -# 4 config____salt -# 5. config___salt -# 6. config__salt -# 7. config_salt [THIS ONE IS ALREADY DEFINED AS THE DEFAULT] -# -# Optionally, define a salt master pre-seed function, which will be called if -# the -k (pre-seed master keys) option is passed. One of: -# 1. preseed____master -# 2. preseed_____master -# 3. preseed___master -# 4 preseed____master -# 5. preseed___master -# 6. preseed__master -# 7. preseed_master [THIS ONE IS ALREADY DEFINED AS THE DEFAULT] -# -# To install salt, which, of course, is required, one of: -# 1. install___ -# 2. install____ -# 3. install__ -# -# Optionally, define a post install function, one of: -# 1. install____post -# 2. install_____post -# 3. install___post -# 4 install____post -# 5. install___post -# 6. install__post -# -# Optionally, define a start daemons function, one of: -# 1. install____restart_daemons -# 2. install_____restart_daemons -# 3. install___restart_daemons -# 4 install____restart_daemons -# 5. install___restart_daemons -# 6. install__restart_daemons -# -# NOTE: The start daemons function should be able to restart any daemons -# which are running, or start if they're not running. -# -# Optionally, define a daemons running function, one of: -# 1. daemons_running___ -# 2. daemons_running____ -# 3. daemons_running__ -# 4 daemons_running___ -# 5. daemons_running__ -# 6. daemons_running_ -# 7. daemons_running [THIS ONE IS ALREADY DEFINED AS THE DEFAULT] -# -# Optionally, check enabled Services: -# 1. install____check_services -# 2. install_____check_services -# 3. install___check_services -# 4 install____check_services -# 5. install___check_services -# 6. install__check_services -# -####################################################################################################################### - - -####################################################################################################################### -# -# Ubuntu Install Functions -# -__enable_universe_repository() { - if [ "$(grep -R universe /etc/apt/sources.list /etc/apt/sources.list.d/ | grep -v '#')" != "" ]; then - # The universe repository is already enabled - return 0 - fi - - echodebug "Enabling the universe repository" - - add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) universe" || return 1 - - return 0 -} - -__install_saltstack_ubuntu_repository() { - # Workaround for latest non-LTS ubuntu - if [ "$DISTRO_MAJOR_VERSION" -gt 18 ] || \ - { [ "$DISTRO_MAJOR_VERSION" -eq 18 ] && [ "$DISTRO_MINOR_VERSION" -eq 10 ]; }; then - echowarn "Non-LTS Ubuntu detected, but stable packages requested. Trying packages for latest LTS release. You may experience problems." - UBUNTU_VERSION=18.04 - UBUNTU_CODENAME="bionic" - else - UBUNTU_VERSION=${DISTRO_VERSION} - UBUNTU_CODENAME=${DISTRO_CODENAME} - fi - - # Install downloader backend for GPG keys fetching - __PACKAGES='wget' - - # Required as it is not installed by default on Ubuntu 18+ - if [ "$DISTRO_MAJOR_VERSION" -ge 18 ]; then - __PACKAGES="${__PACKAGES} gnupg" - fi - - # Make sure https transport is available - if [ "$HTTP_VAL" = "https" ] ; then - __PACKAGES="${__PACKAGES} apt-transport-https ca-certificates" - fi - - # shellcheck disable=SC2086,SC2090 - __apt_get_install_noinput ${__PACKAGES} || return 1 - - __PY_VERSION_REPO="apt" - if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then - __PY_VERSION_REPO="py3" - fi - - # SaltStack's stable Ubuntu repository: - SALTSTACK_UBUNTU_URL="${HTTP_VAL}://${_REPO_URL}/${__PY_VERSION_REPO}/ubuntu/${UBUNTU_VERSION}/${__REPO_ARCH}/${STABLE_REV}" - echo "$__REPO_ARCH_DEB $SALTSTACK_UBUNTU_URL $UBUNTU_CODENAME main" > /etc/apt/sources.list.d/saltstack.list - - __apt_key_fetch "$SALTSTACK_UBUNTU_URL/SALTSTACK-GPG-KEY.pub" || return 1 - - __wait_for_apt apt-get update || return 1 -} - -install_ubuntu_deps() { - if [ $_DISABLE_REPOS -eq $BS_FALSE ]; then - # Install add-apt-repository - if ! __check_command_exists add-apt-repository; then - __apt_get_install_noinput software-properties-common || return 1 - fi - - __enable_universe_repository || return 1 - - __wait_for_apt apt-get update || return 1 - fi - - __PACKAGES='' - - if [ "$DISTRO_MAJOR_VERSION" -lt 16 ]; then - # Minimal systems might not have upstart installed, install it - __PACKAGES="upstart" - fi - - if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then - PY_PKG_VER=3 - else - PY_PKG_VER="" - fi - - if [ "$DISTRO_MAJOR_VERSION" -ge 16 ] && [ -z "$_PY_EXE" ]; then - __PACKAGES="${__PACKAGES} python2.7" - fi - - if [ "$_VIRTUALENV_DIR" != "null" ]; then - __PACKAGES="${__PACKAGES} python-virtualenv" - fi - # Need python-apt for managing packages via Salt - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-apt" - - # requests is still used by many salt modules - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-requests" - - # YAML module is used for generating custom master/minion configs - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-yaml" - - # Additionally install procps and pciutils which allows for Docker bootstraps. See 366#issuecomment-39666813 - __PACKAGES="${__PACKAGES} procps pciutils" - - # shellcheck disable=SC2086,SC2090 - __apt_get_install_noinput ${__PACKAGES} || return 1 - - if [ "${_EXTRA_PACKAGES}" != "" ]; then - echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" - # shellcheck disable=SC2086 - __apt_get_install_noinput ${_EXTRA_PACKAGES} || return 1 - fi - - return 0 -} - -install_ubuntu_stable_deps() { - if [ "${_SLEEP}" -eq "${__DEFAULT_SLEEP}" ] && [ "$DISTRO_MAJOR_VERSION" -lt 16 ]; then - # The user did not pass a custom sleep value as an argument, let's increase the default value - echodebug "On Ubuntu systems we increase the default sleep value to 10." - echodebug "See https://github.com/saltstack/salt/issues/12248 for more info." - _SLEEP=10 - fi - - if [ $_START_DAEMONS -eq $BS_FALSE ]; then - echowarn "Not starting daemons on Debian based distributions is not working mostly because starting them is the default behaviour." - fi - - # No user interaction, libc6 restart services for example - export DEBIAN_FRONTEND=noninteractive - - __wait_for_apt apt-get update || return 1 - - if [ "${_UPGRADE_SYS}" -eq $BS_TRUE ]; then - if [ "${_INSECURE_DL}" -eq $BS_TRUE ]; then - __apt_get_install_noinput --allow-unauthenticated debian-archive-keyring && - apt-key update && apt-get update || return 1 - fi - - __apt_get_upgrade_noinput || return 1 - fi - - if [ "$_DISABLE_REPOS" -eq "$BS_FALSE" ] || [ "$_CUSTOM_REPO_URL" != "null" ]; then - __check_dpkg_architecture || return 1 - __install_saltstack_ubuntu_repository || return 1 - fi - - install_ubuntu_deps || return 1 -} - -install_ubuntu_git_deps() { - __wait_for_apt apt-get update || return 1 - - if ! __check_command_exists git; then - __apt_get_install_noinput git-core || return 1 - fi - - if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then - __apt_get_install_noinput ca-certificates - fi - - __git_clone_and_checkout || return 1 - - __PACKAGES="" - - # See how we are installing packages - if [ "${_PIP_ALL}" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} python-dev swig libssl-dev libzmq3 libzmq3-dev" - - if ! __check_command_exists pip; then - __PACKAGES="${__PACKAGES} python-setuptools python-pip" - fi - - # Get just the apt packages that are required to build all the pythons - # shellcheck disable=SC2086 - __apt_get_install_noinput ${__PACKAGES} || return 1 - # Install the pythons from requirements (only zmq for now) - __install_pip_deps "${_SALT_GIT_CHECKOUT_DIR}/requirements/zeromq.txt" || return 1 - else - install_ubuntu_stable_deps || return 1 - - if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then - PY_PKG_VER=3 - - __PACKAGES="${__PACKAGES} python3-setuptools" - else - PY_PKG_VER="" - - # There is no m2crypto package for Py3 at this time - only install for Py2 - __PACKAGES="${__PACKAGES} python-m2crypto" - fi - - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-crypto python${PY_PKG_VER}-jinja2" - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-msgpack python${PY_PKG_VER}-requests" - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-tornado python${PY_PKG_VER}-yaml" - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-zmq" - __PACKAGES="${__PACKAGES} python-concurrent.futures" - - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then - # Install python-libcloud if asked to - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-libcloud" - fi - - # shellcheck disable=SC2086 - __apt_get_install_noinput ${__PACKAGES} || return 1 - fi - - # Let's trigger config_salt() - if [ "$_TEMP_CONFIG_DIR" = "null" ]; then - _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" - CONFIG_SALT_FUNC="config_salt" - fi - - return 0 -} - -install_ubuntu_stable() { - __PACKAGES="" - - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ];then - __PACKAGES="${__PACKAGES} salt-cloud" - fi - if [ "$_INSTALL_MASTER" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} salt-master" - fi - if [ "$_INSTALL_MINION" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} salt-minion" - fi - if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} salt-syndic" - fi - - # shellcheck disable=SC2086 - __apt_get_install_noinput ${__PACKAGES} || return 1 - - return 0 -} - -install_ubuntu_git() { - # Activate virtualenv before install - if [ "${_VIRTUALENV_DIR}" != "null" ]; then - __activate_virtualenv || return 1 - fi - - if [ -n "$_PY_EXE" ]; then - _PYEXE=${_PY_EXE} - else - _PYEXE=python2.7 - fi - - if [ -f "${_SALT_GIT_CHECKOUT_DIR}/salt/syspaths.py" ]; then - ${_PYEXE} setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install --install-layout=deb || return 1 - else - ${_PYEXE} setup.py ${SETUP_PY_INSTALL_ARGS} install --install-layout=deb || return 1 - fi - - return 0 -} - -install_ubuntu_stable_post() { - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - if [ -f /bin/systemctl ]; then - # Using systemd - /bin/systemctl is-enabled salt-$fname.service > /dev/null 2>&1 || ( - /bin/systemctl preset salt-$fname.service > /dev/null 2>&1 && - /bin/systemctl enable salt-$fname.service > /dev/null 2>&1 - ) - sleep 1 - /bin/systemctl daemon-reload - elif [ -f /etc/init.d/salt-$fname ]; then - update-rc.d salt-$fname defaults - fi - done - - return 0 -} - -install_ubuntu_git_post() { - for fname in api master minion syndic; do - # Skip if not meant to be installed - [ $fname = "api" ] && \ - ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - if [ -f /bin/systemctl ] && [ "$DISTRO_MAJOR_VERSION" -ge 16 ]; then - __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.service" "/lib/systemd/system/salt-${fname}.service" - - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - systemctl is-enabled salt-$fname.service || (systemctl preset salt-$fname.service && systemctl enable salt-$fname.service) - sleep 1 - systemctl daemon-reload - elif [ -f /sbin/initctl ]; then - _upstart_conf="/etc/init/salt-$fname.conf" - # We have upstart support - echodebug "There's upstart support" - if [ ! -f $_upstart_conf ]; then - # upstart does not know about our service, let's copy the proper file - echowarn "Upstart does not appear to know about salt-$fname" - echodebug "Copying ${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-$fname.upstart to $_upstart_conf" - __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.upstart" "$_upstart_conf" - # Set service to know about virtualenv - if [ "${_VIRTUALENV_DIR}" != "null" ]; then - echo "SALT_USE_VIRTUALENV=${_VIRTUALENV_DIR}" > /etc/default/salt-${fname} - fi - /sbin/initctl reload-configuration || return 1 - fi - # No upstart support in Ubuntu!? - elif [ -f "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.init" ]; then - echodebug "There's NO upstart support!?" - echodebug "Copying ${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.init to /etc/init.d/salt-$fname" - __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.init" "/etc/init.d/salt-$fname" - chmod +x /etc/init.d/salt-$fname - - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - update-rc.d salt-$fname defaults - else - echoerror "Neither upstart nor init.d was setup for salt-$fname" - fi - done - - return 0 -} - -install_ubuntu_restart_daemons() { - [ $_START_DAEMONS -eq $BS_FALSE ] && return - - # Ensure upstart configs / systemd units are loaded - if [ -f /bin/systemctl ] && [ "$DISTRO_MAJOR_VERSION" -ge 16 ]; then - systemctl daemon-reload - elif [ -f /sbin/initctl ]; then - /sbin/initctl reload-configuration - fi - - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - if [ -f /bin/systemctl ] && [ "$DISTRO_MAJOR_VERSION" -ge 16 ]; then - echodebug "There's systemd support while checking salt-$fname" - systemctl stop salt-$fname > /dev/null 2>&1 - systemctl start salt-$fname.service && continue - # We failed to start the service, let's test the SysV code below - echodebug "Failed to start salt-$fname using systemd" - fi - - if [ -f /sbin/initctl ]; then - echodebug "There's upstart support while checking salt-$fname" - - if status salt-$fname 2>/dev/null | grep -q running; then - stop salt-$fname || (echodebug "Failed to stop salt-$fname" && return 1) - fi - - start salt-$fname && continue - # We failed to start the service, let's test the SysV code below - echodebug "Failed to start salt-$fname using Upstart" - fi - - if [ ! -f /etc/init.d/salt-$fname ]; then - echoerror "No init.d support for salt-$fname was found" - return 1 - fi - - /etc/init.d/salt-$fname stop > /dev/null 2>&1 - /etc/init.d/salt-$fname start - done - - return 0 -} - -install_ubuntu_check_services() { - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - if [ -f /bin/systemctl ] && [ "$DISTRO_MAJOR_VERSION" -ge 16 ]; then - __check_services_systemd salt-$fname || return 1 - elif [ -f /sbin/initctl ] && [ -f /etc/init/salt-${fname}.conf ]; then - __check_services_upstart salt-$fname || return 1 - elif [ -f /etc/init.d/salt-$fname ]; then - __check_services_debian salt-$fname || return 1 - fi - done - - return 0 -} -# -# End of Ubuntu Install Functions -# -####################################################################################################################### - -####################################################################################################################### -# -# Debian Install Functions -# -__install_saltstack_debian_repository() { - DEBIAN_RELEASE="$DISTRO_MAJOR_VERSION" - DEBIAN_CODENAME="$DISTRO_CODENAME" - - __PY_VERSION_REPO="apt" - if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then - __PY_VERSION_REPO="py3" - fi - - # Install downloader backend for GPG keys fetching - __PACKAGES='wget' - - # Required as it is not installed by default on Debian 9+ - if [ "$DISTRO_MAJOR_VERSION" -ge 9 ]; then - __PACKAGES="${__PACKAGES} gnupg2" - fi - - # Make sure https transport is available - if [ "$HTTP_VAL" = "https" ] ; then - __PACKAGES="${__PACKAGES} apt-transport-https ca-certificates" - fi - - # shellcheck disable=SC2086,SC2090 - __apt_get_install_noinput ${__PACKAGES} || return 1 - - # amd64 is just a part of repository URI, 32-bit pkgs are hosted under the same location - SALTSTACK_DEBIAN_URL="${HTTP_VAL}://${_REPO_URL}/${__PY_VERSION_REPO}/debian/${DEBIAN_RELEASE}/${__REPO_ARCH}/${STABLE_REV}" - echo "$__REPO_ARCH_DEB $SALTSTACK_DEBIAN_URL $DEBIAN_CODENAME main" > "/etc/apt/sources.list.d/saltstack.list" - - __apt_key_fetch "$SALTSTACK_DEBIAN_URL/SALTSTACK-GPG-KEY.pub" || return 1 - - __wait_for_apt apt-get update || return 1 -} - -install_debian_deps() { - if [ $_START_DAEMONS -eq $BS_FALSE ]; then - echowarn "Not starting daemons on Debian based distributions is not working mostly because starting them is the default behaviour." - fi - - # No user interaction, libc6 restart services for example - export DEBIAN_FRONTEND=noninteractive - - __wait_for_apt apt-get update || return 1 - - if [ "${_UPGRADE_SYS}" -eq $BS_TRUE ]; then - # Try to update GPG keys first if allowed - if [ "${_INSECURE_DL}" -eq $BS_TRUE ]; then - __apt_get_install_noinput --allow-unauthenticated debian-archive-keyring && - apt-key update && apt-get update || return 1 - fi - - __apt_get_upgrade_noinput || return 1 - fi - - if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then - PY_PKG_VER=3 - else - PY_PKG_VER="" - fi - - # Additionally install procps and pciutils which allows for Docker bootstraps. See 366#issuecomment-39666813 - __PACKAGES='procps pciutils' - - # YAML module is used for generating custom master/minion configs - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-yaml" - - # shellcheck disable=SC2086 - __apt_get_install_noinput ${__PACKAGES} || return 1 - - if [ "$_DISABLE_REPOS" -eq "$BS_FALSE" ] || [ "$_CUSTOM_REPO_URL" != "null" ]; then - __check_dpkg_architecture || return 1 - __install_saltstack_debian_repository || return 1 - fi - - if [ "${_EXTRA_PACKAGES}" != "" ]; then - echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" - # shellcheck disable=SC2086 - __apt_get_install_noinput ${_EXTRA_PACKAGES} || return 1 - fi - - return 0 -} - -install_debian_git_pre() { - if ! __check_command_exists git; then - __apt_get_install_noinput git || return 1 - fi - - if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then - __apt_get_install_noinput ca-certificates - fi - - __git_clone_and_checkout || return 1 - - # Let's trigger config_salt() - if [ "$_TEMP_CONFIG_DIR" = "null" ]; then - _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" - CONFIG_SALT_FUNC="config_salt" - fi -} - -install_debian_git_deps() { - if ! __check_command_exists git; then - __apt_get_install_noinput git || return 1 - fi - - if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then - __apt_get_install_noinput ca-certificates - fi - - __git_clone_and_checkout || return 1 - - __PACKAGES="libzmq3 libzmq3-dev lsb-release python-apt python-backports.ssl-match-hostname" - __PACKAGES="${__PACKAGES} python-crypto python-jinja2 python-msgpack python-m2crypto" - __PACKAGES="${__PACKAGES} python-requests python-tornado python-yaml python-zmq" - - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then - # Install python-libcloud if asked to - __PACKAGES="${__PACKAGES} python-libcloud" - fi - - # shellcheck disable=SC2086 - __apt_get_install_noinput ${__PACKAGES} || return 1 - - # Let's trigger config_salt() - if [ "$_TEMP_CONFIG_DIR" = "null" ]; then - _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" - CONFIG_SALT_FUNC="config_salt" - fi - - return 0 -} - -install_debian_7_git_deps() { - install_debian_deps || return 1 - install_debian_git_deps || return 1 - - return 0 -} - -install_debian_8_git_deps() { - install_debian_deps || return 1 - - if ! __check_command_exists git; then - __apt_get_install_noinput git || return 1 - fi - - if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then - __apt_get_install_noinput ca-certificates - fi - - __git_clone_and_checkout || return 1 - - __PACKAGES="libzmq3 libzmq3-dev lsb-release python-apt python-crypto python-jinja2" - __PACKAGES="${__PACKAGES} python-m2crypto python-msgpack python-requests python-systemd" - __PACKAGES="${__PACKAGES} python-yaml python-zmq python-concurrent.futures" - - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then - # Install python-libcloud if asked to - __PACKAGES="${__PACKAGES} python-libcloud" - fi - - __PIP_PACKAGES='' - if (__check_pip_allowed >/dev/null 2>&1); then - __PIP_PACKAGES='tornado<5.0' - # Install development environment for building tornado Python module - __PACKAGES="${__PACKAGES} build-essential python-dev" - - if ! __check_command_exists pip; then - __PACKAGES="${__PACKAGES} python-pip" - fi - # Attempt to configure backports repo on non-x86_64 system - elif [ $_DISABLE_REPOS -eq $BS_FALSE ] && [ "$DPKG_ARCHITECTURE" != "amd64" ]; then - # Check if Debian Backports repo already configured - if ! apt-cache policy | grep -q 'Debian Backports'; then - echo 'deb http://httpredir.debian.org/debian jessie-backports main' > \ - /etc/apt/sources.list.d/backports.list - fi - - __wait_for_apt apt-get update || return 1 - - # python-tornado package should be installed from backports repo - __PACKAGES="${__PACKAGES} python-backports.ssl-match-hostname python-tornado/jessie-backports" - else - __PACKAGES="${__PACKAGES} python-backports.ssl-match-hostname python-tornado" - fi - - # shellcheck disable=SC2086 - __apt_get_install_noinput ${__PACKAGES} || return 1 - - if [ "${__PIP_PACKAGES}" != "" ]; then - # shellcheck disable=SC2086,SC2090 - pip install -U ${__PIP_PACKAGES} || return 1 - fi - - # Let's trigger config_salt() - if [ "$_TEMP_CONFIG_DIR" = "null" ]; then - _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" - CONFIG_SALT_FUNC="config_salt" - fi - - return 0 -} - -install_debian_9_git_deps() { - install_debian_deps || return 1 - - if ! __check_command_exists git; then - __apt_get_install_noinput git || return 1 - fi - - if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then - __apt_get_install_noinput ca-certificates - fi - - __git_clone_and_checkout || return 1 - - __PACKAGES="libzmq5 lsb-release" - - if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then - PY_PKG_VER=3 - else - PY_PKG_VER="" - - # These packages are PY2-ONLY - __PACKAGES="${__PACKAGES} python-backports-abc python-m2crypto python-concurrent.futures" - fi - - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-apt python${PY_PKG_VER}-crypto python${PY_PKG_VER}-jinja2" - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-msgpack python${PY_PKG_VER}-requests python${PY_PKG_VER}-systemd" - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-tornado python${PY_PKG_VER}-yaml python${PY_PKG_VER}-zmq" - - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then - # Install python-libcloud if asked to - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-libcloud" - fi - - # shellcheck disable=SC2086 - __apt_get_install_noinput ${__PACKAGES} || return 1 - - # Let's trigger config_salt() - if [ "$_TEMP_CONFIG_DIR" = "null" ]; then - _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" - CONFIG_SALT_FUNC="config_salt" - fi - - return 0 -} - -install_debian_10_git_deps() { - install_debian_git_pre || return 1 - - if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then - _py=${_PY_EXE} - PY_PKG_VER=3 - __PACKAGES="python${PY_PKG_VER}-distutils" - else - _py="python" - PY_PKG_VER="" - __PACKAGES="" - fi - - __install_tornado_pip ${_py}|| return 1 - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-msgpack python${PY_PKG_VER}-jinja2" - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-tornado python${PY_PKG_VER}-yaml python${PY_PKG_VER}-zmq" - - # shellcheck disable=SC2086 - __apt_get_install_noinput ${__PACKAGES} || return 1 - - return 0 -} - -install_debian_stable() { - __PACKAGES="" - - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ];then - __PACKAGES="${__PACKAGES} salt-cloud" - fi - if [ "$_INSTALL_MASTER" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} salt-master" - fi - if [ "$_INSTALL_MINION" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} salt-minion" - fi - if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} salt-syndic" - fi - - # shellcheck disable=SC2086 - __apt_get_install_noinput ${__PACKAGES} || return 1 - - return 0 -} - -install_debian_7_stable() { - install_debian_stable || return 1 - return 0 -} - -install_debian_8_stable() { - install_debian_stable || return 1 - return 0 -} - -install_debian_9_stable() { - install_debian_stable || return 1 - return 0 -} - -install_debian_git() { - if [ -n "$_PY_EXE" ]; then - _PYEXE=${_PY_EXE} - else - _PYEXE=python - fi - - if [ -f "${_SALT_GIT_CHECKOUT_DIR}/salt/syspaths.py" ]; then - ${_PYEXE} setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install --install-layout=deb || return 1 - else - ${_PYEXE} setup.py ${SETUP_PY_INSTALL_ARGS} install --install-layout=deb || return 1 - fi -} - -install_debian_7_git() { - install_debian_git || return 1 - return 0 -} - -install_debian_8_git() { - install_debian_git || return 1 - return 0 -} - -install_debian_9_git() { - install_debian_git || return 1 - return 0 -} - -install_debian_git_post() { - for fname in api master minion syndic; do - # Skip if not meant to be installed - [ "$fname" = "api" ] && \ - ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue - [ "$fname" = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ "$fname" = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ "$fname" = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - # Configure SystemD for Debian 8 "Jessie" and later - if [ -f /bin/systemctl ]; then - if [ ! -f /lib/systemd/system/salt-${fname}.service ] || \ - { [ -f /lib/systemd/system/salt-${fname}.service ] && [ $_FORCE_OVERWRITE -eq $BS_TRUE ]; }; then - if [ -f "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.service" ]; then - __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.service" /lib/systemd/system - __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.environment" "/etc/default/salt-${fname}" - else - # workaround before adding Debian-specific unit files to the Salt main repo - __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.service" /lib/systemd/system - sed -i -e '/^Type/ s/notify/simple/' /lib/systemd/system/salt-${fname}.service - fi - fi - - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ "$fname" = "api" ] && continue - - /bin/systemctl enable "salt-${fname}.service" - SYSTEMD_RELOAD=$BS_TRUE - - # Install initscripts for Debian 7 "Wheezy" - elif [ ! -f "/etc/init.d/salt-$fname" ] || \ - { [ -f "/etc/init.d/salt-$fname" ] && [ "$_FORCE_OVERWRITE" -eq $BS_TRUE ]; }; then - __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/deb/salt-${fname}.init" "/etc/init.d/salt-${fname}" - __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/deb/salt-${fname}.environment" "/etc/default/salt-${fname}" - - if [ ! -f "/etc/init.d/salt-${fname}" ]; then - echowarn "The init script for salt-${fname} was not found, skipping it..." - continue - fi - - chmod +x "/etc/init.d/salt-${fname}" - - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ "$fname" = "api" ] && continue - - update-rc.d "salt-${fname}" defaults - fi - done -} - -install_debian_restart_daemons() { - [ "$_START_DAEMONS" -eq $BS_FALSE ] && return 0 - - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - if [ -f /bin/systemctl ]; then - # Debian 8 uses systemd - /bin/systemctl stop salt-$fname > /dev/null 2>&1 - /bin/systemctl start salt-$fname.service - elif [ -f /etc/init.d/salt-$fname ]; then - # Still in SysV init - /etc/init.d/salt-$fname stop > /dev/null 2>&1 - /etc/init.d/salt-$fname start - fi - done -} - -install_debian_check_services() { - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - if [ -f /bin/systemctl ]; then - __check_services_systemd salt-$fname || return 1 - elif [ -f /etc/init.d/salt-$fname ]; then - __check_services_debian salt-$fname || return 1 - fi - done - return 0 -} -# -# Ended Debian Install Functions -# -####################################################################################################################### - -####################################################################################################################### -# -# Fedora Install Functions -# - -install_fedora_deps() { - if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then - dnf -y update || return 1 - fi - - __PACKAGES="${__PACKAGES:=}" - if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then - # Packages are named python3- - PY_PKG_VER=3 - __PACKAGES="${__PACKAGES} python3-m2crypto python3-PyYAML" - else - PY_PKG_VER=2 - __PACKAGES="${__PACKAGES} m2crypto" - if [ "$DISTRO_MAJOR_VERSION" -ge 28 ]; then - __PACKAGES="${__PACKAGES} python2-pyyaml" - else - __PACKAGES="${__PACKAGES} PyYAML" - fi - fi - __PACKAGES="${__PACKAGES} dnf-utils libyaml procps-ng python${PY_PKG_VER}-crypto python${PY_PKG_VER}-jinja2" - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-msgpack python${PY_PKG_VER}-requests python${PY_PKG_VER}-zmq" - if [ "${_EXTRA_PACKAGES}" != "" ]; then - echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" - fi - - # shellcheck disable=SC2086 - dnf install -y ${__PACKAGES} ${_EXTRA_PACKAGES} || return 1 - - return 0 -} - -install_fedora_stable() { - __PACKAGES="" - - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ];then - __PACKAGES="${__PACKAGES} salt-cloud" - fi - if [ "$_INSTALL_MASTER" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} salt-master" - fi - if [ "$_INSTALL_MINION" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} salt-minion" - fi - if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} salt-syndic" - fi - - # shellcheck disable=SC2086 - dnf install -y ${__PACKAGES} || return 1 - - return 0 -} - -install_fedora_stable_post() { - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - systemctl is-enabled salt-$fname.service || (systemctl preset salt-$fname.service && systemctl enable salt-$fname.service) - sleep 1 - systemctl daemon-reload - done -} - -install_fedora_git_deps() { - if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then - # Packages are named python3- - PY_PKG_VER=3 - else - PY_PKG_VER=2 - fi - - __PACKAGES="${__PACKAGES:=}" - if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then - __PACKAGES="${__PACKAGES} ca-certificates" - fi - if ! __check_command_exists git; then - __PACKAGES="${__PACKAGES} git" - fi - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-libcloud python${PY_PKG_VER}-netaddr" - fi - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-systemd" - - # Fedora 28+ ships with tornado 5.0+ which is broken for salt on py3 - # https://github.com/saltstack/salt-bootstrap/issues/1220 - if [ "${PY_PKG_VER}" -lt 3 ] || [ "$DISTRO_MAJOR_VERSION" -lt 28 ]; then - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-tornado" - fi - - install_fedora_deps || return 1 - - __git_clone_and_checkout || return 1 - - # Fedora 28+ needs tornado <5.0 from pip - # https://github.com/saltstack/salt-bootstrap/issues/1220 - if [ "${PY_PKG_VER}" -eq 3 ] && [ "$DISTRO_MAJOR_VERSION" -ge 28 ]; then - __check_pip_allowed "You need to allow pip based installations (-P) for Tornado <5.0 in order to install Salt on Python 3" - grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" | while IFS=' -' read -r dep; do - "${_PY_EXE}" -m pip install "${dep}" || return 1 - done - fi - - # Let's trigger config_salt() - if [ "$_TEMP_CONFIG_DIR" = "null" ]; then - _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" - CONFIG_SALT_FUNC="config_salt" - fi - - return 0 -} - -install_fedora_git() { - if [ "${_PY_EXE}" != "" ]; then - _PYEXE=${_PY_EXE} - echoinfo "Using the following python version: ${_PY_EXE} to install salt" - else - _PYEXE='python2' - fi - - if [ -f "${_SALT_GIT_CHECKOUT_DIR}/salt/syspaths.py" ]; then - ${_PYEXE} setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install --prefix=/usr || return 1 - else - ${_PYEXE} setup.py ${SETUP_PY_INSTALL_ARGS} install --prefix=/usr || return 1 - fi - return 0 -} - -install_fedora_git_post() { - for fname in api master minion syndic; do - # Skip if not meant to be installed - [ $fname = "api" ] && \ - ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-${fname}.service" "/lib/systemd/system/salt-${fname}.service" - - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - systemctl is-enabled salt-$fname.service || (systemctl preset salt-$fname.service && systemctl enable salt-$fname.service) - sleep 1 - systemctl daemon-reload - done -} - -install_fedora_restart_daemons() { - [ $_START_DAEMONS -eq $BS_FALSE ] && return - - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - systemctl stop salt-$fname > /dev/null 2>&1 - systemctl start salt-$fname.service - done -} - -install_fedora_check_services() { - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - __check_services_systemd salt-$fname || return 1 - done - - return 0 -} -# -# Ended Fedora Install Functions -# -####################################################################################################################### - -####################################################################################################################### -# -# CentOS Install Functions -# -__install_epel_repository() { - if [ ${_EPEL_REPOS_INSTALLED} -eq $BS_TRUE ]; then - return 0 - fi - - # Check if epel repo is already enabled and flag it accordingly - if yum repolist | grep -q "^[!]\\?${_EPEL_REPO}/"; then - _EPEL_REPOS_INSTALLED=$BS_TRUE - return 0 - fi - - # Download latest 'epel-release' package for the distro version directly - epel_repo_url="${HTTP_VAL}://dl.fedoraproject.org/pub/epel/epel-release-latest-${DISTRO_MAJOR_VERSION}.noarch.rpm" - rpm -Uvh --force "$epel_repo_url" || return 1 - - _EPEL_REPOS_INSTALLED=$BS_TRUE - - return 0 -} - -__install_saltstack_rhel_repository() { - if [ "$ITYPE" = "stable" ]; then - repo_rev="$STABLE_REV" - else - repo_rev="latest" - fi - - __PY_VERSION_REPO="yum" - if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then - __PY_VERSION_REPO="py3" - fi - - # Avoid using '$releasever' variable for yum. - # Instead, this should work correctly on all RHEL variants. - base_url="${HTTP_VAL}://${_REPO_URL}/${__PY_VERSION_REPO}/redhat/${DISTRO_MAJOR_VERSION}/\$basearch/${repo_rev}/" - gpg_key="SALTSTACK-GPG-KEY.pub" - repo_file="/etc/yum.repos.d/saltstack.repo" - - if [ ! -s "$repo_file" ] || [ "$_FORCE_OVERWRITE" -eq $BS_TRUE ]; then - cat <<_eof > "$repo_file" -[saltstack] -name=SaltStack ${repo_rev} Release Channel for RHEL/CentOS \$releasever -baseurl=${base_url} -skip_if_unavailable=True -gpgcheck=1 -gpgkey=${base_url}${gpg_key} -enabled=1 -enabled_metadata=1 -_eof - - fetch_url="${HTTP_VAL}://${_REPO_URL}/${__PY_VERSION_REPO}/redhat/${DISTRO_MAJOR_VERSION}/${CPU_ARCH_L}/${repo_rev}/" - __rpm_import_gpg "${fetch_url}${gpg_key}" || return 1 - yum clean metadata || return 1 - elif [ "$repo_rev" != "latest" ]; then - echowarn "saltstack.repo already exists, ignoring salt version argument." - echowarn "Use -F (forced overwrite) to install $repo_rev." - fi - - return 0 -} - -install_centos_stable_deps() { - if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then - yum -y update || return 1 - fi - - if [ "$_DISABLE_REPOS" -eq "$BS_TRUE" ] && [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then - echoerror "Detected -r or -R option while installing Salt packages for Python 3." - echoerror "Python 3 packages for Salt require the EPEL repository to be installed." - echoerror "The -r and -R options are incompatible with -x and Python 3 bootstrap installs." - return 1 - fi - - if [ "$_DISABLE_REPOS" -eq "$BS_FALSE" ]; then - __install_epel_repository || return 1 - __install_saltstack_rhel_repository || return 1 - fi - - # If -R was passed, we need to configure custom repo url with rsync-ed packages - # Which is still handled in __install_saltstack_rhel_repository. This call has - # its own check in case -r was passed without -R. - if [ "$_CUSTOM_REPO_URL" != "null" ]; then - __install_saltstack_rhel_repository || return 1 - fi - - if [ "$DISTRO_MAJOR_VERSION" -ge 8 ]; then - __PACKAGES="dnf-utils chkconfig" - else - __PACKAGES="yum-utils chkconfig" - fi - - if [ "$DISTRO_MAJOR_VERSION" -ge 8 ]; then - # YAML module is used for generating custom master/minion configs - if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then - __PACKAGES="${__PACKAGES} python3-pyyaml" - else - __PACKAGES="${__PACKAGES} python2-pyyaml" - fi - elif [ "$DISTRO_MAJOR_VERSION" -eq 7 ]; then - # YAML module is used for generating custom master/minion configs - if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then - __PACKAGES="${__PACKAGES} python36-PyYAML" - else - __PACKAGES="${__PACKAGES} PyYAML" - fi - else - # YAML module is used for generating custom master/minion configs - if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then - __PACKAGES="${__PACKAGES} python34-PyYAML" - else - __PACKAGES="${__PACKAGES} PyYAML" - fi - fi - - # shellcheck disable=SC2086 - __yum_install_noinput ${__PACKAGES} || return 1 - - if [ "${_EXTRA_PACKAGES}" != "" ]; then - echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" - # shellcheck disable=SC2086 - __yum_install_noinput ${_EXTRA_PACKAGES} || return 1 - fi - - - return 0 -} - -install_centos_stable() { - __PACKAGES="" - - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ];then - __PACKAGES="${__PACKAGES} salt-cloud" - fi - if [ "$_INSTALL_MASTER" -eq $BS_TRUE ];then - __PACKAGES="${__PACKAGES} salt-master" - fi - if [ "$_INSTALL_MINION" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} salt-minion" - fi - if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ];then - __PACKAGES="${__PACKAGES} salt-syndic" - fi - - # shellcheck disable=SC2086 - __yum_install_noinput ${__PACKAGES} || return 1 - - return 0 -} - -install_centos_stable_post() { - SYSTEMD_RELOAD=$BS_FALSE - - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - if [ -f /bin/systemctl ]; then - /bin/systemctl is-enabled salt-${fname}.service > /dev/null 2>&1 || ( - /bin/systemctl preset salt-${fname}.service > /dev/null 2>&1 && - /bin/systemctl enable salt-${fname}.service > /dev/null 2>&1 - ) - - SYSTEMD_RELOAD=$BS_TRUE - elif [ -f "/etc/init.d/salt-${fname}" ]; then - /sbin/chkconfig salt-${fname} on - fi - done - - if [ "$SYSTEMD_RELOAD" -eq $BS_TRUE ]; then - /bin/systemctl daemon-reload - fi - - return 0 -} - -install_centos_git_deps() { - install_centos_stable_deps || return 1 - - if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then - __yum_install_noinput ca-certificates || return 1 - fi - - if ! __check_command_exists git; then - __yum_install_noinput git || return 1 - fi - - __git_clone_and_checkout || return 1 - - - __PACKAGES="" - _install_m2crypto_req=false - if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then - _py=${_PY_EXE} - if [ "$DISTRO_MAJOR_VERSION" -gt 6 ]; then - _install_m2crypto_req=true - fi - if [ "$DISTRO_MAJOR_VERSION" -ge 8 ]; then - # Packages are named python3- - PY_PKG_VER=3 - else - # Packages are named python36- - PY_PKG_VER=36 - fi - else - if [ "$DISTRO_MAJOR_VERSION" -eq 6 ]; then - _install_m2crypto_req=true - fi - _py="python" - PY_PKG_VER="" - - # Only Py2 needs python-futures - __PACKAGES="${__PACKAGES} python-futures" - - # There is no systemd-python3 package as of this writing - if [ "$DISTRO_MAJOR_VERSION" -ge 7 ]; then - __PACKAGES="${__PACKAGES} systemd-python" - fi - fi - - if [ "$DISTRO_MAJOR_VERSION" -ge 8 ]; then - __install_tornado_pip ${_py} || return 1 - __PACKAGES="${__PACKAGES} python3-m2crypto" - else - __PACKAGES="${__PACKAGES} m2crypto python${PY_PKG_VER}-crypto" - fi - - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-jinja2" - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-msgpack python${PY_PKG_VER}-requests" - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-tornado python${PY_PKG_VER}-zmq" - - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-libcloud" - fi - - if [ "${_INSTALL_PY}" -eq "${BS_TRUE}" ]; then - # Install Python if "-y" was passed in. - __install_python || return 1 - fi - - if [ "${_PY_EXE}" != "" ] && [ "$_PIP_ALLOWED" -eq "$BS_TRUE" ]; then - # If "-x" is defined, install dependencies with pip based on the Python version given. - _PIP_PACKAGES="m2crypto!=0.33.0 jinja2 msgpack-python pycrypto PyYAML tornado<5.0 zmq futures>=2.0" - - # install swig and openssl on cent6 - if $_install_m2crypto_req; then - __yum_install_noinput openssl-devel swig || return 1 - fi - - if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then - # Filter out any commented lines from the requirements file - _REQ_LINES="$(grep '^[^#]' "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" - for SINGLE_PACKAGE in ${_PIP_PACKAGES}; do - __REQUIRED_VERSION="$(grep "${SINGLE_PACKAGE}" "${_REQ_LINES}")" - if [ "${__REQUIRED_VERSION}" != "" ]; then - _PIP_PACKAGES=$(echo "$_PIP_PACKAGES" | sed "s/${SINGLE_PACKAGE}/${__REQUIRED_VERSION}/") - fi - done - fi - - if [ "$_INSTALL_CLOUD" -eq "${BS_TRUE}" ]; then - _PIP_PACKAGES="${_PIP_PACKAGES} apache-libcloud" - fi - - __install_pip_pkgs "${_PIP_PACKAGES}" "${_PY_EXE}" || return 1 - else - # shellcheck disable=SC2086 - __yum_install_noinput ${__PACKAGES} || return 1 - fi - - # Let's trigger config_salt() - if [ "$_TEMP_CONFIG_DIR" = "null" ]; then - _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" - CONFIG_SALT_FUNC="config_salt" - fi - - return 0 -} - -install_centos_git() { - if [ "${_PY_EXE}" != "" ]; then - _PYEXE=${_PY_EXE} - echoinfo "Using the following python version: ${_PY_EXE} to install salt" - else - _PYEXE='python2' - fi - - if [ -f "${_SALT_GIT_CHECKOUT_DIR}/salt/syspaths.py" ]; then - $_PYEXE setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install --prefix=/usr || return 1 - else - $_PYEXE setup.py ${SETUP_PY_INSTALL_ARGS} install --prefix=/usr || return 1 - fi - - return 0 -} - -install_centos_git_post() { - SYSTEMD_RELOAD=$BS_FALSE - - for fname in api master minion syndic; do - # Skip if not meant to be installed - [ $fname = "api" ] && \ - ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - if [ -f /bin/systemctl ]; then - if [ ! -f "/usr/lib/systemd/system/salt-${fname}.service" ] || \ - { [ -f "/usr/lib/systemd/system/salt-${fname}.service" ] && [ "$_FORCE_OVERWRITE" -eq $BS_TRUE ]; }; then - __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-${fname}.service" /usr/lib/systemd/system - fi - - SYSTEMD_RELOAD=$BS_TRUE - elif [ ! -f "/etc/init.d/salt-$fname" ] || \ - { [ -f "/etc/init.d/salt-$fname" ] && [ "$_FORCE_OVERWRITE" -eq $BS_TRUE ]; }; then - __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-${fname}" /etc/init.d - chmod +x /etc/init.d/salt-${fname} - fi - done - - if [ "$SYSTEMD_RELOAD" -eq $BS_TRUE ]; then - /bin/systemctl daemon-reload - fi - - install_centos_stable_post || return 1 - - return 0 -} - -install_centos_restart_daemons() { - [ $_START_DAEMONS -eq $BS_FALSE ] && return - - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - if [ -f /sbin/initctl ] && [ -f /etc/init/salt-${fname}.conf ]; then - # We have upstart support and upstart knows about our service - if ! /sbin/initctl status salt-$fname > /dev/null 2>&1; then - # Everything is in place and upstart gave us an error code? Fail! - return 1 - fi - - # upstart knows about this service. - # Let's try to stop it, and then start it - /sbin/initctl stop salt-$fname > /dev/null 2>&1 - # Restart service - if ! /sbin/initctl start salt-$fname > /dev/null 2>&1; then - # Failed the restart?! - return 1 - fi - elif [ -f /etc/init.d/salt-$fname ]; then - # Disable stdin to fix shell session hang on killing tee pipe - service salt-$fname stop < /dev/null > /dev/null 2>&1 - service salt-$fname start < /dev/null - elif [ -f /usr/bin/systemctl ]; then - # CentOS 7 uses systemd - /usr/bin/systemctl stop salt-$fname > /dev/null 2>&1 - /usr/bin/systemctl start salt-$fname.service - fi - done -} - -install_centos_testing_deps() { - install_centos_stable_deps || return 1 - return 0 -} - -install_centos_testing() { - install_centos_stable || return 1 - return 0 -} - -install_centos_testing_post() { - install_centos_stable_post || return 1 - return 0 -} - -install_centos_check_services() { - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - if [ -f /sbin/initctl ] && [ -f /etc/init/salt-${fname}.conf ]; then - __check_services_upstart salt-$fname || return 1 - elif [ -f /etc/init.d/salt-$fname ]; then - __check_services_sysvinit salt-$fname || return 1 - elif [ -f /usr/bin/systemctl ]; then - __check_services_systemd salt-$fname || return 1 - fi - done - - return 0 -} -# -# Ended CentOS Install Functions -# -####################################################################################################################### - -####################################################################################################################### -# -# RedHat Install Functions -# -install_red_hat_linux_stable_deps() { - install_centos_stable_deps || return 1 - return 0 -} - -install_red_hat_linux_git_deps() { - install_centos_git_deps || return 1 - return 0 -} - -install_red_hat_enterprise_linux_stable_deps() { - install_red_hat_linux_stable_deps || return 1 - return 0 -} - -install_red_hat_enterprise_linux_git_deps() { - install_red_hat_linux_git_deps || return 1 - return 0 -} - -install_red_hat_enterprise_server_stable_deps() { - install_red_hat_linux_stable_deps || return 1 - return 0 -} - -install_red_hat_enterprise_server_git_deps() { - install_red_hat_linux_git_deps || return 1 - return 0 -} - -install_red_hat_enterprise_workstation_stable_deps() { - install_red_hat_linux_stable_deps || return 1 - return 0 -} - -install_red_hat_enterprise_workstation_git_deps() { - install_red_hat_linux_git_deps || return 1 - return 0 -} - -install_red_hat_linux_stable() { - install_centos_stable || return 1 - return 0 -} - -install_red_hat_linux_git() { - install_centos_git || return 1 - return 0 -} - -install_red_hat_enterprise_linux_stable() { - install_red_hat_linux_stable || return 1 - return 0 -} - -install_red_hat_enterprise_linux_git() { - install_red_hat_linux_git || return 1 - return 0 -} - -install_red_hat_enterprise_server_stable() { - install_red_hat_linux_stable || return 1 - return 0 -} - -install_red_hat_enterprise_server_git() { - install_red_hat_linux_git || return 1 - return 0 -} - -install_red_hat_enterprise_workstation_stable() { - install_red_hat_linux_stable || return 1 - return 0 -} - -install_red_hat_enterprise_workstation_git() { - install_red_hat_linux_git || return 1 - return 0 -} - -install_red_hat_linux_stable_post() { - install_centos_stable_post || return 1 - return 0 -} - -install_red_hat_linux_restart_daemons() { - install_centos_restart_daemons || return 1 - return 0 -} - -install_red_hat_linux_git_post() { - install_centos_git_post || return 1 - return 0 -} - -install_red_hat_enterprise_linux_stable_post() { - install_red_hat_linux_stable_post || return 1 - return 0 -} - -install_red_hat_enterprise_linux_restart_daemons() { - install_red_hat_linux_restart_daemons || return 1 - return 0 -} - -install_red_hat_enterprise_linux_git_post() { - install_red_hat_linux_git_post || return 1 - return 0 -} - -install_red_hat_enterprise_server_stable_post() { - install_red_hat_linux_stable_post || return 1 - return 0 -} - -install_red_hat_enterprise_server_restart_daemons() { - install_red_hat_linux_restart_daemons || return 1 - return 0 -} - -install_red_hat_enterprise_server_git_post() { - install_red_hat_linux_git_post || return 1 - return 0 -} - -install_red_hat_enterprise_workstation_stable_post() { - install_red_hat_linux_stable_post || return 1 - return 0 -} - -install_red_hat_enterprise_workstation_restart_daemons() { - install_red_hat_linux_restart_daemons || return 1 - return 0 -} - -install_red_hat_enterprise_workstation_git_post() { - install_red_hat_linux_git_post || return 1 - return 0 -} - -install_red_hat_linux_testing_deps() { - install_centos_testing_deps || return 1 - return 0 -} - -install_red_hat_linux_testing() { - install_centos_testing || return 1 - return 0 -} - -install_red_hat_linux_testing_post() { - install_centos_testing_post || return 1 - return 0 -} - -install_red_hat_enterprise_server_testing_deps() { - install_centos_testing_deps || return 1 - return 0 -} - -install_red_hat_enterprise_server_testing() { - install_centos_testing || return 1 - return 0 -} - -install_red_hat_enterprise_server_testing_post() { - install_centos_testing_post || return 1 - return 0 -} - -install_red_hat_enterprise_workstation_testing_deps() { - install_centos_testing_deps || return 1 - return 0 -} - -install_red_hat_enterprise_workstation_testing() { - install_centos_testing || return 1 - return 0 -} - -install_red_hat_enterprise_workstation_testing_post() { - install_centos_testing_post || return 1 - return 0 -} -# -# Ended RedHat Install Functions -# -####################################################################################################################### - -####################################################################################################################### -# -# Oracle Linux Install Functions -# -install_oracle_linux_stable_deps() { - install_centos_stable_deps || return 1 - return 0 -} - -install_oracle_linux_git_deps() { - install_centos_git_deps || return 1 - return 0 -} - -install_oracle_linux_testing_deps() { - install_centos_testing_deps || return 1 - return 0 -} - -install_oracle_linux_stable() { - install_centos_stable || return 1 - return 0 -} - -install_oracle_linux_git() { - install_centos_git || return 1 - return 0 -} - -install_oracle_linux_testing() { - install_centos_testing || return 1 - return 0 -} - -install_oracle_linux_stable_post() { - install_centos_stable_post || return 1 - return 0 -} - -install_oracle_linux_git_post() { - install_centos_git_post || return 1 - return 0 -} - -install_oracle_linux_testing_post() { - install_centos_testing_post || return 1 - return 0 -} - -install_oracle_linux_restart_daemons() { - install_centos_restart_daemons || return 1 - return 0 -} - -install_oracle_linux_check_services() { - install_centos_check_services || return 1 - return 0 -} -# -# Ended Oracle Linux Install Functions -# -####################################################################################################################### - -####################################################################################################################### -# -# Scientific Linux Install Functions -# -install_scientific_linux_stable_deps() { - install_centos_stable_deps || return 1 - return 0 -} - -install_scientific_linux_git_deps() { - install_centos_git_deps || return 1 - return 0 -} - -install_scientific_linux_testing_deps() { - install_centos_testing_deps || return 1 - return 0 -} - -install_scientific_linux_stable() { - install_centos_stable || return 1 - return 0 -} - -install_scientific_linux_git() { - install_centos_git || return 1 - return 0 -} - -install_scientific_linux_testing() { - install_centos_testing || return 1 - return 0 -} - -install_scientific_linux_stable_post() { - install_centos_stable_post || return 1 - return 0 -} - -install_scientific_linux_git_post() { - install_centos_git_post || return 1 - return 0 -} - -install_scientific_linux_testing_post() { - install_centos_testing_post || return 1 - return 0 -} - -install_scientific_linux_restart_daemons() { - install_centos_restart_daemons || return 1 - return 0 -} - -install_scientific_linux_check_services() { - install_centos_check_services || return 1 - return 0 -} -# -# Ended Scientific Linux Install Functions -# -####################################################################################################################### - -####################################################################################################################### -# -# CloudLinux Install Functions -# -install_cloud_linux_stable_deps() { - install_centos_stable_deps || return 1 - return 0 -} - -install_cloud_linux_git_deps() { - install_centos_git_deps || return 1 - return 0 -} - -install_cloud_linux_testing_deps() { - install_centos_testing_deps || return 1 - return 0 -} - -install_cloud_linux_stable() { - install_centos_stable || return 1 - return 0 -} - -install_cloud_linux_git() { - install_centos_git || return 1 - return 0 -} - -install_cloud_linux_testing() { - install_centos_testing || return 1 - return 0 -} - -install_cloud_linux_stable_post() { - install_centos_stable_post || return 1 - return 0 -} - -install_cloud_linux_git_post() { - install_centos_git_post || return 1 - return 0 -} - -install_cloud_linux_testing_post() { - install_centos_testing_post || return 1 - return 0 -} - -install_cloud_linux_restart_daemons() { - install_centos_restart_daemons || return 1 - return 0 -} - -install_cloud_linux_check_services() { - install_centos_check_services || return 1 - return 0 -} -# -# End of CloudLinux Install Functions -# -####################################################################################################################### - -####################################################################################################################### -# -# Alpine Linux Install Functions -# -install_alpine_linux_stable_deps() { - if ! grep -q '^[^#].\+alpine/.\+/community' /etc/apk/repositories; then - # Add community repository entry based on the "main" repo URL - __REPO=$(grep '^[^#].\+alpine/.\+/main\>' /etc/apk/repositories) - echo "${__REPO}" | sed -e 's/main/community/' >> /etc/apk/repositories - fi - - apk update - - # Get latest root CA certs - apk -U add ca-certificates - - if ! __check_command_exists openssl; then - # Install OpenSSL to be able to pull from https:// URLs - apk -U add openssl - fi -} - -install_alpine_linux_git_deps() { - install_alpine_linux_stable_deps || return 1 - - apk -U add python2 py-virtualenv py2-crypto py2-m2crypto py2-setuptools \ - py2-jinja2 py2-yaml py2-markupsafe py2-msgpack py2-psutil \ - py2-zmq zeromq py2-requests || return 1 - - if ! __check_command_exists git; then - apk -U add git || return 1 - fi - - __git_clone_and_checkout || return 1 - - if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then - # We're on the develop branch, install whichever tornado is on the requirements file - __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" - if [ "${__REQUIRED_TORNADO}" != "" ]; then - apk -U add py2-tornado || return 1 - fi - fi - - # Let's trigger config_salt() - if [ "$_TEMP_CONFIG_DIR" = "null" ]; then - _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" - CONFIG_SALT_FUNC="config_salt" - fi -} - -install_alpine_linux_stable() { - __PACKAGES="salt" - - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ];then - __PACKAGES="${__PACKAGES} salt-cloud" - fi - if [ "$_INSTALL_MASTER" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} salt-master" - fi - if [ "$_INSTALL_MINION" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} salt-minion" - fi - if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} salt-syndic" - fi - - # shellcheck disable=SC2086 - apk -U add ${__PACKAGES} || return 1 - return 0 -} - -install_alpine_linux_git() { - if [ -f "${_SALT_GIT_CHECKOUT_DIR}/salt/syspaths.py" ]; then - python2 setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install || return 1 - else - python2 setup.py ${SETUP_PY_INSTALL_ARGS} install || return 1 - fi -} - -install_alpine_linux_post() { - for fname in api master minion syndic; do - # Skip if not meant to be installed - [ $fname = "api" ] && \ - ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - if [ -f /sbin/rc-update ]; then - script_url="${_SALTSTACK_REPO_URL%.git}/raw/develop/pkg/alpine/salt-$fname" - [ -f "/etc/init.d/salt-$fname" ] || __fetch_url "/etc/init.d/salt-$fname" "$script_url" - - # shellcheck disable=SC2181 - if [ $? -eq 0 ]; then - chmod +x "/etc/init.d/salt-$fname" - else - echoerror "Failed to get OpenRC init script for $OS_NAME from $script_url." - return 1 - fi - - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - /sbin/rc-update add "salt-$fname" > /dev/null 2>&1 || return 1 - fi - done -} - -install_alpine_linux_restart_daemons() { - [ "${_START_DAEMONS}" -eq $BS_FALSE ] && return - - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - # Disable stdin to fix shell session hang on killing tee pipe - /sbin/rc-service salt-$fname stop < /dev/null > /dev/null 2>&1 - /sbin/rc-service salt-$fname start < /dev/null || return 1 - done -} - -install_alpine_linux_check_services() { - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - __check_services_alpine salt-$fname || return 1 - done - - return 0 -} - -daemons_running_alpine_linux() { - [ "${_START_DAEMONS}" -eq $BS_FALSE ] && return - - FAILED_DAEMONS=0 - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - # shellcheck disable=SC2009 - if [ "$(ps wwwaux | grep -v grep | grep salt-$fname)" = "" ]; then - echoerror "salt-$fname was not found running" - FAILED_DAEMONS=$((FAILED_DAEMONS + 1)) - fi - done - - return $FAILED_DAEMONS -} - -# -# Ended Alpine Linux Install Functions -# -####################################################################################################################### - - -####################################################################################################################### -# -# Amazon Linux AMI Install Functions -# - -install_amazon_linux_ami_deps() { - # Shim to figure out if we're using old (rhel) or new (aws) rpms. - _USEAWS=$BS_FALSE - pkg_append="python" - - if [ "$ITYPE" = "stable" ]; then - repo_rev="$STABLE_REV" - else - repo_rev="latest" - fi - - if echo $repo_rev | grep -E -q '^archive'; then - year=$(echo "$repo_rev" | cut -d '/' -f 2 | cut -c1-4) - else - year=$(echo "$repo_rev" | cut -c1-4) - fi - - if echo "$repo_rev" | grep -E -q '^(latest|2016\.11)$' || \ - [ "$year" -gt 2016 ]; then - _USEAWS=$BS_TRUE - pkg_append="python27" - fi - - # We need to install yum-utils before doing anything else when installing on - # Amazon Linux ECS-optimized images. See issue #974. - __yum_install_noinput yum-utils - - # Do upgrade early - if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then - yum -y update || return 1 - fi - - if [ $_DISABLE_REPOS -eq $BS_FALSE ] || [ "$_CUSTOM_REPO_URL" != "null" ]; then - __REPO_FILENAME="saltstack-repo.repo" - - # Set a few vars to make life easier. - if [ $_USEAWS -eq $BS_TRUE ]; then - base_url="$HTTP_VAL://${_REPO_URL}/yum/amazon/latest/\$basearch/$repo_rev/" - gpg_key="${base_url}SALTSTACK-GPG-KEY.pub" - repo_name="SaltStack repo for Amazon Linux" - else - base_url="$HTTP_VAL://${_REPO_URL}/yum/redhat/6/\$basearch/$repo_rev/" - gpg_key="${base_url}SALTSTACK-GPG-KEY.pub" - repo_name="SaltStack repo for RHEL/CentOS 6" - fi - - # This should prob be refactored to use __install_saltstack_rhel_repository() - # With args passed in to do the right thing. Reformatted to be more like the - # amazon linux yum file. - if [ ! -s "/etc/yum.repos.d/${__REPO_FILENAME}" ]; then - cat <<_eof > "/etc/yum.repos.d/${__REPO_FILENAME}" -[saltstack-repo] -name=$repo_name -failovermethod=priority -priority=10 -gpgcheck=1 -gpgkey=$gpg_key -baseurl=$base_url -_eof - fi - - fi - - # Package python-ordereddict-1.1-2.el6.noarch is obsoleted by python26-2.6.9-2.88.amzn1.x86_64 - # which is already installed - __PACKAGES="m2crypto ${pkg_append}-crypto ${pkg_append}-jinja2 ${pkg_append}-PyYAML" - __PACKAGES="${__PACKAGES} ${pkg_append}-msgpack ${pkg_append}-requests ${pkg_append}-zmq" - __PACKAGES="${__PACKAGES} ${pkg_append}-futures" - - # shellcheck disable=SC2086 - __yum_install_noinput ${__PACKAGES} || return 1 - - if [ "${_EXTRA_PACKAGES}" != "" ]; then - echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" - # shellcheck disable=SC2086 - __yum_install_noinput ${_EXTRA_PACKAGES} || return 1 - fi -} - -install_amazon_linux_ami_git_deps() { - if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then - yum -y install ca-certificates || return 1 - fi - - PIP_EXE='pip' - if __check_command_exists python2.7; then - if ! __check_command_exists pip2.7; then - if ! __check_command_exists easy_install-2.7; then - __yum_install_noinput python27-setuptools - fi - /usr/bin/easy_install-2.7 pip || return 1 - fi - PIP_EXE='/usr/local/bin/pip2.7' - _PY_EXE='python2.7' - fi - - install_amazon_linux_ami_deps || return 1 - - if ! __check_command_exists git; then - __yum_install_noinput git || return 1 - fi - - __git_clone_and_checkout || return 1 - - __PACKAGES="" - __PIP_PACKAGES="" - - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then - __check_pip_allowed "You need to allow pip based installations (-P) in order to install apache-libcloud" - __PACKAGES="${__PACKAGES} python27-pip" - __PIP_PACKAGES="${__PIP_PACKAGES} apache-libcloud>=$_LIBCLOUD_MIN_VERSION" - fi - - if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then - # We're on the develop branch, install whichever tornado is on the requirements file - __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" - if [ "${__REQUIRED_TORNADO}" != "" ]; then - __PACKAGES="${__PACKAGES} ${pkg_append}-tornado" - fi - fi - - if [ "${__PACKAGES}" != "" ]; then - # shellcheck disable=SC2086 - __yum_install_noinput ${__PACKAGES} || return 1 - fi - - if [ "${__PIP_PACKAGES}" != "" ]; then - # shellcheck disable=SC2086 - ${PIP_EXE} install ${__PIP_PACKAGES} || return 1 - fi - - # Let's trigger config_salt() - if [ "$_TEMP_CONFIG_DIR" = "null" ]; then - _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" - CONFIG_SALT_FUNC="config_salt" - fi - - return 0 -} - -install_amazon_linux_ami_2_git_deps() { - if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then - yum -y install ca-certificates || return 1 - fi - - PIP_EXE='pip' - if __check_command_exists python2.7; then - if ! __check_command_exists pip2.7; then - __yum_install_noinput python2-pip - fi - PIP_EXE='/bin/pip' - _PY_EXE='python2.7' - fi - - install_amazon_linux_ami_2_deps || return 1 - - if ! __check_command_exists git; then - __yum_install_noinput git || return 1 - fi - - __git_clone_and_checkout || return 1 - - __PACKAGES="" - __PIP_PACKAGES="" - - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then - __check_pip_allowed "You need to allow pip based installations (-P) in order to install apache-libcloud" - __PACKAGES="${__PACKAGES} python27-pip" - __PIP_PACKAGES="${__PIP_PACKAGES} apache-libcloud>=$_LIBCLOUD_MIN_VERSION" - fi - - if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then - # We're on the develop branch, install whichever tornado is on the requirements file - __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" - if [ "${__REQUIRED_TORNADO}" != "" ]; then - __PACKAGES="${__PACKAGES} ${pkg_append}-tornado" - fi - fi - - if [ "${__PACKAGES}" != "" ]; then - # shellcheck disable=SC2086 - __yum_install_noinput ${__PACKAGES} || return 1 - fi - - if [ "${__PIP_PACKAGES}" != "" ]; then - # shellcheck disable=SC2086 - ${PIP_EXE} install ${__PIP_PACKAGES} || return 1 - fi - - # Let's trigger config_salt() - if [ "$_TEMP_CONFIG_DIR" = "null" ]; then - _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" - CONFIG_SALT_FUNC="config_salt" - fi - - return 0 -} - -install_amazon_linux_ami_2_deps() { - # Shim to figure out if we're using old (rhel) or new (aws) rpms. - _USEAWS=$BS_FALSE - pkg_append="python" - - if [ "$ITYPE" = "stable" ]; then - repo_rev="$STABLE_REV" - else - repo_rev="latest" - fi - - if echo $repo_rev | grep -E -q '^archive'; then - year=$(echo "$repo_rev" | cut -d '/' -f 2 | cut -c1-4) - else - year=$(echo "$repo_rev" | cut -c1-4) - fi - - if echo "$repo_rev" | grep -E -q '^(latest|2016\.11)$' || \ - [ "$year" -gt 2016 ]; then - _USEAWS=$BS_TRUE - pkg_append="python" - fi - - # We need to install yum-utils before doing anything else when installing on - # Amazon Linux ECS-optimized images. See issue #974. - __yum_install_noinput yum-utils - - # Do upgrade early - if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then - yum -y update || return 1 - fi - - if [ $_DISABLE_REPOS -eq $BS_FALSE ] || [ "$_CUSTOM_REPO_URL" != "null" ]; then - __REPO_FILENAME="saltstack-repo.repo" - - base_url="$HTTP_VAL://${_REPO_URL}/yum/amazon/2/\$basearch/$repo_rev/" - gpg_key="${base_url}SALTSTACK-GPG-KEY.pub - ${base_url}base/RPM-GPG-KEY-CentOS-7" - repo_name="SaltStack repo for Amazon Linux 2.0" - - # This should prob be refactored to use __install_saltstack_rhel_repository() - # With args passed in to do the right thing. Reformatted to be more like the - # amazon linux yum file. - if [ ! -s "/etc/yum.repos.d/${__REPO_FILENAME}" ]; then - cat <<_eof > "/etc/yum.repos.d/${__REPO_FILENAME}" -[saltstack-repo] -name=$repo_name -failovermethod=priority -priority=10 -gpgcheck=1 -gpgkey=$gpg_key -baseurl=$base_url -_eof - fi - - fi - - # Package python-ordereddict-1.1-2.el6.noarch is obsoleted by python26-2.6.9-2.88.amzn1.x86_64 - # which is already installed - __PACKAGES="m2crypto ${pkg_append}-crypto ${pkg_append}-jinja2 PyYAML procps-ng" - __PACKAGES="${__PACKAGES} ${pkg_append}-msgpack ${pkg_append}-requests ${pkg_append}-zmq" - __PACKAGES="${__PACKAGES} ${pkg_append}-futures" - - # shellcheck disable=SC2086 - __yum_install_noinput ${__PACKAGES} || return 1 - - if [ "${_EXTRA_PACKAGES}" != "" ]; then - echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" - # shellcheck disable=SC2086 - __yum_install_noinput ${_EXTRA_PACKAGES} || return 1 - fi -} - -install_amazon_linux_ami_stable() { - install_centos_stable || return 1 - return 0 -} - -install_amazon_linux_ami_stable_post() { - install_centos_stable_post || return 1 - return 0 -} - -install_amazon_linux_ami_restart_daemons() { - install_centos_restart_daemons || return 1 - return 0 -} - -install_amazon_linux_ami_git() { - install_centos_git || return 1 - return 0 -} - -install_amazon_linux_ami_git_post() { - install_centos_git_post || return 1 - return 0 -} - -install_amazon_linux_ami_testing() { - install_centos_testing || return 1 - return 0 -} - -install_amazon_linux_ami_testing_post() { - install_centos_testing_post || return 1 - return 0 -} - -install_amazon_linux_ami_2_stable() { - install_centos_stable || return 1 - return 0 -} - -install_amazon_linux_ami_2_stable_post() { - install_centos_stable_post || return 1 - return 0 -} - -install_amazon_linux_ami_2_restart_daemons() { - install_centos_restart_daemons || return 1 - return 0 -} - -install_amazon_linux_ami_2_git() { - install_centos_git || return 1 - return 0 -} - -install_amazon_linux_ami_2_git_post() { - install_centos_git_post || return 1 - return 0 -} - -install_amazon_linux_ami_2_testing() { - install_centos_testing || return 1 - return 0 -} - -install_amazon_linux_ami_2_testing_post() { - install_centos_testing_post || return 1 - return 0 -} -# -# Ended Amazon Linux AMI Install Functions -# -####################################################################################################################### - -####################################################################################################################### -# -# Arch Install Functions -# -install_arch_linux_stable_deps() { - if [ ! -f /etc/pacman.d/gnupg ]; then - pacman-key --init && pacman-key --populate archlinux || return 1 - fi - - # Pacman does not resolve dependencies on outdated versions - # They always need to be updated - pacman -Syy --noconfirm - - pacman -S --noconfirm --needed archlinux-keyring || return 1 - - pacman -Su --noconfirm --needed pacman || return 1 - - if __check_command_exists pacman-db-upgrade; then - pacman-db-upgrade || return 1 - fi - - # YAML module is used for generating custom master/minion configs - pacman -Su --noconfirm --needed python2-yaml - - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then - pacman -Su --noconfirm --needed python2-apache-libcloud || return 1 - fi - - if [ "${_EXTRA_PACKAGES}" != "" ]; then - echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" - # shellcheck disable=SC2086 - pacman -Su --noconfirm --needed ${_EXTRA_PACKAGES} || return 1 - fi -} - -install_arch_linux_git_deps() { - install_arch_linux_stable_deps - - # Don't fail if un-installing python2-distribute threw an error - if ! __check_command_exists git; then - pacman -Sy --noconfirm --needed git || return 1 - fi - pacman -R --noconfirm python2-distribute - pacman -Su --noconfirm --needed python2-crypto python2-setuptools python2-jinja \ - python2-m2crypto python2-futures python2-markupsafe python2-msgpack python2-psutil \ - python2-pyzmq zeromq python2-requests python2-systemd || return 1 - - __git_clone_and_checkout || return 1 - - if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then - # We're on the develop branch, install whichever tornado is on the requirements file - __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" - if [ "${__REQUIRED_TORNADO}" != "" ]; then - pacman -Su --noconfirm --needed python2-tornado - fi - fi - - - # Let's trigger config_salt() - if [ "$_TEMP_CONFIG_DIR" = "null" ]; then - _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" - CONFIG_SALT_FUNC="config_salt" - fi - - return 0 -} - -install_arch_linux_stable() { - # Pacman does not resolve dependencies on outdated versions - # They always need to be updated - pacman -Syy --noconfirm - - pacman -Su --noconfirm --needed pacman || return 1 - # See https://mailman.archlinux.org/pipermail/arch-dev-public/2013-June/025043.html - # to know why we're ignoring below. - pacman -Syu --noconfirm --ignore filesystem,bash || return 1 - pacman -S --noconfirm --needed bash || return 1 - pacman -Su --noconfirm || return 1 - # We can now resume regular salt update - pacman -Syu --noconfirm salt python2-futures || return 1 - return 0 -} - -install_arch_linux_git() { - if [ -f "${_SALT_GIT_CHECKOUT_DIR}/salt/syspaths.py" ]; then - python2 setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install || return 1 - else - python2 setup.py ${SETUP_PY_INSTALL_ARGS} install || return 1 - fi - return 0 -} - -install_arch_linux_post() { - for fname in api master minion syndic; do - # Skip if not meant to be installed - [ $fname = "api" ] && \ - ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - # Since Arch's pacman renames configuration files - if [ "$_TEMP_CONFIG_DIR" != "null" ] && [ -f "$_SALT_ETC_DIR/$fname.pacorig" ]; then - # Since a configuration directory was provided, it also means that any - # configuration file copied was renamed by Arch, see: - # https://wiki.archlinux.org/index.php/Pacnew_and_Pacsave_Files#.pacorig - __copyfile "$_SALT_ETC_DIR/$fname.pacorig" "$_SALT_ETC_DIR/$fname" $BS_TRUE - fi - - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - if [ -f /usr/bin/systemctl ]; then - # Using systemd - /usr/bin/systemctl is-enabled salt-$fname.service > /dev/null 2>&1 || ( - /usr/bin/systemctl preset salt-$fname.service > /dev/null 2>&1 && - /usr/bin/systemctl enable salt-$fname.service > /dev/null 2>&1 - ) - sleep 1 - /usr/bin/systemctl daemon-reload - continue - fi - - # XXX: How do we enable old Arch init.d scripts? - done -} - -install_arch_linux_git_post() { - for fname in api master minion syndic; do - # Skip if not meant to be installed - [ $fname = "api" ] && \ - ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - if [ -f /usr/bin/systemctl ]; then - __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-${fname}.service" "/lib/systemd/system/salt-${fname}.service" - - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - /usr/bin/systemctl is-enabled salt-${fname}.service > /dev/null 2>&1 || ( - /usr/bin/systemctl preset salt-${fname}.service > /dev/null 2>&1 && - /usr/bin/systemctl enable salt-${fname}.service > /dev/null 2>&1 - ) - sleep 1 - /usr/bin/systemctl daemon-reload - continue - fi - - # SysV init!? - __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-$fname" "/etc/rc.d/init.d/salt-$fname" - chmod +x /etc/rc.d/init.d/salt-$fname - done -} - -install_arch_linux_restart_daemons() { - [ $_START_DAEMONS -eq $BS_FALSE ] && return - - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - if [ -f /usr/bin/systemctl ]; then - /usr/bin/systemctl stop salt-$fname.service > /dev/null 2>&1 - /usr/bin/systemctl start salt-$fname.service - continue - fi - - /etc/rc.d/salt-$fname stop > /dev/null 2>&1 - /etc/rc.d/salt-$fname start - done -} - -install_arch_check_services() { - if [ ! -f /usr/bin/systemctl ]; then - # Not running systemd!? Don't check! - return 0 - fi - - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - __check_services_systemd salt-$fname || return 1 - done - - return 0 -} -# -# Ended Arch Install Functions -# -####################################################################################################################### - -####################################################################################################################### -# -# FreeBSD Install Functions -# - -__freebsd_get_packagesite() { - if [ "$CPU_ARCH_L" = "amd64" ]; then - BSD_ARCH="x86:64" - elif [ "$CPU_ARCH_L" = "x86_64" ]; then - BSD_ARCH="x86:64" - elif [ "$CPU_ARCH_L" = "i386" ]; then - BSD_ARCH="x86:32" - elif [ "$CPU_ARCH_L" = "i686" ]; then - BSD_ARCH="x86:32" - fi - - # Since the variable might not be set, don't, momentarily treat it as a - # failure - set +o nounset - - # ABI is a std format for identifying release / architecture combos - ABI="freebsd:${DISTRO_MAJOR_VERSION}:${BSD_ARCH}" - _PACKAGESITE="http://pkg.freebsd.org/${ABI}/latest" - # Awkwardly, we want the `${ABI}` to be in conf file without escaping - PKGCONFURL="pkg+http://pkg.freebsd.org/\${ABI}/latest" - SALTPKGCONFURL="http://repo.saltstack.com/freebsd/\${ABI}/" - - # Treat unset variables as errors once more - set -o nounset -} - -# Using a separate conf step to head for idempotent install... -__configure_freebsd_pkg_details() { - ## pkg.conf is deprecated. - ## We use conf files in /usr/local or /etc instead - mkdir -p /usr/local/etc/pkg/repos/ - mkdir -p /etc/pkg/ - - ## Use new JSON-like format for pkg repo configs - ## check if /etc/pkg/FreeBSD.conf is already in place - if [ ! -f /etc/pkg/FreeBSD.conf ]; then - conf_file=/usr/local/etc/pkg/repos/freebsd.conf - { - echo "FreeBSD:{" - echo " url: \"${PKGCONFURL}\"," - echo " mirror_type: \"srv\"," - echo " signature_type: \"fingerprints\"," - echo " fingerprints: \"/usr/share/keys/pkg\"," - echo " enabled: true" - echo "}" - } > $conf_file - __copyfile $conf_file /etc/pkg/FreeBSD.conf - fi - FROM_FREEBSD="-r FreeBSD" - - ##### Workaround : Waiting for SaltStack Repository to be available for FreeBSD 12 #### - if [ "${DISTRO_MAJOR_VERSION}" -ne 12 ]; then - ## add saltstack freebsd repo - salt_conf_file=/usr/local/etc/pkg/repos/saltstack.conf - { - echo "SaltStack:{" - echo " url: \"${SALTPKGCONFURL}\"," - echo " mirror_type: \"http\"," - echo " enabled: true" - echo " priority: 10" - echo "}" - } > $salt_conf_file - FROM_SALTSTACK="-r SaltStack" - fi - ##### End Workaround : Waiting for SaltStack Repository to be available for FreeBSD 12 #### - - ## ensure future ports builds use pkgng - echo "WITH_PKGNG= yes" >> /etc/make.conf - - /usr/local/sbin/pkg update -f || return 1 -} - -install_freebsd_9_stable_deps() { - _SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/usr/local/etc/salt} - _PKI_DIR=${_SALT_ETC_DIR}/pki - - if [ $_DISABLE_REPOS -eq $BS_FALSE ]; then - #make variables available even if pkg already installed - __freebsd_get_packagesite - - if [ ! -x /usr/local/sbin/pkg ]; then - - # install new `pkg` code from its own tarball. - fetch "${_PACKAGESITE}/Latest/pkg.txz" || return 1 - tar xf ./pkg.txz -s ",/.*/,,g" "*/pkg-static" || return 1 - ./pkg-static add ./pkg.txz || return 1 - /usr/local/sbin/pkg2ng || return 1 - fi - - # Configure the pkg repository using new approach - __configure_freebsd_pkg_details || return 1 - fi - - # Now install swig30 - # shellcheck disable=SC2086 - /usr/local/sbin/pkg install ${FROM_FREEBSD} -y swig30 || return 1 - - # YAML module is used for generating custom master/minion configs - # shellcheck disable=SC2086 - /usr/local/sbin/pkg install ${FROM_FREEBSD} -y py27-yaml || return 1 - - if [ "${_EXTRA_PACKAGES}" != "" ]; then - echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" - # shellcheck disable=SC2086 - /usr/local/sbin/pkg install ${FROM_FREEBSD} -y ${_EXTRA_PACKAGES} || return 1 - fi - - if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then - pkg upgrade -y || return 1 - fi - - return 0 -} - -install_freebsd_10_stable_deps() { - install_freebsd_9_stable_deps -} - -install_freebsd_11_stable_deps() { - install_freebsd_9_stable_deps -} - -install_freebsd_12_stable_deps() { - install_freebsd_9_stable_deps -} - -install_freebsd_git_deps() { - install_freebsd_9_stable_deps || return 1 - - # shellcheck disable=SC2086 - SALT_DEPENDENCIES=$(/usr/local/sbin/pkg search ${FROM_FREEBSD} -R -d sysutils/py-salt | grep -i origin | sed -e 's/^[[:space:]]*//' | tail -n +2 | awk -F\" '{print $2}' | tr '\n' ' ') - # shellcheck disable=SC2086 - /usr/local/sbin/pkg install ${FROM_FREEBSD} -y ${SALT_DEPENDENCIES} || return 1 - # install python meta package - /usr/local/sbin/pkg install -y lang/python || return 1 - - if ! __check_command_exists git; then - /usr/local/sbin/pkg install -y git || return 1 - fi - - /usr/local/sbin/pkg install -y www/py-requests || return 1 - - __git_clone_and_checkout || return 1 - - if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then - # We're on the develop branch, install whichever tornado is on the requirements file - __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" - if [ "${__REQUIRED_TORNADO}" != "" ]; then - /usr/local/sbin/pkg install -y www/py-tornado4 || return 1 - fi - fi - - echodebug "Adapting paths to FreeBSD" - # The list of files was taken from Salt's BSD port Makefile - for file in doc/man/salt-key.1 doc/man/salt-cp.1 doc/man/salt-minion.1 \ - doc/man/salt-syndic.1 doc/man/salt-master.1 doc/man/salt-run.1 \ - doc/man/salt.7 doc/man/salt.1 doc/man/salt-call.1; do - [ ! -f $file ] && continue - echodebug "Patching ${file}" - sed -in -e "s|/etc/salt|${_SALT_ETC_DIR}|" \ - -e "s|/srv/salt|${_SALT_ETC_DIR}/states|" \ - -e "s|/srv/pillar|${_SALT_ETC_DIR}/pillar|" ${file} - done - if [ ! -f salt/syspaths.py ]; then - # We still can't provide the system paths, salt 0.16.x - # Let's patch salt's source and adapt paths to what's expected on FreeBSD - echodebug "Replacing occurrences of '/etc/salt' with ${_SALT_ETC_DIR}" - # The list of files was taken from Salt's BSD port Makefile - for file in conf/minion conf/master salt/config.py salt/client.py \ - salt/modules/mysql.py salt/utils/parsers.py salt/modules/tls.py \ - salt/modules/postgres.py salt/utils/migrations.py; do - [ ! -f $file ] && continue - echodebug "Patching ${file}" - sed -in -e "s|/etc/salt|${_SALT_ETC_DIR}|" \ - -e "s|/srv/salt|${_SALT_ETC_DIR}/states|" \ - -e "s|/srv/pillar|${_SALT_ETC_DIR}/pillar|" ${file} - done - fi - echodebug "Finished patching" - - # Let's trigger config_salt() - if [ "$_TEMP_CONFIG_DIR" = "null" ]; then - _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" - CONFIG_SALT_FUNC="config_salt" - - fi - - return 0 -} - -install_freebsd_9_stable() { - # shellcheck disable=SC2086 - /usr/local/sbin/pkg install ${FROM_SALTSTACK} -y sysutils/py-salt || return 1 - return 0 -} - -install_freebsd_10_stable() { - # shellcheck disable=SC2086 - /usr/local/sbin/pkg install ${FROM_FREEBSD} -y sysutils/py-salt || return 1 - return 0 -} - -install_freebsd_11_stable() { -# -# installing latest version of salt from FreeBSD CURRENT ports repo -# - # shellcheck disable=SC2086 - /usr/local/sbin/pkg install ${FROM_FREEBSD} -y sysutils/py-salt || return 1 - - return 0 -} - -install_freebsd_12_stable() { -# -# installing latest version of salt from FreeBSD CURRENT ports repo -# - # shellcheck disable=SC2086 - /usr/local/sbin/pkg install ${FROM_FREEBSD} -y sysutils/py-salt || return 1 - - return 0 -} - -install_freebsd_git() { - - # /usr/local/bin/python2 in FreeBSD is a symlink to /usr/local/bin/python2.7 - __PYTHON_PATH=$(readlink -f "$(command -v python2)") - __ESCAPED_PYTHON_PATH=$(echo "${__PYTHON_PATH}" | sed 's/\//\\\//g') - - # Install from git - if [ ! -f salt/syspaths.py ]; then - # We still can't provide the system paths, salt 0.16.x - ${__PYTHON_PATH} setup.py ${SETUP_PY_INSTALL_ARGS} install || return 1 - else - ${__PYTHON_PATH} setup.py \ - --salt-root-dir=/ \ - --salt-config-dir="${_SALT_ETC_DIR}" \ - --salt-cache-dir="${_SALT_CACHE_DIR}" \ - --salt-sock-dir=/var/run/salt \ - --salt-srv-root-dir="${_SALT_ETC_DIR}" \ - --salt-base-file-roots-dir="${_SALT_ETC_DIR}/states" \ - --salt-base-pillar-roots-dir="${_SALT_ETC_DIR}/pillar" \ - --salt-base-master-roots-dir="${_SALT_ETC_DIR}/salt-master" \ - --salt-logs-dir=/var/log/salt \ - --salt-pidfile-dir=/var/run \ - ${SETUP_PY_INSTALL_ARGS} install \ - || return 1 - fi - - for script in salt_api salt_master salt_minion salt_proxy salt_syndic; do - __fetch_url "/usr/local/etc/rc.d/${script}" "https://raw.githubusercontent.com/freebsd/freebsd-ports/master/sysutils/py-salt/files/${script}.in" || return 1 - sed -i '' 's/%%PREFIX%%/\/usr\/local/g' /usr/local/etc/rc.d/${script} - sed -i '' "s/%%PYTHON_CMD%%/${__ESCAPED_PYTHON_PATH}/g" /usr/local/etc/rc.d/${script} - chmod +x /usr/local/etc/rc.d/${script} || return 1 - done - - # And we're good to go - return 0 -} - -install_freebsd_9_stable_post() { - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - enable_string="salt_${fname}_enable=\"YES\"" - grep "$enable_string" /etc/rc.conf >/dev/null 2>&1 - [ $? -eq 1 ] && echo "$enable_string" >> /etc/rc.conf - - if [ $fname = "minion" ] ; then - grep "salt_minion_paths" /etc/rc.conf >/dev/null 2>&1 - [ $? -eq 1 ] && echo "salt_minion_paths=\"/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin\"" >> /etc/rc.conf - fi - done -} - -install_freebsd_10_stable_post() { - install_freebsd_9_stable_post -} - -install_freebsd_11_stable_post() { - install_freebsd_9_stable_post -} - -install_freebsd_12_stable_post() { - install_freebsd_9_stable_post -} - -install_freebsd_git_post() { - if [ -f $salt_conf_file ]; then - rm -f $salt_conf_file - fi - install_freebsd_9_stable_post || return 1 - return 0 -} - -install_freebsd_restart_daemons() { - [ $_START_DAEMONS -eq $BS_FALSE ] && return - - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - service salt_$fname stop > /dev/null 2>&1 - service salt_$fname start - done -} -# -# Ended FreeBSD Install Functions -# -####################################################################################################################### - -####################################################################################################################### -# -# OpenBSD Install Functions -# - -install_openbsd_deps() { - if [ $_DISABLE_REPOS -eq $BS_FALSE ]; then - OPENBSD_REPO='https://cdn.openbsd.org/pub/OpenBSD' - echoinfo "setting package repository to $OPENBSD_REPO" - echo "${OPENBSD_REPO}" >/etc/installurl || return 1 - fi - - if [ "${_EXTRA_PACKAGES}" != "" ]; then - echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" - # shellcheck disable=SC2086 - pkg_add -I -v ${_EXTRA_PACKAGES} || return 1 - fi - return 0 -} - -install_openbsd_git_deps() { - install_openbsd_deps || return 1 - pkg_add -I -v git || return 1 - __git_clone_and_checkout || return 1 - # - # Let's trigger config_salt() - # - if [ "$_TEMP_CONFIG_DIR" = "null" ]; then - _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" - CONFIG_SALT_FUNC="config_salt" - fi - return 0 -} - -install_openbsd_git() { - # - # Install from git - # - if [ ! -f salt/syspaths.py ]; then - # We still can't provide the system paths, salt 0.16.x - /usr/local/bin/python2.7 setup.py ${SETUP_PY_INSTALL_ARGS} install || return 1 - fi - return 0 -} - -install_openbsd_stable() { - pkg_add -r -I -v salt || return 1 - return 0 -} - -install_openbsd_post() { - for fname in api master minion syndic; do - [ $fname = "api" ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - rcctl enable salt_$fname - done - - return 0 -} - -install_openbsd_check_services() { - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && continue - - if [ -f /etc/rc.d/salt_${fname} ]; then - __check_services_openbsd salt_${fname} || return 1 - fi - done - - return 0 -} - -install_openbsd_restart_daemons() { - [ $_START_DAEMONS -eq $BS_FALSE ] && return - - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - rcctl restart salt_${fname} - done - - return 0 -} - -# -# Ended OpenBSD Install Functions -# -####################################################################################################################### - -####################################################################################################################### -# -# SmartOS Install Functions -# -install_smartos_deps() { - smartos_deps="$(pkgin show-deps salt | grep '^\s' | grep -v '\snot' | xargs) py27-m2crypto" - pkgin -y install "${smartos_deps}" || return 1 - - # Set _SALT_ETC_DIR to SmartOS default if they didn't specify - _SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/opt/local/etc/salt} - # We also need to redefine the PKI directory - _PKI_DIR=${_SALT_ETC_DIR}/pki - - # Let's trigger config_salt() - if [ "$_TEMP_CONFIG_DIR" = "null" ]; then - # Let's set the configuration directory to /tmp - _TEMP_CONFIG_DIR="/tmp" - CONFIG_SALT_FUNC="config_salt" - - # Let's download, since they were not provided, the default configuration files - if [ ! -f "$_SALT_ETC_DIR/minion" ] && [ ! -f "$_TEMP_CONFIG_DIR/minion" ]; then - # shellcheck disable=SC2086 - curl $_CURL_ARGS -s -o "$_TEMP_CONFIG_DIR/minion" -L \ - https://raw.githubusercontent.com/saltstack/salt/develop/conf/minion || return 1 - fi - if [ ! -f "$_SALT_ETC_DIR/master" ] && [ ! -f $_TEMP_CONFIG_DIR/master ]; then - # shellcheck disable=SC2086 - curl $_CURL_ARGS -s -o "$_TEMP_CONFIG_DIR/master" -L \ - https://raw.githubusercontent.com/saltstack/salt/develop/conf/master || return 1 - fi - fi - - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then - pkgin -y install py27-apache-libcloud || return 1 - fi - - if [ "${_EXTRA_PACKAGES}" != "" ]; then - echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" - # shellcheck disable=SC2086 - pkgin -y install ${_EXTRA_PACKAGES} || return 1 - fi - - return 0 -} - -install_smartos_git_deps() { - install_smartos_deps || return 1 - - if ! __check_command_exists git; then - pkgin -y install git || return 1 - fi - - if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then - # Install whichever tornado is in the requirements file - __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" - __check_pip_allowed "You need to allow pip based installations (-P) in order to install the python package '${__REQUIRED_TORNADO}'" - - # Install whichever futures is in the requirements file - __REQUIRED_FUTURES="$(grep futures "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" - __check_pip_allowed "You need to allow pip based installations (-P) in order to install the python package '${__REQUIRED_FUTURES}'" - - if [ "${__REQUIRED_TORNADO}" != "" ]; then - if ! __check_command_exists pip; then - pkgin -y install py27-pip - fi - pip install -U "${__REQUIRED_TORNADO}" - fi - - if [ "${__REQUIRED_FUTURES}" != "" ]; then - if ! __check_command_exists pip; then - pkgin -y install py27-pip - fi - pip install -U "${__REQUIRED_FUTURES}" - fi - fi - - __git_clone_and_checkout || return 1 - # Let's trigger config_salt() - if [ "$_TEMP_CONFIG_DIR" = "null" ]; then - _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" - CONFIG_SALT_FUNC="config_salt" - fi - - return 0 -} - -install_smartos_stable() { - pkgin -y install salt || return 1 - return 0 -} - -install_smartos_git() { - # Use setuptools in order to also install dependencies - # lets force our config path on the setup for now, since salt/syspaths.py only got fixed in 2015.5.0 - USE_SETUPTOOLS=1 /opt/local/bin/python setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install || return 1 - return 0 -} - -install_smartos_post() { - smf_dir="/opt/custom/smf" - - # Install manifest files if needed. - for fname in api master minion syndic; do - # Skip if not meant to be installed - [ $fname = "api" ] && \ - ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - svcs network/salt-$fname > /dev/null 2>&1 - if [ $? -eq 1 ]; then - if [ ! -f "$_TEMP_CONFIG_DIR/salt-$fname.xml" ]; then - # shellcheck disable=SC2086 - curl $_CURL_ARGS -s -o "$_TEMP_CONFIG_DIR/salt-$fname.xml" -L \ - "https://raw.githubusercontent.com/saltstack/salt/develop/pkg/smartos/salt-$fname.xml" - fi - svccfg import "$_TEMP_CONFIG_DIR/salt-$fname.xml" - if [ "${VIRTUAL_TYPE}" = "global" ]; then - if [ ! -d "$smf_dir" ]; then - mkdir -p "$smf_dir" || return 1 - fi - if [ ! -f "$smf_dir/salt-$fname.xml" ]; then - __copyfile "$_TEMP_CONFIG_DIR/salt-$fname.xml" "$smf_dir/" || return 1 - fi - fi - fi - done - - return 0 -} - -install_smartos_git_post() { - smf_dir="/opt/custom/smf" - - # Install manifest files if needed. - for fname in api master minion syndic; do - # Skip if not meant to be installed - [ $fname = "api" ] && \ - ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - svcs "network/salt-$fname" > /dev/null 2>&1 - if [ $? -eq 1 ]; then - svccfg import "${_SALT_GIT_CHECKOUT_DIR}/pkg/smartos/salt-$fname.xml" - if [ "${VIRTUAL_TYPE}" = "global" ]; then - if [ ! -d $smf_dir ]; then - mkdir -p "$smf_dir" - fi - if [ ! -f "$smf_dir/salt-$fname.xml" ]; then - __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/smartos/salt-$fname.xml" "$smf_dir/" - fi - fi - fi - done - - return 0 -} - -install_smartos_restart_daemons() { - [ $_START_DAEMONS -eq $BS_FALSE ] && return - - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - # Stop if running && Start service - svcadm disable salt-$fname > /dev/null 2>&1 - svcadm enable salt-$fname - done - - return 0 -} -# -# Ended SmartOS Install Functions -# -####################################################################################################################### - -####################################################################################################################### -# -# openSUSE Install Functions. -# -__ZYPPER_REQUIRES_REPLACE_FILES=-1 - -__set_suse_pkg_repo() { - - # Set distro repo variable - if [ "${DISTRO_MAJOR_VERSION}" -gt 2015 ]; then - DISTRO_REPO="openSUSE_Tumbleweed" - elif [ "${DISTRO_MAJOR_VERSION}" -ge 42 ] || [ "${DISTRO_MAJOR_VERSION}" -eq 15 ]; then - DISTRO_REPO="openSUSE_Leap_${DISTRO_MAJOR_VERSION}.${DISTRO_MINOR_VERSION}" - else - DISTRO_REPO="SLE_${DISTRO_MAJOR_VERSION}_SP${SUSE_PATCHLEVEL}" - fi - - if [ "$_DOWNSTREAM_PKG_REPO" -eq $BS_TRUE ]; then - suse_pkg_url_base="https://download.opensuse.org/repositories/systemsmanagement:/saltstack" - suse_pkg_url_path="${DISTRO_REPO}/systemsmanagement:saltstack.repo" - else - suse_pkg_url_base="${HTTP_VAL}://repo.saltstack.com/opensuse" - suse_pkg_url_path="${DISTRO_REPO}/systemsmanagement:saltstack:products.repo" - fi - SUSE_PKG_URL="$suse_pkg_url_base/$suse_pkg_url_path" -} - -__check_and_refresh_suse_pkg_repo() { - # Check to see if systemsmanagement_saltstack exists - __zypper repos | grep -q systemsmanagement_saltstack - - if [ $? -eq 1 ]; then - # zypper does not yet know anything about systemsmanagement_saltstack - __zypper addrepo --refresh "${SUSE_PKG_URL}" || return 1 - fi -} - -__version_lte() { - if ! __check_command_exists python; then - zypper zypper --non-interactive install --replacefiles --auto-agree-with-licenses python || \ - zypper zypper --non-interactive install --auto-agree-with-licenses python || return 1 - fi - - if [ "$(python -c 'import sys; V1=tuple([int(i) for i in sys.argv[1].split(".")]); V2=tuple([int(i) for i in sys.argv[2].split(".")]); print V1<=V2' "$1" "$2")" = "True" ]; then - __ZYPPER_REQUIRES_REPLACE_FILES=${BS_TRUE} - else - __ZYPPER_REQUIRES_REPLACE_FILES=${BS_FALSE} - fi -} - -__zypper() { - # Check if any zypper process is running before calling zypper again. - # This is useful when a zypper call is part of a boot process and will - # wait until the zypper process is finished, such as on AWS AMIs. - while pgrep -l zypper; do - sleep 1 - done - - zypper --non-interactive "${@}"; return $? -} - -__zypper_install() { - if [ "${__ZYPPER_REQUIRES_REPLACE_FILES}" = "-1" ]; then - __version_lte "1.10.4" "$(zypper --version | awk '{ print $2 }')" - fi - if [ "${__ZYPPER_REQUIRES_REPLACE_FILES}" = "${BS_TRUE}" ]; then - # In case of file conflicts replace old files. - # Option present in zypper 1.10.4 and newer: - # https://github.com/openSUSE/zypper/blob/95655728d26d6d5aef7796b675f4cc69bc0c05c0/package/zypper.changes#L253 - __zypper install --auto-agree-with-licenses --replacefiles "${@}"; return $? - else - __zypper install --auto-agree-with-licenses "${@}"; return $? - fi -} - -__opensuse_prep_install() { - # DRY function for common installation preparatory steps for SUSE - if [ $_DISABLE_REPOS -eq $BS_FALSE ]; then - # Is the repository already known - __set_suse_pkg_repo - # Check zypper repos and refresh if necessary - __check_and_refresh_suse_pkg_repo - fi - - __zypper --gpg-auto-import-keys refresh - - # shellcheck disable=SC2181 - if [ $? -ne 0 ] && [ $? -ne 4 ]; then - # If the exit code is not 0, and it's not 4 (failed to update a - # repository) return a failure. Otherwise continue. - return 1 - fi - - if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then - __zypper --gpg-auto-import-keys update || return 1 - fi -} - -install_opensuse_stable_deps() { - __opensuse_prep_install || return 1 - - if [ "$DISTRO_MAJOR_VERSION" -eq 12 ] && [ "$DISTRO_MINOR_VERSION" -eq 3 ]; then - # Because patterns-openSUSE-minimal_base-conflicts conflicts with python, lets remove the first one - __zypper remove patterns-openSUSE-minimal_base-conflicts - fi - - # YAML module is used for generating custom master/minion configs - # requests is still used by many salt modules - # Salt needs python-zypp installed in order to use the zypper module - __PACKAGES="python-PyYAML python-requests python-zypp" - - # shellcheck disable=SC2086 - __zypper_install ${__PACKAGES} || return 1 - - if [ "${_EXTRA_PACKAGES}" != "" ]; then - echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" - # shellcheck disable=SC2086 - __zypper_install ${_EXTRA_PACKAGES} || return 1 - fi - - return 0 -} - -install_opensuse_git_deps() { - if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ] && ! __check_command_exists update-ca-certificates; then - __zypper_install ca-certificates || return 1 - fi - - install_opensuse_stable_deps || return 1 - - if ! __check_command_exists git; then - __zypper_install git || return 1 - fi - - __zypper_install patch || return 1 - - __git_clone_and_checkout || return 1 - - __PACKAGES="libzmq5 python-Jinja2 python-m2crypto python-msgpack-python python-pycrypto python-pyzmq python-xml python-futures" - - if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then - # We're on the develop branch, install whichever tornado is on the requirements file - __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" - if [ "${__REQUIRED_TORNADO}" != "" ]; then - __PACKAGES="${__PACKAGES} python-tornado" - fi - fi - - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} python-apache-libcloud" - fi - - # shellcheck disable=SC2086 - __zypper_install ${__PACKAGES} || return 1 - - # Let's trigger config_salt() - if [ "$_TEMP_CONFIG_DIR" = "null" ]; then - _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" - CONFIG_SALT_FUNC="config_salt" - fi - - return 0 -} - -install_opensuse_stable() { - __PACKAGES="" - - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ];then - __PACKAGES="${__PACKAGES} salt-cloud" - fi - if [ "$_INSTALL_MASTER" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} salt-master" - fi - if [ "$_INSTALL_MINION" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} salt-minion" - fi - if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} salt-syndic" - fi - - # shellcheck disable=SC2086 - __zypper_install $__PACKAGES || return 1 - - return 0 -} - -install_opensuse_git() { - python setup.py ${SETUP_PY_INSTALL_ARGS} install --prefix=/usr || return 1 - return 0 -} - -install_opensuse_stable_post() { - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - if [ -f /bin/systemctl ]; then - systemctl is-enabled salt-$fname.service || (systemctl preset salt-$fname.service && systemctl enable salt-$fname.service) - sleep 1 - systemctl daemon-reload - continue - fi - - /sbin/chkconfig --add salt-$fname - /sbin/chkconfig salt-$fname on - done - - return 0 -} - -install_opensuse_git_post() { - for fname in api master minion syndic; do - # Skip if not meant to be installed - [ $fname = "api" ] && \ - ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - if [ -f /bin/systemctl ]; then - use_usr_lib=$BS_FALSE - - if [ "${DISTRO_MAJOR_VERSION}" -ge 15 ]; then - use_usr_lib=$BS_TRUE - fi - - if [ "${DISTRO_MAJOR_VERSION}" -eq 12 ] && [ -d "/usr/lib/systemd/" ]; then - use_usr_lib=$BS_TRUE - fi - - if [ "${use_usr_lib}" -eq $BS_TRUE ]; then - __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.service" "/usr/lib/systemd/system/salt-${fname}.service" - else - __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.service" "/lib/systemd/system/salt-${fname}.service" - fi - - continue - fi - - __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-$fname" "/etc/init.d/salt-$fname" - chmod +x /etc/init.d/salt-$fname - done - - install_opensuse_stable_post || return 1 - - return 0 -} - -install_opensuse_restart_daemons() { - [ $_START_DAEMONS -eq $BS_FALSE ] && return - - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - if [ -f /bin/systemctl ]; then - systemctl stop salt-$fname > /dev/null 2>&1 - systemctl start salt-$fname.service - continue - fi - - service salt-$fname stop > /dev/null 2>&1 - service salt-$fname start - done -} - -install_opensuse_check_services() { - if [ ! -f /bin/systemctl ]; then - # Not running systemd!? Don't check! - return 0 - fi - - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - __check_services_systemd salt-$fname > /dev/null 2>&1 || __check_services_systemd salt-$fname.service > /dev/null 2>&1 || return 1 - done - - return 0 -} -# -# End of openSUSE Install Functions. -# -####################################################################################################################### - -####################################################################################################################### -# -# openSUSE Leap 15 -# - -install_opensuse_15_stable_deps() { - __opensuse_prep_install || return 1 - - # SUSE only packages Salt for Python 3 on Leap 15 - # Py3 is the default bootstrap install for Leap 15 - # However, git installs might specify "-x python2" - if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 2 ]; then - PY_PKG_VER=2 - else - PY_PKG_VER=3 - fi - - # YAML module is used for generating custom master/minion configs - # requests is still used by many salt modules - __PACKAGES="python${PY_PKG_VER}-PyYAML python${PY_PKG_VER}-requests" - - # shellcheck disable=SC2086 - __zypper_install ${__PACKAGES} || return 1 - - if [ "${_EXTRA_PACKAGES}" != "" ]; then - echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" - # shellcheck disable=SC2086 - __zypper_install ${_EXTRA_PACKAGES} || return 1 - fi - - return 0 -} - -install_opensuse_15_git_deps() { - install_opensuse_15_stable_deps || return 1 - - if ! __check_command_exists git; then - __zypper_install git || return 1 - fi - - __git_clone_and_checkout || return 1 - - # Py3 is the default bootstrap install for Leap 15 - # However, git installs might specify "-x python2" - if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 2 ]; then - PY_PKG_VER=2 - - # This is required by some of the python2 packages below - __PACKAGES="libpython2_7-1_0 python2-futures python-ipaddress" - else - PY_PKG_VER=3 - __PACKAGES="" - fi - - __PACKAGES="${__PACKAGES} libzmq5 python${PY_PKG_VER}-Jinja2 python${PY_PKG_VER}-msgpack" - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-pycrypto python${PY_PKG_VER}-pyzmq" - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-xml" - - if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then - # We're on the develop branch, install whichever tornado is on the requirements file - __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" - if [ "${__REQUIRED_TORNADO}" != "" ]; then - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-tornado" - fi - fi - - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} python${PY_PKG_VER}-apache-libcloud" - fi - - # shellcheck disable=SC2086 - __zypper_install ${__PACKAGES} || return 1 - - # Let's trigger config_salt() - if [ "$_TEMP_CONFIG_DIR" = "null" ]; then - _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" - CONFIG_SALT_FUNC="config_salt" - fi - - return 0 -} - -install_opensuse_15_git() { - - # Py3 is the default bootstrap install for Leap 15 - if [ -n "$_PY_EXE" ]; then - _PYEXE=${_PY_EXE} - else - _PYEXE=python3 - fi - - ${_PYEXE} setup.py ${SETUP_PY_INSTALL_ARGS} install --prefix=/usr || return 1 - return 0 -} - -# -# End of openSUSE Leap 15 -# -####################################################################################################################### - -####################################################################################################################### -# -# SUSE Enterprise 12 -# - -install_suse_12_stable_deps() { - __opensuse_prep_install || return 1 - - # YAML module is used for generating custom master/minion configs - # requests is still used by many salt modules - # Salt needs python-zypp installed in order to use the zypper module - __PACKAGES="python-PyYAML python-requests python-zypp" - - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} python-apache-libcloud" - fi - - # shellcheck disable=SC2086,SC2090 - __zypper_install ${__PACKAGES} || return 1 - - # SLES 11 SP3 ships with both python-M2Crypto-0.22.* and python-m2crypto-0.21 and we will be asked which - # we want to install, even with --non-interactive. - # Let's try to install the higher version first and then the lower one in case of failure - __zypper_install 'python-M2Crypto>=0.22' || __zypper_install 'python-M2Crypto>=0.21' || return 1 - - if [ "${_EXTRA_PACKAGES}" != "" ]; then - echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" - # shellcheck disable=SC2086 - __zypper_install ${_EXTRA_PACKAGES} || return 1 - fi - - return 0 -} - -install_suse_12_git_deps() { - install_suse_12_stable_deps || return 1 - - if ! __check_command_exists git; then - __zypper_install git-core || return 1 - fi - - __git_clone_and_checkout || return 1 - - __PACKAGES="" - # shellcheck disable=SC2089 - __PACKAGES="${__PACKAGES} libzmq4 python-Jinja2 python-msgpack-python python-pycrypto" - __PACKAGES="${__PACKAGES} python-pyzmq python-xml" - - if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then - # We're on the develop branch, install whichever tornado is on the requirements file - __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" - if [ "${__REQUIRED_TORNADO}" != "" ]; then - __PACKAGES="${__PACKAGES} python-tornado" - fi - fi - - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} python-apache-libcloud" - fi - - # shellcheck disable=SC2086 - __zypper_install ${__PACKAGES} || return 1 - - # Let's trigger config_salt() - if [ "$_TEMP_CONFIG_DIR" = "null" ]; then - _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" - CONFIG_SALT_FUNC="config_salt" - fi - - return 0 -} - -install_suse_12_stable() { - install_opensuse_stable || return 1 - return 0 -} - -install_suse_12_git() { - install_opensuse_git || return 1 - return 0 -} - -install_suse_12_stable_post() { - install_opensuse_stable_post || return 1 - return 0 -} - -install_suse_12_git_post() { - install_opensuse_git_post || return 1 - return 0 -} - -install_suse_12_restart_daemons() { - install_opensuse_restart_daemons || return 1 - return 0 -} - -# -# End of SUSE Enterprise 12 -# -####################################################################################################################### - -####################################################################################################################### -# -# SUSE Enterprise 11 -# - -install_suse_11_stable_deps() { - __opensuse_prep_install || return 1 - - # YAML module is used for generating custom master/minion configs - __PACKAGES="python-PyYAML" - - # shellcheck disable=SC2086,SC2090 - __zypper_install ${__PACKAGES} || return 1 - - # SLES 11 SP3 ships with both python-M2Crypto-0.22.* and python-m2crypto-0.21 and we will be asked which - # we want to install, even with --non-interactive. - # Let's try to install the higher version first and then the lower one in case of failure - __zypper_install 'python-M2Crypto>=0.22' || __zypper_install 'python-M2Crypto>=0.21' || return 1 - - if [ "${_EXTRA_PACKAGES}" != "" ]; then - echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" - # shellcheck disable=SC2086 - __zypper_install ${_EXTRA_PACKAGES} || return 1 - fi - - return 0 -} - -install_suse_11_git_deps() { - install_suse_11_stable_deps || return 1 - - if ! __check_command_exists git; then - __zypper_install git || return 1 - fi - - __git_clone_and_checkout || return 1 - - __PACKAGES="" - # shellcheck disable=SC2089 - __PACKAGES="${__PACKAGES} libzmq4 python-Jinja2 python-msgpack-python python-pycrypto" - __PACKAGES="${__PACKAGES} python-pyzmq python-xml python-zypp" - - if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then - # We're on the develop branch, install whichever tornado is on the requirements file - __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" - if [ "${__REQUIRED_TORNADO}" != "" ]; then - __PACKAGES="${__PACKAGES} python-tornado" - fi - fi - - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then - __PACKAGES="${__PACKAGES} python-apache-libcloud" - fi - - # shellcheck disable=SC2086 - __zypper_install ${__PACKAGES} || return 1 - - # Let's trigger config_salt() - if [ "$_TEMP_CONFIG_DIR" = "null" ]; then - _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" - CONFIG_SALT_FUNC="config_salt" - fi - - return 0 -} - -install_suse_11_stable() { - install_opensuse_stable || return 1 - return 0 -} - -install_suse_11_git() { - install_opensuse_git || return 1 - return 0 -} - -install_suse_11_stable_post() { - install_opensuse_stable_post || return 1 - return 0 -} - -install_suse_11_git_post() { - install_opensuse_git_post || return 1 - return 0 -} - -install_suse_11_restart_daemons() { - install_opensuse_restart_daemons || return 1 - return 0 -} - - -# -# End of SUSE Enterprise 11 -# -####################################################################################################################### - -####################################################################################################################### -# -# SUSE Enterprise General Functions -# - -# Used for both SLE 11 and 12 -install_suse_check_services() { - if [ ! -f /bin/systemctl ]; then - # Not running systemd!? Don't check! - return 0 - fi - - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - __check_services_systemd salt-$fname || return 1 - done - - return 0 -} - -# -# End of SUSE Enterprise General Functions -# -####################################################################################################################### - -####################################################################################################################### -# -# Gentoo Install Functions. -# -__autounmask() { - emerge --autounmask-write --autounmask-only "${@}"; return $? -} - -__emerge() { - if [ "$_GENTOO_USE_BINHOST" -eq $BS_TRUE ]; then - emerge --getbinpkg "${@}"; return $? - fi - emerge "${@}"; return $? -} - -__gentoo_config_protection() { - # usually it's a good thing to have config files protected by portage, but - # in this case this would require to interrupt the bootstrapping script at - # this point, manually merge the changes using etc-update/dispatch-conf/ - # cfg-update and then restart the bootstrapping script, so instead we allow - # at this point to modify certain config files directly - export CONFIG_PROTECT_MASK="${CONFIG_PROTECT_MASK:-} /etc/portage/package.accept_keywords /etc/portage/package.keywords /etc/portage/package.license /etc/portage/package.unmask /etc/portage/package.use" - - # emerge currently won't write to files that aren't there, so we need to ensure their presence - touch /etc/portage/package.accept_keywords /etc/portage/package.keywords /etc/portage/package.license /etc/portage/package.unmask /etc/portage/package.use -} - -__gentoo_pre_dep() { - if [ "$_ECHO_DEBUG" -eq $BS_TRUE ]; then - if __check_command_exists eix; then - eix-sync - else - emerge --sync - fi - else - if __check_command_exists eix; then - eix-sync -q - else - emerge --sync --quiet - fi - fi - if [ ! -d /etc/portage ]; then - mkdir /etc/portage - fi -} - -__gentoo_post_dep() { - # ensures dev-lib/crypto++ compiles happily - __emerge --oneshot 'sys-devel/libtool' - # the -o option asks it to emerge the deps but not the package. - __gentoo_config_protection - - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then - __autounmask 'dev-python/libcloud' - __emerge -v 'dev-python/libcloud' - fi - - __autounmask 'dev-python/requests' - __autounmask 'app-admin/salt' - - __emerge -vo 'dev-python/requests' - __emerge -vo 'app-admin/salt' - - if [ "${_EXTRA_PACKAGES}" != "" ]; then - echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" - # shellcheck disable=SC2086 - __autounmask ${_EXTRA_PACKAGES} || return 1 - # shellcheck disable=SC2086 - __emerge -v ${_EXTRA_PACKAGES} || return 1 - fi -} - -install_gentoo_deps() { - __gentoo_pre_dep || return 1 - __gentoo_post_dep || return 1 -} - -install_gentoo_git_deps() { - __gentoo_pre_dep || return 1 - __gentoo_post_dep || return 1 -} - -install_gentoo_stable() { - __gentoo_config_protection - __emerge -v 'app-admin/salt' || return 1 -} - -install_gentoo_git() { - __gentoo_config_protection - __emerge -v '=app-admin/salt-9999' || return 1 -} - -install_gentoo_post() { - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - if [ -d "/run/systemd/system" ]; then - systemctl enable salt-$fname.service - systemctl start salt-$fname.service - else - rc-update add salt-$fname default - /etc/init.d/salt-$fname start - fi - done -} - -install_gentoo_restart_daemons() { - [ $_START_DAEMONS -eq $BS_FALSE ] && return - - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - if [ -d "/run/systemd/system" ]; then - systemctl stop salt-$fname > /dev/null 2>&1 - systemctl start salt-$fname.service - else - /etc/init.d/salt-$fname stop > /dev/null 2>&1 - /etc/init.d/salt-$fname start - fi - done -} - -install_gentoo_check_services() { - if [ ! -d "/run/systemd/system" ]; then - # Not running systemd!? Don't check! - return 0 - fi - - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - __check_services_systemd salt-$fname || return 1 - done - - return 0 -} -# -# End of Gentoo Install Functions. -# -####################################################################################################################### - -####################################################################################################################### -# -# VoidLinux Install Functions -# -install_voidlinux_stable_deps() { - if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then - xbps-install -Suy || return 1 - fi - - if [ "${_EXTRA_PACKAGES}" != "" ]; then - echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" - xbps-install -Suy "${_EXTRA_PACKAGES}" || return 1 - fi - - return 0 -} - -install_voidlinux_stable() { - xbps-install -Suy salt || return 1 - return 0 -} - -install_voidlinux_stable_post() { - for fname in master minion syndic; do - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - ln -s /etc/sv/salt-$fname /var/service/. - done -} - -install_voidlinux_restart_daemons() { - [ $_START_DAEMONS -eq $BS_FALSE ] && return - - for fname in master minion syndic; do - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - sv restart salt-$fname - done -} - -install_voidlinux_check_services() { - for fname in master minion syndic; do - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - [ -e /var/service/salt-$fname ] || return 1 - done - - return 0 -} - -daemons_running_voidlinux() { - [ "$_START_DAEMONS" -eq $BS_FALSE ] && return 0 - - FAILED_DAEMONS=0 - for fname in master minion syndic; do - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - if [ "$(sv status salt-$fname | grep run)" = "" ]; then - echoerror "salt-$fname was not found running" - FAILED_DAEMONS=$((FAILED_DAEMONS + 1)) - fi - done - - return $FAILED_DAEMONS -} -# -# Ended VoidLinux Install Functions -# -####################################################################################################################### - -####################################################################################################################### -# -# OS X / Darwin Install Functions -# - -__macosx_get_packagesite() { - DARWIN_ARCH="x86_64" - - __PY_VERSION_REPO="py2" - if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then - __PY_VERSION_REPO="py3" - fi - - PKG="salt-${STABLE_REV}-${__PY_VERSION_REPO}-${DARWIN_ARCH}.pkg" - SALTPKGCONFURL="https://repo.saltstack.com/osx/${PKG}" -} - -# Using a separate conf step to head for idempotent install... -__configure_macosx_pkg_details() { - __macosx_get_packagesite || return 1 - return 0 -} - -install_macosx_stable_deps() { - __configure_macosx_pkg_details || return 1 - return 0 -} - -install_macosx_git_deps() { - install_macosx_stable_deps || return 1 - - __fetch_url "/tmp/get-pip.py" "https://bootstrap.pypa.io/get-pip.py" || return 1 - - if [ -n "$_PY_EXE" ]; then - _PYEXE=${_PY_EXE} - else - _PYEXE=python2.7 - fi - - # Install PIP - $_PYEXE /tmp/get-pip.py || return 1 - - __git_clone_and_checkout || return 1 - - __PIP_REQUIREMENTS="dev_python27.txt" - if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then - __PIP_REQUIREMENTS="dev_python34.txt" - fi - - requirements_file="${_SALT_GIT_CHECKOUT_DIR}/requirements/${__PIP_REQUIREMENTS}" - pip install -U -r "${requirements_file}" --install-option="--prefix=/opt/salt" || return 1 - - return 0 -} - -install_macosx_stable() { - install_macosx_stable_deps || return 1 - - /usr/bin/curl "${SALTPKGCONFURL}" > "/tmp/${PKG}" || return 1 - - /usr/sbin/installer -pkg "/tmp/${PKG}" -target / || return 1 - - return 0 -} - -install_macosx_git() { - - if [ -n "$_PY_EXE" ]; then - _PYEXE=${_PY_EXE} - else - _PYEXE=python2.7 - fi - - if [ -f "${_SALT_GIT_CHECKOUT_DIR}/salt/syspaths.py" ]; then - $_PYEXE setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install --prefix=/opt/salt || return 1 - else - $_PYEXE setup.py ${SETUP_PY_INSTALL_ARGS} install --prefix=/opt/salt || return 1 - fi - - return 0 -} - -install_macosx_stable_post() { - if [ ! -f /etc/paths.d/salt ]; then - print "%s\n" "/opt/salt/bin" "/usr/local/sbin" > /etc/paths.d/salt - fi - - # shellcheck disable=SC1091 - . /etc/profile - - return 0 -} - -install_macosx_git_post() { - install_macosx_stable_post || return 1 - return 0 -} - -install_macosx_restart_daemons() { - [ $_START_DAEMONS -eq $BS_FALSE ] && return - - /bin/launchctl unload -w /Library/LaunchDaemons/com.saltstack.salt.minion.plist || return 1 - /bin/launchctl load -w /Library/LaunchDaemons/com.saltstack.salt.minion.plist || return 1 - - return 0 -} -# -# Ended OS X / Darwin Install Functions -# -####################################################################################################################### - -####################################################################################################################### -# -# Default minion configuration function. Matches ANY distribution as long as -# the -c options is passed. -# -config_salt() { - # If the configuration directory is not passed, return - [ "$_TEMP_CONFIG_DIR" = "null" ] && return - - if [ "$_CONFIG_ONLY" -eq $BS_TRUE ]; then - echowarn "Passing -C (config only) option implies -F (forced overwrite)." - - if [ "$_FORCE_OVERWRITE" -ne $BS_TRUE ]; then - echowarn "Overwriting configs in 11 seconds!" - sleep 11 - _FORCE_OVERWRITE=$BS_TRUE - fi - fi - - # Let's create the necessary directories - [ -d "$_SALT_ETC_DIR" ] || mkdir "$_SALT_ETC_DIR" || return 1 - [ -d "$_PKI_DIR" ] || (mkdir -p "$_PKI_DIR" && chmod 700 "$_PKI_DIR") || return 1 - - # If -C or -F was passed, we don't need a .bak file for the config we're updating - # This is used in the custom master/minion config file checks below - CREATE_BAK=$BS_TRUE - if [ "$_FORCE_OVERWRITE" -eq $BS_TRUE ]; then - CREATE_BAK=$BS_FALSE - fi - - CONFIGURED_ANYTHING=$BS_FALSE - - # Copy the grains file if found - if [ -f "$_TEMP_CONFIG_DIR/grains" ]; then - echodebug "Moving provided grains file from $_TEMP_CONFIG_DIR/grains to $_SALT_ETC_DIR/grains" - __movefile "$_TEMP_CONFIG_DIR/grains" "$_SALT_ETC_DIR/grains" || return 1 - CONFIGURED_ANYTHING=$BS_TRUE - fi - - if [ "$_INSTALL_MINION" -eq $BS_TRUE ] || \ - [ "$_CONFIG_ONLY" -eq $BS_TRUE ] || [ "$_CUSTOM_MINION_CONFIG" != "null" ]; then - # Create the PKI directory - [ -d "$_PKI_DIR/minion" ] || (mkdir -p "$_PKI_DIR/minion" && chmod 700 "$_PKI_DIR/minion") || return 1 - - # Check to see if a custom minion config json dict was provided - if [ "$_CUSTOM_MINION_CONFIG" != "null" ]; then - - # Check if a minion config file already exists and move to .bak if needed - if [ -f "$_SALT_ETC_DIR/minion" ] && [ "$CREATE_BAK" -eq "$BS_TRUE" ]; then - __movefile "$_SALT_ETC_DIR/minion" "$_SALT_ETC_DIR/minion.bak" $BS_TRUE || return 1 - CONFIGURED_ANYTHING=$BS_TRUE - fi - - # Overwrite/create the config file with the yaml string - __overwriteconfig "$_SALT_ETC_DIR/minion" "$_CUSTOM_MINION_CONFIG" || return 1 - CONFIGURED_ANYTHING=$BS_TRUE - - # Copy the minions configuration if found - # Explicitly check for custom master config to avoid moving the minion config - elif [ -f "$_TEMP_CONFIG_DIR/minion" ] && [ "$_CUSTOM_MASTER_CONFIG" = "null" ]; then - __movefile "$_TEMP_CONFIG_DIR/minion" "$_SALT_ETC_DIR" "$_FORCE_OVERWRITE" || return 1 - CONFIGURED_ANYTHING=$BS_TRUE - fi - - # Copy the minion's keys if found - if [ -f "$_TEMP_CONFIG_DIR/minion.pem" ]; then - __movefile "$_TEMP_CONFIG_DIR/minion.pem" "$_PKI_DIR/minion/" "$_FORCE_OVERWRITE" || return 1 - chmod 400 "$_PKI_DIR/minion/minion.pem" || return 1 - CONFIGURED_ANYTHING=$BS_TRUE - fi - if [ -f "$_TEMP_CONFIG_DIR/minion.pub" ]; then - __movefile "$_TEMP_CONFIG_DIR/minion.pub" "$_PKI_DIR/minion/" "$_FORCE_OVERWRITE" || return 1 - chmod 664 "$_PKI_DIR/minion/minion.pub" || return 1 - CONFIGURED_ANYTHING=$BS_TRUE - fi - # For multi-master-pki, copy the master_sign public key if found - if [ -f "$_TEMP_CONFIG_DIR/master_sign.pub" ]; then - __movefile "$_TEMP_CONFIG_DIR/master_sign.pub" "$_PKI_DIR/minion/" || return 1 - chmod 664 "$_PKI_DIR/minion/master_sign.pub" || return 1 - CONFIGURED_ANYTHING=$BS_TRUE - fi - fi - - # only (re)place master or syndic configs if -M (install master) or -S - # (install syndic) specified - OVERWRITE_MASTER_CONFIGS=$BS_FALSE - if [ "$_INSTALL_MASTER" -eq $BS_TRUE ] && [ "$_CONFIG_ONLY" -eq $BS_TRUE ]; then - OVERWRITE_MASTER_CONFIGS=$BS_TRUE - fi - if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ] && [ "$_CONFIG_ONLY" -eq $BS_TRUE ]; then - OVERWRITE_MASTER_CONFIGS=$BS_TRUE - fi - - if [ "$_INSTALL_MASTER" -eq $BS_TRUE ] || [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ] || [ "$OVERWRITE_MASTER_CONFIGS" -eq $BS_TRUE ] || [ "$_CUSTOM_MASTER_CONFIG" != "null" ]; then - # Create the PKI directory - [ -d "$_PKI_DIR/master" ] || (mkdir -p "$_PKI_DIR/master" && chmod 700 "$_PKI_DIR/master") || return 1 - - # Check to see if a custom master config json dict was provided - if [ "$_CUSTOM_MASTER_CONFIG" != "null" ]; then - - # Check if a master config file already exists and move to .bak if needed - if [ -f "$_SALT_ETC_DIR/master" ] && [ "$CREATE_BAK" -eq "$BS_TRUE" ]; then - __movefile "$_SALT_ETC_DIR/master" "$_SALT_ETC_DIR/master.bak" $BS_TRUE || return 1 - CONFIGURED_ANYTHING=$BS_TRUE - fi - - # Overwrite/create the config file with the yaml string - __overwriteconfig "$_SALT_ETC_DIR/master" "$_CUSTOM_MASTER_CONFIG" || return 1 - CONFIGURED_ANYTHING=$BS_TRUE - - # Copy the masters configuration if found - elif [ -f "$_TEMP_CONFIG_DIR/master" ]; then - __movefile "$_TEMP_CONFIG_DIR/master" "$_SALT_ETC_DIR" || return 1 - CONFIGURED_ANYTHING=$BS_TRUE - fi - - # Copy the master's keys if found - if [ -f "$_TEMP_CONFIG_DIR/master.pem" ]; then - __movefile "$_TEMP_CONFIG_DIR/master.pem" "$_PKI_DIR/master/" || return 1 - chmod 400 "$_PKI_DIR/master/master.pem" || return 1 - CONFIGURED_ANYTHING=$BS_TRUE - fi - if [ -f "$_TEMP_CONFIG_DIR/master.pub" ]; then - __movefile "$_TEMP_CONFIG_DIR/master.pub" "$_PKI_DIR/master/" || return 1 - chmod 664 "$_PKI_DIR/master/master.pub" || return 1 - CONFIGURED_ANYTHING=$BS_TRUE - fi - fi - - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then - # Recursively copy salt-cloud configs with overwriting if necessary - for file in "$_TEMP_CONFIG_DIR"/cloud*; do - if [ -f "$file" ]; then - __copyfile "$file" "$_SALT_ETC_DIR" || return 1 - elif [ -d "$file" ]; then - subdir="$(basename "$file")" - mkdir -p "$_SALT_ETC_DIR/$subdir" - for file_d in "$_TEMP_CONFIG_DIR/$subdir"/*; do - if [ -f "$file_d" ]; then - __copyfile "$file_d" "$_SALT_ETC_DIR/$subdir" || return 1 - fi - done - fi - done - fi - - if [ "$_CONFIG_ONLY" -eq $BS_TRUE ] && [ $CONFIGURED_ANYTHING -eq $BS_FALSE ]; then - echowarn "No configuration or keys were copied over. No configuration was done!" - exit 0 - fi - - return 0 -} -# -# Ended Default Configuration function -# -####################################################################################################################### - -####################################################################################################################### -# -# Default salt master minion keys pre-seed function. Matches ANY distribution -# as long as the -k option is passed. -# -preseed_master() { - # Create the PKI directory - - if [ "$(find "$_TEMP_KEYS_DIR" -maxdepth 1 -type f | wc -l)" -lt 1 ]; then - echoerror "No minion keys were uploaded. Unable to pre-seed master" - return 1 - fi - - SEED_DEST="$_PKI_DIR/master/minions" - [ -d "$SEED_DEST" ] || (mkdir -p "$SEED_DEST" && chmod 700 "$SEED_DEST") || return 1 - - for keyfile in "$_TEMP_KEYS_DIR"/*; do - keyfile=$(basename "${keyfile}") - src_keyfile="${_TEMP_KEYS_DIR}/${keyfile}" - dst_keyfile="${SEED_DEST}/${keyfile}" - - # If it's not a file, skip to the next - [ ! -f "$src_keyfile" ] && continue - - __movefile "$src_keyfile" "$dst_keyfile" || return 1 - chmod 664 "$dst_keyfile" || return 1 - done - - return 0 -} -# -# Ended Default Salt Master Pre-Seed minion keys function -# -####################################################################################################################### - -####################################################################################################################### -# -# This function checks if all of the installed daemons are running or not. -# -daemons_running() { - [ "$_START_DAEMONS" -eq $BS_FALSE ] && return 0 - - FAILED_DAEMONS=0 - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - # shellcheck disable=SC2009 - if [ "${DISTRO_NAME}" = "SmartOS" ]; then - if [ "$(svcs -Ho STA salt-$fname)" != "ON" ]; then - echoerror "salt-$fname was not found running" - FAILED_DAEMONS=$((FAILED_DAEMONS + 1)) - fi - elif [ "$(ps wwwaux | grep -v grep | grep salt-$fname)" = "" ]; then - echoerror "salt-$fname was not found running" - FAILED_DAEMONS=$((FAILED_DAEMONS + 1)) - fi - done - - return $FAILED_DAEMONS -} -# -# Ended daemons running check function -# -####################################################################################################################### - -#====================================================================================================================== -# LET'S PROCEED WITH OUR INSTALLATION -#====================================================================================================================== - -# Let's get the dependencies install function -DEP_FUNC_NAMES="" -if [ ${_NO_DEPS} -eq $BS_FALSE ]; then - DEP_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_deps" - DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_deps" - DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_deps" - DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_deps" - DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}_deps" - DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}_deps" -fi - -DEPS_INSTALL_FUNC="null" -for FUNC_NAME in $(__strip_duplicates "$DEP_FUNC_NAMES"); do - if __function_defined "$FUNC_NAME"; then - DEPS_INSTALL_FUNC="$FUNC_NAME" - break - fi -done -echodebug "DEPS_INSTALL_FUNC=${DEPS_INSTALL_FUNC}" - -# Let's get the Salt config function -CONFIG_FUNC_NAMES="config_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_salt" -CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_salt" -CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_salt" -CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_salt" -CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}_${ITYPE}_salt" -CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}_salt" -CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_salt" - -CONFIG_SALT_FUNC="null" -for FUNC_NAME in $(__strip_duplicates "$CONFIG_FUNC_NAMES"); do - if __function_defined "$FUNC_NAME"; then - CONFIG_SALT_FUNC="$FUNC_NAME" - break - fi -done -echodebug "CONFIG_SALT_FUNC=${CONFIG_SALT_FUNC}" - -# Let's get the pre-seed master function -PRESEED_FUNC_NAMES="preseed_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_master" -PRESEED_FUNC_NAMES="$PRESEED_FUNC_NAMES preseed_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_master" -PRESEED_FUNC_NAMES="$PRESEED_FUNC_NAMES preseed_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_master" -PRESEED_FUNC_NAMES="$PRESEED_FUNC_NAMES preseed_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_master" -PRESEED_FUNC_NAMES="$PRESEED_FUNC_NAMES preseed_${DISTRO_NAME_L}_${ITYPE}_master" -PRESEED_FUNC_NAMES="$PRESEED_FUNC_NAMES preseed_${DISTRO_NAME_L}_master" -PRESEED_FUNC_NAMES="$PRESEED_FUNC_NAMES preseed_master" - -PRESEED_MASTER_FUNC="null" -for FUNC_NAME in $(__strip_duplicates "$PRESEED_FUNC_NAMES"); do - if __function_defined "$FUNC_NAME"; then - PRESEED_MASTER_FUNC="$FUNC_NAME" - break - fi -done -echodebug "PRESEED_MASTER_FUNC=${PRESEED_MASTER_FUNC}" - -# Let's get the install function -INSTALL_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}" -INSTALL_FUNC_NAMES="$INSTALL_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}" -INSTALL_FUNC_NAMES="$INSTALL_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}" - -INSTALL_FUNC="null" -for FUNC_NAME in $(__strip_duplicates "$INSTALL_FUNC_NAMES"); do - if __function_defined "$FUNC_NAME"; then - INSTALL_FUNC="$FUNC_NAME" - break - fi -done -echodebug "INSTALL_FUNC=${INSTALL_FUNC}" - -# Let's get the post install function -POST_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_post" -POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_post" -POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_post" -POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_post" -POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}_post" -POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}_post" - -POST_INSTALL_FUNC="null" -for FUNC_NAME in $(__strip_duplicates "$POST_FUNC_NAMES"); do - if __function_defined "$FUNC_NAME"; then - POST_INSTALL_FUNC="$FUNC_NAME" - break - fi -done -echodebug "POST_INSTALL_FUNC=${POST_INSTALL_FUNC}" - -# Let's get the start daemons install function -STARTDAEMONS_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_restart_daemons" -STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_restart_daemons" -STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_restart_daemons" -STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_restart_daemons" -STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}_restart_daemons" -STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}_restart_daemons" - -STARTDAEMONS_INSTALL_FUNC="null" -for FUNC_NAME in $(__strip_duplicates "$STARTDAEMONS_FUNC_NAMES"); do - if __function_defined "$FUNC_NAME"; then - STARTDAEMONS_INSTALL_FUNC="$FUNC_NAME" - break - fi -done -echodebug "STARTDAEMONS_INSTALL_FUNC=${STARTDAEMONS_INSTALL_FUNC}" - -# Let's get the daemons running check function. -DAEMONS_RUNNING_FUNC_NAMES="daemons_running_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}" -DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}" -DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}" -DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}" -DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running_${DISTRO_NAME_L}_${ITYPE}" -DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running_${DISTRO_NAME_L}" -DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running" - -DAEMONS_RUNNING_FUNC="null" -for FUNC_NAME in $(__strip_duplicates "$DAEMONS_RUNNING_FUNC_NAMES"); do - if __function_defined "$FUNC_NAME"; then - DAEMONS_RUNNING_FUNC="$FUNC_NAME" - break - fi -done -echodebug "DAEMONS_RUNNING_FUNC=${DAEMONS_RUNNING_FUNC}" - -# Let's get the check services function -if [ ${_DISABLE_SALT_CHECKS} -eq $BS_FALSE ]; then - CHECK_SERVICES_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_check_services" - CHECK_SERVICES_FUNC_NAMES="$CHECK_SERVICES_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_check_services" - CHECK_SERVICES_FUNC_NAMES="$CHECK_SERVICES_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_check_services" - CHECK_SERVICES_FUNC_NAMES="$CHECK_SERVICES_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_check_services" - CHECK_SERVICES_FUNC_NAMES="$CHECK_SERVICES_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}_check_services" - CHECK_SERVICES_FUNC_NAMES="$CHECK_SERVICES_FUNC_NAMES install_${DISTRO_NAME_L}_check_services" -else - CHECK_SERVICES_FUNC_NAMES="" -fi - -CHECK_SERVICES_FUNC="null" -for FUNC_NAME in $(__strip_duplicates "$CHECK_SERVICES_FUNC_NAMES"); do - if __function_defined "$FUNC_NAME"; then - CHECK_SERVICES_FUNC="$FUNC_NAME" - break - fi -done -echodebug "CHECK_SERVICES_FUNC=${CHECK_SERVICES_FUNC}" - -if [ ${_NO_DEPS} -eq $BS_FALSE ] && [ "$DEPS_INSTALL_FUNC" = "null" ]; then - echoerror "No dependencies installation function found. Exiting..." - exit 1 -fi - -if [ "$INSTALL_FUNC" = "null" ]; then - echoerror "No installation function found. Exiting..." - exit 1 -fi - - -# Install dependencies -if [ ${_NO_DEPS} -eq $BS_FALSE ] && [ $_CONFIG_ONLY -eq $BS_FALSE ]; then - # Only execute function is not in config mode only - echoinfo "Running ${DEPS_INSTALL_FUNC}()" - if ! ${DEPS_INSTALL_FUNC}; then - echoerror "Failed to run ${DEPS_INSTALL_FUNC}()!!!" - exit 1 - fi -fi - - -if [ "${ITYPE}" = "git" ] && [ ${_NO_DEPS} -eq ${BS_TRUE} ]; then - if ! __git_clone_and_checkout; then - echo "Failed to clone and checkout git repository." - exit 1 - fi -fi - - -# Triggering config_salt() if overwriting master or minion configs -if [ "$_CUSTOM_MASTER_CONFIG" != "null" ] || [ "$_CUSTOM_MINION_CONFIG" != "null" ]; then - if [ "$_TEMP_CONFIG_DIR" = "null" ]; then - _TEMP_CONFIG_DIR="$_SALT_ETC_DIR" - fi - - if [ ${_NO_DEPS} -eq $BS_FALSE ] && [ $_CONFIG_ONLY -eq $BS_TRUE ]; then - # Execute function to satisfy dependencies for configuration step - echoinfo "Running ${DEPS_INSTALL_FUNC}()" - if ! ${DEPS_INSTALL_FUNC}; then - echoerror "Failed to run ${DEPS_INSTALL_FUNC}()!!!" - exit 1 - fi - fi -fi - -# Configure Salt -if [ "$CONFIG_SALT_FUNC" != "null" ] && [ "$_TEMP_CONFIG_DIR" != "null" ]; then - echoinfo "Running ${CONFIG_SALT_FUNC}()" - if ! ${CONFIG_SALT_FUNC}; then - echoerror "Failed to run ${CONFIG_SALT_FUNC}()!!!" - exit 1 - fi -fi - -# Drop the master address if passed -if [ "$_SALT_MASTER_ADDRESS" != "null" ]; then - [ ! -d "$_SALT_ETC_DIR/minion.d" ] && mkdir -p "$_SALT_ETC_DIR/minion.d" - cat <<_eof > "$_SALT_ETC_DIR/minion.d/99-master-address.conf" -master: $_SALT_MASTER_ADDRESS -_eof -fi - -# Drop the minion id if passed -if [ "$_SALT_MINION_ID" != "null" ]; then - [ ! -d "$_SALT_ETC_DIR" ] && mkdir -p "$_SALT_ETC_DIR" - echo "$_SALT_MINION_ID" > "$_SALT_ETC_DIR/minion_id" -fi - -# Pre-seed master keys -if [ "$PRESEED_MASTER_FUNC" != "null" ] && [ "$_TEMP_KEYS_DIR" != "null" ]; then - echoinfo "Running ${PRESEED_MASTER_FUNC}()" - if ! ${PRESEED_MASTER_FUNC}; then - echoerror "Failed to run ${PRESEED_MASTER_FUNC}()!!!" - exit 1 - fi -fi - -# Install Salt -if [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then - # Only execute function is not in config mode only - echoinfo "Running ${INSTALL_FUNC}()" - if ! ${INSTALL_FUNC}; then - echoerror "Failed to run ${INSTALL_FUNC}()!!!" - exit 1 - fi -fi - -# Run any post install function. Only execute function if not in config mode only -if [ "$POST_INSTALL_FUNC" != "null" ] && [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then - echoinfo "Running ${POST_INSTALL_FUNC}()" - if ! ${POST_INSTALL_FUNC}; then - echoerror "Failed to run ${POST_INSTALL_FUNC}()!!!" - exit 1 - fi -fi - -# Run any check services function, Only execute function if not in config mode only -if [ "$CHECK_SERVICES_FUNC" != "null" ] && [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then - echoinfo "Running ${CHECK_SERVICES_FUNC}()" - if ! ${CHECK_SERVICES_FUNC}; then - echoerror "Failed to run ${CHECK_SERVICES_FUNC}()!!!" - exit 1 - fi -fi - -# Run any start daemons function -if [ "$STARTDAEMONS_INSTALL_FUNC" != "null" ] && [ ${_START_DAEMONS} -eq $BS_TRUE ]; then - echoinfo "Running ${STARTDAEMONS_INSTALL_FUNC}()" - echodebug "Waiting ${_SLEEP} seconds for processes to settle before checking for them" - sleep ${_SLEEP} - if ! ${STARTDAEMONS_INSTALL_FUNC}; then - echoerror "Failed to run ${STARTDAEMONS_INSTALL_FUNC}()!!!" - exit 1 - fi -fi - -# Check if the installed daemons are running or not -if [ "$DAEMONS_RUNNING_FUNC" != "null" ] && [ ${_START_DAEMONS} -eq $BS_TRUE ]; then - echoinfo "Running ${DAEMONS_RUNNING_FUNC}()" - echodebug "Waiting ${_SLEEP} seconds for processes to settle before checking for them" - sleep ${_SLEEP} # Sleep a little bit to let daemons start - if ! ${DAEMONS_RUNNING_FUNC}; then - echoerror "Failed to run ${DAEMONS_RUNNING_FUNC}()!!!" - - for fname in api master minion syndic; do - # Skip salt-api since the service should be opt-in and not necessarily started on boot - [ $fname = "api" ] && continue - - # Skip if not meant to be installed - [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue - [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue - [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - - if [ "$_ECHO_DEBUG" -eq $BS_FALSE ]; then - echoerror "salt-$fname was not found running. Pass '-D' to ${__ScriptName} when bootstrapping for additional debugging information..." - continue - fi - - [ ! -f "$_SALT_ETC_DIR/$fname" ] && [ $fname != "syndic" ] && echodebug "$_SALT_ETC_DIR/$fname does not exist" - - echodebug "Running salt-$fname by hand outputs: $(nohup salt-$fname -l debug)" - - [ ! -f /var/log/salt/$fname ] && echodebug "/var/log/salt/$fname does not exist. Can't cat its contents!" && continue - - echodebug "DAEMON LOGS for $fname:" - echodebug "$(cat /var/log/salt/$fname)" - echo - done - - echodebug "Running Processes:" - echodebug "$(ps auxwww)" - - exit 1 - fi -fi - -# Done! -if [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then - echoinfo "Salt installed!" -else - echoinfo "Salt configured!" -fi - -exit 0 - -# vim: set sts=4 ts=4 et From 1f93b93da6bcc92eb97c764b262e3dd6f98d6791 Mon Sep 17 00:00:00 2001 From: ch3ll Date: Mon, 4 Nov 2019 13:20:30 -0500 Subject: [PATCH 05/64] clarify tornado workaround only for git installs --- README.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 757645a..6bf2b57 100644 --- a/README.rst +++ b/README.rst @@ -213,9 +213,10 @@ Tornado 5/6 Workaround Salt does not support tornado>=5.0 currently. This support will not be added until the neon release. In order to work around this requirement on OSs that no longer have the tornado 4 package available in their repositories we are pip installing tornado<5.0 in the bootstrap script. This -requires the user to pass -P to the bootstrap script to ensure tornado is pip installed. If a user -does not pass this argument they will be warned that it is required for the tornado 5 workaround. -So far the OSs that are using this workaround are Debian 10, Centos 8 and Fedora 31. +requires the user to pass -P to the bootstrap script if installing via git to ensure tornado is pip +installed. If a user does not pass this argument they will be warned that it is required for the +tornado 5 workaround. So far the OSs that are using this workaround are Debian 10, Centos 8 and +Fedora 31. Supported Operating Systems --------------------------- From 8dd087a72bd52f3bc4b2a2613724003e45c5f153 Mon Sep 17 00:00:00 2001 From: ch3ll Date: Tue, 5 Nov 2019 09:52:55 -0500 Subject: [PATCH 06/64] move tornado warning to python3 --- README.rst | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/README.rst b/README.rst index 6bf2b57..18ff739 100644 --- a/README.rst +++ b/README.rst @@ -208,16 +208,6 @@ Installing the latest develop branch of Salt: curl -L https://bootstrap.saltstack.com | sudo sh -s -- git develop -Tornado 5/6 Workaround ----------------------- -Salt does not support tornado>=5.0 currently. This support will not be added until the neon -release. In order to work around this requirement on OSs that no longer have the tornado 4 package -available in their repositories we are pip installing tornado<5.0 in the bootstrap script. This -requires the user to pass -P to the bootstrap script if installing via git to ensure tornado is pip -installed. If a user does not pass this argument they will be warned that it is required for the -tornado 5 workaround. So far the OSs that are using this workaround are Debian 10, Centos 8 and -Fedora 31. - Supported Operating Systems --------------------------- @@ -362,7 +352,9 @@ Some distributions support installing Salt to use Python 3 instead of Python 2. this offering, while limited, is as follows: - CentOS 7 +- Centos 8 - Debian 9 +- Debian 10 - Fedora (only git installations) - Ubuntu 16.04 - Ubuntu 18.04 @@ -377,6 +369,16 @@ Installing the Python 3 packages for Salt is done via the ``-x`` option: See the ``-x`` option for more information. +Tornado 5/6 Workaround +---------------------- +Salt does not support tornado>=5.0 currently. This support will not be added until the neon +release. In order to work around this requirement on OSs that no longer have the tornado 4 package +available in their repositories we are pip installing tornado<5.0 in the bootstrap script. This +requires the user to pass -P to the bootstrap script if installing via git to ensure tornado is pip +installed. If a user does not pass this argument they will be warned that it is required for the +tornado 5 workaround. So far the OSs that are using this workaround are Debian 10, Centos 8 and +Fedora 31. + Testing ------- From ff3e42c9deae3b917671abe820a13524821e3c6d Mon Sep 17 00:00:00 2001 From: ch3ll Date: Tue, 5 Nov 2019 09:53:55 -0500 Subject: [PATCH 07/64] readd space --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index 18ff739..5b5a37e 100644 --- a/README.rst +++ b/README.rst @@ -208,6 +208,7 @@ Installing the latest develop branch of Salt: curl -L https://bootstrap.saltstack.com | sudo sh -s -- git develop + Supported Operating Systems --------------------------- From 49aa155631600fcb99e813c2042b2e5d3d5b44e3 Mon Sep 17 00:00:00 2001 From: ch3ll Date: Thu, 7 Nov 2019 12:36:42 -0500 Subject: [PATCH 08/64] Update supported platforms in README --- README.rst | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 5b5a37e..2f1c76f 100644 --- a/README.rst +++ b/README.rst @@ -213,9 +213,10 @@ Supported Operating Systems --------------------------- The salt-bootstrap script officially supports the distributions outlined in -`Salt's Supported Operating Systems`_ document. The operating systems listed below should reflect -this document but may become out of date. If an operating system is listed below, but is not -listed on the official supported operating systems document, the level of support is "best-effort". +`Salt's Supported Operating Systems`_ document, except for Solaris and AIX. The operating systems +listed below should reflect this document but may become out of date. If an operating system is +listed below, but is not listed on the official supported operating systems document, the level of +support is "best-effort". Since Salt is written in Python, the packages available from `SaltStack's corporate repository`_ are CPU architecture independent and could be installed on any hardware supported by Linux kernel. @@ -242,7 +243,7 @@ Debian and derivatives ~~~~~~~~~~~~~~~~~~~~~~ - Cumulus Linux 2/3 -- Debian GNU/Linux 7/8/9 +- Debian GNU/Linux 7/8/9/10 - Devuan GNU/Linux 1/2 - Kali Linux 1.0 (based on Debian 7) - Linux Mint Debian Edition 1 (based on Debian 8) @@ -265,11 +266,12 @@ Red Hat family ~~~~~~~~~~~~~~ - Amazon Linux 2012.3 and later -- CentOS 6/7 +- Amazon Linux 2 +- CentOS 6/7/8 - Cloud Linux 6/7 -- Fedora 27/28 (install latest stable from standard repositories) +- Fedora 30/31 (install latest stable from standard repositories) - Oracle Linux 6/7 -- Red Hat Enterprise Linux 6/7 +- Red Hat Enterprise Linux 6/7/8 - Scientific Linux 6/7 From f375c6dd53017d4f0af01c65a76116db4c9b7feb Mon Sep 17 00:00:00 2001 From: ch3ll Date: Thu, 7 Nov 2019 12:44:31 -0500 Subject: [PATCH 09/64] Update supported platforms url --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 2f1c76f..8e45818 100644 --- a/README.rst +++ b/README.rst @@ -436,7 +436,7 @@ Salt components, custom configurations, and even `pre-accepted Minion keys`_ alr .. _`pre-accepted Minion keys`: https://docs.saltstack.com/en/latest/topics/tutorials/preseed_key.html .. _`read the source`: https://github.com/saltstack/salt-bootstrap/blob/develop/bootstrap-salt.sh .. _`Salt`: https://saltstack.com/community/ -.. _`Salt's Supported Operating Systems`: http://saltstack.com/wp-content/uploads/2016/08/SaltStack-Supported-Operating-Systems.pdf +.. _`Salt's Supported Operating Systems`: http://get.saltstack.com/rs/304-PHQ-615/images/SaltStack-Supported-Operating-Systems.pdf .. _`SaltStack's corporate repository`: https://repo.saltstack.com/ .. _`SaltStack's Debian repository`: http://repo.saltstack.com/#debian .. _`SaltStack's Ubuntu repository`: http://repo.saltstack.com/#ubuntu From da991e3e1abda1777065d9deb65e1e5c3e3fc609 Mon Sep 17 00:00:00 2001 From: kgbsd <45101782+kgbsd@users.noreply.github.com> Date: Fri, 15 Nov 2019 16:05:31 -0700 Subject: [PATCH 10/64] working on FreeBSD --- bootstrap-salt.sh | 166 +++++++++++++++++++++++++++++----------------- 1 file changed, 104 insertions(+), 62 deletions(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 6bd8dac..f39b884 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -239,9 +239,9 @@ _CONFIG_ONLY=$BS_FALSE _PIP_ALLOWED=${BS_PIP_ALLOWED:-$BS_FALSE} _PIP_ALL=${BS_PIP_ALL:-$BS_FALSE} if uname -a | grep FreeBSD > /dev/null; then - _SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/usr/local/etc/salt} + _SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/usr/local/etc/salt} else - _SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/etc/salt} + _SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/etc/salt} fi _SALT_CACHE_DIR=${BS_SALT_CACHE_DIR:-/var/cache/salt} _PKI_DIR=${_SALT_ETC_DIR}/pki @@ -5275,63 +5275,114 @@ __configure_freebsd_pkg_details() { echo 'not hijacking pkg repo configurations' } -install_freebsd_9_stable_deps() { - _SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/usr/local/etc/salt} - _PKI_DIR=${_SALT_ETC_DIR}/pki - - if [ $_DISABLE_REPOS -eq $BS_FALSE ]; then - #make variables available even if pkg already installed - __freebsd_get_packagesite - - if [ ! -x /usr/local/sbin/pkg ]; then - pkg install -y pkg - fi - fi - return 0 -} - -install_freebsd_10_stable_deps() { - install_freebsd_9_stable_deps -} - -install_freebsd_11_stable_deps() { - install_freebsd_9_stable_deps -} - -install_freebsd_12_stable_deps() { - install_freebsd_9_stable_deps +install_freebsd_deps() { + pkg install -y pkg } install_freebsd_git_deps() { - echo 'do not need to git on FreeBSD salt install' -} + install_freebsd_9_stable_deps || return 1 + + # shellcheck disable=SC2086 + SALT_DEPENDENCIES=$(/usr/local/sbin/pkg search -R -d sysutils/py-salt | grep -i origin | sed -e 's/^[[:space:]]*//' | tail -n +2 | awk -F\" '{print $2}' | tr '\n' ' ') + SALT_DEPENDENCIES=$(/usr/local/sbin/pkg search -R -d py36-salt | grep 'origin:' \ + | tail -n +2 | awk -F\" '{print $2}' | sed 's#.*/py-#py36-#g') + # shellcheck disable=SC2086 + /usr/local/sbin/pkg install -y ${SALT_DEPENDENCIES} || return 1 + + if ! __check_command_exists git; then + /usr/local/sbin/pkg install -y git || return 1 + fi + + /usr/local/sbin/pkg install -y www/py-requests || return 1 + + __git_clone_and_checkout || return 1 + + echodebug "Adapting paths to FreeBSD" + # The list of files was taken from Salt's BSD port Makefile + for file in doc/man/salt-key.1 doc/man/salt-cp.1 doc/man/salt-minion.1 \ + doc/man/salt-syndic.1 doc/man/salt-master.1 doc/man/salt-run.1 \ + doc/man/salt.7 doc/man/salt.1 doc/man/salt-call.1; do + [ ! -f $file ] && continue + echodebug "Patching ${file}" + sed -in -e "s|/etc/salt|${_SALT_ETC_DIR}|" \ + -e "s|/srv/salt|${_SALT_ETC_DIR}/states|" \ + -e "s|/srv/pillar|${_SALT_ETC_DIR}/pillar|" ${file} + done + if [ ! -f salt/syspaths.py ]; then + # We still can't provide the system paths, salt 0.16.x + # Let's patch salt's source and adapt paths to what's expected on FreeBSD + echodebug "Replacing occurrences of '/etc/salt' with ${_SALT_ETC_DIR}" + # The list of files was taken from Salt's BSD port Makefile + for file in conf/minion conf/master salt/config.py salt/client.py \ + salt/modules/mysql.py salt/utils/parsers.py salt/modules/tls.py \ + salt/modules/postgres.py salt/utils/migrations.py; do + [ ! -f $file ] && continue + echodebug "Patching ${file}" + sed -in -e "s|/etc/salt|${_SALT_ETC_DIR}|" \ + -e "s|/srv/salt|${_SALT_ETC_DIR}/states|" \ + -e "s|/srv/pillar|${_SALT_ETC_DIR}/pillar|" ${file} + done + fi + echodebug "Finished patching" + + # Let's trigger config_salt() + if [ "$_TEMP_CONFIG_DIR" = "null" ]; then + _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" + CONFIG_SALT_FUNC="config_salt" + + fi -install_freebsd_9_stable() { - pkg install -y py36-salt return 0 } -install_freebsd_10_stable() { - pkg install -y py36-salt +install_freebsd_stable() { +# +# installing latest version of salt from FreeBSD CURRENT ports repo +# + # shellcheck disable=SC2086 + /usr/local/sbin/pkg install -y py36-salt || return 1 + return 0 } -install_freebsd_11_stable() { - pkg install -y py36-salt - return 0 -} - -install_freebsd_12_stable() { - pkg install -y py36-salt - return 0 -} - install_freebsd_git() { - echo 'do not need to git on FreeBSD salt install' - return 0 + + # /usr/local/bin/python2 in FreeBSD is a symlink to /usr/local/bin/python2.7 + __PYTHON_PATH=$(readlink -f "$(command -v python2)") + __ESCAPED_PYTHON_PATH=$(echo "${__PYTHON_PATH}" | sed 's/\//\\\//g') + + # Install from git + if [ ! -f salt/syspaths.py ]; then + # We still can't provide the system paths, salt 0.16.x + ${__PYTHON_PATH} setup.py ${SETUP_PY_INSTALL_ARGS} install || return 1 + else + ${__PYTHON_PATH} setup.py \ + --salt-root-dir=/ \ + --salt-config-dir="${_SALT_ETC_DIR}" \ + --salt-cache-dir="${_SALT_CACHE_DIR}" \ + --salt-sock-dir=/var/run/salt \ + --salt-srv-root-dir="${_SALT_ETC_DIR}" \ + --salt-base-file-roots-dir="${_SALT_ETC_DIR}/states" \ + --salt-base-pillar-roots-dir="${_SALT_ETC_DIR}/pillar" \ + --salt-base-master-roots-dir="${_SALT_ETC_DIR}/salt-master" \ + --salt-logs-dir=/var/log/salt \ + --salt-pidfile-dir=/var/run \ + ${SETUP_PY_INSTALL_ARGS} install \ + || return 1 + fi + + for script in salt_api salt_master salt_minion salt_proxy salt_syndic; do + __fetch_url "/usr/local/etc/rc.d/${script}" "https://raw.githubusercontent.com/freebsd/freebsd-ports/master/sysutils/py-salt/files/${script}.in" || return 1 + sed -i '' 's/%%PREFIX%%/\/usr\/local/g' /usr/local/etc/rc.d/${script} + sed -i '' "s/%%PYTHON_CMD%%/${__ESCAPED_PYTHON_PATH}/g" /usr/local/etc/rc.d/${script} + chmod +x /usr/local/etc/rc.d/${script} || return 1 + done + + # And we're good to go + return 0 } -install_freebsd_9_stable_post() { +install_freebsd_stable_post() { for fname in api master minion syndic; do # Skip salt-api since the service should be opt-in and not necessarily started on boot [ $fname = "api" ] && continue @@ -5341,32 +5392,23 @@ install_freebsd_9_stable_post() { [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue - enable_string="salt_${fname}_enable=\"YES\"" + enable_string="salt_${fname}_enable=YES" grep "$enable_string" /etc/rc.conf >/dev/null 2>&1 - [ $? -eq 1 ] && echo "$enable_string" >> /etc/rc.conf + [ $? -eq 1 ] && sysrc $enable_string + done } -install_freebsd_10_stable_post() { - install_freebsd_9_stable_post -} - -install_freebsd_11_stable_post() { - install_freebsd_9_stable_post -} - -install_freebsd_12_stable_post() { - install_freebsd_9_stable_post -} - install_freebsd_git_post() { - echo 'no git post for freebsd' + if [ -f $salt_conf_file ]; then + rm -f $salt_conf_file + fi + install_freebsd_stable_post || return 1 return 0 } install_freebsd_restart_daemons() { [ $_START_DAEMONS -eq $BS_FALSE ] && return - /usr/sbin/sysrc salt_minion_enable="YES" for fname in api master minion syndic; do # Skip salt-api since the service should be opt-in and not necessarily started on boot From ccebf6ce82f77f85a62d4ed082df8f3af0c704fe Mon Sep 17 00:00:00 2001 From: kgbsd <45101782+kgbsd@users.noreply.github.com> Date: Mon, 18 Nov 2019 07:25:28 -0700 Subject: [PATCH 11/64] Update bootstrap-salt.sh missed a freebsd_9_stable_deps part Co-Authored-By: Denys Havrysh --- bootstrap-salt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index f39b884..edad5e1 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -5280,7 +5280,7 @@ install_freebsd_deps() { } install_freebsd_git_deps() { - install_freebsd_9_stable_deps || return 1 + install_freebsd_stable_deps || return 1 # shellcheck disable=SC2086 SALT_DEPENDENCIES=$(/usr/local/sbin/pkg search -R -d sysutils/py-salt | grep -i origin | sed -e 's/^[[:space:]]*//' | tail -n +2 | awk -F\" '{print $2}' | tr '\n' ' ') From 274af65d5fe5f08947edfba6c6429e9dd0d10dc3 Mon Sep 17 00:00:00 2001 From: kgbsd <45101782+kgbsd@users.noreply.github.com> Date: Mon, 18 Nov 2019 07:28:31 -0700 Subject: [PATCH 12/64] Update bootstrap-salt.sh --- bootstrap-salt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index edad5e1..3c3206a 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -5293,7 +5293,7 @@ install_freebsd_git_deps() { /usr/local/sbin/pkg install -y git || return 1 fi - /usr/local/sbin/pkg install -y www/py-requests || return 1 + /usr/local/sbin/pkg install -y www/py36-requests || return 1 __git_clone_and_checkout || return 1 From 676c98bba3017424cd88a41fd8092b7538845775 Mon Sep 17 00:00:00 2001 From: kgbsd <45101782+kgbsd@users.noreply.github.com> Date: Mon, 18 Nov 2019 09:47:01 -0700 Subject: [PATCH 13/64] update script per comments / review move FreeBSD specifics to be under 'FreeBSD Install Functions' remove old code that was left in there just for reference while debugging --- bootstrap-salt.sh | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 3c3206a..8462792 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -238,11 +238,7 @@ _ECHO_DEBUG=${BS_ECHO_DEBUG:-$BS_FALSE} _CONFIG_ONLY=$BS_FALSE _PIP_ALLOWED=${BS_PIP_ALLOWED:-$BS_FALSE} _PIP_ALL=${BS_PIP_ALL:-$BS_FALSE} -if uname -a | grep FreeBSD > /dev/null; then - _SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/usr/local/etc/salt} -else - _SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/etc/salt} -fi +_SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/etc/salt} _SALT_CACHE_DIR=${BS_SALT_CACHE_DIR:-/var/cache/salt} _PKI_DIR=${_SALT_ETC_DIR}/pki _FORCE_OVERWRITE=${BS_FORCE_OVERWRITE:-$BS_FALSE} @@ -5272,18 +5268,17 @@ __freebsd_get_packagesite() { # Using a separate conf step to head for idempotent install... __configure_freebsd_pkg_details() { - echo 'not hijacking pkg repo configurations' + _SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/usr/local/etc/salt} } install_freebsd_deps() { + __configure_freebsd_pkg_details() pkg install -y pkg } install_freebsd_git_deps() { install_freebsd_stable_deps || return 1 - # shellcheck disable=SC2086 - SALT_DEPENDENCIES=$(/usr/local/sbin/pkg search -R -d sysutils/py-salt | grep -i origin | sed -e 's/^[[:space:]]*//' | tail -n +2 | awk -F\" '{print $2}' | tr '\n' ' ') SALT_DEPENDENCIES=$(/usr/local/sbin/pkg search -R -d py36-salt | grep 'origin:' \ | tail -n +2 | awk -F\" '{print $2}' | sed 's#.*/py-#py36-#g') # shellcheck disable=SC2086 From 8bda2159de55feff0dd81c58c18d2321f8c158e5 Mon Sep 17 00:00:00 2001 From: kgbsd <45101782+kgbsd@users.noreply.github.com> Date: Mon, 18 Nov 2019 09:49:55 -0700 Subject: [PATCH 14/64] give py-requests pkg proper name --- bootstrap-salt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 8462792..9e23c3b 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -5288,7 +5288,7 @@ install_freebsd_git_deps() { /usr/local/sbin/pkg install -y git || return 1 fi - /usr/local/sbin/pkg install -y www/py36-requests || return 1 + /usr/local/sbin/pkg install -y py36-requests || return 1 __git_clone_and_checkout || return 1 From b7081f4ccc7c5a8fc8a5ec4bd086e694bf9d1289 Mon Sep 17 00:00:00 2001 From: kgbsd <45101782+kgbsd@users.noreply.github.com> Date: Mon, 18 Nov 2019 10:46:18 -0700 Subject: [PATCH 15/64] cannot use 'if not set' expression here _SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/usr/local/etc/salt} Says if variable is not set, set it to that. By the time the script gets this far down, the variable is already set, so have to hardcode it to be /usr/local/etc/salt - part of the reason I had an 'if' statement around line 242, before the variable is set to default. --- bootstrap-salt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 9e23c3b..fbe2c9b 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -5268,7 +5268,7 @@ __freebsd_get_packagesite() { # Using a separate conf step to head for idempotent install... __configure_freebsd_pkg_details() { - _SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/usr/local/etc/salt} + _SALT_ETC_DIR="/usr/local/etc/salt" } install_freebsd_deps() { From 2b32957ae3147dc0d7cd2ae150a42cb3fbd9957b Mon Sep 17 00:00:00 2001 From: kgbsd <45101782+kgbsd@users.noreply.github.com> Date: Tue, 19 Nov 2019 07:36:34 -0700 Subject: [PATCH 16/64] fix copy paste error remove () in a call to shell function. Co-Authored-By: Denys Havrysh --- bootstrap-salt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index fbe2c9b..655dc8e 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -5272,7 +5272,7 @@ __configure_freebsd_pkg_details() { } install_freebsd_deps() { - __configure_freebsd_pkg_details() + __configure_freebsd_pkg_details pkg install -y pkg } From 269d337e32cdd117956610dfad1a8acbc37d7457 Mon Sep 17 00:00:00 2001 From: kgbsd <45101782+kgbsd@users.noreply.github.com> Date: Tue, 19 Nov 2019 10:46:18 -0700 Subject: [PATCH 17/64] Update bootstrap-salt.sh --- bootstrap-salt.sh | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 655dc8e..a9fc741 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -5240,32 +5240,6 @@ install_arch_check_services() { # FreeBSD Install Functions # -__freebsd_get_packagesite() { - if [ "$CPU_ARCH_L" = "amd64" ]; then - BSD_ARCH="x86:64" - elif [ "$CPU_ARCH_L" = "x86_64" ]; then - BSD_ARCH="x86:64" - elif [ "$CPU_ARCH_L" = "i386" ]; then - BSD_ARCH="x86:32" - elif [ "$CPU_ARCH_L" = "i686" ]; then - BSD_ARCH="x86:32" - fi - - # Since the variable might not be set, don't, momentarily treat it as a - # failure - set +o nounset - - # ABI is a std format for identifying release / architecture combos - ABI="freebsd:${DISTRO_MAJOR_VERSION}:${BSD_ARCH}" - _PACKAGESITE="http://pkg.freebsd.org/${ABI}/latest" - # Awkwardly, we want the `${ABI}` to be in conf file without escaping - PKGCONFURL="pkg+http://pkg.freebsd.org/\${ABI}/latest" - SALTPKGCONFURL="http://repo.saltstack.com/freebsd/\${ABI}/" - - # Treat unset variables as errors once more - set -o nounset -} - # Using a separate conf step to head for idempotent install... __configure_freebsd_pkg_details() { _SALT_ETC_DIR="/usr/local/etc/salt" From c89ea5ed992d0e035268bf94122d61af34109b92 Mon Sep 17 00:00:00 2001 From: kgbsd <45101782+kgbsd@users.noreply.github.com> Date: Wed, 20 Nov 2019 07:35:01 -0700 Subject: [PATCH 18/64] salt_conf_file unused ${salt_conf_file} var ${salt_conf_file} no longer needed, this conf file for saltstack repo which is not used. --- bootstrap-salt.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index a9fc741..f5fb30e 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -5369,9 +5369,6 @@ install_freebsd_stable_post() { } install_freebsd_git_post() { - if [ -f $salt_conf_file ]; then - rm -f $salt_conf_file - fi install_freebsd_stable_post || return 1 return 0 } From 15968cbdf6d6d29c6c9125886dbd43e3499cfed3 Mon Sep 17 00:00:00 2001 From: twangboy Date: Mon, 25 Nov 2019 13:00:06 -0700 Subject: [PATCH 19/64] Use Latest instead of detecting latest We now use symlinks that always point to latest --- bootstrap-salt.ps1 | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/bootstrap-salt.ps1 b/bootstrap-salt.ps1 index 34c8984..7957631 100644 --- a/bootstrap-salt.ps1 +++ b/bootstrap-salt.ps1 @@ -211,27 +211,10 @@ Else { } #=============================================================================== -# Figure out the latest version if no version is passed +# Use version "Latest" if no version is passed #=============================================================================== -# If version isn't supplied, use latest. If (!$version) { - # Find latest version of Salt Minion - $repo = Invoke-Restmethod "$repourl" - $regex = "<\s*a\s*[^>]*?href\s*=\s*[`"']*([^`"'>]+)[^>]*?>" - $returnMatches = New-Object System.Collections.ArrayList - $resultingMatches = [Regex]::Matches($repo, $regex, "IgnoreCase") - foreach($match in $resultingMatches) { - $cleanedMatch = $match.Groups[1].Value.Trim() - [void] $returnMatches.Add($cleanedMatch) - } - If ($arch -eq 'x86') { - $returnMatches = $returnMatches | Where {$_ -like "Salt-Minion*x86-Setup.exe"} - } - Else { - $returnMatches = $returnMatches | Where {$_ -like "Salt-Minion*AMD64-Setup.exe"} - } - - $version = $($returnMatches[$returnMatches.Count -1]).Split(("n-","-A","-x","-P"),([System.StringSplitOptions]::RemoveEmptyEntries))[1] + $version = "Latest" } $versionSection = $version From 495464f6ddb4bc0331eb273bcc29fd115f81ad39 Mon Sep 17 00:00:00 2001 From: twangboy Date: Mon, 25 Nov 2019 13:28:52 -0700 Subject: [PATCH 20/64] A few fixes Actually default to Py2 like the docs say Allow and actual version to be passed Handle older versions Write-Output when starting service --- bootstrap-salt.ps1 | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/bootstrap-salt.ps1 b/bootstrap-salt.ps1 index 7957631..cc443b7 100644 --- a/bootstrap-salt.ps1 +++ b/bootstrap-salt.ps1 @@ -83,7 +83,7 @@ Param( [Parameter(Mandatory=$false,ValueFromPipeline=$true)] # Doesn't support versions prior to "2017.7.0" [ValidateSet("2","3")] - [string]$pythonVersion = "", + [string]$pythonVersion = "2", [Parameter(Mandatory=$false,ValueFromPipeline=$true)] [ValidateSet("true","false")] @@ -214,18 +214,16 @@ Else { # Use version "Latest" if no version is passed #=============================================================================== If (!$version) { - $version = "Latest" -} - -$versionSection = $version - -$year = $version.Substring(0, 4) -If ([int]$year -ge 2017) { - If ($pythonVersion -eq "3") { - $versionSection = "$version-Py3" - } - Else { - $versionSection = "$version-Py2" + $versionSection = "Latest-Py$pythonVersion" +} else { + $versionSection = $version + $year = $version.Substring(0, 4) + If ([int]$year -ge 2017) { + If ($pythonVersion -eq "3") { + $versionSection = "$version-Py3" + } Else { + $versionSection = "$version-Py2" + } } } @@ -270,6 +268,7 @@ While (!$service) { If($runservice) { # Start service + Write-Output "Starting the Salt minion service" Start-Service -Name "salt-minion" -ErrorAction SilentlyContinue # Check if service is started, otherwise retry starting the From 4cada80295bac01a1033930e00bc473defc7f7e1 Mon Sep 17 00:00:00 2001 From: Denys Havrysh Date: Tue, 26 Nov 2019 18:53:07 +0200 Subject: [PATCH 21/64] Pin previous release of ShellCheck in CI tests The latest and greatest version of ShellCheck seems to have more hardened rules. This currently breaks CI tests in lint phase and shows error messages for untouched lines in a PR. It would be better to freeze the SC version and update it explicitly with fixing all new founded issues. --- .drone.jsonnet | 2 +- .drone.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index e7145b5..766de28 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -76,7 +76,7 @@ local Shellcheck() = { steps: [ { name: 'shellcheck', - image: 'koalaman/shellcheck-alpine', + image: 'koalaman/shellcheck-alpine:v0.6.0', commands: [ 'shellcheck -s sh -f checkstyle bootstrap-salt.sh', ], diff --git a/.drone.yml b/.drone.yml index f7d4ecf..27b7aeb 100644 --- a/.drone.yml +++ b/.drone.yml @@ -8,7 +8,7 @@ platform: steps: - name: shellcheck - image: koalaman/shellcheck-alpine + image: koalaman/shellcheck-alpine:v0.6.0 commands: - shellcheck -s sh -f checkstyle bootstrap-salt.sh From 2c1fb041c41cdbb32227a9120ecc5cbc67075997 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Wed, 27 Nov 2019 16:10:26 +0000 Subject: [PATCH 22/64] Fix `.drone.yml` signature --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 27b7aeb..4b93b4b 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1182,6 +1182,6 @@ depends_on: --- kind: signature -hmac: 906ceab2f0ec44b6e9c99f698feeb4874c503fd9db2a8525ed2916445069c403 +hmac: 6f9e82fb6d1fc4166a76b998fecb456cb5e931f5c2914d023008e30fba1c8822 ... From 8647b74cbc7f134b22d8b5ab6f9975440736dc37 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Wed, 6 Nov 2019 22:27:16 +0000 Subject: [PATCH 23/64] Use the POSIX compliant flag for `sed`. Fixes Mac OS bootstrapping. --- bootstrap-salt.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 9bc4030..9991fed 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -674,7 +674,7 @@ if [ -n "$_PY_EXE" ]; then if [ "$(uname)" = "Darwin" ]; then _PY_PKG_VER=$(echo "$_PY_EXE" | sed "s/\\.//g") else - _PY_PKG_VER=$(echo "$_PY_EXE" | sed -r "s/\\.//g") + _PY_PKG_VER=$(echo "$_PY_EXE" | sed -E "s/\\.//g") fi _PY_MAJOR_VERSION=$(echo "$_PY_PKG_VER" | cut -c 7) @@ -933,11 +933,11 @@ __strip_duplicates() { __sort_release_files() { KNOWN_RELEASE_FILES=$(echo "(arch|alpine|centos|debian|ubuntu|fedora|redhat|suse|\ mandrake|mandriva|gentoo|slackware|turbolinux|unitedlinux|void|lsb|system|\ - oracle|os)(-|_)(release|version)" | sed -r 's:[[:space:]]::g') + oracle|os)(-|_)(release|version)" | sed -E 's:[[:space:]]::g') primary_release_files="" secondary_release_files="" # Sort know VS un-known files first - for release_file in $(echo "${@}" | sed -r 's:[[:space:]]:\n:g' | sort -f | uniq); do + for release_file in $(echo "${@}" | sed -E 's:[[:space:]]:\n:g' | sort -f | uniq); do match=$(echo "$release_file" | grep -E -i "${KNOWN_RELEASE_FILES}") if [ "${match}" != "" ]; then primary_release_files="${primary_release_files} ${release_file}" @@ -962,7 +962,7 @@ __sort_release_files() { done # Echo the results collapsing multiple white-space into a single white-space - echo "${primary_release_files} ${secondary_release_files}" | sed -r 's:[[:space:]]+:\n:g' + echo "${primary_release_files} ${secondary_release_files}" | sed -E 's:[[:space:]]+:\n:g' } @@ -1181,17 +1181,17 @@ __gather_sunos_system_info() { case "$line" in *OpenIndiana*oi_[0-9]*) DISTRO_NAME="OpenIndiana" - DISTRO_VERSION=$(echo "$line" | sed -nr "s/OpenIndiana(.*)oi_([[:digit:]]+)(.*)/\\2/p") + DISTRO_VERSION=$(echo "$line" | sed -nE "s/OpenIndiana(.*)oi_([[:digit:]]+)(.*)/\\2/p") break ;; *OpenSolaris*snv_[0-9]*) DISTRO_NAME="OpenSolaris" - DISTRO_VERSION=$(echo "$line" | sed -nr "s/OpenSolaris(.*)snv_([[:digit:]]+)(.*)/\\2/p") + DISTRO_VERSION=$(echo "$line" | sed -nE "s/OpenSolaris(.*)snv_([[:digit:]]+)(.*)/\\2/p") break ;; *Oracle*Solaris*[0-9]*) DISTRO_NAME="Oracle Solaris" - DISTRO_VERSION=$(echo "$line" | sed -nr "s/(Oracle Solaris) ([[:digit:]]+)(.*)/\\2/p") + DISTRO_VERSION=$(echo "$line" | sed -nE "s/(Oracle Solaris) ([[:digit:]]+)(.*)/\\2/p") break ;; *Solaris*) @@ -1712,7 +1712,7 @@ echoinfo " Distribution: ${DISTRO_NAME} ${DISTRO_VERSION}" echo # Simplify distro name naming on functions -DISTRO_NAME_L=$(echo "$DISTRO_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-zA-Z0-9_ ]//g' | sed -re 's/([[:space:]])+/_/g') +DISTRO_NAME_L=$(echo "$DISTRO_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-zA-Z0-9_ ]//g' | sed -Ee 's/([[:space:]])+/_/g') # Simplify version naming on functions if [ "$DISTRO_VERSION" = "" ] || [ ${_SIMPLIFY_VERSION} -eq $BS_FALSE ]; then @@ -2507,7 +2507,7 @@ __activate_virtualenv() { __install_pip_pkgs() { _pip_pkgs="$1" _py_exe="$2" - _py_pkg=$(echo "$_py_exe" | sed -r "s/\\.//g") + _py_pkg=$(echo "$_py_exe" | sed -E "s/\\.//g") _pip_cmd="${_py_exe} -m pip" if [ "${_py_exe}" = "" ]; then From c3afd1797424b6a8cb0daa96f0e86c3272bdb02a Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Wed, 6 Nov 2019 22:52:10 +0000 Subject: [PATCH 24/64] Have Mac OS use the right regex for the salt version parsing --- bootstrap-salt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 9991fed..5e3d517 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -1981,7 +1981,7 @@ __git_clone_and_checkout() { fi case ${OS_NAME_L} in - openbsd|freebsd|netbsd ) + openbsd|freebsd|netbsd|darwin ) __TAG_REGEX_MATCH=$(echo "${GIT_REV}" | sed -E 's/^(v?[0-9]{1,4}\.[0-9]{1,2})(\.[0-9]{1,2})?.*$/MATCH/') ;; * ) From 8e6b6246dda7b4fce3c63ef10eb1975de5570762 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Wed, 6 Nov 2019 22:56:14 +0000 Subject: [PATCH 25/64] `pip` will be installed to `/usr/local/bin`. Make sure we can find it. --- bootstrap-salt.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 5e3d517..36bbe75 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -6750,6 +6750,12 @@ install_macosx_stable_deps() { install_macosx_git_deps() { install_macosx_stable_deps || return 1 + echo "$PATH" | grep -q /usr/local/bin + if [ $? -eq 1 ]; then + echowarn "/usr/local/bin was not found in \$PATH. Adding it for the duration of the script execution." + export PATH=/usr/local/bin:$PATH + fi + __fetch_url "/tmp/get-pip.py" "https://bootstrap.pypa.io/get-pip.py" || return 1 if [ -n "$_PY_EXE" ]; then From 1180463c3432d9a5b50d5776e3290d384a35fcaf Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Thu, 7 Nov 2019 11:04:53 +0000 Subject: [PATCH 26/64] Mac OSX also has support to install older stable versions of salt --- bootstrap-salt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 36bbe75..e12f02b 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -1790,7 +1790,7 @@ elif [ "${DISTRO_NAME_L}" = "debian" ]; then __debian_codename_translation fi -if [ "$(echo "${DISTRO_NAME_L}" | grep -E '(debian|ubuntu|centos|red_hat|oracle|scientific|amazon|fedora)')" = "" ] && [ "$ITYPE" = "stable" ] && [ "$STABLE_REV" != "latest" ]; then +if [ "$(echo "${DISTRO_NAME_L}" | grep -E '(debian|ubuntu|centos|red_hat|oracle|scientific|amazon|fedora|macosx)')" = "" ] && [ "$ITYPE" = "stable" ] && [ "$STABLE_REV" != "latest" ]; then echoerror "${DISTRO_NAME} does not have major version pegged packages support" exit 1 fi From 9b0ef8094ad2bc8090cc894b19f710fd43389a2b Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Thu, 7 Nov 2019 12:12:31 +0000 Subject: [PATCH 27/64] Don't fail when sourcing `/etc/profile` --- bootstrap-salt.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index e12f02b..7969d4f 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -6808,14 +6808,18 @@ install_macosx_git() { } install_macosx_stable_post() { - if [ ! -f /etc/paths.d/salt ]; then - print "%s\n" "/opt/salt/bin" "/usr/local/sbin" > /etc/paths.d/salt - fi + if [ ! -f /etc/paths.d/salt ]; then + print "%s\n" "/opt/salt/bin" "/usr/local/sbin" > /etc/paths.d/salt + fi - # shellcheck disable=SC1091 - . /etc/profile + # Don'f fail because of unknown variable on the next step + set +o nounset + # shellcheck disable=SC1091 + . /etc/profile + # Revert nounset to it's previous state + set -o nounset - return 0 + return 0 } install_macosx_git_post() { From 7860b2b84c11e37bc5a8ee60c5d3b52d331a08c2 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 29 Nov 2019 16:40:12 +0000 Subject: [PATCH 28/64] Single line if check, as suggested Co-Authored-By: Denys Havrysh --- bootstrap-salt.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 7969d4f..ebd8ee3 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -6750,8 +6750,7 @@ install_macosx_stable_deps() { install_macosx_git_deps() { install_macosx_stable_deps || return 1 - echo "$PATH" | grep -q /usr/local/bin - if [ $? -eq 1 ]; then + if ! echo "$PATH" | grep -q /usr/local/bin; then echowarn "/usr/local/bin was not found in \$PATH. Adding it for the duration of the script execution." export PATH=/usr/local/bin:$PATH fi From 2e6fc20258b2d0d56cff893c8c67ad1a1b8a712f Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Wed, 11 Dec 2019 09:09:51 +0000 Subject: [PATCH 29/64] Enable Amazon 1 and Amazon 2 builds --- .drone.jsonnet | 4 +- .drone.yml | 238 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 239 insertions(+), 3 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index 766de28..adb93ae 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -21,8 +21,8 @@ local stable_py3_suites = [ local distros = [ { name: 'Arch', slug: 'arch', multiplier: 0, depends: [] }, - // { name: 'Amazon 1', slug: 'amazon-1', multiplier: 1, depends: [] }, - // { name: 'Amazon 2', slug: 'amazon-2', multiplier: 2, depends: [] }, + { name: 'Amazon 1', slug: 'amazon-1', multiplier: 1, depends: [] }, + { name: 'Amazon 2', slug: 'amazon-2', multiplier: 2, depends: [] }, { name: 'CentOS 6', slug: 'centos-6', multiplier: 3, depends: [] }, { name: 'CentOS 7', slug: 'centos-7', multiplier: 4, depends: [] }, { name: 'CentOS 8', slug: 'centos-8', multiplier: 4, depends: [] }, diff --git a/.drone.yml b/.drone.yml index 4b93b4b..cdf33ca 100644 --- a/.drone.yml +++ b/.drone.yml @@ -78,6 +78,242 @@ node: depends_on: - Lint +--- +kind: pipeline +name: Amazon 1 + +platform: + os: linux + arch: amd64 + +steps: +- name: throttle-build + image: alpine + commands: + - sh -c 't=20; echo Sleeping 20 seconds; sleep 20' + +- name: create + image: saltstack/drone-salt-bootstrap-testing + commands: + - bundle install --with docker --without opennebula ec2 windows vagrant + - echo 'Waiting for docker to start' + - sleep 10 + - docker ps -a + - bundle exec kitchen create amazon-1 + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + +- name: Py2 2018.3(Git) + image: saltstack/drone-salt-bootstrap-testing + commands: + - pip install -U pip + - pip install -r tests/requirements.txt + - bundle install --with docker --without opennebula ec2 windows vagrant + - bundle exec kitchen test py2-git-2018-3-amazon-1 + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + - create + +- name: Py2 2019.2(Git) + image: saltstack/drone-salt-bootstrap-testing + commands: + - pip install -U pip + - pip install -r tests/requirements.txt + - bundle install --with docker --without opennebula ec2 windows vagrant + - bundle exec kitchen test py2-git-2019-2-amazon-1 + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + - create + +- name: Py2 2018.3(Stable) + image: saltstack/drone-salt-bootstrap-testing + commands: + - pip install -U pip + - pip install -r tests/requirements.txt + - bundle install --with docker --without opennebula ec2 windows vagrant + - bundle exec kitchen test py2-stable-2018-3-amazon-1 + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + - create + +- name: Py2 2019.2(Stable) + image: saltstack/drone-salt-bootstrap-testing + commands: + - pip install -U pip + - pip install -r tests/requirements.txt + - bundle install --with docker --without opennebula ec2 windows vagrant + - bundle exec kitchen test py2-stable-2019-2-amazon-1 + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + - create + +services: +- name: docker + image: saltstack/drone-salt-bootstrap-testing + command: + - --storage-driver=overlay2 + privileged: true + +node: + project: open + +depends_on: +- Lint + +--- +kind: pipeline +name: Amazon 2 + +platform: + os: linux + arch: amd64 + +steps: +- name: throttle-build + image: alpine + commands: + - sh -c 't=80; echo Sleeping 80 seconds; sleep 80' + +- name: create + image: saltstack/drone-salt-bootstrap-testing + commands: + - bundle install --with docker --without opennebula ec2 windows vagrant + - echo 'Waiting for docker to start' + - sleep 10 + - docker ps -a + - bundle exec kitchen create amazon-2 + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + +- name: Py2 2018.3(Git) + image: saltstack/drone-salt-bootstrap-testing + commands: + - pip install -U pip + - pip install -r tests/requirements.txt + - bundle install --with docker --without opennebula ec2 windows vagrant + - bundle exec kitchen test py2-git-2018-3-amazon-2 + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + - create + +- name: Py2 2019.2(Git) + image: saltstack/drone-salt-bootstrap-testing + commands: + - pip install -U pip + - pip install -r tests/requirements.txt + - bundle install --with docker --without opennebula ec2 windows vagrant + - bundle exec kitchen test py2-git-2019-2-amazon-2 + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + - create + +- name: Py2 2018.3(Stable) + image: saltstack/drone-salt-bootstrap-testing + commands: + - pip install -U pip + - pip install -r tests/requirements.txt + - bundle install --with docker --without opennebula ec2 windows vagrant + - bundle exec kitchen test py2-stable-2018-3-amazon-2 + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + - create + +- name: Py2 2019.2(Stable) + image: saltstack/drone-salt-bootstrap-testing + commands: + - pip install -U pip + - pip install -r tests/requirements.txt + - bundle install --with docker --without opennebula ec2 windows vagrant + - bundle exec kitchen test py2-stable-2019-2-amazon-2 + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + - create + +- name: Py3 2018.3(Git) + image: saltstack/drone-salt-bootstrap-testing + commands: + - pip install -U pip + - pip install -r tests/requirements.txt + - bundle install --with docker --without opennebula ec2 windows vagrant + - bundle exec kitchen test py3-git-2018-3-amazon-2 + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + - create + +- name: Py3 2019.2(Git) + image: saltstack/drone-salt-bootstrap-testing + commands: + - pip install -U pip + - pip install -r tests/requirements.txt + - bundle install --with docker --without opennebula ec2 windows vagrant + - bundle exec kitchen test py3-git-2019-2-amazon-2 + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + - create + +- name: Py3 2018.3(Stable) + image: saltstack/drone-salt-bootstrap-testing + commands: + - pip install -U pip + - pip install -r tests/requirements.txt + - bundle install --with docker --without opennebula ec2 windows vagrant + - bundle exec kitchen test py3-stable-2018-3-amazon-2 + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + - create + +- name: Py3 2019.2(Stable) + image: saltstack/drone-salt-bootstrap-testing + commands: + - pip install -U pip + - pip install -r tests/requirements.txt + - bundle install --with docker --without opennebula ec2 windows vagrant + - bundle exec kitchen test py3-stable-2019-2-amazon-2 + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + - create + +services: +- name: docker + image: saltstack/drone-salt-bootstrap-testing + command: + - --storage-driver=overlay2 + privileged: true + +node: + project: open + +depends_on: +- Lint + --- kind: pipeline name: CentOS 6 @@ -1182,6 +1418,6 @@ depends_on: --- kind: signature -hmac: 6f9e82fb6d1fc4166a76b998fecb456cb5e931f5c2914d023008e30fba1c8822 +hmac: 36e72916e48ce52fc701835c18a781e89d8a6fc6b47650abc3506aff4f131783 ... From 74c1f934dfddb12ac33a76a3423d694b64e0fb22 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Wed, 11 Dec 2019 09:52:05 +0000 Subject: [PATCH 30/64] Pre-install required packages to see if Opensuse stops failing --- .kitchen.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.kitchen.yml b/.kitchen.yml index 3fd2af7..ee6f733 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -85,6 +85,7 @@ platforms: run_command: /usr/lib/systemd/systemd provision_command: - zypper --non-interactive install --auto-agree-with-licenses dbus-1 + - zypper --non-interactive install --auto-agree-with-licenses sudo openssh which curl - systemctl enable sshd.service provisioner: salt_bootstrap_options: -MPfq -y -x python2 git %s From 079c27bf14d6b5a80db12d25ca3747577b07840b Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Wed, 11 Dec 2019 09:57:31 +0000 Subject: [PATCH 31/64] Adjust offset and multipliers --- .drone.jsonnet | 16 ++++++++-------- .drone.yml | 48 ++++++++++++++++++++++++------------------------ 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index adb93ae..edd3a24 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -25,12 +25,12 @@ local distros = [ { name: 'Amazon 2', slug: 'amazon-2', multiplier: 2, depends: [] }, { name: 'CentOS 6', slug: 'centos-6', multiplier: 3, depends: [] }, { name: 'CentOS 7', slug: 'centos-7', multiplier: 4, depends: [] }, - { name: 'CentOS 8', slug: 'centos-8', multiplier: 4, depends: [] }, - { name: 'Debian 8', slug: 'debian-8', multiplier: 5, depends: [] }, - { name: 'Debian 9', slug: 'debian-9', multiplier: 6, depends: [] }, - { name: 'Debian 10', slug: 'debian-10', multiplier: 6, depends: [] }, - { name: 'Fedora 30', slug: 'fedora-30', multiplier: 6, depends: [] }, - { name: 'Opensuse 15.0', slug: 'opensuse-15', multiplier: 4, depends: [] }, + { name: 'CentOS 8', slug: 'centos-8', multiplier: 5, depends: [] }, + { name: 'Debian 8', slug: 'debian-8', multiplier: 6, depends: [] }, + { name: 'Debian 9', slug: 'debian-9', multiplier: 5, depends: [] }, + { name: 'Debian 10', slug: 'debian-10', multiplier: 4, depends: [] }, + { name: 'Fedora 30', slug: 'fedora-30', multiplier: 3, depends: [] }, + { name: 'Opensuse 15.0', slug: 'opensuse-15', multiplier: 2, depends: [] }, { name: 'Ubuntu 16.04', slug: 'ubuntu-1604', multiplier: 1, depends: [] }, { name: 'Ubuntu 18.04', slug: 'ubuntu-1804', multiplier: 0, depends: [] }, ]; @@ -111,7 +111,7 @@ local Build(distro) = { commands: [ std.format( "sh -c 't=%(offset)s; echo Sleeping %(offset)s seconds; sleep %(offset)s'", - { offset: 5 * std.length(suites) * distro.multiplier } + { offset: 6 * std.length(suites) * distro.multiplier } ), ], }, @@ -127,7 +127,7 @@ local Build(distro) = { commands: [ 'bundle install --with docker --without opennebula ec2 windows vagrant', "echo 'Waiting for docker to start'", - 'sleep 10', // give docker enough time to start + 'sleep 15', // give docker enough time to start 'docker ps -a', std.format('bundle exec kitchen create %s', [distro.slug]), ], diff --git a/.drone.yml b/.drone.yml index cdf33ca..eda7df1 100644 --- a/.drone.yml +++ b/.drone.yml @@ -31,7 +31,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 10 + - sleep 15 - docker ps -a - bundle exec kitchen create arch environment: @@ -90,14 +90,14 @@ steps: - name: throttle-build image: alpine commands: - - sh -c 't=20; echo Sleeping 20 seconds; sleep 20' + - sh -c 't=24; echo Sleeping 24 seconds; sleep 24' - name: create image: saltstack/drone-salt-bootstrap-testing commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 10 + - sleep 15 - docker ps -a - bundle exec kitchen create amazon-1 environment: @@ -182,14 +182,14 @@ steps: - name: throttle-build image: alpine commands: - - sh -c 't=80; echo Sleeping 80 seconds; sleep 80' + - sh -c 't=96; echo Sleeping 96 seconds; sleep 96' - name: create image: saltstack/drone-salt-bootstrap-testing commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 10 + - sleep 15 - docker ps -a - bundle exec kitchen create amazon-2 environment: @@ -326,14 +326,14 @@ steps: - name: throttle-build image: alpine commands: - - sh -c 't=60; echo Sleeping 60 seconds; sleep 60' + - sh -c 't=72; echo Sleeping 72 seconds; sleep 72' - name: create image: saltstack/drone-salt-bootstrap-testing commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 10 + - sleep 15 - docker ps -a - bundle exec kitchen create centos-6 environment: @@ -418,14 +418,14 @@ steps: - name: throttle-build image: alpine commands: - - sh -c 't=160; echo Sleeping 160 seconds; sleep 160' + - sh -c 't=192; echo Sleeping 192 seconds; sleep 192' - name: create image: saltstack/drone-salt-bootstrap-testing commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 10 + - sleep 15 - docker ps -a - bundle exec kitchen create centos-7 environment: @@ -562,14 +562,14 @@ steps: - name: throttle-build image: alpine commands: - - sh -c 't=60; echo Sleeping 60 seconds; sleep 60' + - sh -c 't=90; echo Sleeping 90 seconds; sleep 90' - name: create image: saltstack/drone-salt-bootstrap-testing commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 10 + - sleep 15 - docker ps -a - bundle exec kitchen create centos-8 environment: @@ -641,14 +641,14 @@ steps: - name: throttle-build image: alpine commands: - - sh -c 't=100; echo Sleeping 100 seconds; sleep 100' + - sh -c 't=144; echo Sleeping 144 seconds; sleep 144' - name: create image: saltstack/drone-salt-bootstrap-testing commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 10 + - sleep 15 - docker ps -a - bundle exec kitchen create debian-8 environment: @@ -740,7 +740,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 10 + - sleep 15 - docker ps -a - bundle exec kitchen create debian-9 environment: @@ -877,14 +877,14 @@ steps: - name: throttle-build image: alpine commands: - - sh -c 't=90; echo Sleeping 90 seconds; sleep 90' + - sh -c 't=72; echo Sleeping 72 seconds; sleep 72' - name: create image: saltstack/drone-salt-bootstrap-testing commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 10 + - sleep 15 - docker ps -a - bundle exec kitchen create debian-10 environment: @@ -956,14 +956,14 @@ steps: - name: throttle-build image: alpine commands: - - sh -c 't=180; echo Sleeping 180 seconds; sleep 180' + - sh -c 't=108; echo Sleeping 108 seconds; sleep 108' - name: create image: saltstack/drone-salt-bootstrap-testing commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 10 + - sleep 15 - docker ps -a - bundle exec kitchen create fedora-30 environment: @@ -1074,14 +1074,14 @@ steps: - name: throttle-build image: alpine commands: - - sh -c 't=40; echo Sleeping 40 seconds; sleep 40' + - sh -c 't=24; echo Sleeping 24 seconds; sleep 24' - name: create image: saltstack/drone-salt-bootstrap-testing commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 10 + - sleep 15 - docker ps -a - bundle exec kitchen create opensuse-15 environment: @@ -1140,14 +1140,14 @@ steps: - name: throttle-build image: alpine commands: - - sh -c 't=40; echo Sleeping 40 seconds; sleep 40' + - sh -c 't=48; echo Sleeping 48 seconds; sleep 48' - name: create image: saltstack/drone-salt-bootstrap-testing commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 10 + - sleep 15 - docker ps -a - bundle exec kitchen create ubuntu-1604 environment: @@ -1291,7 +1291,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 10 + - sleep 15 - docker ps -a - bundle exec kitchen create ubuntu-1804 environment: @@ -1418,6 +1418,6 @@ depends_on: --- kind: signature -hmac: 36e72916e48ce52fc701835c18a781e89d8a6fc6b47650abc3506aff4f131783 +hmac: 75351adc28ff8346787e9fc0c42330fb60d5df79580cf5718d814dcc7a530cf7 ... From 8f1235601f3e8e8ca71fcfc8668174f051052ac6 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Wed, 11 Dec 2019 17:51:40 +0000 Subject: [PATCH 32/64] Just Amazon 2 for now --- .drone.jsonnet | 2 +- .drone.yml | 94 +------------------------------------------------- 2 files changed, 2 insertions(+), 94 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index edd3a24..c6834fd 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -21,7 +21,7 @@ local stable_py3_suites = [ local distros = [ { name: 'Arch', slug: 'arch', multiplier: 0, depends: [] }, - { name: 'Amazon 1', slug: 'amazon-1', multiplier: 1, depends: [] }, +// { name: 'Amazon 1', slug: 'amazon-1', multiplier: 1, depends: [] }, { name: 'Amazon 2', slug: 'amazon-2', multiplier: 2, depends: [] }, { name: 'CentOS 6', slug: 'centos-6', multiplier: 3, depends: [] }, { name: 'CentOS 7', slug: 'centos-7', multiplier: 4, depends: [] }, diff --git a/.drone.yml b/.drone.yml index eda7df1..57e9069 100644 --- a/.drone.yml +++ b/.drone.yml @@ -78,98 +78,6 @@ node: depends_on: - Lint ---- -kind: pipeline -name: Amazon 1 - -platform: - os: linux - arch: amd64 - -steps: -- name: throttle-build - image: alpine - commands: - - sh -c 't=24; echo Sleeping 24 seconds; sleep 24' - -- name: create - image: saltstack/drone-salt-bootstrap-testing - commands: - - bundle install --with docker --without opennebula ec2 windows vagrant - - echo 'Waiting for docker to start' - - sleep 15 - - docker ps -a - - bundle exec kitchen create amazon-1 - environment: - DOCKER_HOST: tcp://docker:2375 - depends_on: - - throttle-build - -- name: Py2 2018.3(Git) - image: saltstack/drone-salt-bootstrap-testing - commands: - - pip install -U pip - - pip install -r tests/requirements.txt - - bundle install --with docker --without opennebula ec2 windows vagrant - - bundle exec kitchen test py2-git-2018-3-amazon-1 - environment: - DOCKER_HOST: tcp://docker:2375 - depends_on: - - throttle-build - - create - -- name: Py2 2019.2(Git) - image: saltstack/drone-salt-bootstrap-testing - commands: - - pip install -U pip - - pip install -r tests/requirements.txt - - bundle install --with docker --without opennebula ec2 windows vagrant - - bundle exec kitchen test py2-git-2019-2-amazon-1 - environment: - DOCKER_HOST: tcp://docker:2375 - depends_on: - - throttle-build - - create - -- name: Py2 2018.3(Stable) - image: saltstack/drone-salt-bootstrap-testing - commands: - - pip install -U pip - - pip install -r tests/requirements.txt - - bundle install --with docker --without opennebula ec2 windows vagrant - - bundle exec kitchen test py2-stable-2018-3-amazon-1 - environment: - DOCKER_HOST: tcp://docker:2375 - depends_on: - - throttle-build - - create - -- name: Py2 2019.2(Stable) - image: saltstack/drone-salt-bootstrap-testing - commands: - - pip install -U pip - - pip install -r tests/requirements.txt - - bundle install --with docker --without opennebula ec2 windows vagrant - - bundle exec kitchen test py2-stable-2019-2-amazon-1 - environment: - DOCKER_HOST: tcp://docker:2375 - depends_on: - - throttle-build - - create - -services: -- name: docker - image: saltstack/drone-salt-bootstrap-testing - command: - - --storage-driver=overlay2 - privileged: true - -node: - project: open - -depends_on: -- Lint - --- kind: pipeline name: Amazon 2 @@ -1418,6 +1326,6 @@ depends_on: --- kind: signature -hmac: 75351adc28ff8346787e9fc0c42330fb60d5df79580cf5718d814dcc7a530cf7 +hmac: 2965bebb9df629cca7184c1b3e63b55a4b5a364927a04d66f7e9abab840323de ... From 64bb6fb4e1d17b74f02f99bfa5393a6488acdb74 Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Fri, 22 Nov 2019 12:52:08 -0700 Subject: [PATCH 33/64] Initial support for Amazon Linux 2 and Python3 plus other fixes --- bootstrap-salt.sh | 68 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 0d703c9..3103d7b 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -1,5 +1,7 @@ #!/bin/sh - +set -o functrace + # WARNING: Changes to this file in the salt repo will be overwritten! # Please submit pull requests against the salt-bootstrap repo: # https://github.com/saltstack/salt-bootstrap @@ -4830,15 +4832,23 @@ install_amazon_linux_ami_2_git_deps() { yum -y install ca-certificates || return 1 fi - PIP_EXE='pip' - if __check_command_exists python2.7; then - if ! __check_command_exists pip2.7; then - __yum_install_noinput python2-pip + if __check_command_exists python3; then + if ! __check_command_exists pip3; then + __yum_install_noinput python3-pip + fi + PIP_EXE='/bin/pip3' + _PY_EXE='python3' + fi + else + PIP_EXE='pip' + if __check_command_exists python2.7; then + if ! __check_command_exists pip2.7; then + __yum_install_noinput python2-pip + fi + PIP_EXE='/bin/pip' + _PY_EXE='python2.7' fi - PIP_EXE='/bin/pip' - _PY_EXE='python2.7' fi - install_amazon_linux_ami_2_deps || return 1 if ! __check_command_exists git; then @@ -4852,7 +4862,15 @@ install_amazon_linux_ami_2_git_deps() { if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then __check_pip_allowed "You need to allow pip based installations (-P) in order to install apache-libcloud" - __PACKAGES="${__PACKAGES} python27-pip" + if [ $PARSED_VERSION -eq 2 ]; then + if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then + __PACKAGES="${__PACKAGES} python3-pip" + else + __PACKAGES="${__PACKAGES} python2-pip" + fi + else + __PACKAGES="${__PACKAGES} python27-pip" + fi __PIP_PACKAGES="${__PIP_PACKAGES} apache-libcloud>=$_LIBCLOUD_MIN_VERSION" fi @@ -4918,10 +4936,20 @@ install_amazon_linux_ami_2_deps() { if [ $_DISABLE_REPOS -eq $BS_FALSE ] || [ "$_CUSTOM_REPO_URL" != "null" ]; then __REPO_FILENAME="saltstack-repo.repo" - base_url="$HTTP_VAL://${_REPO_URL}/yum/amazon/2/\$basearch/$repo_rev/" - gpg_key="${base_url}SALTSTACK-GPG-KEY.pub - ${base_url}base/RPM-GPG-KEY-CentOS-7" + __PY_VERSION_REPO="yum" + PY_PKG_VER="" repo_name="SaltStack repo for Amazon Linux 2.0" + if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then + __PY_VERSION_REPO="py3" + PY_PKG_VER=3 + repo_name="SaltStack Python 3 repo for Amazon Linux 2.0" + fi + + base_url="$HTTP_VAL://${_REPO_URL}/${__PY_VERSION_REPO}/amazon/2/\$basearch/$repo_rev/" + gpg_key="${base_url}SALTSTACK-GPG-KEY.pub + if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -ne 3 ]; then + ${base_url}base/RPM-GPG-KEY-CentOS-7" + fi # This should prob be refactored to use __install_saltstack_rhel_repository() # With args passed in to do the right thing. Reformatted to be more like the @@ -4942,9 +4970,15 @@ _eof # Package python-ordereddict-1.1-2.el6.noarch is obsoleted by python26-2.6.9-2.88.amzn1.x86_64 # which is already installed - __PACKAGES="m2crypto ${pkg_append}-crypto ${pkg_append}-jinja2 PyYAML procps-ng" - __PACKAGES="${__PACKAGES} ${pkg_append}-msgpack ${pkg_append}-requests ${pkg_append}-zmq" - __PACKAGES="${__PACKAGES} ${pkg_append}-futures" + if [ "${PY_PKG_VER}" -eq 3 ]; then + __PACKAGES="${pkg_append}${PY_PKG_VER}-m2crypto ${pkg_append}${PY_PKG_VER}-pyyaml" + + else + __PACKAGES="m2crypto PyYAML ${pkg_append}-futures" + fi + + __PACKAGES="${__PACKAGES} ${pkg_append}${PY_PKG_VER}-crypto ${pkg_append}${PY_PKG_VER}-jinja2 procps-ng" + __PACKAGES="${__PACKAGES} ${pkg_append}${PY_PKG_VER}-msgpack ${pkg_append}${PY_PKG_VER}-requests ${pkg_append}${PY_PKG_VER}-zmq" # shellcheck disable=SC2086 __yum_install_noinput ${__PACKAGES} || return 1 @@ -5025,6 +5059,12 @@ install_amazon_linux_ami_2_testing_post() { install_centos_testing_post || return 1 return 0 } + +install_amazon_linux_ami_2_check_services() { + install_centos_check_services || return 1 + return 0 +} + # # Ended Amazon Linux AMI Install Functions # From 6c0e7b9a0b71ab9973c782624c2ae32c7b641df3 Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Tue, 10 Dec 2019 15:53:50 -0700 Subject: [PATCH 34/64] Further fixes for Py 3 Amazon Linux 2 support and test changes --- .drone.jsonnet | 1 + bootstrap-salt.sh | 59 +++++++++++++++++++++++------------------------ 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index c6834fd..7396ee1 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -67,6 +67,7 @@ local py2_blacklist = [ local blacklist_2018 = [ 'centos-8', 'debian-10', + 'amazon-2', ]; local Shellcheck() = { diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 3103d7b..5d37e1d 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -2110,7 +2110,7 @@ __copyfile() { dfile=$2 overwrite=$3 else - echoerror "Wrong number of arguments for __copyfile()" + echoerror "Wrong number of arguments for __copyfile\(\)" echoinfo "USAGE: __copyfile OR __copyfile " exit 1 fi @@ -2158,7 +2158,7 @@ __movefile() { dfile=$2 overwrite=$3 else - echoerror "Wrong number of arguments for __movefile()" + echoerror "Wrong number of arguments for __movefile\(\)" echoinfo "USAGE: __movefile OR __movefile " exit 1 fi @@ -2215,7 +2215,7 @@ __linkfile() { linkname=$2 overwrite=$3 else - echoerror "Wrong number of arguments for __linkfile()" + echoerror "Wrong number of arguments for __linkfile\(\)" echoinfo "USAGE: __linkfile OR __linkfile " exit 1 fi @@ -2260,7 +2260,7 @@ __overwriteconfig() { target=$1 json=$2 else - echoerror "Wrong number of arguments for __convert_json_to_yaml_str()" + echoerror "Wrong number of arguments for __convert_json_to_yaml_str\(\)" echoinfo "USAGE: __convert_json_to_yaml_str " exit 1 fi @@ -4832,13 +4832,12 @@ install_amazon_linux_ami_2_git_deps() { yum -y install ca-certificates || return 1 fi - if __check_command_exists python3; then + if __check_command_exists python3; then if ! __check_command_exists pip3; then __yum_install_noinput python3-pip fi PIP_EXE='/bin/pip3' _PY_EXE='python3' - fi else PIP_EXE='pip' if __check_command_exists python2.7; then @@ -4942,13 +4941,13 @@ install_amazon_linux_ami_2_deps() { if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then __PY_VERSION_REPO="py3" PY_PKG_VER=3 - repo_name="SaltStack Python 3 repo for Amazon Linux 2.0" + repo_name="SaltStack Python 3 repo for Amazon Linux 2" fi base_url="$HTTP_VAL://${_REPO_URL}/${__PY_VERSION_REPO}/amazon/2/\$basearch/$repo_rev/" - gpg_key="${base_url}SALTSTACK-GPG-KEY.pub + gpg_key="${base_url}SALTSTACK-GPG-KEY.pub" if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -ne 3 ]; then - ${base_url}base/RPM-GPG-KEY-CentOS-7" + "${base_url}base/RPM-GPG-KEY-CentOS-7" fi # This should prob be refactored to use __install_saltstack_rhel_repository() @@ -5593,11 +5592,11 @@ install_smartos_git_deps() { if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then # Install whichever tornado is in the requirements file __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" - __check_pip_allowed "You need to allow pip based installations (-P) in order to install the python package '${__REQUIRED_TORNADO}'" + __check_pip_allowed "You need to allow pip based installations \(-P\) in order to install the python package '${__REQUIRED_TORNADO}'" # Install whichever futures is in the requirements file __REQUIRED_FUTURES="$(grep futures "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" - __check_pip_allowed "You need to allow pip based installations (-P) in order to install the python package '${__REQUIRED_FUTURES}'" + __check_pip_allowed "You need to allow pip based installations \(-P\) in order to install the python package '${__REQUIRED_FUTURES}'" if [ "${__REQUIRED_TORNADO}" != "" ]; then if ! __check_command_exists pip; then @@ -6722,7 +6721,7 @@ config_salt() { [ "$_TEMP_CONFIG_DIR" = "null" ] && return if [ "$_CONFIG_ONLY" -eq $BS_TRUE ]; then - echowarn "Passing -C (config only) option implies -F (forced overwrite)." + echowarn "Passing -C \(config only\) option implies -F \(forced overwrite\)." if [ "$_FORCE_OVERWRITE" -ne $BS_TRUE ]; then echowarn "Overwriting configs in 11 seconds!" @@ -7102,9 +7101,9 @@ fi # Install dependencies if [ ${_NO_DEPS} -eq $BS_FALSE ] && [ $_CONFIG_ONLY -eq $BS_FALSE ]; then # Only execute function is not in config mode only - echoinfo "Running ${DEPS_INSTALL_FUNC}()" + echoinfo "Running ${DEPS_INSTALL_FUNC}\(\)" if ! ${DEPS_INSTALL_FUNC}; then - echoerror "Failed to run ${DEPS_INSTALL_FUNC}()!!!" + echoerror "Failed to run ${DEPS_INSTALL_FUNC}\(\)!!!" exit 1 fi fi @@ -7126,9 +7125,9 @@ if [ "$_CUSTOM_MASTER_CONFIG" != "null" ] || [ "$_CUSTOM_MINION_CONFIG" != "null if [ ${_NO_DEPS} -eq $BS_FALSE ] && [ $_CONFIG_ONLY -eq $BS_TRUE ]; then # Execute function to satisfy dependencies for configuration step - echoinfo "Running ${DEPS_INSTALL_FUNC}()" + echoinfo "Running ${DEPS_INSTALL_FUNC}\(\)" if ! ${DEPS_INSTALL_FUNC}; then - echoerror "Failed to run ${DEPS_INSTALL_FUNC}()!!!" + echoerror "Failed to run ${DEPS_INSTALL_FUNC}\(\)!!!" exit 1 fi fi @@ -7136,9 +7135,9 @@ fi # Configure Salt if [ "$CONFIG_SALT_FUNC" != "null" ] && [ "$_TEMP_CONFIG_DIR" != "null" ]; then - echoinfo "Running ${CONFIG_SALT_FUNC}()" + echoinfo "Running ${CONFIG_SALT_FUNC}\(\)" if ! ${CONFIG_SALT_FUNC}; then - echoerror "Failed to run ${CONFIG_SALT_FUNC}()!!!" + echoerror "Failed to run ${CONFIG_SALT_FUNC}\(\)!!!" exit 1 fi fi @@ -7159,9 +7158,9 @@ fi # Pre-seed master keys if [ "$PRESEED_MASTER_FUNC" != "null" ] && [ "$_TEMP_KEYS_DIR" != "null" ]; then - echoinfo "Running ${PRESEED_MASTER_FUNC}()" + echoinfo "Running ${PRESEED_MASTER_FUNC}\(\)" if ! ${PRESEED_MASTER_FUNC}; then - echoerror "Failed to run ${PRESEED_MASTER_FUNC}()!!!" + echoerror "Failed to run ${PRESEED_MASTER_FUNC}\(\)!!!" exit 1 fi fi @@ -7169,49 +7168,49 @@ fi # Install Salt if [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then # Only execute function is not in config mode only - echoinfo "Running ${INSTALL_FUNC}()" + echoinfo "Running ${INSTALL_FUNC}\(\)" if ! ${INSTALL_FUNC}; then - echoerror "Failed to run ${INSTALL_FUNC}()!!!" + echoerror "Failed to run ${INSTALL_FUNC}\(\)!!!" exit 1 fi fi # Run any post install function. Only execute function if not in config mode only if [ "$POST_INSTALL_FUNC" != "null" ] && [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then - echoinfo "Running ${POST_INSTALL_FUNC}()" + echoinfo "Running ${POST_INSTALL_FUNC}\(\)" if ! ${POST_INSTALL_FUNC}; then - echoerror "Failed to run ${POST_INSTALL_FUNC}()!!!" + echoerror "Failed to run ${POST_INSTALL_FUNC}\(\)!!!" exit 1 fi fi # Run any check services function, Only execute function if not in config mode only if [ "$CHECK_SERVICES_FUNC" != "null" ] && [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then - echoinfo "Running ${CHECK_SERVICES_FUNC}()" + echoinfo "Running ${CHECK_SERVICES_FUNC}\(\)" if ! ${CHECK_SERVICES_FUNC}; then - echoerror "Failed to run ${CHECK_SERVICES_FUNC}()!!!" + echoerror "Failed to run ${CHECK_SERVICES_FUNC}\(\)!!!" exit 1 fi fi # Run any start daemons function if [ "$STARTDAEMONS_INSTALL_FUNC" != "null" ] && [ ${_START_DAEMONS} -eq $BS_TRUE ]; then - echoinfo "Running ${STARTDAEMONS_INSTALL_FUNC}()" + echoinfo "Running ${STARTDAEMONS_INSTALL_FUNC}\(\)" echodebug "Waiting ${_SLEEP} seconds for processes to settle before checking for them" sleep ${_SLEEP} if ! ${STARTDAEMONS_INSTALL_FUNC}; then - echoerror "Failed to run ${STARTDAEMONS_INSTALL_FUNC}()!!!" + echoerror "Failed to run ${STARTDAEMONS_INSTALL_FUNC}\(\)!!!" exit 1 fi fi # Check if the installed daemons are running or not if [ "$DAEMONS_RUNNING_FUNC" != "null" ] && [ ${_START_DAEMONS} -eq $BS_TRUE ]; then - echoinfo "Running ${DAEMONS_RUNNING_FUNC}()" + echoinfo "Running ${DAEMONS_RUNNING_FUNC}\(\)" echodebug "Waiting ${_SLEEP} seconds for processes to settle before checking for them" sleep ${_SLEEP} # Sleep a little bit to let daemons start if ! ${DAEMONS_RUNNING_FUNC}; then - echoerror "Failed to run ${DAEMONS_RUNNING_FUNC}()!!!" + echoerror "Failed to run ${DAEMONS_RUNNING_FUNC}\(\)!!!" for fname in api master minion syndic; do # Skip salt-api since the service should be opt-in and not necessarily started on boot From 63f52a9cb0a7f9f77cd4624524b97f845931c78a Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Tue, 10 Dec 2019 16:49:34 -0700 Subject: [PATCH 35/64] Remove debugging info from script --- bootstrap-salt.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 5d37e1d..ffe8f07 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -1,7 +1,5 @@ #!/bin/sh - -set -o functrace - # WARNING: Changes to this file in the salt repo will be overwritten! # Please submit pull requests against the salt-bootstrap repo: # https://github.com/saltstack/salt-bootstrap From 286944eab4838cea4dd690745592241c98a76069 Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Wed, 11 Dec 2019 13:58:57 -0700 Subject: [PATCH 36/64] Cleanup of () in echo output --- .drone.yml | 17 ++--------------- bootstrap-salt.sh | 8 ++++---- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/.drone.yml b/.drone.yml index 57e9069..61d943a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -90,7 +90,7 @@ steps: - name: throttle-build image: alpine commands: - - sh -c 't=96; echo Sleeping 96 seconds; sleep 96' + - sh -c 't=84; echo Sleeping 84 seconds; sleep 84' - name: create image: saltstack/drone-salt-bootstrap-testing @@ -183,19 +183,6 @@ steps: - throttle-build - create -- name: Py3 2018.3(Stable) - image: saltstack/drone-salt-bootstrap-testing - commands: - - pip install -U pip - - pip install -r tests/requirements.txt - - bundle install --with docker --without opennebula ec2 windows vagrant - - bundle exec kitchen test py3-stable-2018-3-amazon-2 - environment: - DOCKER_HOST: tcp://docker:2375 - depends_on: - - throttle-build - - create - - name: Py3 2019.2(Stable) image: saltstack/drone-salt-bootstrap-testing commands: @@ -1326,6 +1313,6 @@ depends_on: --- kind: signature -hmac: 2965bebb9df629cca7184c1b3e63b55a4b5a364927a04d66f7e9abab840323de +hmac: 01bfd9713517348f9861dd811b44531bb17d6cf1e6635083aa27415824f36bed ... diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index ffe8f07..8682b02 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -2542,7 +2542,7 @@ __install_pip_pkgs() { #---------------------------------------------------------------------------------------------------------------------- __install_tornado_pip() { # OS needs tornado <5.0 from pip - __check_pip_allowed "You need to allow pip based installations (-P) for Tornado <5.0 in order to install Salt on Python 3" + __check_pip_allowed "You need to allow pip based installations \(-P\) for Tornado <5.0 in order to install Salt on Python 3" ## install pip if its not installed and install tornado __install_pip_pkgs "tornado<5.0" "${1}" || return 1 } @@ -3620,7 +3620,7 @@ install_fedora_git_deps() { # Fedora 28+ needs tornado <5.0 from pip # https://github.com/saltstack/salt-bootstrap/issues/1220 if [ "${PY_PKG_VER}" -eq 3 ] && [ "$DISTRO_MAJOR_VERSION" -ge 28 ]; then - __check_pip_allowed "You need to allow pip based installations (-P) for Tornado <5.0 in order to install Salt on Python 3" + __check_pip_allowed "You need to allow pip based installations \(-P\) for Tornado <5.0 in order to install Salt on Python 3" grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" | while IFS=' ' read -r dep; do "${_PY_EXE}" -m pip install "${dep}" || return 1 @@ -4793,7 +4793,7 @@ install_amazon_linux_ami_git_deps() { __PIP_PACKAGES="" if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then - __check_pip_allowed "You need to allow pip based installations (-P) in order to install apache-libcloud" + __check_pip_allowed "You need to allow pip based installations \(-P\) in order to install apache-libcloud" __PACKAGES="${__PACKAGES} python27-pip" __PIP_PACKAGES="${__PIP_PACKAGES} apache-libcloud>=$_LIBCLOUD_MIN_VERSION" fi @@ -4858,7 +4858,7 @@ install_amazon_linux_ami_2_git_deps() { __PIP_PACKAGES="" if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then - __check_pip_allowed "You need to allow pip based installations (-P) in order to install apache-libcloud" + __check_pip_allowed "You need to allow pip based installations \(-P\) in order to install apache-libcloud" if [ $PARSED_VERSION -eq 2 ]; then if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then __PACKAGES="${__PACKAGES} python3-pip" From f08e9386d49dfeee0b44d79b1018dce3c8db8de3 Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Wed, 11 Dec 2019 14:04:32 -0700 Subject: [PATCH 37/64] Cleanup lint --- bootstrap-salt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 8682b02..e11c034 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -4859,7 +4859,7 @@ install_amazon_linux_ami_2_git_deps() { if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then __check_pip_allowed "You need to allow pip based installations \(-P\) in order to install apache-libcloud" - if [ $PARSED_VERSION -eq 2 ]; then + if [ "$PARSED_VERSION" -eq 2 ]; then if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then __PACKAGES="${__PACKAGES} python3-pip" else From 70f5b8b6a66f73e3617d7d4f8758d40304ee1409 Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Wed, 11 Dec 2019 14:45:52 -0700 Subject: [PATCH 38/64] Further Lint cleanup --- bootstrap-salt.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index e11c034..946db19 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -4857,10 +4857,10 @@ install_amazon_linux_ami_2_git_deps() { __PACKAGES="" __PIP_PACKAGES="" - if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then + if [ "$_INSTALL_CLOUD" -eq "$BS_TRUE" ]; then __check_pip_allowed "You need to allow pip based installations \(-P\) in order to install apache-libcloud" - if [ "$PARSED_VERSION" -eq 2 ]; then - if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then + if [ "$PARSED_VERSION" -eq "2" ]; then + if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq "3" ]; then __PACKAGES="${__PACKAGES} python3-pip" else __PACKAGES="${__PACKAGES} python2-pip" From 7568b2bf4354736dd33ab768a35f2641de3da38c Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Wed, 11 Dec 2019 15:37:50 -0700 Subject: [PATCH 39/64] Fixed echo output for parentheses --- bootstrap-salt.sh | 58 +++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 946db19..5624bd1 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -2108,7 +2108,7 @@ __copyfile() { dfile=$2 overwrite=$3 else - echoerror "Wrong number of arguments for __copyfile\(\)" + echoerror "Wrong number of arguments for __copyfile()" echoinfo "USAGE: __copyfile OR __copyfile " exit 1 fi @@ -2156,7 +2156,7 @@ __movefile() { dfile=$2 overwrite=$3 else - echoerror "Wrong number of arguments for __movefile\(\)" + echoerror "Wrong number of arguments for __movefile()" echoinfo "USAGE: __movefile OR __movefile " exit 1 fi @@ -2213,7 +2213,7 @@ __linkfile() { linkname=$2 overwrite=$3 else - echoerror "Wrong number of arguments for __linkfile\(\)" + echoerror "Wrong number of arguments for __linkfile()" echoinfo "USAGE: __linkfile OR __linkfile " exit 1 fi @@ -2258,7 +2258,7 @@ __overwriteconfig() { target=$1 json=$2 else - echoerror "Wrong number of arguments for __convert_json_to_yaml_str\(\)" + echoerror "Wrong number of arguments for __convert_json_to_yaml_str()" echoinfo "USAGE: __convert_json_to_yaml_str " exit 1 fi @@ -2542,7 +2542,7 @@ __install_pip_pkgs() { #---------------------------------------------------------------------------------------------------------------------- __install_tornado_pip() { # OS needs tornado <5.0 from pip - __check_pip_allowed "You need to allow pip based installations \(-P\) for Tornado <5.0 in order to install Salt on Python 3" + __check_pip_allowed "You need to allow pip based installations (-P) for Tornado <5.0 in order to install Salt on Python 3" ## install pip if its not installed and install tornado __install_pip_pkgs "tornado<5.0" "${1}" || return 1 } @@ -3620,7 +3620,7 @@ install_fedora_git_deps() { # Fedora 28+ needs tornado <5.0 from pip # https://github.com/saltstack/salt-bootstrap/issues/1220 if [ "${PY_PKG_VER}" -eq 3 ] && [ "$DISTRO_MAJOR_VERSION" -ge 28 ]; then - __check_pip_allowed "You need to allow pip based installations \(-P\) for Tornado <5.0 in order to install Salt on Python 3" + __check_pip_allowed "You need to allow pip based installations (-P) for Tornado <5.0 in order to install Salt on Python 3" grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" | while IFS=' ' read -r dep; do "${_PY_EXE}" -m pip install "${dep}" || return 1 @@ -4793,7 +4793,7 @@ install_amazon_linux_ami_git_deps() { __PIP_PACKAGES="" if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then - __check_pip_allowed "You need to allow pip based installations \(-P\) in order to install apache-libcloud" + __check_pip_allowed "You need to allow pip based installations (-P) in order to install apache-libcloud" __PACKAGES="${__PACKAGES} python27-pip" __PIP_PACKAGES="${__PIP_PACKAGES} apache-libcloud>=$_LIBCLOUD_MIN_VERSION" fi @@ -4858,7 +4858,7 @@ install_amazon_linux_ami_2_git_deps() { __PIP_PACKAGES="" if [ "$_INSTALL_CLOUD" -eq "$BS_TRUE" ]; then - __check_pip_allowed "You need to allow pip based installations \(-P\) in order to install apache-libcloud" + __check_pip_allowed "You need to allow pip based installations (-P) in order to install apache-libcloud" if [ "$PARSED_VERSION" -eq "2" ]; then if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq "3" ]; then __PACKAGES="${__PACKAGES} python3-pip" @@ -5590,11 +5590,11 @@ install_smartos_git_deps() { if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then # Install whichever tornado is in the requirements file __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" - __check_pip_allowed "You need to allow pip based installations \(-P\) in order to install the python package '${__REQUIRED_TORNADO}'" + __check_pip_allowed "You need to allow pip based installations (-P) in order to install the python package '${__REQUIRED_TORNADO}'" # Install whichever futures is in the requirements file __REQUIRED_FUTURES="$(grep futures "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" - __check_pip_allowed "You need to allow pip based installations \(-P\) in order to install the python package '${__REQUIRED_FUTURES}'" + __check_pip_allowed "You need to allow pip based installations (-P) in order to install the python package '${__REQUIRED_FUTURES}'" if [ "${__REQUIRED_TORNADO}" != "" ]; then if ! __check_command_exists pip; then @@ -6719,7 +6719,7 @@ config_salt() { [ "$_TEMP_CONFIG_DIR" = "null" ] && return if [ "$_CONFIG_ONLY" -eq $BS_TRUE ]; then - echowarn "Passing -C \(config only\) option implies -F \(forced overwrite\)." + echowarn "Passing -C (config only) option implies -F (forced overwrite)." if [ "$_FORCE_OVERWRITE" -ne $BS_TRUE ]; then echowarn "Overwriting configs in 11 seconds!" @@ -7099,9 +7099,9 @@ fi # Install dependencies if [ ${_NO_DEPS} -eq $BS_FALSE ] && [ $_CONFIG_ONLY -eq $BS_FALSE ]; then # Only execute function is not in config mode only - echoinfo "Running ${DEPS_INSTALL_FUNC}\(\)" + echoinfo "Running ${DEPS_INSTALL_FUNC}()" if ! ${DEPS_INSTALL_FUNC}; then - echoerror "Failed to run ${DEPS_INSTALL_FUNC}\(\)!!!" + echoerror "Failed to run ${DEPS_INSTALL_FUNC}()!!!" exit 1 fi fi @@ -7123,9 +7123,9 @@ if [ "$_CUSTOM_MASTER_CONFIG" != "null" ] || [ "$_CUSTOM_MINION_CONFIG" != "null if [ ${_NO_DEPS} -eq $BS_FALSE ] && [ $_CONFIG_ONLY -eq $BS_TRUE ]; then # Execute function to satisfy dependencies for configuration step - echoinfo "Running ${DEPS_INSTALL_FUNC}\(\)" + echoinfo "Running ${DEPS_INSTALL_FUNC}()" if ! ${DEPS_INSTALL_FUNC}; then - echoerror "Failed to run ${DEPS_INSTALL_FUNC}\(\)!!!" + echoerror "Failed to run ${DEPS_INSTALL_FUNC}()!!!" exit 1 fi fi @@ -7133,9 +7133,9 @@ fi # Configure Salt if [ "$CONFIG_SALT_FUNC" != "null" ] && [ "$_TEMP_CONFIG_DIR" != "null" ]; then - echoinfo "Running ${CONFIG_SALT_FUNC}\(\)" + echoinfo "Running ${CONFIG_SALT_FUNC}()" if ! ${CONFIG_SALT_FUNC}; then - echoerror "Failed to run ${CONFIG_SALT_FUNC}\(\)!!!" + echoerror "Failed to run ${CONFIG_SALT_FUNC}()!!!" exit 1 fi fi @@ -7156,9 +7156,9 @@ fi # Pre-seed master keys if [ "$PRESEED_MASTER_FUNC" != "null" ] && [ "$_TEMP_KEYS_DIR" != "null" ]; then - echoinfo "Running ${PRESEED_MASTER_FUNC}\(\)" + echoinfo "Running ${PRESEED_MASTER_FUNC}()" if ! ${PRESEED_MASTER_FUNC}; then - echoerror "Failed to run ${PRESEED_MASTER_FUNC}\(\)!!!" + echoerror "Failed to run ${PRESEED_MASTER_FUNC}()!!!" exit 1 fi fi @@ -7166,49 +7166,49 @@ fi # Install Salt if [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then # Only execute function is not in config mode only - echoinfo "Running ${INSTALL_FUNC}\(\)" + echoinfo "Running ${INSTALL_FUNC}()" if ! ${INSTALL_FUNC}; then - echoerror "Failed to run ${INSTALL_FUNC}\(\)!!!" + echoerror "Failed to run ${INSTALL_FUNC}()!!!" exit 1 fi fi # Run any post install function. Only execute function if not in config mode only if [ "$POST_INSTALL_FUNC" != "null" ] && [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then - echoinfo "Running ${POST_INSTALL_FUNC}\(\)" + echoinfo "Running ${POST_INSTALL_FUNC}()" if ! ${POST_INSTALL_FUNC}; then - echoerror "Failed to run ${POST_INSTALL_FUNC}\(\)!!!" + echoerror "Failed to run ${POST_INSTALL_FUNC}()!!!" exit 1 fi fi # Run any check services function, Only execute function if not in config mode only if [ "$CHECK_SERVICES_FUNC" != "null" ] && [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then - echoinfo "Running ${CHECK_SERVICES_FUNC}\(\)" + echoinfo "Running ${CHECK_SERVICES_FUNC}()" if ! ${CHECK_SERVICES_FUNC}; then - echoerror "Failed to run ${CHECK_SERVICES_FUNC}\(\)!!!" + echoerror "Failed to run ${CHECK_SERVICES_FUNC}()!!!" exit 1 fi fi # Run any start daemons function if [ "$STARTDAEMONS_INSTALL_FUNC" != "null" ] && [ ${_START_DAEMONS} -eq $BS_TRUE ]; then - echoinfo "Running ${STARTDAEMONS_INSTALL_FUNC}\(\)" + echoinfo "Running ${STARTDAEMONS_INSTALL_FUNC}()" echodebug "Waiting ${_SLEEP} seconds for processes to settle before checking for them" sleep ${_SLEEP} if ! ${STARTDAEMONS_INSTALL_FUNC}; then - echoerror "Failed to run ${STARTDAEMONS_INSTALL_FUNC}\(\)!!!" + echoerror "Failed to run ${STARTDAEMONS_INSTALL_FUNC}()!!!" exit 1 fi fi # Check if the installed daemons are running or not if [ "$DAEMONS_RUNNING_FUNC" != "null" ] && [ ${_START_DAEMONS} -eq $BS_TRUE ]; then - echoinfo "Running ${DAEMONS_RUNNING_FUNC}\(\)" + echoinfo "Running ${DAEMONS_RUNNING_FUNC}()" echodebug "Waiting ${_SLEEP} seconds for processes to settle before checking for them" sleep ${_SLEEP} # Sleep a little bit to let daemons start if ! ${DAEMONS_RUNNING_FUNC}; then - echoerror "Failed to run ${DAEMONS_RUNNING_FUNC}\(\)!!!" + echoerror "Failed to run ${DAEMONS_RUNNING_FUNC}()!!!" for fname in api master minion syndic; do # Skip salt-api since the service should be opt-in and not necessarily started on boot From fc7c0e70b71b5632f519abdd48cfea7b2ddb0715 Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Wed, 11 Dec 2019 16:15:06 -0700 Subject: [PATCH 40/64] Update due to testing errors --- bootstrap-salt.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 5624bd1..a1cf490 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -4935,6 +4935,7 @@ install_amazon_linux_ami_2_deps() { __PY_VERSION_REPO="yum" PY_PKG_VER="" + _PY_MAJOR_VERSION=$(echo "$_PY_PKG_VER" | cut -c 7) repo_name="SaltStack repo for Amazon Linux 2.0" if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then __PY_VERSION_REPO="py3" From 97d981dd961b2c37b5c419d579d169166f230092 Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Thu, 12 Dec 2019 11:02:39 -0700 Subject: [PATCH 41/64] Pull relevent changes from PR 1381 minus Fedora --- .drone.jsonnet | 38 +++++++++++++++++++++++++++----------- .drone.yml | 30 ++---------------------------- bootstrap-salt.sh | 12 ++++++++---- 3 files changed, 37 insertions(+), 43 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index 7396ee1..5169230 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -93,17 +93,33 @@ local Build(distro) = { project: 'open', }, - local suite = - if std.count(py2_blacklist, distro.slug) > 0 then - [] - else if std.count(stable_distros, distro.slug) > 0 then - git_suites + stable_suites - else git_suites, - local suites = suite + if std.count(blacklist_2018, distro.slug) > 0 then - git_py3_suites + stable_py3_suites[1:] - else if std.count(py3_distros, distro.slug) > 0 then - git_py3_suites + stable_py3_suites - else [], + local temp_git_suites = if std.count(py2_blacklist, distro.slug) > 0 then + [] + else + git_suites, + + local temp_stable_suites = if std.count(py2_blacklist, distro.slug) > 0 then + [] + else if std.count(stable_distros, distro.slug) > 0 then + stable_suites + else + [], + + local temp_git_py3_suites = if std.count(py3_distros, distro.slug) > 0 then + git_py3_suites + else + [], + + local temp_stable_py3_suites = if std.count(stable_distros, distro.slug) < 1 then + [] + else if std.count(blacklist_2018, distro.slug) > 0 then + stable_py3_suites[1:] + else if std.count(py3_distros, distro.slug) > 0 then + stable_py3_suites + else + [], + + local suites = temp_git_suites + temp_stable_suites + temp_git_py3_suites + temp_stable_py3_suites, steps: [ { diff --git a/.drone.yml b/.drone.yml index 61d943a..fcad439 100644 --- a/.drone.yml +++ b/.drone.yml @@ -851,7 +851,7 @@ steps: - name: throttle-build image: alpine commands: - - sh -c 't=108; echo Sleeping 108 seconds; sleep 108' + - sh -c 't=72; echo Sleeping 72 seconds; sleep 72' - name: create image: saltstack/drone-salt-bootstrap-testing @@ -918,32 +918,6 @@ steps: - throttle-build - create -- name: Py3 2018.3(Stable) - image: saltstack/drone-salt-bootstrap-testing - commands: - - pip install -U pip - - pip install -r tests/requirements.txt - - bundle install --with docker --without opennebula ec2 windows vagrant - - bundle exec kitchen test py3-stable-2018-3-fedora-30 - environment: - DOCKER_HOST: tcp://docker:2375 - depends_on: - - throttle-build - - create - -- name: Py3 2019.2(Stable) - image: saltstack/drone-salt-bootstrap-testing - commands: - - pip install -U pip - - pip install -r tests/requirements.txt - - bundle install --with docker --without opennebula ec2 windows vagrant - - bundle exec kitchen test py3-stable-2019-2-fedora-30 - environment: - DOCKER_HOST: tcp://docker:2375 - depends_on: - - throttle-build - - create - services: - name: docker image: saltstack/drone-salt-bootstrap-testing @@ -1313,6 +1287,6 @@ depends_on: --- kind: signature -hmac: 01bfd9713517348f9861dd811b44531bb17d6cf1e6635083aa27415824f36bed +hmac: da059b4d6fe84b6de7a7406e52a05e1c8c3666782b0e7191cecc5803014c4d60 ... diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index a1cf490..091d770 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -2911,9 +2911,11 @@ install_ubuntu_git() { fi if [ -f "${_SALT_GIT_CHECKOUT_DIR}/salt/syspaths.py" ]; then - ${_PYEXE} setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install --install-layout=deb || return 1 + # shellcheck disable=SC2086 + "${_PYEXE}" setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install --install-layout=deb || return 1 else - ${_PYEXE} setup.py ${SETUP_PY_INSTALL_ARGS} install --install-layout=deb || return 1 + # shellcheck disable=SC2086 + "${_PYEXE}" setup.py ${SETUP_PY_INSTALL_ARGS} install --install-layout=deb || return 1 fi return 0 @@ -3395,9 +3397,11 @@ install_debian_git() { fi if [ -f "${_SALT_GIT_CHECKOUT_DIR}/salt/syspaths.py" ]; then - ${_PYEXE} setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install --install-layout=deb || return 1 + # shellcheck disable=SC2086 + "${_PYEXE}" setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install --install-layout=deb || return 1 else - ${_PYEXE} setup.py ${SETUP_PY_INSTALL_ARGS} install --install-layout=deb || return 1 + # shellcheck disable=SC2086 + "${_PYEXE}" setup.py ${SETUP_PY_INSTALL_ARGS} install --install-layout=deb || return 1 fi } From 786022e2589b7371aeebf12be844226cc8482ba6 Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Thu, 12 Dec 2019 13:30:36 -0700 Subject: [PATCH 42/64] Ensure kitchen Amazon 2 has ps, and adjust gpg-key for Amazon 2 --- bootstrap-salt.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 091d770..c3038f7 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -4940,7 +4940,7 @@ install_amazon_linux_ami_2_deps() { __PY_VERSION_REPO="yum" PY_PKG_VER="" _PY_MAJOR_VERSION=$(echo "$_PY_PKG_VER" | cut -c 7) - repo_name="SaltStack repo for Amazon Linux 2.0" + repo_name="SaltStack repo for Amazon Linux 2" if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then __PY_VERSION_REPO="py3" PY_PKG_VER=3 @@ -4948,9 +4948,9 @@ install_amazon_linux_ami_2_deps() { fi base_url="$HTTP_VAL://${_REPO_URL}/${__PY_VERSION_REPO}/amazon/2/\$basearch/$repo_rev/" - gpg_key="${base_url}SALTSTACK-GPG-KEY.pub" - if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -ne 3 ]; then - "${base_url}base/RPM-GPG-KEY-CentOS-7" + gpg_key="${base_url}SALTSTACK-GPG-KEY.pub,${base_url}base/RPM-GPG-KEY-CentOS-7" + if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then + gpg_key="${base_url}SALTSTACK-GPG-KEY.pub" fi # This should prob be refactored to use __install_saltstack_rhel_repository() From 0ead2c80c9ee179e32554385a0d373a816b50dc4 Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Thu, 12 Dec 2019 14:22:31 -0700 Subject: [PATCH 43/64] Updated tests run for Python 3 Amazon Linux 2 and ensure Python 3 installed for Py 3 tests --- .kitchen.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.kitchen.yml b/.kitchen.yml index ee6f733..f7ffcca 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -40,6 +40,8 @@ platforms: image: amazonlinux:2 platform: rhel run_command: /usr/lib/systemd/systemd + provision_command: + - yum install -y procps-ng - name: arch driver_config: image: archlinux/base @@ -129,10 +131,11 @@ suites: - centos-6 - debian-8 - opensuse-15 + - amazon-2 - name: py3-git-2019-2 provisioner: salt_version: 2019.2 - salt_bootstrap_options: -x python3 -MPfq git %s + salt_bootstrap_options: -y -x python3 -MPfq git %s excludes: - amazon-1 - centos-6 @@ -150,7 +153,7 @@ suites: - name: py3-stable-2019-2 provisioner: salt_version: 2019.2 - salt_bootstrap_options: -x python3 -MP stable %s + salt_bootstrap_options: -y -x python3 -MP stable %s excludes: - amazon-1 - centos-6 From 73545457f892173f87571fd475cf5632f260d908 Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Thu, 12 Dec 2019 15:15:36 -0700 Subject: [PATCH 44/64] Attempt to not test 2018.3 and Amazon Linux 2 Py 3 --- .kitchen.yml | 2 +- bootstrap-salt.sh | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.kitchen.yml b/.kitchen.yml index f7ffcca..be5e2c2 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -153,7 +153,7 @@ suites: - name: py3-stable-2019-2 provisioner: salt_version: 2019.2 - salt_bootstrap_options: -y -x python3 -MP stable %s + salt_bootstrap_options: -x python3 -MP stable %s excludes: - amazon-1 - centos-6 diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index c3038f7..0edeaae 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -4834,6 +4834,7 @@ install_amazon_linux_ami_2_git_deps() { yum -y install ca-certificates || return 1 fi + install_amazon_linux_ami_2_deps || return 1 if __check_command_exists python3; then if ! __check_command_exists pip3; then __yum_install_noinput python3-pip @@ -4850,7 +4851,6 @@ install_amazon_linux_ami_2_git_deps() { _PY_EXE='python2.7' fi fi - install_amazon_linux_ami_2_deps || return 1 if ! __check_command_exists git; then __yum_install_noinput git || return 1 @@ -4936,14 +4936,16 @@ install_amazon_linux_ami_2_deps() { if [ $_DISABLE_REPOS -eq $BS_FALSE ] || [ "$_CUSTOM_REPO_URL" != "null" ]; then __REPO_FILENAME="saltstack-repo.repo" - __PY_VERSION_REPO="yum" PY_PKG_VER="" _PY_MAJOR_VERSION=$(echo "$_PY_PKG_VER" | cut -c 7) + repo_label="saltstack-repo" repo_name="SaltStack repo for Amazon Linux 2" if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq 3 ]; then + __REPO_FILENAME="saltstack-py3-repo.repo" __PY_VERSION_REPO="py3" PY_PKG_VER=3 + repo_label="saltstack-py3-repo" repo_name="SaltStack Python 3 repo for Amazon Linux 2" fi @@ -4958,7 +4960,7 @@ install_amazon_linux_ami_2_deps() { # amazon linux yum file. if [ ! -s "/etc/yum.repos.d/${__REPO_FILENAME}" ]; then cat <<_eof > "/etc/yum.repos.d/${__REPO_FILENAME}" -[saltstack-repo] +[$repo_label] name=$repo_name failovermethod=priority priority=10 @@ -4973,10 +4975,9 @@ _eof # Package python-ordereddict-1.1-2.el6.noarch is obsoleted by python26-2.6.9-2.88.amzn1.x86_64 # which is already installed if [ "${PY_PKG_VER}" -eq 3 ]; then - __PACKAGES="${pkg_append}${PY_PKG_VER}-m2crypto ${pkg_append}${PY_PKG_VER}-pyyaml" - + __PACKAGES="python3 ${pkg_append}${PY_PKG_VER}-m2crypto ${pkg_append}${PY_PKG_VER}-pyyaml" else - __PACKAGES="m2crypto PyYAML ${pkg_append}-futures" + __PACKAGES="m2crypto PyYAML ${pkg_append}-futures" fi __PACKAGES="${__PACKAGES} ${pkg_append}${PY_PKG_VER}-crypto ${pkg_append}${PY_PKG_VER}-jinja2 procps-ng" From b3120c497d65e1014bd7eb343249a95864f58f32 Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Thu, 12 Dec 2019 17:55:16 -0700 Subject: [PATCH 45/64] Allow for correct Py 3 Tornado --- .kitchen.yml | 2 +- bootstrap-salt.sh | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.kitchen.yml b/.kitchen.yml index be5e2c2..4ebb187 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -135,7 +135,7 @@ suites: - name: py3-git-2019-2 provisioner: salt_version: 2019.2 - salt_bootstrap_options: -y -x python3 -MPfq git %s + salt_bootstrap_options: -x python3 -MPfq git %s excludes: - amazon-1 - centos-6 diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 0edeaae..0aa6fd8 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -270,6 +270,7 @@ _QUIET_GIT_INSTALLATION=$BS_FALSE _REPO_URL="repo.saltstack.com" _PY_EXE="" _INSTALL_PY="$BS_FALSE" +_TORNADO_MAX_PY3_VERSION="5.0" # Defaults for install arguments ITYPE="stable" @@ -4866,6 +4867,7 @@ install_amazon_linux_ami_2_git_deps() { if [ "$PARSED_VERSION" -eq "2" ]; then if [ -n "$_PY_EXE" ] && [ "$_PY_MAJOR_VERSION" -eq "3" ]; then __PACKAGES="${__PACKAGES} python3-pip" + __PIP_PACKAGES="${__PIP_PACKAGES} tornado<$_TORNADO_MAX_PY3_VERSION" else __PACKAGES="${__PACKAGES} python2-pip" fi @@ -4879,7 +4881,7 @@ install_amazon_linux_ami_2_git_deps() { # We're on the develop branch, install whichever tornado is on the requirements file __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" if [ "${__REQUIRED_TORNADO}" != "" ]; then - __PACKAGES="${__PACKAGES} ${pkg_append}-tornado" + __PACKAGES="${__PACKAGES} ${pkg_append}${PY_PKG_VER}-tornado" fi fi From 39afc11bc9b4ad6dda5a1460bad9c60799e28d0b Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Thu, 12 Dec 2019 18:23:32 -0700 Subject: [PATCH 46/64] Python 3 support for Amazon Linux 2 on 2018.3 branch --- .drone.jsonnet | 1 - .drone.yml | 17 +++++++++++++++-- .kitchen.yml | 1 - 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index 5169230..0acc4b1 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -67,7 +67,6 @@ local py2_blacklist = [ local blacklist_2018 = [ 'centos-8', 'debian-10', - 'amazon-2', ]; local Shellcheck() = { diff --git a/.drone.yml b/.drone.yml index fcad439..101d721 100644 --- a/.drone.yml +++ b/.drone.yml @@ -90,7 +90,7 @@ steps: - name: throttle-build image: alpine commands: - - sh -c 't=84; echo Sleeping 84 seconds; sleep 84' + - sh -c 't=96; echo Sleeping 96 seconds; sleep 96' - name: create image: saltstack/drone-salt-bootstrap-testing @@ -183,6 +183,19 @@ steps: - throttle-build - create +- name: Py3 2018.3(Stable) + image: saltstack/drone-salt-bootstrap-testing + commands: + - pip install -U pip + - pip install -r tests/requirements.txt + - bundle install --with docker --without opennebula ec2 windows vagrant + - bundle exec kitchen test py3-stable-2018-3-amazon-2 + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + - create + - name: Py3 2019.2(Stable) image: saltstack/drone-salt-bootstrap-testing commands: @@ -1287,6 +1300,6 @@ depends_on: --- kind: signature -hmac: da059b4d6fe84b6de7a7406e52a05e1c8c3666782b0e7191cecc5803014c4d60 +hmac: 7149a0a774f38abdd26d312c9df3febaaa4ca7b3e502da0847d42c3973e373ae ... diff --git a/.kitchen.yml b/.kitchen.yml index 4ebb187..cf1dee4 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -131,7 +131,6 @@ suites: - centos-6 - debian-8 - opensuse-15 - - amazon-2 - name: py3-git-2019-2 provisioner: salt_version: 2019.2 From 7dc6ba06d64cb7ba05e9b4dd42fab700daf8d19d Mon Sep 17 00:00:00 2001 From: LSH Date: Fri, 13 Dec 2019 12:38:02 +1030 Subject: [PATCH 47/64] readme.rst, adds minimum Salt version for python3 --- README.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.rst b/README.rst index 8e45818..7a7e0bc 100644 --- a/README.rst +++ b/README.rst @@ -372,6 +372,8 @@ Installing the Python 3 packages for Salt is done via the ``-x`` option: See the ``-x`` option for more information. +The earliest release of Salt that supports Python3 is `2018.3.4`. + Tornado 5/6 Workaround ---------------------- Salt does not support tornado>=5.0 currently. This support will not be added until the neon From 46e9d91b2b1effb50de0c2dbb76cc7331af811aa Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Thu, 12 Dec 2019 19:12:27 -0700 Subject: [PATCH 48/64] Removed Amazon 2 for Py 3 git and stable --- .kitchen.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.kitchen.yml b/.kitchen.yml index cf1dee4..cb86ed7 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -131,6 +131,7 @@ suites: - centos-6 - debian-8 - opensuse-15 + - amazon-2 - name: py3-git-2019-2 provisioner: salt_version: 2019.2 @@ -149,6 +150,7 @@ suites: - centos-6 - debian-8 - opensuse-15 + - amazon-2 - name: py3-stable-2019-2 provisioner: salt_version: 2019.2 From 74b60e69d77b42246b1a9f48928c05e032a1b674 Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Thu, 12 Dec 2019 21:52:45 -0700 Subject: [PATCH 49/64] Further attempts to remove branch 2018.3 for Amazon Linux 2 Py 3 Git and Stable --- .drone.jsonnet | 7 +++++- .drone.yml | 60 ++++---------------------------------------------- 2 files changed, 10 insertions(+), 57 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index 0acc4b1..a460ac9 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -67,6 +67,7 @@ local py2_blacklist = [ local blacklist_2018 = [ 'centos-8', 'debian-10', + 'amazon-2', ]; local Shellcheck() = { @@ -104,7 +105,11 @@ local Build(distro) = { else [], - local temp_git_py3_suites = if std.count(py3_distros, distro.slug) > 0 then + local temp_git_py3_suites = if std.count(py3_distros, distro.slug) < 1 then + [] + else if std.count(blacklist_2018, distro.slug) > 0 then + git_py3_suites[1:] + else if std.count(py3_distros, distro.slug) > 0 then git_py3_suites else [], diff --git a/.drone.yml b/.drone.yml index 101d721..44ceaf4 100644 --- a/.drone.yml +++ b/.drone.yml @@ -90,7 +90,7 @@ steps: - name: throttle-build image: alpine commands: - - sh -c 't=96; echo Sleeping 96 seconds; sleep 96' + - sh -c 't=72; echo Sleeping 72 seconds; sleep 72' - name: create image: saltstack/drone-salt-bootstrap-testing @@ -157,19 +157,6 @@ steps: - throttle-build - create -- name: Py3 2018.3(Git) - image: saltstack/drone-salt-bootstrap-testing - commands: - - pip install -U pip - - pip install -r tests/requirements.txt - - bundle install --with docker --without opennebula ec2 windows vagrant - - bundle exec kitchen test py3-git-2018-3-amazon-2 - environment: - DOCKER_HOST: tcp://docker:2375 - depends_on: - - throttle-build - - create - - name: Py3 2019.2(Git) image: saltstack/drone-salt-bootstrap-testing commands: @@ -183,19 +170,6 @@ steps: - throttle-build - create -- name: Py3 2018.3(Stable) - image: saltstack/drone-salt-bootstrap-testing - commands: - - pip install -U pip - - pip install -r tests/requirements.txt - - bundle install --with docker --without opennebula ec2 windows vagrant - - bundle exec kitchen test py3-stable-2018-3-amazon-2 - environment: - DOCKER_HOST: tcp://docker:2375 - depends_on: - - throttle-build - - create - - name: Py3 2019.2(Stable) image: saltstack/drone-salt-bootstrap-testing commands: @@ -470,7 +444,7 @@ steps: - name: throttle-build image: alpine commands: - - sh -c 't=90; echo Sleeping 90 seconds; sleep 90' + - sh -c 't=60; echo Sleeping 60 seconds; sleep 60' - name: create image: saltstack/drone-salt-bootstrap-testing @@ -485,19 +459,6 @@ steps: depends_on: - throttle-build -- name: Py3 2018.3(Git) - image: saltstack/drone-salt-bootstrap-testing - commands: - - pip install -U pip - - pip install -r tests/requirements.txt - - bundle install --with docker --without opennebula ec2 windows vagrant - - bundle exec kitchen test py3-git-2018-3-centos-8 - environment: - DOCKER_HOST: tcp://docker:2375 - depends_on: - - throttle-build - - create - - name: Py3 2019.2(Git) image: saltstack/drone-salt-bootstrap-testing commands: @@ -785,7 +746,7 @@ steps: - name: throttle-build image: alpine commands: - - sh -c 't=72; echo Sleeping 72 seconds; sleep 72' + - sh -c 't=48; echo Sleeping 48 seconds; sleep 48' - name: create image: saltstack/drone-salt-bootstrap-testing @@ -800,19 +761,6 @@ steps: depends_on: - throttle-build -- name: Py3 2018.3(Git) - image: saltstack/drone-salt-bootstrap-testing - commands: - - pip install -U pip - - pip install -r tests/requirements.txt - - bundle install --with docker --without opennebula ec2 windows vagrant - - bundle exec kitchen test py3-git-2018-3-debian-10 - environment: - DOCKER_HOST: tcp://docker:2375 - depends_on: - - throttle-build - - create - - name: Py3 2019.2(Git) image: saltstack/drone-salt-bootstrap-testing commands: @@ -1300,6 +1248,6 @@ depends_on: --- kind: signature -hmac: 7149a0a774f38abdd26d312c9df3febaaa4ca7b3e502da0847d42c3973e373ae +hmac: a1e3b561c227bc7ec6fa8c0319d4c55d98f42c7311015123d63cf78292e9d318 ... From 3ea5668fd0158f3c9ca1d710e9e96e4188cc8106 Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Fri, 13 Dec 2019 08:31:06 -0700 Subject: [PATCH 50/64] Added arch to Python 3 distros --- .drone.jsonnet | 1 + .drone.yml | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index a460ac9..f67f5ce 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -50,6 +50,7 @@ local stable_distros = [ local py3_distros = [ 'amazon-2', + 'arch', 'centos-7', 'centos-8', 'debian-9', diff --git a/.drone.yml b/.drone.yml index 44ceaf4..0caf8ad 100644 --- a/.drone.yml +++ b/.drone.yml @@ -65,6 +65,32 @@ steps: - throttle-build - create +- name: Py3 2018.3(Git) + image: saltstack/drone-salt-bootstrap-testing + commands: + - pip install -U pip + - pip install -r tests/requirements.txt + - bundle install --with docker --without opennebula ec2 windows vagrant + - bundle exec kitchen test py3-git-2018-3-arch + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + - create + +- name: Py3 2019.2(Git) + image: saltstack/drone-salt-bootstrap-testing + commands: + - pip install -U pip + - pip install -r tests/requirements.txt + - bundle install --with docker --without opennebula ec2 windows vagrant + - bundle exec kitchen test py3-git-2019-2-arch + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + - create + services: - name: docker image: saltstack/drone-salt-bootstrap-testing @@ -1248,6 +1274,6 @@ depends_on: --- kind: signature -hmac: a1e3b561c227bc7ec6fa8c0319d4c55d98f42c7311015123d63cf78292e9d318 +hmac: d34adb5aae5ec297aaf275c1fc17ae87369b57b0d043be2a6c15b294456a57a3 ... From 2f14c09f1b70741333973128d29784e0d727b7f1 Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Fri, 13 Dec 2019 10:32:36 -0700 Subject: [PATCH 51/64] Increased drone startup time --- .drone.jsonnet | 2 +- .drone.yml | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index f67f5ce..412c6fc 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -149,7 +149,7 @@ local Build(distro) = { commands: [ 'bundle install --with docker --without opennebula ec2 windows vagrant', "echo 'Waiting for docker to start'", - 'sleep 15', // give docker enough time to start + 'sleep 30', // give docker enough time to start 'docker ps -a', std.format('bundle exec kitchen create %s', [distro.slug]), ], diff --git a/.drone.yml b/.drone.yml index 0caf8ad..9da7314 100644 --- a/.drone.yml +++ b/.drone.yml @@ -31,7 +31,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 15 + - sleep 30 - docker ps -a - bundle exec kitchen create arch environment: @@ -123,7 +123,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 15 + - sleep 30 - docker ps -a - bundle exec kitchen create amazon-2 environment: @@ -241,7 +241,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 15 + - sleep 30 - docker ps -a - bundle exec kitchen create centos-6 environment: @@ -333,7 +333,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 15 + - sleep 30 - docker ps -a - bundle exec kitchen create centos-7 environment: @@ -477,7 +477,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 15 + - sleep 30 - docker ps -a - bundle exec kitchen create centos-8 environment: @@ -543,7 +543,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 15 + - sleep 30 - docker ps -a - bundle exec kitchen create debian-8 environment: @@ -635,7 +635,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 15 + - sleep 30 - docker ps -a - bundle exec kitchen create debian-9 environment: @@ -779,7 +779,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 15 + - sleep 30 - docker ps -a - bundle exec kitchen create debian-10 environment: @@ -845,7 +845,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 15 + - sleep 30 - docker ps -a - bundle exec kitchen create fedora-30 environment: @@ -937,7 +937,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 15 + - sleep 30 - docker ps -a - bundle exec kitchen create opensuse-15 environment: @@ -1003,7 +1003,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 15 + - sleep 30 - docker ps -a - bundle exec kitchen create ubuntu-1604 environment: @@ -1147,7 +1147,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 15 + - sleep 30 - docker ps -a - bundle exec kitchen create ubuntu-1804 environment: @@ -1274,6 +1274,6 @@ depends_on: --- kind: signature -hmac: d34adb5aae5ec297aaf275c1fc17ae87369b57b0d043be2a6c15b294456a57a3 +hmac: 5b2b9370523a7c47e068ffd8e99fda323bfa69f4d2a489b8e96241028ebd1967 ... From fc30af2e12776a89c258ddfbbfb5ee3e9a310ecd Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Fri, 13 Dec 2019 11:56:55 -0700 Subject: [PATCH 52/64] Removed arch changes since arch failing to install its keys --- .drone.jsonnet | 1 - .drone.yml | 28 +--------------------------- bootstrap-salt.sh | 2 +- 3 files changed, 2 insertions(+), 29 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index 412c6fc..a3d2e64 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -50,7 +50,6 @@ local stable_distros = [ local py3_distros = [ 'amazon-2', - 'arch', 'centos-7', 'centos-8', 'debian-9', diff --git a/.drone.yml b/.drone.yml index 9da7314..1c3c697 100644 --- a/.drone.yml +++ b/.drone.yml @@ -65,32 +65,6 @@ steps: - throttle-build - create -- name: Py3 2018.3(Git) - image: saltstack/drone-salt-bootstrap-testing - commands: - - pip install -U pip - - pip install -r tests/requirements.txt - - bundle install --with docker --without opennebula ec2 windows vagrant - - bundle exec kitchen test py3-git-2018-3-arch - environment: - DOCKER_HOST: tcp://docker:2375 - depends_on: - - throttle-build - - create - -- name: Py3 2019.2(Git) - image: saltstack/drone-salt-bootstrap-testing - commands: - - pip install -U pip - - pip install -r tests/requirements.txt - - bundle install --with docker --without opennebula ec2 windows vagrant - - bundle exec kitchen test py3-git-2019-2-arch - environment: - DOCKER_HOST: tcp://docker:2375 - depends_on: - - throttle-build - - create - services: - name: docker image: saltstack/drone-salt-bootstrap-testing @@ -1274,6 +1248,6 @@ depends_on: --- kind: signature -hmac: 5b2b9370523a7c47e068ffd8e99fda323bfa69f4d2a489b8e96241028ebd1967 +hmac: 1501ae2ebbd8a40fdb84727c1144aaf4b58e3aa4a4d354e49f820acb213d4a4e ... diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 0aa6fd8..f8c0511 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -4977,7 +4977,7 @@ _eof # Package python-ordereddict-1.1-2.el6.noarch is obsoleted by python26-2.6.9-2.88.amzn1.x86_64 # which is already installed if [ "${PY_PKG_VER}" -eq 3 ]; then - __PACKAGES="python3 ${pkg_append}${PY_PKG_VER}-m2crypto ${pkg_append}${PY_PKG_VER}-pyyaml" + __PACKAGES="${pkg_append}${PY_PKG_VER}-m2crypto ${pkg_append}${PY_PKG_VER}-pyyaml" else __PACKAGES="m2crypto PyYAML ${pkg_append}-futures" fi From 4d9ee532e59b69d249ce102a9d8bcd625031b5cf Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Fri, 13 Dec 2019 13:37:33 -0700 Subject: [PATCH 53/64] Disabled 'arch' testing --- .drone.jsonnet | 2 +- .drone.yml | 68 +------------------------------------------------- 2 files changed, 2 insertions(+), 68 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index a3d2e64..ad1dc05 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -20,7 +20,7 @@ local stable_py3_suites = [ ]; local distros = [ - { name: 'Arch', slug: 'arch', multiplier: 0, depends: [] }, +// { name: 'Arch', slug: 'arch', multiplier: 0, depends: [] }, // { name: 'Amazon 1', slug: 'amazon-1', multiplier: 1, depends: [] }, { name: 'Amazon 2', slug: 'amazon-2', multiplier: 2, depends: [] }, { name: 'CentOS 6', slug: 'centos-6', multiplier: 3, depends: [] }, diff --git a/.drone.yml b/.drone.yml index 1c3c697..035f974 100644 --- a/.drone.yml +++ b/.drone.yml @@ -12,72 +12,6 @@ steps: commands: - shellcheck -s sh -f checkstyle bootstrap-salt.sh ---- -kind: pipeline -name: Arch - -platform: - os: linux - arch: amd64 - -steps: -- name: throttle-build - image: alpine - commands: - - sh -c 't=0; echo Sleeping 0 seconds; sleep 0' - -- name: create - image: saltstack/drone-salt-bootstrap-testing - commands: - - bundle install --with docker --without opennebula ec2 windows vagrant - - echo 'Waiting for docker to start' - - sleep 30 - - docker ps -a - - bundle exec kitchen create arch - environment: - DOCKER_HOST: tcp://docker:2375 - depends_on: - - throttle-build - -- name: Py2 2018.3(Git) - image: saltstack/drone-salt-bootstrap-testing - commands: - - pip install -U pip - - pip install -r tests/requirements.txt - - bundle install --with docker --without opennebula ec2 windows vagrant - - bundle exec kitchen test py2-git-2018-3-arch - environment: - DOCKER_HOST: tcp://docker:2375 - depends_on: - - throttle-build - - create - -- name: Py2 2019.2(Git) - image: saltstack/drone-salt-bootstrap-testing - commands: - - pip install -U pip - - pip install -r tests/requirements.txt - - bundle install --with docker --without opennebula ec2 windows vagrant - - bundle exec kitchen test py2-git-2019-2-arch - environment: - DOCKER_HOST: tcp://docker:2375 - depends_on: - - throttle-build - - create - -services: -- name: docker - image: saltstack/drone-salt-bootstrap-testing - command: - - --storage-driver=overlay2 - privileged: true - -node: - project: open - -depends_on: -- Lint - --- kind: pipeline name: Amazon 2 @@ -1248,6 +1182,6 @@ depends_on: --- kind: signature -hmac: 1501ae2ebbd8a40fdb84727c1144aaf4b58e3aa4a4d354e49f820acb213d4a4e +hmac: b6b552aff7d2d8de9fc31b11c86faae9d5da0f58499fd529210c94854e70b45b ... From c4782d2743988cd7e75680f11e0509515cd0075e Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Fri, 13 Dec 2019 16:55:25 -0700 Subject: [PATCH 54/64] Adding back Arch --- .drone.jsonnet | 5 ++- .drone.yml | 116 ++++++++++++++++++++++++++++++++++++++++++++----- .kitchen.yml | 2 +- 3 files changed, 108 insertions(+), 15 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index ad1dc05..02df5e6 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -20,7 +20,7 @@ local stable_py3_suites = [ ]; local distros = [ -// { name: 'Arch', slug: 'arch', multiplier: 0, depends: [] }, + { name: 'Arch', slug: 'arch', multiplier: 0, depends: [] }, // { name: 'Amazon 1', slug: 'amazon-1', multiplier: 1, depends: [] }, { name: 'Amazon 2', slug: 'amazon-2', multiplier: 2, depends: [] }, { name: 'CentOS 6', slug: 'centos-6', multiplier: 3, depends: [] }, @@ -50,6 +50,7 @@ local stable_distros = [ local py3_distros = [ 'amazon-2', + 'arch', 'centos-7', 'centos-8', 'debian-9', @@ -148,7 +149,7 @@ local Build(distro) = { commands: [ 'bundle install --with docker --without opennebula ec2 windows vagrant', "echo 'Waiting for docker to start'", - 'sleep 30', // give docker enough time to start + 'sleep 20', // give docker enough time to start 'docker ps -a', std.format('bundle exec kitchen create %s', [distro.slug]), ], diff --git a/.drone.yml b/.drone.yml index 035f974..ceb9c83 100644 --- a/.drone.yml +++ b/.drone.yml @@ -12,6 +12,98 @@ steps: commands: - shellcheck -s sh -f checkstyle bootstrap-salt.sh +--- +kind: pipeline +name: Arch + +platform: + os: linux + arch: amd64 + +steps: +- name: throttle-build + image: alpine + commands: + - sh -c 't=0; echo Sleeping 0 seconds; sleep 0' + +- name: create + image: saltstack/drone-salt-bootstrap-testing + commands: + - bundle install --with docker --without opennebula ec2 windows vagrant + - echo 'Waiting for docker to start' + - sleep 20 + - docker ps -a + - bundle exec kitchen create arch + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + +- name: Py2 2018.3(Git) + image: saltstack/drone-salt-bootstrap-testing + commands: + - pip install -U pip + - pip install -r tests/requirements.txt + - bundle install --with docker --without opennebula ec2 windows vagrant + - bundle exec kitchen test py2-git-2018-3-arch + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + - create + +- name: Py2 2019.2(Git) + image: saltstack/drone-salt-bootstrap-testing + commands: + - pip install -U pip + - pip install -r tests/requirements.txt + - bundle install --with docker --without opennebula ec2 windows vagrant + - bundle exec kitchen test py2-git-2019-2-arch + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + - create + +- name: Py3 2018.3(Git) + image: saltstack/drone-salt-bootstrap-testing + commands: + - pip install -U pip + - pip install -r tests/requirements.txt + - bundle install --with docker --without opennebula ec2 windows vagrant + - bundle exec kitchen test py3-git-2018-3-arch + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + - create + +- name: Py3 2019.2(Git) + image: saltstack/drone-salt-bootstrap-testing + commands: + - pip install -U pip + - pip install -r tests/requirements.txt + - bundle install --with docker --without opennebula ec2 windows vagrant + - bundle exec kitchen test py3-git-2019-2-arch + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + - create + +services: +- name: docker + image: saltstack/drone-salt-bootstrap-testing + command: + - --storage-driver=overlay2 + privileged: true + +node: + project: open + +depends_on: +- Lint + --- kind: pipeline name: Amazon 2 @@ -31,7 +123,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 30 + - sleep 20 - docker ps -a - bundle exec kitchen create amazon-2 environment: @@ -149,7 +241,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 30 + - sleep 20 - docker ps -a - bundle exec kitchen create centos-6 environment: @@ -241,7 +333,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 30 + - sleep 20 - docker ps -a - bundle exec kitchen create centos-7 environment: @@ -385,7 +477,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 30 + - sleep 20 - docker ps -a - bundle exec kitchen create centos-8 environment: @@ -451,7 +543,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 30 + - sleep 20 - docker ps -a - bundle exec kitchen create debian-8 environment: @@ -543,7 +635,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 30 + - sleep 20 - docker ps -a - bundle exec kitchen create debian-9 environment: @@ -687,7 +779,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 30 + - sleep 20 - docker ps -a - bundle exec kitchen create debian-10 environment: @@ -753,7 +845,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 30 + - sleep 20 - docker ps -a - bundle exec kitchen create fedora-30 environment: @@ -845,7 +937,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 30 + - sleep 20 - docker ps -a - bundle exec kitchen create opensuse-15 environment: @@ -911,7 +1003,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 30 + - sleep 20 - docker ps -a - bundle exec kitchen create ubuntu-1604 environment: @@ -1055,7 +1147,7 @@ steps: commands: - bundle install --with docker --without opennebula ec2 windows vagrant - echo 'Waiting for docker to start' - - sleep 30 + - sleep 20 - docker ps -a - bundle exec kitchen create ubuntu-1804 environment: @@ -1182,6 +1274,6 @@ depends_on: --- kind: signature -hmac: b6b552aff7d2d8de9fc31b11c86faae9d5da0f58499fd529210c94854e70b45b +hmac: 93a6ec723c8cd2d30cb3926f1faaffc1876b68438b8be2abaece471941026d78 ... diff --git a/.kitchen.yml b/.kitchen.yml index cb86ed7..4fd2a8c 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -41,7 +41,7 @@ platforms: platform: rhel run_command: /usr/lib/systemd/systemd provision_command: - - yum install -y procps-ng + - yum -y install procps-ng - name: arch driver_config: image: archlinux/base From 254457d53c85a9ad1aed589899e7105393e861b9 Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Mon, 16 Dec 2019 12:50:35 -0700 Subject: [PATCH 55/64] Attempt to fix issue on Arch with Arch keys failing to install --- .kitchen.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.kitchen.yml b/.kitchen.yml index 4fd2a8c..229ffa3 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -47,6 +47,7 @@ platforms: image: archlinux/base run_command: /usr/lib/systemd/systemd provision_command: + - pacman-key --refresh-keys - pacman -Syu --noconfirm --needed systemd grep awk procps which - systemctl enable sshd - name: centos-8 From a0342a70875f0cbd07b7e9eae8d6e827ccaca924 Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Mon, 16 Dec 2019 14:26:45 -0700 Subject: [PATCH 56/64] Reinstalling pacman keys for Arch --- .kitchen.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.kitchen.yml b/.kitchen.yml index 229ffa3..686b43a 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -47,7 +47,9 @@ platforms: image: archlinux/base run_command: /usr/lib/systemd/systemd provision_command: - - pacman-key --refresh-keys + - rm -fR /etc/pacman.d/gnupg + - pacman-key --init + - pacman-key --populate archlinux - pacman -Syu --noconfirm --needed systemd grep awk procps which - systemctl enable sshd - name: centos-8 From ec04f5404c4c3f622739ce171cea283763056c46 Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Tue, 17 Dec 2019 11:19:34 -0700 Subject: [PATCH 57/64] Futher attempts to get Arch to run successfully, noting no gold test image --- .drone.jsonnet | 1 + .drone.yml | 56 ++++++++++++++++++++++++++++++++++++++++++++++++-- .kitchen.yml | 3 --- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index 02df5e6..545a443 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -44,6 +44,7 @@ local stable_distros = [ 'debian-8', 'debian-9', 'debian-10', + 'fedora-30', 'ubuntu-1604', 'ubuntu-1804', ]; diff --git a/.drone.yml b/.drone.yml index ceb9c83..17c18bd 100644 --- a/.drone.yml +++ b/.drone.yml @@ -838,7 +838,7 @@ steps: - name: throttle-build image: alpine commands: - - sh -c 't=72; echo Sleeping 72 seconds; sleep 72' + - sh -c 't=144; echo Sleeping 144 seconds; sleep 144' - name: create image: saltstack/drone-salt-bootstrap-testing @@ -879,6 +879,32 @@ steps: - throttle-build - create +- name: Py2 2018.3(Stable) + image: saltstack/drone-salt-bootstrap-testing + commands: + - pip install -U pip + - pip install -r tests/requirements.txt + - bundle install --with docker --without opennebula ec2 windows vagrant + - bundle exec kitchen test py2-stable-2018-3-fedora-30 + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + - create + +- name: Py2 2019.2(Stable) + image: saltstack/drone-salt-bootstrap-testing + commands: + - pip install -U pip + - pip install -r tests/requirements.txt + - bundle install --with docker --without opennebula ec2 windows vagrant + - bundle exec kitchen test py2-stable-2019-2-fedora-30 + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + - create + - name: Py3 2018.3(Git) image: saltstack/drone-salt-bootstrap-testing commands: @@ -905,6 +931,32 @@ steps: - throttle-build - create +- name: Py3 2018.3(Stable) + image: saltstack/drone-salt-bootstrap-testing + commands: + - pip install -U pip + - pip install -r tests/requirements.txt + - bundle install --with docker --without opennebula ec2 windows vagrant + - bundle exec kitchen test py3-stable-2018-3-fedora-30 + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + - create + +- name: Py3 2019.2(Stable) + image: saltstack/drone-salt-bootstrap-testing + commands: + - pip install -U pip + - pip install -r tests/requirements.txt + - bundle install --with docker --without opennebula ec2 windows vagrant + - bundle exec kitchen test py3-stable-2019-2-fedora-30 + environment: + DOCKER_HOST: tcp://docker:2375 + depends_on: + - throttle-build + - create + services: - name: docker image: saltstack/drone-salt-bootstrap-testing @@ -1274,6 +1326,6 @@ depends_on: --- kind: signature -hmac: 93a6ec723c8cd2d30cb3926f1faaffc1876b68438b8be2abaece471941026d78 +hmac: 59c8f7c861aea35dba9890b536519e10b6e41452bb6c15f88b6a7dbc6e158506 ... diff --git a/.kitchen.yml b/.kitchen.yml index 686b43a..4fd2a8c 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -47,9 +47,6 @@ platforms: image: archlinux/base run_command: /usr/lib/systemd/systemd provision_command: - - rm -fR /etc/pacman.d/gnupg - - pacman-key --init - - pacman-key --populate archlinux - pacman -Syu --noconfirm --needed systemd grep awk procps which - systemctl enable sshd - name: centos-8 From e82be4f0eeaa741eeec821eb11d896af76ef74b2 Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Wed, 18 Dec 2019 15:57:10 -0700 Subject: [PATCH 58/64] Updated script version --- bootstrap-salt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index f8c0511..1053c3d 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -23,7 +23,7 @@ #====================================================================================================================== set -o nounset # Treat unset variables as an error -__ScriptVersion="2019.11.04" +__ScriptVersion="2019.12.18" __ScriptName="bootstrap-salt.sh" __ScriptFullName="$0" From 0fbc27b28c064323f94eb72d528a1eb55352110c Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Thu, 19 Dec 2019 10:24:39 -0700 Subject: [PATCH 59/64] Futher attempts to compenstate for Drone's bad restart of tests --- bootstrap-salt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 1053c3d..1b0f834 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -23,7 +23,7 @@ #====================================================================================================================== set -o nounset # Treat unset variables as an error -__ScriptVersion="2019.12.18" +__ScriptVersion="2019.12.19" __ScriptName="bootstrap-salt.sh" __ScriptFullName="$0" From e153981ad67c17e248ffdb3524e637b1507093cc Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Thu, 2 Jan 2020 12:10:37 -0700 Subject: [PATCH 60/64] Revert version for script version to original value --- bootstrap-salt.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 1b0f834..24f7f42 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -1,4 +1,4 @@ -#!/bin/sh - +!/bin/sh - # WARNING: Changes to this file in the salt repo will be overwritten! # Please submit pull requests against the salt-bootstrap repo: @@ -23,7 +23,7 @@ #====================================================================================================================== set -o nounset # Treat unset variables as an error -__ScriptVersion="2019.12.19" +__ScriptVersion="2019.11.04" __ScriptName="bootstrap-salt.sh" __ScriptFullName="$0" From 5d6945c5eda87bde8542956562b7834b22e3c99f Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Thu, 2 Jan 2020 12:34:04 -0700 Subject: [PATCH 61/64] Fix typo --- bootstrap-salt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index 24f7f42..f8c0511 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -1,4 +1,4 @@ -!/bin/sh - +#!/bin/sh - # WARNING: Changes to this file in the salt repo will be overwritten! # Please submit pull requests against the salt-bootstrap repo: From e794ddadf32376e95c313b47bd9aa123841ecdbe Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Mon, 6 Jan 2020 13:54:01 -0700 Subject: [PATCH 62/64] Updated Opensuse from 15.0 to 15.1 to get past Opensuse curl induced SIGSEGV --- .kitchen.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.kitchen.yml b/.kitchen.yml index 4fd2a8c..3d4db93 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -83,7 +83,7 @@ platforms: run_command: /usr/lib/systemd/systemd - name: opensuse-15 driver_config: - image: opensuse/leap:15.0 + image: opensuse/leap:15.1 run_command: /usr/lib/systemd/systemd provision_command: - zypper --non-interactive install --auto-agree-with-licenses dbus-1 From 42155ce8f947fc6dae5fa6c5a3530cc11ea84012 Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Mon, 6 Jan 2020 14:13:45 -0700 Subject: [PATCH 63/64] Updated Opensuse label from 15.0 to 15.1 --- .drone.jsonnet | 2 +- .drone.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index 545a443..a3dafff 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -30,7 +30,7 @@ local distros = [ { name: 'Debian 9', slug: 'debian-9', multiplier: 5, depends: [] }, { name: 'Debian 10', slug: 'debian-10', multiplier: 4, depends: [] }, { name: 'Fedora 30', slug: 'fedora-30', multiplier: 3, depends: [] }, - { name: 'Opensuse 15.0', slug: 'opensuse-15', multiplier: 2, depends: [] }, + { name: 'Opensuse 15.1', slug: 'opensuse-15', multiplier: 2, depends: [] }, { name: 'Ubuntu 16.04', slug: 'ubuntu-1604', multiplier: 1, depends: [] }, { name: 'Ubuntu 18.04', slug: 'ubuntu-1804', multiplier: 0, depends: [] }, ]; diff --git a/.drone.yml b/.drone.yml index 17c18bd..20eddb9 100644 --- a/.drone.yml +++ b/.drone.yml @@ -972,7 +972,7 @@ depends_on: --- kind: pipeline -name: Opensuse 15.0 +name: Opensuse 15.1 platform: os: linux @@ -1326,6 +1326,6 @@ depends_on: --- kind: signature -hmac: 59c8f7c861aea35dba9890b536519e10b6e41452bb6c15f88b6a7dbc6e158506 +hmac: 9c01a5f3f8d8fe0b09aad2cc73976678a432edf3c81aafdff0d17e52ce4cc7f8 ... From b8e3da692b52c7e731dde7ec4bb22162716fc684 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Tue, 21 Jan 2020 17:50:34 +0000 Subject: [PATCH 64/64] Update version, ChangeLog and AUTHORS for stable merge --- AUTHORS.rst | 1 + ChangeLog | 4 ++++ bootstrap-salt.sh | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 3fc7c87..b3a9322 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -86,6 +86,7 @@ Jorge Schrauwen sjorge sjorge@blackdot.be Juan A. Moyano wincus wincus.public@gmail.com Justin Anderson justinta justin.ta@outlook.com Justin Findlay jfindlay jfindlay@gmail.com + kgbsd Karl Grzeszczak karlgrz Kenneth Wilke KennethWilke Kevin Quinn kevinquinnyo kevin.quinn@totalserversolutions.com diff --git a/ChangeLog b/ChangeLog index dd36fa2..07bc592 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ Version TBD (In Progress on the Develop Branch): +Version 2020.01.21: + * FreeBSD fixes (kgbsd) #1376 + * Fix macOS support (s0undt3ch) #1397 + Version 2019.11.04: * Fix busybox mktemp compatibility (stanzgy) #1369 * Install debian 10 packages on debian 10 instead of 9 (kiemlicz) #1375 diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index f8c0511..3c6131d 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -23,7 +23,7 @@ #====================================================================================================================== set -o nounset # Treat unset variables as an error -__ScriptVersion="2019.11.04" +__ScriptVersion="2020.01.21" __ScriptName="bootstrap-salt.sh" __ScriptFullName="$0"