Jiri Broulik | 4ea221c | 2018-04-10 13:48:06 +0200 | [diff] [blame^] | 1 | #!/bin/sh - |
| 2 | #====================================================================================================================== |
| 3 | # vim: softtabstop=4 shiftwidth=4 expandtab fenc=utf-8 spell spelllang=en cc=120 |
| 4 | #====================================================================================================================== |
| 5 | # |
| 6 | # FILE: bootstrap-salt.sh |
| 7 | # |
| 8 | # DESCRIPTION: Bootstrap Salt installation for various systems/distributions |
| 9 | # |
| 10 | # BUGS: https://github.com/saltstack/salt-bootstrap/issues |
| 11 | # |
| 12 | # COPYRIGHT: (c) 2012-2017 by the SaltStack Team, see AUTHORS.rst for more |
| 13 | # details. |
| 14 | # |
| 15 | # LICENSE: Apache 2.0 |
| 16 | # ORGANIZATION: SaltStack (saltstack.com) |
| 17 | # CREATED: 10/15/2012 09:49:37 PM WEST |
| 18 | #====================================================================================================================== |
| 19 | set -o nounset # Treat unset variables as an error |
| 20 | |
| 21 | __ScriptVersion="2017.12.13" |
| 22 | __ScriptName="bootstrap-salt.sh" |
| 23 | |
| 24 | __ScriptFullName="$0" |
| 25 | __ScriptArgs="$*" |
| 26 | |
| 27 | #====================================================================================================================== |
| 28 | # Environment variables taken into account. |
| 29 | #---------------------------------------------------------------------------------------------------------------------- |
| 30 | # * BS_COLORS: If 0 disables colour support |
| 31 | # * BS_PIP_ALLOWED: If 1 enable pip based installations(if needed) |
| 32 | # * BS_PIP_ALL: If 1 enable all python packages to be installed via pip instead of apt, requires setting virtualenv |
| 33 | # * BS_VIRTUALENV_DIR: The virtualenv to install salt into (shouldn't exist yet) |
| 34 | # * BS_ECHO_DEBUG: If 1 enable debug echo which can also be set by -D |
| 35 | # * BS_SALT_ETC_DIR: Defaults to /etc/salt (Only tweak'able on git based installations) |
| 36 | # * BS_SALT_CACHE_DIR: Defaults to /var/cache/salt (Only tweak'able on git based installations) |
| 37 | # * BS_KEEP_TEMP_FILES: If 1, don't move temporary files, instead copy them |
| 38 | # * BS_FORCE_OVERWRITE: Force overriding copied files(config, init.d, etc) |
| 39 | # * BS_UPGRADE_SYS: If 1 and an option, upgrade system. Default 0. |
| 40 | # * BS_GENTOO_USE_BINHOST: If 1 add `--getbinpkg` to gentoo's emerge |
| 41 | # * BS_SALT_MASTER_ADDRESS: The IP or DNS name of the salt-master the minion should connect to |
| 42 | # * BS_SALT_GIT_CHECKOUT_DIR: The directory where to clone Salt on git installations |
| 43 | #====================================================================================================================== |
| 44 | |
| 45 | |
| 46 | #====================================================================================================================== |
| 47 | # LET THE BLACK MAGIC BEGIN!!!! |
| 48 | #====================================================================================================================== |
| 49 | |
| 50 | # Bootstrap script truth values |
| 51 | BS_TRUE=1 |
| 52 | BS_FALSE=0 |
| 53 | |
| 54 | # Default sleep time used when waiting for daemons to start, restart and checking for these running |
| 55 | __DEFAULT_SLEEP=3 |
| 56 | |
| 57 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 58 | # NAME: __detect_color_support |
| 59 | # DESCRIPTION: Try to detect color support. |
| 60 | #---------------------------------------------------------------------------------------------------------------------- |
| 61 | _COLORS=${BS_COLORS:-$(tput colors 2>/dev/null || echo 0)} |
| 62 | __detect_color_support() { |
| 63 | if [ $? -eq 0 ] && [ "$_COLORS" -gt 2 ]; then |
| 64 | RC="\033[1;31m" |
| 65 | GC="\033[1;32m" |
| 66 | BC="\033[1;34m" |
| 67 | YC="\033[1;33m" |
| 68 | EC="\033[0m" |
| 69 | else |
| 70 | RC="" |
| 71 | GC="" |
| 72 | BC="" |
| 73 | YC="" |
| 74 | EC="" |
| 75 | fi |
| 76 | } |
| 77 | __detect_color_support |
| 78 | |
| 79 | |
| 80 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 81 | # NAME: echoerr |
| 82 | # DESCRIPTION: Echo errors to stderr. |
| 83 | #---------------------------------------------------------------------------------------------------------------------- |
| 84 | echoerror() { |
| 85 | printf "${RC} * ERROR${EC}: %s\n" "$@" 1>&2; |
| 86 | } |
| 87 | |
| 88 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 89 | # NAME: echoinfo |
| 90 | # DESCRIPTION: Echo information to stdout. |
| 91 | #---------------------------------------------------------------------------------------------------------------------- |
| 92 | echoinfo() { |
| 93 | printf "${GC} * INFO${EC}: %s\n" "$@"; |
| 94 | } |
| 95 | |
| 96 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 97 | # NAME: echowarn |
| 98 | # DESCRIPTION: Echo warning informations to stdout. |
| 99 | #---------------------------------------------------------------------------------------------------------------------- |
| 100 | echowarn() { |
| 101 | printf "${YC} * WARN${EC}: %s\n" "$@"; |
| 102 | } |
| 103 | |
| 104 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 105 | # NAME: echodebug |
| 106 | # DESCRIPTION: Echo debug information to stdout. |
| 107 | #---------------------------------------------------------------------------------------------------------------------- |
| 108 | echodebug() { |
| 109 | if [ "$_ECHO_DEBUG" -eq $BS_TRUE ]; then |
| 110 | printf "${BC} * DEBUG${EC}: %s\n" "$@"; |
| 111 | fi |
| 112 | } |
| 113 | |
| 114 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 115 | # NAME: __check_command_exists |
| 116 | # DESCRIPTION: Check if a command exists. |
| 117 | #---------------------------------------------------------------------------------------------------------------------- |
| 118 | __check_command_exists() { |
| 119 | command -v "$1" > /dev/null 2>&1 |
| 120 | } |
| 121 | |
| 122 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 123 | # NAME: __check_pip_allowed |
| 124 | # DESCRIPTION: Simple function to let the users know that -P needs to be used. |
| 125 | #---------------------------------------------------------------------------------------------------------------------- |
| 126 | __check_pip_allowed() { |
| 127 | if [ $# -eq 1 ]; then |
| 128 | _PIP_ALLOWED_ERROR_MSG=$1 |
| 129 | else |
| 130 | _PIP_ALLOWED_ERROR_MSG="pip based installations were not allowed. Retry using '-P'" |
| 131 | fi |
| 132 | |
| 133 | if [ "$_PIP_ALLOWED" -eq $BS_FALSE ]; then |
| 134 | echoerror "$_PIP_ALLOWED_ERROR_MSG" |
| 135 | __usage |
| 136 | exit 1 |
| 137 | fi |
| 138 | } |
| 139 | |
| 140 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 141 | # NAME: __check_config_dir |
| 142 | # DESCRIPTION: Checks the config directory, retrieves URLs if provided. |
| 143 | #---------------------------------------------------------------------------------------------------------------------- |
| 144 | __check_config_dir() { |
| 145 | CC_DIR_NAME="$1" |
| 146 | CC_DIR_BASE=$(basename "${CC_DIR_NAME}") |
| 147 | |
| 148 | case "$CC_DIR_NAME" in |
| 149 | http://*|https://*) |
| 150 | __fetch_url "/tmp/${CC_DIR_BASE}" "${CC_DIR_NAME}" |
| 151 | CC_DIR_NAME="/tmp/${CC_DIR_BASE}" |
| 152 | ;; |
| 153 | ftp://*) |
| 154 | __fetch_url "/tmp/${CC_DIR_BASE}" "${CC_DIR_NAME}" |
| 155 | CC_DIR_NAME="/tmp/${CC_DIR_BASE}" |
| 156 | ;; |
| 157 | *://*) |
| 158 | echoerror "Unsupported URI scheme for $CC_DIR_NAME" |
| 159 | echo "null" |
| 160 | return |
| 161 | ;; |
| 162 | *) |
| 163 | if [ ! -e "${CC_DIR_NAME}" ]; then |
| 164 | echoerror "The configuration directory or archive $CC_DIR_NAME does not exist." |
| 165 | echo "null" |
| 166 | return |
| 167 | fi |
| 168 | ;; |
| 169 | esac |
| 170 | |
| 171 | case "$CC_DIR_NAME" in |
| 172 | *.tgz|*.tar.gz) |
| 173 | tar -zxf "${CC_DIR_NAME}" -C /tmp |
| 174 | CC_DIR_BASE=$(basename "${CC_DIR_BASE}" ".tgz") |
| 175 | CC_DIR_BASE=$(basename "${CC_DIR_BASE}" ".tar.gz") |
| 176 | CC_DIR_NAME="/tmp/${CC_DIR_BASE}" |
| 177 | ;; |
| 178 | *.tbz|*.tar.bz2) |
| 179 | tar -xjf "${CC_DIR_NAME}" -C /tmp |
| 180 | CC_DIR_BASE=$(basename "${CC_DIR_BASE}" ".tbz") |
| 181 | CC_DIR_BASE=$(basename "${CC_DIR_BASE}" ".tar.bz2") |
| 182 | CC_DIR_NAME="/tmp/${CC_DIR_BASE}" |
| 183 | ;; |
| 184 | *.txz|*.tar.xz) |
| 185 | tar -xJf "${CC_DIR_NAME}" -C /tmp |
| 186 | CC_DIR_BASE=$(basename "${CC_DIR_BASE}" ".txz") |
| 187 | CC_DIR_BASE=$(basename "${CC_DIR_BASE}" ".tar.xz") |
| 188 | CC_DIR_NAME="/tmp/${CC_DIR_BASE}" |
| 189 | ;; |
| 190 | esac |
| 191 | |
| 192 | echo "${CC_DIR_NAME}" |
| 193 | } |
| 194 | |
| 195 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 196 | # NAME: __check_unparsed_options |
| 197 | # DESCRIPTION: Checks the placed after the install arguments |
| 198 | #---------------------------------------------------------------------------------------------------------------------- |
| 199 | __check_unparsed_options() { |
| 200 | shellopts="$1" |
| 201 | # grep alternative for SunOS |
| 202 | if [ -f /usr/xpg4/bin/grep ]; then |
| 203 | grep='/usr/xpg4/bin/grep' |
| 204 | else |
| 205 | grep='grep' |
| 206 | fi |
| 207 | unparsed_options=$( echo "$shellopts" | ${grep} -E '(^|[[:space:]])[-]+[[:alnum:]]' ) |
| 208 | if [ "$unparsed_options" != "" ]; then |
| 209 | __usage |
| 210 | echo |
| 211 | echoerror "options are only allowed before install arguments" |
| 212 | echo |
| 213 | exit 1 |
| 214 | fi |
| 215 | } |
| 216 | |
| 217 | |
| 218 | #---------------------------------------------------------------------------------------------------------------------- |
| 219 | # Handle command line arguments |
| 220 | #---------------------------------------------------------------------------------------------------------------------- |
| 221 | _KEEP_TEMP_FILES=${BS_KEEP_TEMP_FILES:-$BS_FALSE} |
| 222 | _TEMP_CONFIG_DIR="null" |
| 223 | _SALTSTACK_REPO_URL="https://github.com/saltstack/salt.git" |
| 224 | _SALT_REPO_URL=${_SALTSTACK_REPO_URL} |
| 225 | _DOWNSTREAM_PKG_REPO=$BS_FALSE |
| 226 | _TEMP_KEYS_DIR="null" |
| 227 | _SLEEP="${__DEFAULT_SLEEP}" |
| 228 | _INSTALL_MASTER=$BS_FALSE |
| 229 | _INSTALL_SYNDIC=$BS_FALSE |
| 230 | _INSTALL_MINION=$BS_TRUE |
| 231 | _INSTALL_CLOUD=$BS_FALSE |
| 232 | _VIRTUALENV_DIR=${BS_VIRTUALENV_DIR:-"null"} |
| 233 | _START_DAEMONS=$BS_TRUE |
| 234 | _DISABLE_SALT_CHECKS=$BS_FALSE |
| 235 | _ECHO_DEBUG=${BS_ECHO_DEBUG:-$BS_FALSE} |
| 236 | _CONFIG_ONLY=$BS_FALSE |
| 237 | _PIP_ALLOWED=${BS_PIP_ALLOWED:-$BS_FALSE} |
| 238 | _PIP_ALL=${BS_PIP_ALL:-$BS_FALSE} |
| 239 | _SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/etc/salt} |
| 240 | _SALT_CACHE_DIR=${BS_SALT_CACHE_DIR:-/var/cache/salt} |
| 241 | _PKI_DIR=${_SALT_ETC_DIR}/pki |
| 242 | _FORCE_OVERWRITE=${BS_FORCE_OVERWRITE:-$BS_FALSE} |
| 243 | _GENTOO_USE_BINHOST=${BS_GENTOO_USE_BINHOST:-$BS_FALSE} |
| 244 | _EPEL_REPO=${BS_EPEL_REPO:-epel} |
| 245 | _EPEL_REPOS_INSTALLED=$BS_FALSE |
| 246 | _UPGRADE_SYS=${BS_UPGRADE_SYS:-$BS_FALSE} |
| 247 | _INSECURE_DL=${BS_INSECURE_DL:-$BS_FALSE} |
| 248 | _CURL_ARGS=${BS_CURL_ARGS:-} |
| 249 | _FETCH_ARGS=${BS_FETCH_ARGS:-} |
| 250 | _GPG_ARGS=${BS_GPG_ARGS:-} |
| 251 | _WGET_ARGS=${BS_WGET_ARGS:-} |
| 252 | _ENABLE_EXTERNAL_ZMQ_REPOS=${BS_ENABLE_EXTERNAL_ZMQ_REPOS:-$BS_FALSE} |
| 253 | _SALT_MASTER_ADDRESS=${BS_SALT_MASTER_ADDRESS:-null} |
| 254 | _SALT_MINION_ID="null" |
| 255 | # _SIMPLIFY_VERSION is mostly used in Solaris based distributions |
| 256 | _SIMPLIFY_VERSION=$BS_TRUE |
| 257 | _LIBCLOUD_MIN_VERSION="0.14.0" |
| 258 | _EXTRA_PACKAGES="" |
| 259 | _HTTP_PROXY="" |
| 260 | _SALT_GIT_CHECKOUT_DIR=${BS_SALT_GIT_CHECKOUT_DIR:-/tmp/git/salt} |
| 261 | _NO_DEPS=$BS_FALSE |
| 262 | _FORCE_SHALLOW_CLONE=$BS_FALSE |
| 263 | _DISABLE_SSL=$BS_FALSE |
| 264 | _DISABLE_REPOS=$BS_FALSE |
| 265 | _CUSTOM_REPO_URL="null" |
| 266 | _CUSTOM_MASTER_CONFIG="null" |
| 267 | _CUSTOM_MINION_CONFIG="null" |
| 268 | _QUIET_GIT_INSTALLATION=$BS_FALSE |
| 269 | _REPO_URL="repo.saltstack.com" |
| 270 | _PY_EXE="" |
| 271 | _INSTALL_PY="$BS_FALSE" |
| 272 | |
| 273 | # Defaults for install arguments |
| 274 | ITYPE="stable" |
| 275 | |
| 276 | |
| 277 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 278 | # NAME: __usage |
| 279 | # DESCRIPTION: Display usage information. |
| 280 | #---------------------------------------------------------------------------------------------------------------------- |
| 281 | __usage() { |
| 282 | cat << EOT |
| 283 | |
| 284 | Usage : ${__ScriptName} [options] <install-type> [install-type-args] |
| 285 | |
| 286 | Installation types: |
| 287 | - stable Install latest stable release. This is the default |
| 288 | install type |
| 289 | - stable [branch] Install latest version on a branch. Only supported |
| 290 | for packages available at repo.saltstack.com |
| 291 | - stable [version] Install a specific version. Only supported for |
| 292 | packages available at repo.saltstack.com |
| 293 | - daily Ubuntu specific: configure SaltStack Daily PPA |
| 294 | - testing RHEL-family specific: configure EPEL testing repo |
| 295 | - git Install from the head of the develop branch |
| 296 | - git [ref] Install from any git ref (such as a branch, tag, or |
| 297 | commit) |
| 298 | |
| 299 | Examples: |
| 300 | - ${__ScriptName} |
| 301 | - ${__ScriptName} stable |
| 302 | - ${__ScriptName} stable 2016.3 |
| 303 | - ${__ScriptName} stable 2016.3.1 |
| 304 | - ${__ScriptName} daily |
| 305 | - ${__ScriptName} testing |
| 306 | - ${__ScriptName} git |
| 307 | - ${__ScriptName} git 2016.3 |
| 308 | - ${__ScriptName} git v2016.3.1 |
| 309 | - ${__ScriptName} git 06f249901a2e2f1ed310d58ea3921a129f214358 |
| 310 | |
| 311 | Options: |
| 312 | -h Display this message |
| 313 | -v Display script version |
| 314 | -n No colours |
| 315 | -D Show debug output |
| 316 | -c Temporary configuration directory |
| 317 | -g Salt Git repository URL. Default: ${_SALTSTACK_REPO_URL} |
| 318 | -w Install packages from downstream package repository rather than |
| 319 | upstream, saltstack package repository. This is currently only |
| 320 | implemented for SUSE. |
| 321 | -k Temporary directory holding the minion keys which will pre-seed |
| 322 | the master. |
| 323 | -s Sleep time used when waiting for daemons to start, restart and when |
| 324 | checking for the services running. Default: ${__DEFAULT_SLEEP} |
| 325 | -L Also install salt-cloud and required python-libcloud package |
| 326 | -M Also install salt-master |
| 327 | -S Also install salt-syndic |
| 328 | -N Do not install salt-minion |
| 329 | -X Do not start daemons after installation |
| 330 | -d Disables checking if Salt services are enabled to start on system boot. |
| 331 | You can also do this by touching /tmp/disable_salt_checks on the target |
| 332 | host. Default: \${BS_FALSE} |
| 333 | -P Allow pip based installations. On some distributions the required salt |
| 334 | packages or its dependencies are not available as a package for that |
| 335 | distribution. Using this flag allows the script to use pip as a last |
| 336 | resort method. NOTE: This only works for functions which actually |
| 337 | implement pip based installations. |
| 338 | -U If set, fully upgrade the system prior to bootstrapping Salt |
| 339 | -I If set, allow insecure connections while downloading any files. For |
| 340 | example, pass '--no-check-certificate' to 'wget' or '--insecure' to |
| 341 | 'curl'. On Debian and Ubuntu, using this option with -U allows to obtain |
| 342 | GnuPG archive keys insecurely if distro has changed release signatures. |
| 343 | -F Allow copied files to overwrite existing (config, init.d, etc) |
| 344 | -K If set, keep the temporary files in the temporary directories specified |
| 345 | with -c and -k |
| 346 | -C Only run the configuration function. Implies -F (forced overwrite). |
| 347 | To overwrite Master or Syndic configs, -M or -S, respectively, must |
| 348 | also be specified. Salt installation will be ommitted, but some of the |
| 349 | dependencies could be installed to write configuration with -j or -J. |
| 350 | -A Pass the salt-master DNS name or IP. This will be stored under |
| 351 | \${BS_SALT_ETC_DIR}/minion.d/99-master-address.conf |
| 352 | -i Pass the salt-minion id. This will be stored under |
| 353 | \${BS_SALT_ETC_DIR}/minion_id |
| 354 | -p Extra-package to install while installing Salt dependencies. One package |
| 355 | per -p flag. You're responsible for providing the proper package name. |
| 356 | -H Use the specified HTTP proxy for all download URLs (including https://). |
| 357 | For example: http://myproxy.example.com:3128 |
| 358 | -Z Enable additional package repository for newer ZeroMQ |
| 359 | (only available for RHEL/CentOS/Fedora/Ubuntu based distributions) |
| 360 | -b Assume that dependencies are already installed and software sources are |
| 361 | set up. If git is selected, git tree is still checked out as dependency |
| 362 | step. |
| 363 | -f Force shallow cloning for git installations. |
| 364 | This may result in an "n/a" in the version number. |
| 365 | -l Disable ssl checks. When passed, switches "https" calls to "http" where |
| 366 | possible. |
| 367 | -V Install Salt into virtualenv |
| 368 | (only available for Ubuntu based distributions) |
| 369 | -a Pip install all Python pkg dependencies for Salt. Requires -V to install |
| 370 | all pip pkgs into the virtualenv. |
| 371 | (Only available for Ubuntu based distributions) |
| 372 | -r Disable all repository configuration performed by this script. This |
| 373 | option assumes all necessary repository configuration is already present |
| 374 | on the system. |
| 375 | -R Specify a custom repository URL. Assumes the custom repository URL |
| 376 | points to a repository that mirrors Salt packages located at |
| 377 | repo.saltstack.com. The option passed with -R replaces the |
| 378 | "repo.saltstack.com". If -R is passed, -r is also set. Currently only |
| 379 | works on CentOS/RHEL and Debian based distributions. |
| 380 | -J Replace the Master config file with data passed in as a JSON string. If |
| 381 | a Master config file is found, a reasonable effort will be made to save |
| 382 | the file with a ".bak" extension. If used in conjunction with -C or -F, |
| 383 | no ".bak" file will be created as either of those options will force |
| 384 | a complete overwrite of the file. |
| 385 | -j Replace the Minion config file with data passed in as a JSON string. If |
| 386 | a Minion config file is found, a reasonable effort will be made to save |
| 387 | the file with a ".bak" extension. If used in conjunction with -C or -F, |
| 388 | no ".bak" file will be created as either of those options will force |
| 389 | a complete overwrite of the file. |
| 390 | -q Quiet salt installation from git (setup.py install -q) |
| 391 | -x Changes the python version used to install a git version of salt. Currently |
| 392 | this is considered experimental and has only been tested on Centos 6. This |
| 393 | only works for git installations. |
| 394 | -y Installs a different python version on host. Currently this has only been |
| 395 | tested with Centos 6 and is considered experimental. This will install the |
| 396 | ius repo on the box if disable repo is false. This must be used in conjunction |
| 397 | with -x <pythonversion>. For example: |
| 398 | sh bootstrap.sh -P -y -x python2.7 git v2016.11.3 |
| 399 | The above will install python27 and install the git version of salt using the |
| 400 | python2.7 executable. This only works for git and pip installations. |
| 401 | |
| 402 | EOT |
| 403 | } # ---------- end of function __usage ---------- |
| 404 | |
| 405 | |
| 406 | while getopts ':hvnDc:g:Gyx:wk:s:MSNXCPFUKIA:i:Lp:dH:ZbflV:J:j:rR:aq' opt |
| 407 | do |
| 408 | case "${opt}" in |
| 409 | |
| 410 | h ) __usage; exit 0 ;; |
| 411 | v ) echo "$0 -- Version $__ScriptVersion"; exit 0 ;; |
| 412 | n ) _COLORS=0; __detect_color_support ;; |
| 413 | D ) _ECHO_DEBUG=$BS_TRUE ;; |
| 414 | c ) _TEMP_CONFIG_DIR="$OPTARG" ;; |
| 415 | g ) _SALT_REPO_URL=$OPTARG ;; |
| 416 | |
| 417 | G ) echowarn "The '-G' option is DEPRECATED and will be removed in the future stable release!" |
| 418 | echowarn "Bootstrap will always use 'https' protocol to clone from SaltStack GitHub repo." |
| 419 | echowarn "No need to provide this option anymore, now it is a default behavior." |
| 420 | ;; |
| 421 | |
| 422 | w ) _DOWNSTREAM_PKG_REPO=$BS_TRUE ;; |
| 423 | k ) _TEMP_KEYS_DIR="$OPTARG" ;; |
| 424 | s ) _SLEEP=$OPTARG ;; |
| 425 | M ) _INSTALL_MASTER=$BS_TRUE ;; |
| 426 | S ) _INSTALL_SYNDIC=$BS_TRUE ;; |
| 427 | N ) _INSTALL_MINION=$BS_FALSE ;; |
| 428 | X ) _START_DAEMONS=$BS_FALSE ;; |
| 429 | C ) _CONFIG_ONLY=$BS_TRUE ;; |
| 430 | P ) _PIP_ALLOWED=$BS_TRUE ;; |
| 431 | F ) _FORCE_OVERWRITE=$BS_TRUE ;; |
| 432 | U ) _UPGRADE_SYS=$BS_TRUE ;; |
| 433 | K ) _KEEP_TEMP_FILES=$BS_TRUE ;; |
| 434 | I ) _INSECURE_DL=$BS_TRUE ;; |
| 435 | A ) _SALT_MASTER_ADDRESS=$OPTARG ;; |
| 436 | i ) _SALT_MINION_ID=$OPTARG ;; |
| 437 | L ) _INSTALL_CLOUD=$BS_TRUE ;; |
| 438 | p ) _EXTRA_PACKAGES="$_EXTRA_PACKAGES $OPTARG" ;; |
| 439 | d ) _DISABLE_SALT_CHECKS=$BS_TRUE ;; |
| 440 | H ) _HTTP_PROXY="$OPTARG" ;; |
| 441 | Z ) _ENABLE_EXTERNAL_ZMQ_REPOS=$BS_TRUE ;; |
| 442 | b ) _NO_DEPS=$BS_TRUE ;; |
| 443 | f ) _FORCE_SHALLOW_CLONE=$BS_TRUE ;; |
| 444 | l ) _DISABLE_SSL=$BS_TRUE ;; |
| 445 | V ) _VIRTUALENV_DIR="$OPTARG" ;; |
| 446 | a ) _PIP_ALL=$BS_TRUE ;; |
| 447 | r ) _DISABLE_REPOS=$BS_TRUE ;; |
| 448 | R ) _CUSTOM_REPO_URL=$OPTARG ;; |
| 449 | J ) _CUSTOM_MASTER_CONFIG=$OPTARG ;; |
| 450 | j ) _CUSTOM_MINION_CONFIG=$OPTARG ;; |
| 451 | q ) _QUIET_GIT_INSTALLATION=$BS_TRUE ;; |
| 452 | x ) _PY_EXE="$OPTARG" ;; |
| 453 | y ) _INSTALL_PY="$BS_TRUE" ;; |
| 454 | |
| 455 | \?) echo |
| 456 | echoerror "Option does not exist : $OPTARG" |
| 457 | __usage |
| 458 | exit 1 |
| 459 | ;; |
| 460 | |
| 461 | esac # --- end of case --- |
| 462 | done |
| 463 | shift $((OPTIND-1)) |
| 464 | |
| 465 | |
| 466 | # Define our logging file and pipe paths |
| 467 | LOGFILE="/tmp/$( echo "$__ScriptName" | sed s/.sh/.log/g )" |
| 468 | LOGPIPE="/tmp/$( echo "$__ScriptName" | sed s/.sh/.logpipe/g )" |
| 469 | |
| 470 | # Create our logging pipe |
| 471 | # On FreeBSD we have to use mkfifo instead of mknod |
| 472 | mknod "$LOGPIPE" p >/dev/null 2>&1 || mkfifo "$LOGPIPE" >/dev/null 2>&1 |
| 473 | if [ $? -ne 0 ]; then |
| 474 | echoerror "Failed to create the named pipe required to log" |
| 475 | exit 1 |
| 476 | fi |
| 477 | |
| 478 | # What ever is written to the logpipe gets written to the logfile |
| 479 | tee < "$LOGPIPE" "$LOGFILE" & |
| 480 | |
| 481 | # Close STDOUT, reopen it directing it to the logpipe |
| 482 | exec 1>&- |
| 483 | exec 1>"$LOGPIPE" |
| 484 | # Close STDERR, reopen it directing it to the logpipe |
| 485 | exec 2>&- |
| 486 | exec 2>"$LOGPIPE" |
| 487 | |
| 488 | |
| 489 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 490 | # NAME: __exit_cleanup |
| 491 | # DESCRIPTION: Cleanup any leftovers after script has ended |
| 492 | # |
| 493 | # |
| 494 | # http://www.unix.com/man-page/POSIX/1posix/trap/ |
| 495 | # |
| 496 | # Signal Number Signal Name |
| 497 | # 1 SIGHUP |
| 498 | # 2 SIGINT |
| 499 | # 3 SIGQUIT |
| 500 | # 6 SIGABRT |
| 501 | # 9 SIGKILL |
| 502 | # 14 SIGALRM |
| 503 | # 15 SIGTERM |
| 504 | #---------------------------------------------------------------------------------------------------------------------- |
| 505 | __exit_cleanup() { |
| 506 | EXIT_CODE=$? |
| 507 | |
| 508 | if [ "$ITYPE" = "git" ] && [ -d "${_SALT_GIT_CHECKOUT_DIR}" ]; then |
| 509 | if [ $_KEEP_TEMP_FILES -eq $BS_FALSE ]; then |
| 510 | # Clean up the checked out repository |
| 511 | echodebug "Cleaning up the Salt Temporary Git Repository" |
| 512 | # shellcheck disable=SC2164 |
| 513 | cd "${__SALT_GIT_CHECKOUT_PARENT_DIR}" |
| 514 | rm -rf "${_SALT_GIT_CHECKOUT_DIR}" |
| 515 | else |
| 516 | echowarn "Not cleaning up the Salt Temporary git repository on request" |
| 517 | echowarn "Note that if you intend to re-run this script using the git approach, you might encounter some issues" |
| 518 | fi |
| 519 | fi |
| 520 | |
| 521 | # Remove the logging pipe when the script exits |
| 522 | if [ -p "$LOGPIPE" ]; then |
| 523 | echodebug "Removing the logging pipe $LOGPIPE" |
| 524 | rm -f "$LOGPIPE" |
| 525 | fi |
| 526 | |
| 527 | # Kill tee when exiting, CentOS, at least requires this |
| 528 | # shellcheck disable=SC2009 |
| 529 | TEE_PID=$(ps ax | grep tee | grep "$LOGFILE" | awk '{print $1}') |
| 530 | |
| 531 | [ "$TEE_PID" = "" ] && exit $EXIT_CODE |
| 532 | |
| 533 | echodebug "Killing logging pipe tee's with pid(s): $TEE_PID" |
| 534 | |
| 535 | # We need to trap errors since killing tee will cause a 127 errno |
| 536 | # We also do this as late as possible so we don't "mis-catch" other errors |
| 537 | __trap_errors() { |
| 538 | echoinfo "Errors Trapped: $EXIT_CODE" |
| 539 | # Exit with the "original" exit code, not the trapped code |
| 540 | exit $EXIT_CODE |
| 541 | } |
| 542 | trap "__trap_errors" INT ABRT QUIT TERM |
| 543 | |
| 544 | # Now we're "good" to kill tee |
| 545 | kill -s TERM "$TEE_PID" |
| 546 | |
| 547 | # In case the 127 errno is not triggered, exit with the "original" exit code |
| 548 | exit $EXIT_CODE |
| 549 | } |
| 550 | trap "__exit_cleanup" EXIT INT |
| 551 | |
| 552 | |
| 553 | # Let's discover how we're being called |
| 554 | # shellcheck disable=SC2009 |
| 555 | CALLER=$(ps -a -o pid,args | grep $$ | grep -v grep | tr -s ' ' | cut -d ' ' -f 3) |
| 556 | |
| 557 | if [ "${CALLER}x" = "${0}x" ]; then |
| 558 | CALLER="shell pipe" |
| 559 | fi |
| 560 | |
| 561 | echoinfo "Running version: ${__ScriptVersion}" |
| 562 | echoinfo "Executed by: ${CALLER}" |
| 563 | echoinfo "Command line: '${__ScriptFullName} ${__ScriptArgs}'" |
| 564 | #echowarn "Running the unstable version of ${__ScriptName}" |
| 565 | |
| 566 | # Define installation type |
| 567 | if [ "$#" -gt 0 ];then |
| 568 | __check_unparsed_options "$*" |
| 569 | ITYPE=$1 |
| 570 | shift |
| 571 | fi |
| 572 | |
| 573 | # Check installation type |
| 574 | if [ "$(echo "$ITYPE" | egrep '(stable|testing|daily|git)')" = "" ]; then |
| 575 | echoerror "Installation type \"$ITYPE\" is not known..." |
| 576 | exit 1 |
| 577 | fi |
| 578 | |
| 579 | # If doing a git install, check what branch/tag/sha will be checked out |
| 580 | if [ "$ITYPE" = "git" ]; then |
| 581 | if [ "$#" -eq 0 ];then |
| 582 | GIT_REV="develop" |
| 583 | else |
| 584 | GIT_REV="$1" |
| 585 | shift |
| 586 | fi |
| 587 | |
| 588 | # Disable shell warning about unbound variable during git install |
| 589 | STABLE_REV="latest" |
| 590 | |
| 591 | # If doing stable install, check if version specified |
| 592 | elif [ "$ITYPE" = "stable" ]; then |
| 593 | if [ "$#" -eq 0 ];then |
| 594 | STABLE_REV="latest" |
| 595 | else |
| 596 | if [ "$(echo "$1" | egrep '^(latest|1\.6|1\.7|2014\.1|2014\.7|2015\.5|2015\.8|2016\.3|2016\.11|2017\.7)$')" != "" ]; then |
| 597 | STABLE_REV="$1" |
| 598 | shift |
| 599 | elif [ "$(echo "$1" | egrep '^([0-9]*\.[0-9]*\.[0-9]*)$')" != "" ]; then |
| 600 | STABLE_REV="archive/$1" |
| 601 | shift |
| 602 | else |
| 603 | echo "Unknown stable version: $1 (valid: 1.6, 1.7, 2014.1, 2014.7, 2015.5, 2015.8, 2016.3, 2016.11, 2017.7, latest, \$MAJOR.\$MINOR.\$PATCH)" |
| 604 | exit 1 |
| 605 | fi |
| 606 | fi |
| 607 | fi |
| 608 | |
| 609 | # Check for any unparsed arguments. Should be an error. |
| 610 | if [ "$#" -gt 0 ]; then |
| 611 | __usage |
| 612 | echo |
| 613 | echoerror "Too many arguments." |
| 614 | exit 1 |
| 615 | fi |
| 616 | |
| 617 | # whoami alternative for SunOS |
| 618 | if [ -f /usr/xpg4/bin/id ]; then |
| 619 | whoami='/usr/xpg4/bin/id -un' |
| 620 | else |
| 621 | whoami='whoami' |
| 622 | fi |
| 623 | |
| 624 | # Root permissions are required to run this script |
| 625 | if [ "$($whoami)" != "root" ]; then |
| 626 | echoerror "Salt requires root privileges to install. Please re-run this script as root." |
| 627 | exit 1 |
| 628 | fi |
| 629 | |
| 630 | # Check that we're actually installing one of minion/master/syndic |
| 631 | if [ "$_INSTALL_MINION" -eq $BS_FALSE ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then |
| 632 | echowarn "Nothing to install or configure" |
| 633 | exit 1 |
| 634 | fi |
| 635 | |
| 636 | # Check that we're installing a minion if we're being passed a master address |
| 637 | if [ "$_INSTALL_MINION" -eq $BS_FALSE ] && [ "$_SALT_MASTER_ADDRESS" != "null" ]; then |
| 638 | echoerror "Don't pass a master address (-A) if no minion is going to be bootstrapped." |
| 639 | exit 1 |
| 640 | fi |
| 641 | |
| 642 | # Check that we're installing a minion if we're being passed a minion id |
| 643 | if [ "$_INSTALL_MINION" -eq $BS_FALSE ] && [ "$_SALT_MINION_ID" != "null" ]; then |
| 644 | echoerror "Don't pass a minion id (-i) if no minion is going to be bootstrapped." |
| 645 | exit 1 |
| 646 | fi |
| 647 | |
| 648 | # Check that we're installing or configuring a master if we're being passed a master config json dict |
| 649 | if [ "$_CUSTOM_MASTER_CONFIG" != "null" ]; then |
| 650 | if [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then |
| 651 | echoerror "Don't pass a master config JSON dict (-J) if no master is going to be bootstrapped or configured." |
| 652 | exit 1 |
| 653 | fi |
| 654 | fi |
| 655 | |
| 656 | # Check that we're installing or configuring a minion if we're being passed a minion config json dict |
| 657 | if [ "$_CUSTOM_MINION_CONFIG" != "null" ]; then |
| 658 | if [ "$_INSTALL_MINION" -eq $BS_FALSE ] && [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then |
| 659 | echoerror "Don't pass a minion config JSON dict (-j) if no minion is going to be bootstrapped or configured." |
| 660 | exit 1 |
| 661 | fi |
| 662 | fi |
| 663 | |
| 664 | # If the configuration directory or archive does not exist, error out |
| 665 | if [ "$_TEMP_CONFIG_DIR" != "null" ]; then |
| 666 | _TEMP_CONFIG_DIR="$(__check_config_dir "$_TEMP_CONFIG_DIR")" |
| 667 | [ "$_TEMP_CONFIG_DIR" = "null" ] && exit 1 |
| 668 | fi |
| 669 | |
| 670 | # If the pre-seed keys directory does not exist, error out |
| 671 | if [ "$_TEMP_KEYS_DIR" != "null" ] && [ ! -d "$_TEMP_KEYS_DIR" ]; then |
| 672 | echoerror "The pre-seed keys directory ${_TEMP_KEYS_DIR} does not exist." |
| 673 | exit 1 |
| 674 | fi |
| 675 | |
| 676 | # -a and -V only work from git |
| 677 | if [ "$ITYPE" != "git" ]; then |
| 678 | if [ $_PIP_ALL -eq $BS_TRUE ]; then |
| 679 | echoerror "Pip installing all python packages with -a is only possible when installing Salt via git" |
| 680 | exit 1 |
| 681 | fi |
| 682 | if [ "$_VIRTUALENV_DIR" != "null" ]; then |
| 683 | echoerror "Virtualenv installs via -V is only possible when installing Salt via git" |
| 684 | exit 1 |
| 685 | fi |
| 686 | fi |
| 687 | |
| 688 | # Set the _REPO_URL value based on if -R was passed or not. Defaults to repo.saltstack.com. |
| 689 | if [ "$_CUSTOM_REPO_URL" != "null" ]; then |
| 690 | _REPO_URL="$_CUSTOM_REPO_URL" |
| 691 | |
| 692 | # Check for -r since -R is being passed. Set -r with a warning. |
| 693 | if [ "$_DISABLE_REPOS" -eq $BS_FALSE ]; then |
| 694 | echowarn "Detected -R option. No other repositories will be configured when -R is used. Setting -r option to True." |
| 695 | _DISABLE_REPOS=$BS_TRUE |
| 696 | fi |
| 697 | fi |
| 698 | |
| 699 | # Check the _DISABLE_SSL value and set HTTP or HTTPS. |
| 700 | if [ "$_DISABLE_SSL" -eq $BS_TRUE ]; then |
| 701 | HTTP_VAL="http" |
| 702 | else |
| 703 | HTTP_VAL="https" |
| 704 | fi |
| 705 | |
| 706 | # Check the _QUIET_GIT_INSTALLATION value and set SETUP_PY_INSTALL_ARGS. |
| 707 | if [ "$_QUIET_GIT_INSTALLATION" -eq $BS_TRUE ]; then |
| 708 | SETUP_PY_INSTALL_ARGS="-q" |
| 709 | else |
| 710 | SETUP_PY_INSTALL_ARGS="" |
| 711 | fi |
| 712 | |
| 713 | # Handle the insecure flags |
| 714 | if [ "$_INSECURE_DL" -eq $BS_TRUE ]; then |
| 715 | _CURL_ARGS="${_CURL_ARGS} --insecure" |
| 716 | _FETCH_ARGS="${_FETCH_ARGS} --no-verify-peer" |
| 717 | _GPG_ARGS="${_GPG_ARGS} --keyserver-options no-check-cert" |
| 718 | _WGET_ARGS="${_WGET_ARGS} --no-check-certificate" |
| 719 | else |
| 720 | _GPG_ARGS="${_GPG_ARGS} --keyserver-options ca-cert-file=/etc/ssl/certs/ca-certificates.crt" |
| 721 | fi |
| 722 | |
| 723 | # Export the http_proxy configuration to our current environment |
| 724 | if [ "${_HTTP_PROXY}" != "" ]; then |
| 725 | export http_proxy="${_HTTP_PROXY}" |
| 726 | export https_proxy="${_HTTP_PROXY}" |
| 727 | # Using "deprecated" option here, but that appears the only way to make it work. |
| 728 | # See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=818802 |
| 729 | # and https://bugs.launchpad.net/ubuntu/+source/gnupg2/+bug/1625848 |
| 730 | _GPG_ARGS="${_GPG_ARGS},http-proxy=${_HTTP_PROXY}" |
| 731 | fi |
| 732 | |
| 733 | # Work around for 'Docker + salt-bootstrap failure' https://github.com/saltstack/salt-bootstrap/issues/394 |
| 734 | if [ "${_DISABLE_SALT_CHECKS}" -eq $BS_FALSE ] && [ -f /tmp/disable_salt_checks ]; then |
| 735 | # shellcheck disable=SC2016 |
| 736 | echowarn 'Found file: /tmp/disable_salt_checks, setting _DISABLE_SALT_CHECKS=$BS_TRUE' |
| 737 | _DISABLE_SALT_CHECKS=$BS_TRUE |
| 738 | fi |
| 739 | |
| 740 | # Because -a can only be installed into virtualenv |
| 741 | if [ "${_PIP_ALL}" -eq $BS_TRUE ] && [ "${_VIRTUALENV_DIR}" = "null" ]; then |
| 742 | usage |
| 743 | # Could possibly set up a default virtualenv location when -a flag is passed |
| 744 | echoerror "Using -a requires -V because pip pkgs should be siloed from python system pkgs" |
| 745 | exit 1 |
| 746 | fi |
| 747 | |
| 748 | # Make sure virtualenv directory does not already exist |
| 749 | if [ -d "${_VIRTUALENV_DIR}" ]; then |
| 750 | echoerror "The directory ${_VIRTUALENV_DIR} for virtualenv already exists" |
| 751 | exit 1 |
| 752 | fi |
| 753 | |
| 754 | |
| 755 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 756 | # NAME: __fetch_url |
| 757 | # DESCRIPTION: Retrieves a URL and writes it to a given path |
| 758 | #---------------------------------------------------------------------------------------------------------------------- |
| 759 | __fetch_url() { |
| 760 | # shellcheck disable=SC2086 |
| 761 | curl $_CURL_ARGS -L -s -o "$1" "$2" >/dev/null 2>&1 || |
| 762 | wget $_WGET_ARGS -q -O "$1" "$2" >/dev/null 2>&1 || |
| 763 | fetch $_FETCH_ARGS -q -o "$1" "$2" >/dev/null 2>&1 || # FreeBSD |
| 764 | fetch -q -o "$1" "$2" >/dev/null 2>&1 || # Pre FreeBSD 10 |
| 765 | ftp -o "$1" "$2" >/dev/null 2>&1 # OpenBSD |
| 766 | } |
| 767 | |
| 768 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 769 | # NAME: __fetch_verify |
| 770 | # DESCRIPTION: Retrieves a URL, verifies its content and writes it to standard output |
| 771 | #---------------------------------------------------------------------------------------------------------------------- |
| 772 | __fetch_verify() { |
| 773 | fetch_verify_url="$1" |
| 774 | fetch_verify_sum="$2" |
| 775 | fetch_verify_size="$3" |
| 776 | |
| 777 | fetch_verify_tmpf=$(mktemp) && \ |
| 778 | __fetch_url "$fetch_verify_tmpf" "$fetch_verify_url" && \ |
| 779 | test "$(stat --format=%s "$fetch_verify_tmpf")" -eq "$fetch_verify_size" && \ |
| 780 | test "$(md5sum "$fetch_verify_tmpf" | awk '{ print $1 }')" = "$fetch_verify_sum" && \ |
| 781 | cat "$fetch_verify_tmpf" && \ |
| 782 | rm -f "$fetch_verify_tmpf" |
| 783 | if [ $? -eq 0 ]; then |
| 784 | return 0 |
| 785 | fi |
| 786 | echo "Failed verification of $fetch_verify_url" |
| 787 | return 1 |
| 788 | } |
| 789 | |
| 790 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 791 | # NAME: __gather_hardware_info |
| 792 | # DESCRIPTION: Discover hardware information |
| 793 | #---------------------------------------------------------------------------------------------------------------------- |
| 794 | __gather_hardware_info() { |
| 795 | if [ -f /proc/cpuinfo ]; then |
| 796 | CPU_VENDOR_ID=$(awk '/vendor_id|Processor/ {sub(/-.*$/,"",$3); print $3; exit}' /proc/cpuinfo ) |
| 797 | elif [ -f /usr/bin/kstat ]; then |
| 798 | # SmartOS. |
| 799 | # Solaris!? |
| 800 | # This has only been tested for a GenuineIntel CPU |
| 801 | CPU_VENDOR_ID=$(/usr/bin/kstat -p cpu_info:0:cpu_info0:vendor_id | awk '{print $2}') |
| 802 | else |
| 803 | CPU_VENDOR_ID=$( sysctl -n hw.model ) |
| 804 | fi |
| 805 | # shellcheck disable=SC2034 |
| 806 | CPU_VENDOR_ID_L=$( echo "$CPU_VENDOR_ID" | tr '[:upper:]' '[:lower:]' ) |
| 807 | CPU_ARCH=$(uname -m 2>/dev/null || uname -p 2>/dev/null || echo "unknown") |
| 808 | CPU_ARCH_L=$( echo "$CPU_ARCH" | tr '[:upper:]' '[:lower:]' ) |
| 809 | } |
| 810 | __gather_hardware_info |
| 811 | |
| 812 | |
| 813 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 814 | # NAME: __gather_os_info |
| 815 | # DESCRIPTION: Discover operating system information |
| 816 | #---------------------------------------------------------------------------------------------------------------------- |
| 817 | __gather_os_info() { |
| 818 | OS_NAME=$(uname -s 2>/dev/null) |
| 819 | OS_NAME_L=$( echo "$OS_NAME" | tr '[:upper:]' '[:lower:]' ) |
| 820 | OS_VERSION=$(uname -r) |
| 821 | # shellcheck disable=SC2034 |
| 822 | OS_VERSION_L=$( echo "$OS_VERSION" | tr '[:upper:]' '[:lower:]' ) |
| 823 | } |
| 824 | __gather_os_info |
| 825 | |
| 826 | |
| 827 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 828 | # NAME: __parse_version_string |
| 829 | # DESCRIPTION: Parse version strings ignoring the revision. |
| 830 | # MAJOR.MINOR.REVISION becomes MAJOR.MINOR |
| 831 | #---------------------------------------------------------------------------------------------------------------------- |
| 832 | __parse_version_string() { |
| 833 | VERSION_STRING="$1" |
| 834 | PARSED_VERSION=$( |
| 835 | echo "$VERSION_STRING" | |
| 836 | sed -e 's/^/#/' \ |
| 837 | -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\)\(\.[0-9][0-9]*\).*$/\1/' \ |
| 838 | -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \ |
| 839 | -e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \ |
| 840 | -e 's/^#.*$//' |
| 841 | ) |
| 842 | echo "$PARSED_VERSION" |
| 843 | } |
| 844 | |
| 845 | |
| 846 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 847 | # NAME: __derive_debian_numeric_version |
| 848 | # DESCRIPTION: Derive the numeric version from a Debian version string. |
| 849 | #---------------------------------------------------------------------------------------------------------------------- |
| 850 | __derive_debian_numeric_version() { |
| 851 | NUMERIC_VERSION="" |
| 852 | INPUT_VERSION="$1" |
| 853 | if echo "$INPUT_VERSION" | grep -q '^[0-9]'; then |
| 854 | NUMERIC_VERSION="$INPUT_VERSION" |
| 855 | elif [ -z "$INPUT_VERSION" ] && [ -f "/etc/debian_version" ]; then |
| 856 | INPUT_VERSION="$(cat /etc/debian_version)" |
| 857 | fi |
| 858 | if [ -z "$NUMERIC_VERSION" ]; then |
| 859 | if [ "$INPUT_VERSION" = "wheezy/sid" ]; then |
| 860 | # I've found an EC2 wheezy image which did not tell its version |
| 861 | NUMERIC_VERSION=$(__parse_version_string "7.0") |
| 862 | elif [ "$INPUT_VERSION" = "jessie/sid" ]; then |
| 863 | NUMERIC_VERSION=$(__parse_version_string "8.0") |
| 864 | elif [ "$INPUT_VERSION" = "stretch/sid" ]; then |
| 865 | NUMERIC_VERSION=$(__parse_version_string "9.0") |
| 866 | elif [ "$INPUT_VERSION" = "buster/sid" ]; then |
| 867 | # Let's start detecting the upcoming Debian 10 (Buster) release |
| 868 | NUMERIC_VERSION=$(__parse_version_string "10.0") |
| 869 | else |
| 870 | echowarn "Unable to parse the Debian Version (codename: '$INPUT_VERSION')" |
| 871 | fi |
| 872 | fi |
| 873 | echo "$NUMERIC_VERSION" |
| 874 | } |
| 875 | |
| 876 | |
| 877 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 878 | # NAME: __unquote_string |
| 879 | # DESCRIPTION: Strip single or double quotes from the provided string. |
| 880 | #---------------------------------------------------------------------------------------------------------------------- |
| 881 | __unquote_string() { |
| 882 | echo "$*" | sed -e "s/^\([\"\']\)\(.*\)\1\$/\2/g" |
| 883 | } |
| 884 | |
| 885 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 886 | # NAME: __camelcase_split |
| 887 | # DESCRIPTION: Convert 'CamelCased' strings to 'Camel Cased' |
| 888 | #---------------------------------------------------------------------------------------------------------------------- |
| 889 | __camelcase_split() { |
| 890 | echo "$*" | sed -e 's/\([^[:upper:][:punct:]]\)\([[:upper:]]\)/\1 \2/g' |
| 891 | } |
| 892 | |
| 893 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 894 | # NAME: __strip_duplicates |
| 895 | # DESCRIPTION: Strip duplicate strings |
| 896 | #---------------------------------------------------------------------------------------------------------------------- |
| 897 | __strip_duplicates() { |
| 898 | echo "$*" | tr -s '[:space:]' '\n' | awk '!x[$0]++' |
| 899 | } |
| 900 | |
| 901 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 902 | # NAME: __sort_release_files |
| 903 | # DESCRIPTION: Custom sort function. Alphabetical or numerical sort is not |
| 904 | # enough. |
| 905 | #---------------------------------------------------------------------------------------------------------------------- |
| 906 | __sort_release_files() { |
| 907 | KNOWN_RELEASE_FILES=$(echo "(arch|alpine|centos|debian|ubuntu|fedora|redhat|suse|\ |
| 908 | mandrake|mandriva|gentoo|slackware|turbolinux|unitedlinux|void|lsb|system|\ |
| 909 | oracle|os)(-|_)(release|version)" | sed -r 's:[[:space:]]::g') |
| 910 | primary_release_files="" |
| 911 | secondary_release_files="" |
| 912 | # Sort know VS un-known files first |
| 913 | for release_file in $(echo "${@}" | sed -r 's:[[:space:]]:\n:g' | sort -f | uniq); do |
| 914 | match=$(echo "$release_file" | egrep -i "${KNOWN_RELEASE_FILES}") |
| 915 | if [ "${match}" != "" ]; then |
| 916 | primary_release_files="${primary_release_files} ${release_file}" |
| 917 | else |
| 918 | secondary_release_files="${secondary_release_files} ${release_file}" |
| 919 | fi |
| 920 | done |
| 921 | |
| 922 | # Now let's sort by know files importance, max important goes last in the max_prio list |
| 923 | max_prio="redhat-release centos-release oracle-release fedora-release" |
| 924 | for entry in $max_prio; do |
| 925 | if [ "$(echo "${primary_release_files}" | grep "$entry")" != "" ]; then |
| 926 | primary_release_files=$(echo "${primary_release_files}" | sed -e "s:\(.*\)\($entry\)\(.*\):\2 \1 \3:g") |
| 927 | fi |
| 928 | done |
| 929 | # Now, least important goes last in the min_prio list |
| 930 | min_prio="lsb-release" |
| 931 | for entry in $min_prio; do |
| 932 | if [ "$(echo "${primary_release_files}" | grep "$entry")" != "" ]; then |
| 933 | primary_release_files=$(echo "${primary_release_files}" | sed -e "s:\(.*\)\($entry\)\(.*\):\1 \3 \2:g") |
| 934 | fi |
| 935 | done |
| 936 | |
| 937 | # Echo the results collapsing multiple white-space into a single white-space |
| 938 | echo "${primary_release_files} ${secondary_release_files}" | sed -r 's:[[:space:]]+:\n:g' |
| 939 | } |
| 940 | |
| 941 | |
| 942 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 943 | # NAME: __gather_linux_system_info |
| 944 | # DESCRIPTION: Discover Linux system information |
| 945 | #---------------------------------------------------------------------------------------------------------------------- |
| 946 | __gather_linux_system_info() { |
| 947 | DISTRO_NAME="" |
| 948 | DISTRO_VERSION="" |
| 949 | |
| 950 | # Let's test if the lsb_release binary is available |
| 951 | rv=$(lsb_release >/dev/null 2>&1) |
| 952 | if [ $? -eq 0 ]; then |
| 953 | DISTRO_NAME=$(lsb_release -si) |
| 954 | if [ "${DISTRO_NAME}" = "Scientific" ]; then |
| 955 | DISTRO_NAME="Scientific Linux" |
| 956 | elif [ "$(echo "$DISTRO_NAME" | grep ^CloudLinux)" != "" ]; then |
| 957 | DISTRO_NAME="Cloud Linux" |
| 958 | elif [ "$(echo "$DISTRO_NAME" | grep ^RedHat)" != "" ]; then |
| 959 | # Let's convert 'CamelCased' to 'Camel Cased' |
| 960 | n=$(__camelcase_split "$DISTRO_NAME") |
| 961 | # Skip setting DISTRO_NAME this time, splitting CamelCase has failed. |
| 962 | # See https://github.com/saltstack/salt-bootstrap/issues/918 |
| 963 | [ "$n" = "$DISTRO_NAME" ] && DISTRO_NAME="" || DISTRO_NAME="$n" |
| 964 | elif [ "${DISTRO_NAME}" = "openSUSE project" ]; then |
| 965 | # lsb_release -si returns "openSUSE project" on openSUSE 12.3 |
| 966 | DISTRO_NAME="opensuse" |
| 967 | elif [ "${DISTRO_NAME}" = "SUSE LINUX" ]; then |
| 968 | if [ "$(lsb_release -sd | grep -i opensuse)" != "" ]; then |
| 969 | # openSUSE 12.2 reports SUSE LINUX on lsb_release -si |
| 970 | DISTRO_NAME="opensuse" |
| 971 | else |
| 972 | # lsb_release -si returns "SUSE LINUX" on SLES 11 SP3 |
| 973 | DISTRO_NAME="suse" |
| 974 | fi |
| 975 | elif [ "${DISTRO_NAME}" = "EnterpriseEnterpriseServer" ]; then |
| 976 | # This the Oracle Linux Enterprise ID before ORACLE LINUX 5 UPDATE 3 |
| 977 | DISTRO_NAME="Oracle Linux" |
| 978 | elif [ "${DISTRO_NAME}" = "OracleServer" ]; then |
| 979 | # This the Oracle Linux Server 6.5 |
| 980 | DISTRO_NAME="Oracle Linux" |
| 981 | elif [ "${DISTRO_NAME}" = "AmazonAMI" ]; then |
| 982 | DISTRO_NAME="Amazon Linux AMI" |
| 983 | elif [ "${DISTRO_NAME}" = "ManjaroLinux" ]; then |
| 984 | DISTRO_NAME="Arch Linux" |
| 985 | elif [ "${DISTRO_NAME}" = "Arch" ]; then |
| 986 | DISTRO_NAME="Arch Linux" |
| 987 | return |
| 988 | fi |
| 989 | rv=$(lsb_release -sr) |
| 990 | [ "${rv}" != "" ] && DISTRO_VERSION=$(__parse_version_string "$rv") |
| 991 | elif [ -f /etc/lsb-release ]; then |
| 992 | # We don't have the lsb_release binary, though, we do have the file it parses |
| 993 | DISTRO_NAME=$(grep DISTRIB_ID /etc/lsb-release | sed -e 's/.*=//') |
| 994 | rv=$(grep DISTRIB_RELEASE /etc/lsb-release | sed -e 's/.*=//') |
| 995 | [ "${rv}" != "" ] && DISTRO_VERSION=$(__parse_version_string "$rv") |
| 996 | fi |
| 997 | |
| 998 | if [ "$DISTRO_NAME" != "" ] && [ "$DISTRO_VERSION" != "" ]; then |
| 999 | # We already have the distribution name and version |
| 1000 | return |
| 1001 | fi |
| 1002 | # shellcheck disable=SC2035,SC2086 |
| 1003 | for rsource in $(__sort_release_files "$( |
| 1004 | cd /etc && /bin/ls *[_-]release *[_-]version 2>/dev/null | env -i sort | \ |
| 1005 | sed -e '/^redhat-release$/d' -e '/^lsb-release$/d'; \ |
| 1006 | echo redhat-release lsb-release |
| 1007 | )"); do |
| 1008 | |
| 1009 | [ ! -f "/etc/${rsource}" ] && continue # Does not exist |
| 1010 | |
| 1011 | n=$(echo "${rsource}" | sed -e 's/[_-]release$//' -e 's/[_-]version$//') |
| 1012 | shortname=$(echo "${n}" | tr '[:upper:]' '[:lower:]') |
| 1013 | if [ "$shortname" = "debian" ]; then |
| 1014 | rv=$(__derive_debian_numeric_version "$(cat /etc/${rsource})") |
| 1015 | else |
| 1016 | rv=$( (grep VERSION "/etc/${rsource}"; cat "/etc/${rsource}") | grep '[0-9]' | sed -e 'q' ) |
| 1017 | fi |
| 1018 | [ "${rv}" = "" ] && [ "$shortname" != "arch" ] && continue # There's no version information. Continue to next rsource |
| 1019 | v=$(__parse_version_string "$rv") |
| 1020 | case $shortname in |
| 1021 | redhat ) |
| 1022 | if [ "$(egrep 'CentOS' /etc/${rsource})" != "" ]; then |
| 1023 | n="CentOS" |
| 1024 | elif [ "$(egrep 'Scientific' /etc/${rsource})" != "" ]; then |
| 1025 | n="Scientific Linux" |
| 1026 | elif [ "$(egrep 'Red Hat Enterprise Linux' /etc/${rsource})" != "" ]; then |
| 1027 | n="<R>ed <H>at <E>nterprise <L>inux" |
| 1028 | else |
| 1029 | n="<R>ed <H>at <L>inux" |
| 1030 | fi |
| 1031 | ;; |
| 1032 | arch ) n="Arch Linux" ;; |
| 1033 | alpine ) n="Alpine Linux" ;; |
| 1034 | centos ) n="CentOS" ;; |
| 1035 | debian ) n="Debian" ;; |
| 1036 | ubuntu ) n="Ubuntu" ;; |
| 1037 | fedora ) n="Fedora" ;; |
| 1038 | suse ) n="SUSE" ;; |
| 1039 | mandrake*|mandriva ) n="Mandriva" ;; |
| 1040 | gentoo ) n="Gentoo" ;; |
| 1041 | slackware ) n="Slackware" ;; |
| 1042 | turbolinux ) n="TurboLinux" ;; |
| 1043 | unitedlinux ) n="UnitedLinux" ;; |
| 1044 | void ) n="VoidLinux" ;; |
| 1045 | oracle ) n="Oracle Linux" ;; |
| 1046 | system ) |
| 1047 | while read -r line; do |
| 1048 | [ "${n}x" != "systemx" ] && break |
| 1049 | case "$line" in |
| 1050 | *Amazon*Linux*AMI*) |
| 1051 | n="Amazon Linux AMI" |
| 1052 | break |
| 1053 | esac |
| 1054 | done < "/etc/${rsource}" |
| 1055 | ;; |
| 1056 | os ) |
| 1057 | nn="$(__unquote_string "$(grep '^ID=' /etc/os-release | sed -e 's/^ID=\(.*\)$/\1/g')")" |
| 1058 | rv="$(__unquote_string "$(grep '^VERSION_ID=' /etc/os-release | sed -e 's/^VERSION_ID=\(.*\)$/\1/g')")" |
| 1059 | [ "${rv}" != "" ] && v=$(__parse_version_string "$rv") || v="" |
| 1060 | case $(echo "${nn}" | tr '[:upper:]' '[:lower:]') in |
| 1061 | alpine ) |
| 1062 | n="Alpine Linux" |
| 1063 | v="${rv}" |
| 1064 | ;; |
| 1065 | amzn ) |
| 1066 | # Amazon AMI's after 2014.09 match here |
| 1067 | n="Amazon Linux AMI" |
| 1068 | ;; |
| 1069 | arch ) |
| 1070 | n="Arch Linux" |
| 1071 | v="" # Arch Linux does not provide a version. |
| 1072 | ;; |
| 1073 | cloudlinux ) |
| 1074 | n="Cloud Linux" |
| 1075 | ;; |
| 1076 | debian ) |
| 1077 | n="Debian" |
| 1078 | v=$(__derive_debian_numeric_version "$v") |
| 1079 | ;; |
| 1080 | sles ) |
| 1081 | n="SUSE" |
| 1082 | v="${rv}" |
| 1083 | ;; |
| 1084 | * ) |
| 1085 | n=${nn} |
| 1086 | ;; |
| 1087 | esac |
| 1088 | ;; |
| 1089 | * ) n="${n}" ; |
| 1090 | esac |
| 1091 | DISTRO_NAME=$n |
| 1092 | DISTRO_VERSION=$v |
| 1093 | break |
| 1094 | done |
| 1095 | } |
| 1096 | |
| 1097 | |
| 1098 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 1099 | # NAME: __install_python() |
| 1100 | # DESCRIPTION: Install a different version of python on a host. Currently this has only been tested on CentOS 6 and |
| 1101 | # is considered experimental. |
| 1102 | #---------------------------------------------------------------------------------------------------------------------- |
| 1103 | __install_python() { |
| 1104 | if [ "$_PY_EXE" = "" ]; then |
| 1105 | echoerror "Must specify -x <pythonversion> with -y to install a specific python version" |
| 1106 | exit 1 |
| 1107 | fi |
| 1108 | |
| 1109 | PY_PKG_V=$(echo "$_PY_EXE" | sed -r "s/\.//g") |
| 1110 | __PACKAGES="${PY_PKG_V}" |
| 1111 | |
| 1112 | |
| 1113 | if [ ${_DISABLE_REPOS} -eq ${BS_FALSE} ]; then |
| 1114 | echoinfo "Attempting to install a repo to help provide a separate python package" |
| 1115 | echoinfo "$DISTRO_NAME_L" |
| 1116 | case "$DISTRO_NAME_L" in |
| 1117 | "red_hat"|"centos") |
| 1118 | __PYTHON_REPO_URL="https://centos${DISTRO_MAJOR_VERSION}.iuscommunity.org/ius-release.rpm" |
| 1119 | ;; |
| 1120 | *) |
| 1121 | echoerror "Installing a repo to provide a python package is only supported on Redhat/CentOS. |
| 1122 | If a repo is already available, please try running script with -r." |
| 1123 | exit 1 |
| 1124 | ;; |
| 1125 | esac |
| 1126 | |
| 1127 | echoinfo "Installing IUS repo" |
| 1128 | __yum_install_noinput "${__PYTHON_REPO_URL}" || return 1 |
| 1129 | fi |
| 1130 | |
| 1131 | echoinfo "Installing ${__PACKAGES}" |
| 1132 | __yum_install_noinput "${__PACKAGES}" || return 1 |
| 1133 | } |
| 1134 | |
| 1135 | |
| 1136 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 1137 | # NAME: __gather_sunos_system_info |
| 1138 | # DESCRIPTION: Discover SunOS system info |
| 1139 | #---------------------------------------------------------------------------------------------------------------------- |
| 1140 | __gather_sunos_system_info() { |
| 1141 | if [ -f /sbin/uname ]; then |
| 1142 | DISTRO_VERSION=$(/sbin/uname -X | awk '/[kK][eE][rR][nN][eE][lL][iI][dD]/ { print $3 }') |
| 1143 | fi |
| 1144 | |
| 1145 | DISTRO_NAME="" |
| 1146 | if [ -f /etc/release ]; then |
| 1147 | while read -r line; do |
| 1148 | [ "${DISTRO_NAME}" != "" ] && break |
| 1149 | case "$line" in |
| 1150 | *OpenIndiana*oi_[0-9]*) |
| 1151 | DISTRO_NAME="OpenIndiana" |
| 1152 | DISTRO_VERSION=$(echo "$line" | sed -nr "s/OpenIndiana(.*)oi_([[:digit:]]+)(.*)/\2/p") |
| 1153 | break |
| 1154 | ;; |
| 1155 | *OpenSolaris*snv_[0-9]*) |
| 1156 | DISTRO_NAME="OpenSolaris" |
| 1157 | DISTRO_VERSION=$(echo "$line" | sed -nr "s/OpenSolaris(.*)snv_([[:digit:]]+)(.*)/\2/p") |
| 1158 | break |
| 1159 | ;; |
| 1160 | *Oracle*Solaris*[0-9]*) |
| 1161 | DISTRO_NAME="Oracle Solaris" |
| 1162 | DISTRO_VERSION=$(echo "$line" | sed -nr "s/(Oracle Solaris) ([[:digit:]]+)(.*)/\2/p") |
| 1163 | break |
| 1164 | ;; |
| 1165 | *Solaris*) |
| 1166 | DISTRO_NAME="Solaris" |
| 1167 | # Let's make sure we not actually on a Joyent's SmartOS VM since some releases |
| 1168 | # don't have SmartOS in `/etc/release`, only `Solaris` |
| 1169 | uname -v | grep joyent >/dev/null 2>&1 |
| 1170 | if [ $? -eq 0 ]; then |
| 1171 | DISTRO_NAME="SmartOS" |
| 1172 | fi |
| 1173 | break |
| 1174 | ;; |
| 1175 | *NexentaCore*) |
| 1176 | DISTRO_NAME="Nexenta Core" |
| 1177 | break |
| 1178 | ;; |
| 1179 | *SmartOS*) |
| 1180 | DISTRO_NAME="SmartOS" |
| 1181 | break |
| 1182 | ;; |
| 1183 | *OmniOS*) |
| 1184 | DISTRO_NAME="OmniOS" |
| 1185 | DISTRO_VERSION=$(echo "$line" | awk '{print $3}') |
| 1186 | _SIMPLIFY_VERSION=$BS_FALSE |
| 1187 | break |
| 1188 | ;; |
| 1189 | esac |
| 1190 | done < /etc/release |
| 1191 | fi |
| 1192 | |
| 1193 | if [ "${DISTRO_NAME}" = "" ]; then |
| 1194 | DISTRO_NAME="Solaris" |
| 1195 | DISTRO_VERSION=$( |
| 1196 | echo "${OS_VERSION}" | |
| 1197 | sed -e 's;^4\.;1.;' \ |
| 1198 | -e 's;^5\.\([0-6]\)[^0-9]*$;2.\1;' \ |
| 1199 | -e 's;^5\.\([0-9][0-9]*\).*;\1;' |
| 1200 | ) |
| 1201 | fi |
| 1202 | |
| 1203 | if [ "${DISTRO_NAME}" = "SmartOS" ]; then |
| 1204 | VIRTUAL_TYPE="smartmachine" |
| 1205 | if [ "$(zonename)" = "global" ]; then |
| 1206 | VIRTUAL_TYPE="global" |
| 1207 | fi |
| 1208 | fi |
| 1209 | } |
| 1210 | |
| 1211 | |
| 1212 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 1213 | # NAME: __gather_bsd_system_info |
| 1214 | # DESCRIPTION: Discover OpenBSD, NetBSD and FreeBSD systems information |
| 1215 | #---------------------------------------------------------------------------------------------------------------------- |
| 1216 | __gather_bsd_system_info() { |
| 1217 | DISTRO_NAME=${OS_NAME} |
| 1218 | DISTRO_VERSION=$(echo "${OS_VERSION}" | sed -e 's;[()];;' -e 's/-.*$//') |
| 1219 | } |
| 1220 | |
| 1221 | |
| 1222 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 1223 | # NAME: __gather_system_info |
| 1224 | # DESCRIPTION: Discover which system and distribution we are running. |
| 1225 | #---------------------------------------------------------------------------------------------------------------------- |
| 1226 | __gather_system_info() { |
| 1227 | case ${OS_NAME_L} in |
| 1228 | linux ) |
| 1229 | __gather_linux_system_info |
| 1230 | ;; |
| 1231 | sunos ) |
| 1232 | __gather_sunos_system_info |
| 1233 | ;; |
| 1234 | openbsd|freebsd|netbsd ) |
| 1235 | __gather_bsd_system_info |
| 1236 | ;; |
| 1237 | * ) |
| 1238 | echoerror "${OS_NAME} not supported."; |
| 1239 | exit 1 |
| 1240 | ;; |
| 1241 | esac |
| 1242 | |
| 1243 | } |
| 1244 | |
| 1245 | |
| 1246 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 1247 | # NAME: __ubuntu_derivatives_translation |
| 1248 | # DESCRIPTION: Map Ubuntu derivatives to their Ubuntu base versions. |
| 1249 | # If distro has a known Ubuntu base version, use those install |
| 1250 | # functions by pretending to be Ubuntu (i.e. change global vars) |
| 1251 | #---------------------------------------------------------------------------------------------------------------------- |
| 1252 | # shellcheck disable=SC2034 |
| 1253 | __ubuntu_derivatives_translation() { |
| 1254 | UBUNTU_DERIVATIVES="(trisquel|linuxmint|linaro|elementary_os|neon)" |
| 1255 | # Mappings |
| 1256 | trisquel_6_ubuntu_base="12.04" |
| 1257 | linuxmint_13_ubuntu_base="12.04" |
| 1258 | linuxmint_17_ubuntu_base="14.04" |
| 1259 | linuxmint_18_ubuntu_base="16.04" |
| 1260 | linaro_12_ubuntu_base="12.04" |
| 1261 | elementary_os_02_ubuntu_base="12.04" |
| 1262 | neon_16_ubuntu_base="16.04" |
| 1263 | |
| 1264 | # Translate Ubuntu derivatives to their base Ubuntu version |
| 1265 | match=$(echo "$DISTRO_NAME_L" | egrep ${UBUNTU_DERIVATIVES}) |
| 1266 | |
| 1267 | if [ "${match}" != "" ]; then |
| 1268 | case $match in |
| 1269 | "elementary_os") |
| 1270 | _major=$(echo "$DISTRO_VERSION" | sed 's/\.//g') |
| 1271 | ;; |
| 1272 | "linuxmint") |
| 1273 | export LSB_ETC_LSB_RELEASE=/etc/upstream-release/lsb-release |
| 1274 | _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') |
| 1275 | ;; |
| 1276 | *) |
| 1277 | _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') |
| 1278 | ;; |
| 1279 | esac |
| 1280 | |
| 1281 | _ubuntu_version=$(eval echo "\$${match}_${_major}_ubuntu_base") |
| 1282 | |
| 1283 | if [ "$_ubuntu_version" != "" ]; then |
| 1284 | echodebug "Detected Ubuntu $_ubuntu_version derivative" |
| 1285 | DISTRO_NAME_L="ubuntu" |
| 1286 | DISTRO_VERSION="$_ubuntu_version" |
| 1287 | fi |
| 1288 | fi |
| 1289 | } |
| 1290 | |
| 1291 | |
| 1292 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 1293 | # NAME: __check_dpkg_architecture |
| 1294 | # DESCRIPTION: Determine the primary architecture for packages to install on Debian and derivatives |
| 1295 | # and issue all necessary error messages. |
| 1296 | #---------------------------------------------------------------------------------------------------------------------- |
| 1297 | __check_dpkg_architecture() { |
| 1298 | if __check_command_exists dpkg; then |
| 1299 | DPKG_ARCHITECTURE="$(dpkg --print-architecture)" |
| 1300 | else |
| 1301 | echoerror "dpkg: command not found." |
| 1302 | return 1 |
| 1303 | fi |
| 1304 | |
| 1305 | __REPO_ARCH="$DPKG_ARCHITECTURE" |
| 1306 | __return_code=0 |
| 1307 | |
| 1308 | case $DPKG_ARCHITECTURE in |
| 1309 | "i386") |
| 1310 | error_msg="$_REPO_URL likely doesn't have all required 32-bit packages for $DISTRO_NAME $DISTRO_MAJOR_VERSION." |
| 1311 | # amd64 is just a part of repository URI, 32-bit pkgs are hosted under the same location |
| 1312 | __REPO_ARCH="amd64" |
| 1313 | ;; |
| 1314 | "amd64") |
| 1315 | error_msg="" |
| 1316 | ;; |
| 1317 | "armhf") |
| 1318 | if [ "$DISTRO_NAME_L" = "ubuntu" ] || [ "$DISTRO_MAJOR_VERSION" -lt 8 ]; then |
| 1319 | error_msg="Support for armhf packages at $_REPO_URL is limited to Debian/Raspbian 8 platforms." |
| 1320 | __return_code=1 |
| 1321 | else |
| 1322 | error_msg="" |
| 1323 | fi |
| 1324 | ;; |
| 1325 | *) |
| 1326 | error_msg="$_REPO_URL doesn't have packages for your system architecture: $DPKG_ARCHITECTURE." |
| 1327 | __return_code=1 |
| 1328 | ;; |
| 1329 | esac |
| 1330 | |
| 1331 | if [ "${error_msg}" != "" ]; then |
| 1332 | echoerror "${error_msg}" |
| 1333 | if [ "$ITYPE" != "git" ]; then |
| 1334 | echoerror "You can try git installation mode, i.e.: sh ${__ScriptName} git v2016.11.5." |
| 1335 | echoerror "It may be necessary to use git installation mode with pip and disable the SaltStack apt repository." |
| 1336 | echoerror "For example:" |
| 1337 | echoerror " sh ${__ScriptName} -r -P git v2016.11.5" |
| 1338 | fi |
| 1339 | fi |
| 1340 | |
| 1341 | if [ "${__return_code}" -eq 0 ]; then |
| 1342 | return 0 |
| 1343 | else |
| 1344 | return 1 |
| 1345 | fi |
| 1346 | } |
| 1347 | |
| 1348 | |
| 1349 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 1350 | # NAME: __ubuntu_codename_translation |
| 1351 | # DESCRIPTION: Map Ubuntu major versions to their corresponding codenames |
| 1352 | #---------------------------------------------------------------------------------------------------------------------- |
| 1353 | # shellcheck disable=SC2034 |
| 1354 | __ubuntu_codename_translation() { |
| 1355 | case $DISTRO_MINOR_VERSION in |
| 1356 | "04") |
| 1357 | _april="yes" |
| 1358 | ;; |
| 1359 | "10") |
| 1360 | _april="" |
| 1361 | ;; |
| 1362 | *) |
| 1363 | _april="yes" |
| 1364 | ;; |
| 1365 | esac |
| 1366 | |
| 1367 | case $DISTRO_MAJOR_VERSION in |
| 1368 | "12") |
| 1369 | DISTRO_CODENAME="precise" |
| 1370 | ;; |
| 1371 | "14") |
| 1372 | DISTRO_CODENAME="trusty" |
| 1373 | ;; |
| 1374 | "16") |
| 1375 | if [ "$_april" ]; then |
| 1376 | DISTRO_CODENAME="xenial" |
| 1377 | else |
| 1378 | DISTRO_CODENAME="yakkety" |
| 1379 | fi |
| 1380 | ;; |
| 1381 | "17") |
| 1382 | if [ "$_april" ]; then |
| 1383 | DISTRO_CODENAME="zesty" |
| 1384 | fi |
| 1385 | ;; |
| 1386 | *) |
| 1387 | DISTRO_CODENAME="trusty" |
| 1388 | ;; |
| 1389 | esac |
| 1390 | } |
| 1391 | |
| 1392 | |
| 1393 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 1394 | # NAME: __debian_derivatives_translation |
| 1395 | # DESCRIPTION: Map Debian derivatives to their Debian base versions. |
| 1396 | # If distro has a known Debian base version, use those install |
| 1397 | # functions by pretending to be Debian (i.e. change global vars) |
| 1398 | #---------------------------------------------------------------------------------------------------------------------- |
| 1399 | # shellcheck disable=SC2034 |
| 1400 | __debian_derivatives_translation() { |
| 1401 | # If the file does not exist, return |
| 1402 | [ ! -f /etc/os-release ] && return |
| 1403 | |
| 1404 | DEBIAN_DERIVATIVES="(cumulus_.+|devuan|kali|linuxmint|raspbian)" |
| 1405 | # Mappings |
| 1406 | cumulus_2_debian_base="7.0" |
| 1407 | cumulus_3_debian_base="8.0" |
| 1408 | devuan_1_debian_base="8.0" |
| 1409 | devuan_2_debian_base="9.0" |
| 1410 | kali_1_debian_base="7.0" |
| 1411 | linuxmint_1_debian_base="8.0" |
| 1412 | raspbian_8_debian_base="8.0" |
| 1413 | raspbian_9_debian_base="9.0" |
| 1414 | |
| 1415 | # Translate Debian derivatives to their base Debian version |
| 1416 | match=$(echo "$DISTRO_NAME_L" | egrep ${DEBIAN_DERIVATIVES}) |
| 1417 | |
| 1418 | if [ "${match}" != "" ]; then |
| 1419 | case $match in |
| 1420 | cumulus_*) |
| 1421 | _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') |
| 1422 | _debian_derivative="cumulus" |
| 1423 | ;; |
| 1424 | devuan) |
| 1425 | _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') |
| 1426 | _debian_derivative="devuan" |
| 1427 | ;; |
| 1428 | kali) |
| 1429 | _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') |
| 1430 | _debian_derivative="kali" |
| 1431 | ;; |
| 1432 | linuxmint) |
| 1433 | _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') |
| 1434 | _debian_derivative="linuxmint" |
| 1435 | ;; |
| 1436 | raspbian) |
| 1437 | _major=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') |
| 1438 | _debian_derivative="raspbian" |
| 1439 | ;; |
| 1440 | esac |
| 1441 | |
| 1442 | _debian_version=$(eval echo "\$${_debian_derivative}_${_major}_debian_base" 2>/dev/null) |
| 1443 | |
| 1444 | if [ "$_debian_version" != "" ]; then |
| 1445 | echodebug "Detected Debian $_debian_version derivative" |
| 1446 | DISTRO_NAME_L="debian" |
| 1447 | DISTRO_VERSION="$_debian_version" |
| 1448 | DISTRO_MAJOR_VERSION="$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g')" |
| 1449 | fi |
| 1450 | fi |
| 1451 | } |
| 1452 | |
| 1453 | |
| 1454 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 1455 | # NAME: __debian_codename_translation |
| 1456 | # DESCRIPTION: Map Debian major versions to their corresponding code names |
| 1457 | #---------------------------------------------------------------------------------------------------------------------- |
| 1458 | # shellcheck disable=SC2034 |
| 1459 | __debian_codename_translation() { |
| 1460 | |
| 1461 | case $DISTRO_MAJOR_VERSION in |
| 1462 | "7") |
| 1463 | DISTRO_CODENAME="wheezy" |
| 1464 | ;; |
| 1465 | "8") |
| 1466 | DISTRO_CODENAME="jessie" |
| 1467 | ;; |
| 1468 | "9") |
| 1469 | DISTRO_CODENAME="stretch" |
| 1470 | ;; |
| 1471 | "10") |
| 1472 | DISTRO_CODENAME="buster" |
| 1473 | ;; |
| 1474 | *) |
| 1475 | DISTRO_CODENAME="jessie" |
| 1476 | ;; |
| 1477 | esac |
| 1478 | } |
| 1479 | |
| 1480 | |
| 1481 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 1482 | # NAME: __check_end_of_life_versions |
| 1483 | # DESCRIPTION: Check for end of life distribution versions |
| 1484 | #---------------------------------------------------------------------------------------------------------------------- |
| 1485 | __check_end_of_life_versions() { |
| 1486 | case "${DISTRO_NAME_L}" in |
| 1487 | debian) |
| 1488 | # Debian versions below 7 are not supported |
| 1489 | if [ "$DISTRO_MAJOR_VERSION" -lt 7 ]; then |
| 1490 | echoerror "End of life distributions are not supported." |
| 1491 | echoerror "Please consider upgrading to the next stable. See:" |
| 1492 | echoerror " https://wiki.debian.org/DebianReleases" |
| 1493 | exit 1 |
| 1494 | fi |
| 1495 | ;; |
| 1496 | |
| 1497 | ubuntu) |
| 1498 | # Ubuntu versions not supported |
| 1499 | # |
| 1500 | # < 14.04 |
| 1501 | # = 14.10 |
| 1502 | # = 15.04, 15.10 |
| 1503 | if [ "$DISTRO_MAJOR_VERSION" -lt 14 ] || \ |
| 1504 | [ "$DISTRO_MAJOR_VERSION" -eq 15 ] || \ |
| 1505 | ([ "$DISTRO_MAJOR_VERSION" -lt 16 ] && [ "$DISTRO_MINOR_VERSION" -eq 10 ]); then |
| 1506 | echoerror "End of life distributions are not supported." |
| 1507 | echoerror "Please consider upgrading to the next stable. See:" |
| 1508 | echoerror " https://wiki.ubuntu.com/Releases" |
| 1509 | exit 1 |
| 1510 | fi |
| 1511 | ;; |
| 1512 | |
| 1513 | opensuse) |
| 1514 | # openSUSE versions not supported |
| 1515 | # |
| 1516 | # <= 13.X |
| 1517 | # <= 42.1 |
| 1518 | if [ "$DISTRO_MAJOR_VERSION" -le 13 ] || \ |
| 1519 | ([ "$DISTRO_MAJOR_VERSION" -eq 42 ] && [ "$DISTRO_MINOR_VERSION" -le 1 ]); then |
| 1520 | echoerror "End of life distributions are not supported." |
| 1521 | echoerror "Please consider upgrading to the next stable. See:" |
| 1522 | echoerror " http://en.opensuse.org/Lifetime" |
| 1523 | exit 1 |
| 1524 | fi |
| 1525 | ;; |
| 1526 | |
| 1527 | suse) |
| 1528 | # SuSE versions not supported |
| 1529 | # |
| 1530 | # < 11 SP4 |
| 1531 | # < 12 SP2 |
| 1532 | SUSE_PATCHLEVEL=$(awk '/PATCHLEVEL/ {print $3}' /etc/SuSE-release ) |
| 1533 | if [ "${SUSE_PATCHLEVEL}" = "" ]; then |
| 1534 | SUSE_PATCHLEVEL="00" |
| 1535 | fi |
| 1536 | if [ "$DISTRO_MAJOR_VERSION" -lt 11 ] || \ |
| 1537 | ([ "$DISTRO_MAJOR_VERSION" -eq 11 ] && [ "$SUSE_PATCHLEVEL" -lt 04 ]) || \ |
| 1538 | ([ "$DISTRO_MAJOR_VERSION" -eq 12 ] && [ "$SUSE_PATCHLEVEL" -lt 02 ]); then |
| 1539 | echoerror "Versions lower than SuSE 11 SP4 or 12 SP2 are not supported." |
| 1540 | echoerror "Please consider upgrading to the next stable" |
| 1541 | echoerror " https://www.suse.com/lifecycle/" |
| 1542 | exit 1 |
| 1543 | fi |
| 1544 | ;; |
| 1545 | |
| 1546 | fedora) |
| 1547 | # Fedora lower than 25 are no longer supported |
| 1548 | if [ "$DISTRO_MAJOR_VERSION" -lt 25 ]; then |
| 1549 | echoerror "End of life distributions are not supported." |
| 1550 | echoerror "Please consider upgrading to the next stable. See:" |
| 1551 | echoerror " https://fedoraproject.org/wiki/Releases" |
| 1552 | exit 1 |
| 1553 | fi |
| 1554 | ;; |
| 1555 | |
| 1556 | centos) |
| 1557 | # CentOS versions lower than 6 are no longer supported |
| 1558 | if [ "$DISTRO_MAJOR_VERSION" -lt 6 ]; then |
| 1559 | echoerror "End of life distributions are not supported." |
| 1560 | echoerror "Please consider upgrading to the next stable. See:" |
| 1561 | echoerror " http://wiki.centos.org/Download" |
| 1562 | exit 1 |
| 1563 | fi |
| 1564 | ;; |
| 1565 | |
| 1566 | red_hat*linux) |
| 1567 | # Red Hat (Enterprise) Linux versions lower than 6 are no longer supported |
| 1568 | if [ "$DISTRO_MAJOR_VERSION" -lt 6 ]; then |
| 1569 | echoerror "End of life distributions are not supported." |
| 1570 | echoerror "Please consider upgrading to the next stable. See:" |
| 1571 | echoerror " https://access.redhat.com/support/policy/updates/errata/" |
| 1572 | exit 1 |
| 1573 | fi |
| 1574 | ;; |
| 1575 | |
| 1576 | oracle*linux) |
| 1577 | # Oracle Linux versions lower than 6 are no longer supported |
| 1578 | if [ "$DISTRO_MAJOR_VERSION" -lt 6 ]; then |
| 1579 | echoerror "End of life distributions are not supported." |
| 1580 | echoerror "Please consider upgrading to the next stable. See:" |
| 1581 | echoerror " http://www.oracle.com/us/support/library/elsp-lifetime-069338.pdf" |
| 1582 | exit 1 |
| 1583 | fi |
| 1584 | ;; |
| 1585 | |
| 1586 | scientific*linux) |
| 1587 | # Scientific Linux versions lower than 6 are no longer supported |
| 1588 | if [ "$DISTRO_MAJOR_VERSION" -lt 6 ]; then |
| 1589 | echoerror "End of life distributions are not supported." |
| 1590 | echoerror "Please consider upgrading to the next stable. See:" |
| 1591 | echoerror " https://www.scientificlinux.org/downloads/sl-versions/" |
| 1592 | exit 1 |
| 1593 | fi |
| 1594 | ;; |
| 1595 | |
| 1596 | cloud*linux) |
| 1597 | # Cloud Linux versions lower than 6 are no longer supported |
| 1598 | if [ "$DISTRO_MAJOR_VERSION" -lt 6 ]; then |
| 1599 | echoerror "End of life distributions are not supported." |
| 1600 | echoerror "Please consider upgrading to the next stable. See:" |
| 1601 | echoerror " https://docs.cloudlinux.com/index.html?cloudlinux_life-cycle.html" |
| 1602 | exit 1 |
| 1603 | fi |
| 1604 | ;; |
| 1605 | |
| 1606 | amazon*linux*ami) |
| 1607 | # Amazon Linux versions lower than 2012.0X no longer supported |
| 1608 | if [ "$DISTRO_MAJOR_VERSION" -lt 2012 ]; then |
| 1609 | echoerror "End of life distributions are not supported." |
| 1610 | echoerror "Please consider upgrading to the next stable. See:" |
| 1611 | echoerror " https://aws.amazon.com/amazon-linux-ami/" |
| 1612 | exit 1 |
| 1613 | fi |
| 1614 | ;; |
| 1615 | |
| 1616 | freebsd) |
| 1617 | # FreeBSD versions lower than 9.1 are not supported. |
| 1618 | if ([ "$DISTRO_MAJOR_VERSION" -eq 9 ] && [ "$DISTRO_MINOR_VERSION" -lt 01 ]) || [ "$DISTRO_MAJOR_VERSION" -lt 9 ]; then |
| 1619 | echoerror "Versions lower than FreeBSD 9.1 are not supported." |
| 1620 | exit 1 |
| 1621 | fi |
| 1622 | ;; |
| 1623 | |
| 1624 | *) |
| 1625 | ;; |
| 1626 | esac |
| 1627 | } |
| 1628 | |
| 1629 | |
| 1630 | __gather_system_info |
| 1631 | |
| 1632 | echo |
| 1633 | echoinfo "System Information:" |
| 1634 | echoinfo " CPU: ${CPU_VENDOR_ID}" |
| 1635 | echoinfo " CPU Arch: ${CPU_ARCH}" |
| 1636 | echoinfo " OS Name: ${OS_NAME}" |
| 1637 | echoinfo " OS Version: ${OS_VERSION}" |
| 1638 | echoinfo " Distribution: ${DISTRO_NAME} ${DISTRO_VERSION}" |
| 1639 | echo |
| 1640 | |
| 1641 | # Simplify distro name naming on functions |
| 1642 | DISTRO_NAME_L=$(echo "$DISTRO_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-zA-Z0-9_ ]//g' | sed -re 's/([[:space:]])+/_/g') |
| 1643 | |
| 1644 | # Simplify version naming on functions |
| 1645 | if [ "$DISTRO_VERSION" = "" ] || [ ${_SIMPLIFY_VERSION} -eq $BS_FALSE ]; then |
| 1646 | DISTRO_MAJOR_VERSION="" |
| 1647 | DISTRO_MINOR_VERSION="" |
| 1648 | PREFIXED_DISTRO_MAJOR_VERSION="" |
| 1649 | PREFIXED_DISTRO_MINOR_VERSION="" |
| 1650 | else |
| 1651 | DISTRO_MAJOR_VERSION=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).*/\1/g') |
| 1652 | DISTRO_MINOR_VERSION=$(echo "$DISTRO_VERSION" | sed 's/^\([0-9]*\).\([0-9]*\).*/\2/g') |
| 1653 | PREFIXED_DISTRO_MAJOR_VERSION="_${DISTRO_MAJOR_VERSION}" |
| 1654 | if [ "${PREFIXED_DISTRO_MAJOR_VERSION}" = "_" ]; then |
| 1655 | PREFIXED_DISTRO_MAJOR_VERSION="" |
| 1656 | fi |
| 1657 | PREFIXED_DISTRO_MINOR_VERSION="_${DISTRO_MINOR_VERSION}" |
| 1658 | if [ "${PREFIXED_DISTRO_MINOR_VERSION}" = "_" ]; then |
| 1659 | PREFIXED_DISTRO_MINOR_VERSION="" |
| 1660 | fi |
| 1661 | fi |
| 1662 | |
| 1663 | # For Ubuntu derivatives, pretend to be their Ubuntu base version |
| 1664 | __ubuntu_derivatives_translation |
| 1665 | |
| 1666 | # For Debian derivates, pretend to be their Debian base version |
| 1667 | __debian_derivatives_translation |
| 1668 | |
| 1669 | # Fail soon for end of life versions |
| 1670 | __check_end_of_life_versions |
| 1671 | |
| 1672 | echodebug "Binaries will be searched using the following \$PATH: ${PATH}" |
| 1673 | |
| 1674 | # Let users know that we'll use a proxy |
| 1675 | if [ "${_HTTP_PROXY}" != "" ]; then |
| 1676 | echoinfo "Using http proxy $_HTTP_PROXY" |
| 1677 | fi |
| 1678 | |
| 1679 | # Let users know what's going to be installed/configured |
| 1680 | if [ "$_INSTALL_MINION" -eq $BS_TRUE ]; then |
| 1681 | if [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then |
| 1682 | echoinfo "Installing minion" |
| 1683 | else |
| 1684 | echoinfo "Configuring minion" |
| 1685 | fi |
| 1686 | fi |
| 1687 | |
| 1688 | if [ "$_INSTALL_MASTER" -eq $BS_TRUE ]; then |
| 1689 | if [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then |
| 1690 | echoinfo "Installing master" |
| 1691 | else |
| 1692 | echoinfo "Configuring master" |
| 1693 | fi |
| 1694 | fi |
| 1695 | |
| 1696 | if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ]; then |
| 1697 | if [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then |
| 1698 | echoinfo "Installing syndic" |
| 1699 | else |
| 1700 | echoinfo "Configuring syndic" |
| 1701 | fi |
| 1702 | fi |
| 1703 | |
| 1704 | if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ] && [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then |
| 1705 | echoinfo "Installing salt-cloud and required python-libcloud package" |
| 1706 | fi |
| 1707 | |
| 1708 | if [ $_START_DAEMONS -eq $BS_FALSE ]; then |
| 1709 | echoinfo "Daemons will not be started" |
| 1710 | fi |
| 1711 | |
| 1712 | if [ "${DISTRO_NAME_L}" = "ubuntu" ]; then |
| 1713 | # For ubuntu versions, obtain the codename from the release version |
| 1714 | __ubuntu_codename_translation |
| 1715 | elif [ "${DISTRO_NAME_L}" = "debian" ]; then |
| 1716 | # For debian versions, obtain the codename from the release version |
| 1717 | __debian_codename_translation |
| 1718 | fi |
| 1719 | |
| 1720 | # Only Ubuntu has daily packages, let's let users know about that |
| 1721 | if ([ "${DISTRO_NAME_L}" != "ubuntu" ] && [ "$ITYPE" = "daily" ]); then |
| 1722 | echoerror "${DISTRO_NAME} does not have daily packages support" |
| 1723 | exit 1 |
| 1724 | elif ([ "$(echo "${DISTRO_NAME_L}" | egrep '(debian|ubuntu|centos|red_hat|oracle|scientific|amazon)')" = "" ] && [ "$ITYPE" = "stable" ] && [ "$STABLE_REV" != "latest" ]); then |
| 1725 | echoerror "${DISTRO_NAME} does not have major version pegged packages support" |
| 1726 | exit 1 |
| 1727 | fi |
| 1728 | |
| 1729 | # Only RedHat based distros have testing support |
| 1730 | if [ "${ITYPE}" = "testing" ]; then |
| 1731 | if [ "$(echo "${DISTRO_NAME_L}" | egrep '(centos|red_hat|amazon|oracle)')" = "" ]; then |
| 1732 | echoerror "${DISTRO_NAME} does not have testing packages support" |
| 1733 | exit 1 |
| 1734 | fi |
| 1735 | _EPEL_REPO="epel-testing" |
| 1736 | fi |
| 1737 | |
| 1738 | # Only Ubuntu has support for installing to virtualenvs |
| 1739 | if ([ "${DISTRO_NAME_L}" != "ubuntu" ] && [ "$_VIRTUALENV_DIR" != "null" ]); then |
| 1740 | echoerror "${DISTRO_NAME} does not have -V support" |
| 1741 | exit 1 |
| 1742 | fi |
| 1743 | |
| 1744 | # Only Ubuntu has support for pip installing all packages |
| 1745 | if ([ "${DISTRO_NAME_L}" != "ubuntu" ] && [ $_PIP_ALL -eq $BS_TRUE ]); then |
| 1746 | echoerror "${DISTRO_NAME} does not have -a support" |
| 1747 | exit 1 |
| 1748 | fi |
| 1749 | |
| 1750 | |
| 1751 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 1752 | # NAME: __function_defined |
| 1753 | # DESCRIPTION: Checks if a function is defined within this scripts scope |
| 1754 | # PARAMETERS: function name |
| 1755 | # RETURNS: 0 or 1 as in defined or not defined |
| 1756 | #---------------------------------------------------------------------------------------------------------------------- |
| 1757 | __function_defined() { |
| 1758 | FUNC_NAME=$1 |
| 1759 | if [ "$(command -v "$FUNC_NAME")" != "" ]; then |
| 1760 | echoinfo "Found function $FUNC_NAME" |
| 1761 | return 0 |
| 1762 | fi |
| 1763 | echodebug "$FUNC_NAME not found...." |
| 1764 | return 1 |
| 1765 | } |
| 1766 | |
| 1767 | |
| 1768 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 1769 | # NAME: __apt_get_install_noinput |
| 1770 | # DESCRIPTION: (DRY) apt-get install with noinput options |
| 1771 | # PARAMETERS: packages |
| 1772 | #---------------------------------------------------------------------------------------------------------------------- |
| 1773 | __apt_get_install_noinput() { |
| 1774 | apt-get install -y -o DPkg::Options::=--force-confold "${@}"; return $? |
| 1775 | } # ---------- end of function __apt_get_install_noinput ---------- |
| 1776 | |
| 1777 | |
| 1778 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 1779 | # NAME: __apt_get_upgrade_noinput |
| 1780 | # DESCRIPTION: (DRY) apt-get upgrade with noinput options |
| 1781 | #---------------------------------------------------------------------------------------------------------------------- |
| 1782 | __apt_get_upgrade_noinput() { |
| 1783 | apt-get upgrade -y -o DPkg::Options::=--force-confold; return $? |
| 1784 | } # ---------- end of function __apt_get_upgrade_noinput ---------- |
| 1785 | |
| 1786 | |
| 1787 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 1788 | # NAME: __apt_key_fetch |
| 1789 | # DESCRIPTION: Download and import GPG public key for "apt-secure" |
| 1790 | # PARAMETERS: url |
| 1791 | #---------------------------------------------------------------------------------------------------------------------- |
| 1792 | __apt_key_fetch() { |
| 1793 | url=$1 |
| 1794 | |
| 1795 | # shellcheck disable=SC2086 |
| 1796 | apt-key adv ${_GPG_ARGS} --fetch-keys "$url"; return $? |
| 1797 | } # ---------- end of function __apt_key_fetch ---------- |
| 1798 | |
| 1799 | |
| 1800 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 1801 | # NAME: __rpm_import_gpg |
| 1802 | # DESCRIPTION: Download and import GPG public key to rpm database |
| 1803 | # PARAMETERS: url |
| 1804 | #---------------------------------------------------------------------------------------------------------------------- |
| 1805 | __rpm_import_gpg() { |
| 1806 | url=$1 |
| 1807 | |
| 1808 | if __check_command_exists mktemp; then |
| 1809 | tempfile="$(mktemp /tmp/salt-gpg-XXXXXXXX.pub 2>/dev/null)" |
| 1810 | |
| 1811 | if [ -z "$tempfile" ]; then |
| 1812 | echoerror "Failed to create temporary file in /tmp" |
| 1813 | return 1 |
| 1814 | fi |
| 1815 | else |
| 1816 | tempfile="/tmp/salt-gpg-$$.pub" |
| 1817 | fi |
| 1818 | |
| 1819 | __fetch_url "$tempfile" "$url" || return 1 |
| 1820 | rpm --import "$tempfile" || return 1 |
| 1821 | rm -f "$tempfile" |
| 1822 | |
| 1823 | return 0 |
| 1824 | } # ---------- end of function __rpm_import_gpg ---------- |
| 1825 | |
| 1826 | |
| 1827 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 1828 | # NAME: __yum_install_noinput |
| 1829 | # DESCRIPTION: (DRY) yum install with noinput options |
| 1830 | #---------------------------------------------------------------------------------------------------------------------- |
| 1831 | __yum_install_noinput() { |
| 1832 | |
| 1833 | ENABLE_EPEL_CMD="" |
| 1834 | # Skip Amazon Linux for the first round, since EPEL is no longer required. |
| 1835 | # See issue #724 |
| 1836 | if [ $_DISABLE_REPOS -eq $BS_FALSE ] && [ "$DISTRO_NAME_L" != "amazon_linux_ami" ]; then |
| 1837 | ENABLE_EPEL_CMD="--enablerepo=${_EPEL_REPO}" |
| 1838 | fi |
| 1839 | |
| 1840 | if [ "$DISTRO_NAME_L" = "oracle_linux" ]; then |
| 1841 | # We need to install one package at a time because --enablerepo=X disables ALL OTHER REPOS!!!! |
| 1842 | for package in "${@}"; do |
| 1843 | yum -y install "${package}" || yum -y install "${package}" ${ENABLE_EPEL_CMD} || return $? |
| 1844 | done |
| 1845 | else |
| 1846 | yum -y install "${@}" ${ENABLE_EPEL_CMD} || return $? |
| 1847 | fi |
| 1848 | } # ---------- end of function __yum_install_noinput ---------- |
| 1849 | |
| 1850 | |
| 1851 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 1852 | # NAME: __git_clone_and_checkout |
| 1853 | # DESCRIPTION: (DRY) Helper function to clone and checkout salt to a |
| 1854 | # specific revision. |
| 1855 | #---------------------------------------------------------------------------------------------------------------------- |
| 1856 | __git_clone_and_checkout() { |
| 1857 | |
| 1858 | echodebug "Installed git version: $(git --version | awk '{ print $3 }')" |
| 1859 | # Turn off SSL verification if -I flag was set for insecure downloads |
| 1860 | if [ "$_INSECURE_DL" -eq $BS_TRUE ]; then |
| 1861 | export GIT_SSL_NO_VERIFY=1 |
| 1862 | fi |
| 1863 | |
| 1864 | case ${OS_NAME_L} in |
| 1865 | openbsd|freebsd|netbsd ) |
| 1866 | __TAG_REGEX_MATCH=$(echo "${GIT_REV}" | sed -E 's/^(v?[0-9]{1,4}\.[0-9]{1,2})(\.[0-9]{1,2})?.*$/MATCH/') |
| 1867 | ;; |
| 1868 | * ) |
| 1869 | __TAG_REGEX_MATCH=$(echo "${GIT_REV}" | sed 's/^.*\(v\?[[:digit:]]\{1,4\}\.[[:digit:]]\{1,2\}\)\(\.[[:digit:]]\{1,2\}\)\?.*$/MATCH/') |
| 1870 | ;; |
| 1871 | esac |
| 1872 | |
| 1873 | __SALT_GIT_CHECKOUT_PARENT_DIR=$(dirname "${_SALT_GIT_CHECKOUT_DIR}" 2>/dev/null) |
| 1874 | __SALT_GIT_CHECKOUT_PARENT_DIR="${__SALT_GIT_CHECKOUT_PARENT_DIR:-/tmp/git}" |
| 1875 | __SALT_CHECKOUT_REPONAME="$(basename "${_SALT_GIT_CHECKOUT_DIR}" 2>/dev/null)" |
| 1876 | __SALT_CHECKOUT_REPONAME="${__SALT_CHECKOUT_REPONAME:-salt}" |
| 1877 | [ -d "${__SALT_GIT_CHECKOUT_PARENT_DIR}" ] || mkdir "${__SALT_GIT_CHECKOUT_PARENT_DIR}" |
| 1878 | # shellcheck disable=SC2164 |
| 1879 | cd "${__SALT_GIT_CHECKOUT_PARENT_DIR}" |
| 1880 | if [ -d "${_SALT_GIT_CHECKOUT_DIR}" ]; then |
| 1881 | echodebug "Found a checked out Salt repository" |
| 1882 | # shellcheck disable=SC2164 |
| 1883 | cd "${_SALT_GIT_CHECKOUT_DIR}" |
| 1884 | echodebug "Fetching git changes" |
| 1885 | git fetch || return 1 |
| 1886 | # Tags are needed because of salt's versioning, also fetch that |
| 1887 | echodebug "Fetching git tags" |
| 1888 | git fetch --tags || return 1 |
| 1889 | |
| 1890 | # If we have the SaltStack remote set as upstream, we also need to fetch the tags from there |
| 1891 | if [ "$(git remote -v | grep $_SALTSTACK_REPO_URL)" != "" ]; then |
| 1892 | echodebug "Fetching upstream(SaltStack's Salt repository) git tags" |
| 1893 | git fetch --tags upstream |
| 1894 | else |
| 1895 | echoinfo "Adding SaltStack's Salt repository as a remote" |
| 1896 | git remote add upstream "$_SALTSTACK_REPO_URL" |
| 1897 | echodebug "Fetching upstream(SaltStack's Salt repository) git tags" |
| 1898 | git fetch --tags upstream |
| 1899 | fi |
| 1900 | |
| 1901 | echodebug "Hard reseting the cloned repository to ${GIT_REV}" |
| 1902 | git reset --hard "$GIT_REV" || return 1 |
| 1903 | |
| 1904 | # Just calling `git reset --hard $GIT_REV` on a branch name that has |
| 1905 | # already been checked out will not update that branch to the upstream |
| 1906 | # HEAD; instead it will simply reset to itself. Check the ref to see |
| 1907 | # if it is a branch name, check out the branch, and pull in the |
| 1908 | # changes. |
| 1909 | git branch -a | grep -q "${GIT_REV}" |
| 1910 | if [ $? -eq 0 ]; then |
| 1911 | echodebug "Rebasing the cloned repository branch" |
| 1912 | git pull --rebase || return 1 |
| 1913 | fi |
| 1914 | else |
| 1915 | if [ "$_FORCE_SHALLOW_CLONE" -eq "${BS_TRUE}" ]; then |
| 1916 | echoinfo "Forced shallow cloning of git repository." |
| 1917 | __SHALLOW_CLONE=$BS_TRUE |
| 1918 | elif [ "$__TAG_REGEX_MATCH" = "MATCH" ]; then |
| 1919 | echoinfo "Git revision matches a Salt version tag, shallow cloning enabled." |
| 1920 | __SHALLOW_CLONE=$BS_TRUE |
| 1921 | else |
| 1922 | echowarn "The git revision being installed does not match a Salt version tag. Shallow cloning disabled" |
| 1923 | __SHALLOW_CLONE=$BS_FALSE |
| 1924 | fi |
| 1925 | |
| 1926 | if [ "$__SHALLOW_CLONE" -eq $BS_TRUE ]; then |
| 1927 | # Let's try shallow cloning to speed up. |
| 1928 | # Test for "--single-branch" option introduced in git 1.7.10, the minimal version of git where the shallow |
| 1929 | # cloning we need actually works |
| 1930 | if [ "$(git clone 2>&1 | grep 'single-branch')" != "" ]; then |
| 1931 | # The "--single-branch" option is supported, attempt shallow cloning |
| 1932 | echoinfo "Attempting to shallow clone $GIT_REV from Salt's repository ${_SALT_REPO_URL}" |
| 1933 | git clone --depth 1 --branch "$GIT_REV" "$_SALT_REPO_URL" "$__SALT_CHECKOUT_REPONAME" |
| 1934 | if [ $? -eq 0 ]; then |
| 1935 | # shellcheck disable=SC2164 |
| 1936 | cd "${_SALT_GIT_CHECKOUT_DIR}" |
| 1937 | __SHALLOW_CLONE=$BS_TRUE |
| 1938 | else |
| 1939 | # Shallow clone above failed(missing upstream tags???), let's resume the old behaviour. |
| 1940 | echowarn "Failed to shallow clone." |
| 1941 | echoinfo "Resuming regular git clone and remote SaltStack repository addition procedure" |
| 1942 | __SHALLOW_CLONE=$BS_FALSE |
| 1943 | fi |
| 1944 | else |
| 1945 | echodebug "Shallow cloning not possible. Required git version not met." |
| 1946 | __SHALLOW_CLONE=$BS_FALSE |
| 1947 | fi |
| 1948 | fi |
| 1949 | |
| 1950 | if [ "$__SHALLOW_CLONE" -eq $BS_FALSE ]; then |
| 1951 | git clone "$_SALT_REPO_URL" "$__SALT_CHECKOUT_REPONAME" || return 1 |
| 1952 | # shellcheck disable=SC2164 |
| 1953 | cd "${_SALT_GIT_CHECKOUT_DIR}" |
| 1954 | |
| 1955 | if ! echo "$_SALT_REPO_URL" | grep -q -F -w "${_SALTSTACK_REPO_URL#*://}"; then |
| 1956 | # We need to add the saltstack repository as a remote and fetch tags for proper versioning |
| 1957 | echoinfo "Adding SaltStack's Salt repository as a remote" |
| 1958 | git remote add upstream "$_SALTSTACK_REPO_URL" || return 1 |
| 1959 | |
| 1960 | echodebug "Fetching upstream (SaltStack's Salt repository) git tags" |
| 1961 | git fetch --tags upstream || return 1 |
| 1962 | |
| 1963 | # Check if GIT_REV is a remote branch or just a commit hash |
| 1964 | if git branch -r | grep -q -F -w "origin/$GIT_REV"; then |
| 1965 | GIT_REV="origin/$GIT_REV" |
| 1966 | fi |
| 1967 | fi |
| 1968 | |
| 1969 | echodebug "Checking out $GIT_REV" |
| 1970 | git checkout "$GIT_REV" || return 1 |
| 1971 | fi |
| 1972 | |
| 1973 | fi |
| 1974 | |
| 1975 | echoinfo "Cloning Salt's git repository succeeded" |
| 1976 | return 0 |
| 1977 | } |
| 1978 | |
| 1979 | |
| 1980 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 1981 | # NAME: __copyfile |
| 1982 | # DESCRIPTION: Simple function to copy files. Overrides if asked. |
| 1983 | #---------------------------------------------------------------------------------------------------------------------- |
| 1984 | __copyfile() { |
| 1985 | overwrite=$_FORCE_OVERWRITE |
| 1986 | if [ $# -eq 2 ]; then |
| 1987 | sfile=$1 |
| 1988 | dfile=$2 |
| 1989 | elif [ $# -eq 3 ]; then |
| 1990 | sfile=$1 |
| 1991 | dfile=$2 |
| 1992 | overwrite=$3 |
| 1993 | else |
| 1994 | echoerror "Wrong number of arguments for __copyfile()" |
| 1995 | echoinfo "USAGE: __copyfile <source> <dest> OR __copyfile <source> <dest> <overwrite>" |
| 1996 | exit 1 |
| 1997 | fi |
| 1998 | |
| 1999 | # Does the source file exist? |
| 2000 | if [ ! -f "$sfile" ]; then |
| 2001 | echowarn "$sfile does not exist!" |
| 2002 | return 1 |
| 2003 | fi |
| 2004 | |
| 2005 | # If the destination is a directory, let's make it a full path so the logic |
| 2006 | # below works as expected |
| 2007 | if [ -d "$dfile" ]; then |
| 2008 | echodebug "The passed destination ($dfile) is a directory" |
| 2009 | dfile="${dfile}/$(basename "$sfile")" |
| 2010 | echodebug "Full destination path is now: $dfile" |
| 2011 | fi |
| 2012 | |
| 2013 | if [ ! -f "$dfile" ]; then |
| 2014 | # The destination file does not exist, copy |
| 2015 | echodebug "Copying $sfile to $dfile" |
| 2016 | cp "$sfile" "$dfile" || return 1 |
| 2017 | elif [ -f "$dfile" ] && [ "$overwrite" -eq $BS_TRUE ]; then |
| 2018 | # The destination exist and we're overwriting |
| 2019 | echodebug "Overwriting $dfile with $sfile" |
| 2020 | cp -f "$sfile" "$dfile" || return 1 |
| 2021 | elif [ -f "$dfile" ] && [ "$overwrite" -ne $BS_TRUE ]; then |
| 2022 | echodebug "Not overwriting $dfile with $sfile" |
| 2023 | fi |
| 2024 | return 0 |
| 2025 | } |
| 2026 | |
| 2027 | |
| 2028 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 2029 | # NAME: __movefile |
| 2030 | # DESCRIPTION: Simple function to move files. Overrides if asked. |
| 2031 | #---------------------------------------------------------------------------------------------------------------------- |
| 2032 | __movefile() { |
| 2033 | overwrite=$_FORCE_OVERWRITE |
| 2034 | if [ $# -eq 2 ]; then |
| 2035 | sfile=$1 |
| 2036 | dfile=$2 |
| 2037 | elif [ $# -eq 3 ]; then |
| 2038 | sfile=$1 |
| 2039 | dfile=$2 |
| 2040 | overwrite=$3 |
| 2041 | else |
| 2042 | echoerror "Wrong number of arguments for __movefile()" |
| 2043 | echoinfo "USAGE: __movefile <source> <dest> OR __movefile <source> <dest> <overwrite>" |
| 2044 | exit 1 |
| 2045 | fi |
| 2046 | |
| 2047 | if [ $_KEEP_TEMP_FILES -eq $BS_TRUE ]; then |
| 2048 | # We're being told not to move files, instead copy them so we can keep |
| 2049 | # them around |
| 2050 | echodebug "Since BS_KEEP_TEMP_FILES=1 we're copying files instead of moving them" |
| 2051 | __copyfile "$sfile" "$dfile" "$overwrite" |
| 2052 | return $? |
| 2053 | fi |
| 2054 | |
| 2055 | # Does the source file exist? |
| 2056 | if [ ! -f "$sfile" ]; then |
| 2057 | echowarn "$sfile does not exist!" |
| 2058 | return 1 |
| 2059 | fi |
| 2060 | |
| 2061 | # If the destination is a directory, let's make it a full path so the logic |
| 2062 | # below works as expected |
| 2063 | if [ -d "$dfile" ]; then |
| 2064 | echodebug "The passed destination($dfile) is a directory" |
| 2065 | dfile="${dfile}/$(basename "$sfile")" |
| 2066 | echodebug "Full destination path is now: $dfile" |
| 2067 | fi |
| 2068 | |
| 2069 | if [ ! -f "$dfile" ]; then |
| 2070 | # The destination file does not exist, move |
| 2071 | echodebug "Moving $sfile to $dfile" |
| 2072 | mv "$sfile" "$dfile" || return 1 |
| 2073 | elif [ -f "$dfile" ] && [ "$overwrite" -eq $BS_TRUE ]; then |
| 2074 | # The destination exist and we're overwriting |
| 2075 | echodebug "Overriding $dfile with $sfile" |
| 2076 | mv -f "$sfile" "$dfile" || return 1 |
| 2077 | elif [ -f "$dfile" ] && [ "$overwrite" -ne $BS_TRUE ]; then |
| 2078 | echodebug "Not overriding $dfile with $sfile" |
| 2079 | fi |
| 2080 | |
| 2081 | return 0 |
| 2082 | } |
| 2083 | |
| 2084 | |
| 2085 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 2086 | # NAME: __linkfile |
| 2087 | # DESCRIPTION: Simple function to create symlinks. Overrides if asked. Accepts globs. |
| 2088 | #---------------------------------------------------------------------------------------------------------------------- |
| 2089 | __linkfile() { |
| 2090 | overwrite=$_FORCE_OVERWRITE |
| 2091 | if [ $# -eq 2 ]; then |
| 2092 | target=$1 |
| 2093 | linkname=$2 |
| 2094 | elif [ $# -eq 3 ]; then |
| 2095 | target=$1 |
| 2096 | linkname=$2 |
| 2097 | overwrite=$3 |
| 2098 | else |
| 2099 | echoerror "Wrong number of arguments for __linkfile()" |
| 2100 | echoinfo "USAGE: __linkfile <target> <link> OR __linkfile <tagret> <link> <overwrite>" |
| 2101 | exit 1 |
| 2102 | fi |
| 2103 | |
| 2104 | for sfile in $target; do |
| 2105 | # Does the source file exist? |
| 2106 | if [ ! -f "$sfile" ]; then |
| 2107 | echowarn "$sfile does not exist!" |
| 2108 | return 1 |
| 2109 | fi |
| 2110 | |
| 2111 | # If the destination is a directory, let's make it a full path so the logic |
| 2112 | # below works as expected |
| 2113 | if [ -d "$linkname" ]; then |
| 2114 | echodebug "The passed link name ($linkname) is a directory" |
| 2115 | linkname="${linkname}/$(basename "$sfile")" |
| 2116 | echodebug "Full destination path is now: $linkname" |
| 2117 | fi |
| 2118 | |
| 2119 | if [ ! -e "$linkname" ]; then |
| 2120 | # The destination file does not exist, create link |
| 2121 | echodebug "Creating $linkname symlink pointing to $sfile" |
| 2122 | ln -s "$sfile" "$linkname" || return 1 |
| 2123 | elif [ -e "$linkname" ] && [ "$overwrite" -eq $BS_TRUE ]; then |
| 2124 | # The destination exist and we're overwriting |
| 2125 | echodebug "Overwriting $linkname symlink to point on $sfile" |
| 2126 | ln -sf "$sfile" "$linkname" || return 1 |
| 2127 | elif [ -e "$linkname" ] && [ "$overwrite" -ne $BS_TRUE ]; then |
| 2128 | echodebug "Not overwriting $linkname symlink to point on $sfile" |
| 2129 | fi |
| 2130 | done |
| 2131 | |
| 2132 | return 0 |
| 2133 | } |
| 2134 | |
| 2135 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 2136 | # NAME: __overwriteconfig() |
| 2137 | # DESCRIPTION: Simple function to overwrite master or minion config files. |
| 2138 | #---------------------------------------------------------------------------------------------------------------------- |
| 2139 | __overwriteconfig() { |
| 2140 | if [ $# -eq 2 ]; then |
| 2141 | target=$1 |
| 2142 | json=$2 |
| 2143 | else |
| 2144 | echoerror "Wrong number of arguments for __convert_json_to_yaml_str()" |
| 2145 | echoinfo "USAGE: __convert_json_to_yaml_str <configfile> <jsonstring>" |
| 2146 | exit 1 |
| 2147 | fi |
| 2148 | |
| 2149 | # Make a tempfile to dump any python errors into. |
| 2150 | if __check_command_exists mktemp; then |
| 2151 | tempfile="$(mktemp /tmp/salt-config-XXXXXXXX 2>/dev/null)" |
| 2152 | |
| 2153 | if [ -z "$tempfile" ]; then |
| 2154 | echoerror "Failed to create temporary file in /tmp" |
| 2155 | return 1 |
| 2156 | fi |
| 2157 | else |
| 2158 | tempfile="/tmp/salt-config-$$" |
| 2159 | fi |
| 2160 | |
| 2161 | # If python does not have yaml installed we're on Arch and should use python2 |
| 2162 | if python -c "import yaml" 2> /dev/null; then |
| 2163 | good_python=python |
| 2164 | else |
| 2165 | good_python=python2 |
| 2166 | fi |
| 2167 | |
| 2168 | # Convert json string to a yaml string and write it to config file. Output is dumped into tempfile. |
| 2169 | $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 |
| 2170 | |
| 2171 | # No python errors output to the tempfile |
| 2172 | if [ ! -s "$tempfile" ]; then |
| 2173 | rm -f "$tempfile" |
| 2174 | return 0 |
| 2175 | fi |
| 2176 | |
| 2177 | # Errors are present in the tempfile - let's expose them to the user. |
| 2178 | fullerror=$(cat "$tempfile") |
| 2179 | echodebug "$fullerror" |
| 2180 | echoerror "Python error encountered. This is likely due to passing in a malformed JSON string. Please use -D to see stacktrace." |
| 2181 | |
| 2182 | rm -f "$tempfile" |
| 2183 | |
| 2184 | return 1 |
| 2185 | |
| 2186 | } |
| 2187 | |
| 2188 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 2189 | # NAME: __check_services_systemd |
| 2190 | # DESCRIPTION: Return 0 or 1 in case the service is enabled or not |
| 2191 | # PARAMETERS: servicename |
| 2192 | #---------------------------------------------------------------------------------------------------------------------- |
| 2193 | __check_services_systemd() { |
| 2194 | if [ $# -eq 0 ]; then |
| 2195 | echoerror "You need to pass a service name to check!" |
| 2196 | exit 1 |
| 2197 | elif [ $# -ne 1 ]; then |
| 2198 | echoerror "You need to pass a service name to check as the single argument to the function" |
| 2199 | fi |
| 2200 | |
| 2201 | servicename=$1 |
| 2202 | echodebug "Checking if service ${servicename} is enabled" |
| 2203 | |
| 2204 | if [ "$(systemctl is-enabled "${servicename}")" = "enabled" ]; then |
| 2205 | echodebug "Service ${servicename} is enabled" |
| 2206 | return 0 |
| 2207 | else |
| 2208 | echodebug "Service ${servicename} is NOT enabled" |
| 2209 | return 1 |
| 2210 | fi |
| 2211 | } # ---------- end of function __check_services_systemd ---------- |
| 2212 | |
| 2213 | |
| 2214 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 2215 | # NAME: __check_services_upstart |
| 2216 | # DESCRIPTION: Return 0 or 1 in case the service is enabled or not |
| 2217 | # PARAMETERS: servicename |
| 2218 | #---------------------------------------------------------------------------------------------------------------------- |
| 2219 | __check_services_upstart() { |
| 2220 | if [ $# -eq 0 ]; then |
| 2221 | echoerror "You need to pass a service name to check!" |
| 2222 | exit 1 |
| 2223 | elif [ $# -ne 1 ]; then |
| 2224 | echoerror "You need to pass a service name to check as the single argument to the function" |
| 2225 | fi |
| 2226 | |
| 2227 | servicename=$1 |
| 2228 | echodebug "Checking if service ${servicename} is enabled" |
| 2229 | |
| 2230 | # Check if service is enabled to start at boot |
| 2231 | initctl list | grep "${servicename}" > /dev/null 2>&1 |
| 2232 | |
| 2233 | if [ $? -eq 0 ]; then |
| 2234 | echodebug "Service ${servicename} is enabled" |
| 2235 | return 0 |
| 2236 | else |
| 2237 | echodebug "Service ${servicename} is NOT enabled" |
| 2238 | return 1 |
| 2239 | fi |
| 2240 | } # ---------- end of function __check_services_upstart ---------- |
| 2241 | |
| 2242 | |
| 2243 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 2244 | # NAME: __check_services_sysvinit |
| 2245 | # DESCRIPTION: Return 0 or 1 in case the service is enabled or not |
| 2246 | # PARAMETERS: servicename |
| 2247 | #---------------------------------------------------------------------------------------------------------------------- |
| 2248 | __check_services_sysvinit() { |
| 2249 | if [ $# -eq 0 ]; then |
| 2250 | echoerror "You need to pass a service name to check!" |
| 2251 | exit 1 |
| 2252 | elif [ $# -ne 1 ]; then |
| 2253 | echoerror "You need to pass a service name to check as the single argument to the function" |
| 2254 | fi |
| 2255 | |
| 2256 | servicename=$1 |
| 2257 | echodebug "Checking if service ${servicename} is enabled" |
| 2258 | |
| 2259 | if [ "$(LC_ALL=C /sbin/chkconfig --list | grep "\<${servicename}\>" | grep '[2-5]:on')" != "" ]; then |
| 2260 | echodebug "Service ${servicename} is enabled" |
| 2261 | return 0 |
| 2262 | else |
| 2263 | echodebug "Service ${servicename} is NOT enabled" |
| 2264 | return 1 |
| 2265 | fi |
| 2266 | } # ---------- end of function __check_services_sysvinit ---------- |
| 2267 | |
| 2268 | |
| 2269 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 2270 | # NAME: __check_services_debian |
| 2271 | # DESCRIPTION: Return 0 or 1 in case the service is enabled or not |
| 2272 | # PARAMETERS: servicename |
| 2273 | #---------------------------------------------------------------------------------------------------------------------- |
| 2274 | __check_services_debian() { |
| 2275 | if [ $# -eq 0 ]; then |
| 2276 | echoerror "You need to pass a service name to check!" |
| 2277 | exit 1 |
| 2278 | elif [ $# -ne 1 ]; then |
| 2279 | echoerror "You need to pass a service name to check as the single argument to the function" |
| 2280 | fi |
| 2281 | |
| 2282 | servicename=$1 |
| 2283 | echodebug "Checking if service ${servicename} is enabled" |
| 2284 | |
| 2285 | # Check if the service is going to be started at any runlevel, fixes bootstrap in container (Docker, LXC) |
| 2286 | if ls /etc/rc?.d/S*"${servicename}" >/dev/null 2>&1; then |
| 2287 | echodebug "Service ${servicename} is enabled" |
| 2288 | return 0 |
| 2289 | else |
| 2290 | echodebug "Service ${servicename} is NOT enabled" |
| 2291 | return 1 |
| 2292 | fi |
| 2293 | } # ---------- end of function __check_services_debian ---------- |
| 2294 | |
| 2295 | |
| 2296 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 2297 | # NAME: __check_services_openbsd |
| 2298 | # DESCRIPTION: Return 0 or 1 in case the service is enabled or not |
| 2299 | # PARAMETERS: servicename |
| 2300 | #---------------------------------------------------------------------------------------------------------------------- |
| 2301 | __check_services_openbsd() { |
| 2302 | if [ $# -eq 0 ]; then |
| 2303 | echoerror "You need to pass a service name to check!" |
| 2304 | exit 1 |
| 2305 | elif [ $# -ne 1 ]; then |
| 2306 | echoerror "You need to pass a service name to check as the single argument to the function" |
| 2307 | fi |
| 2308 | |
| 2309 | servicename=$1 |
| 2310 | echodebug "Checking if service ${servicename} is enabled" |
| 2311 | |
| 2312 | # shellcheck disable=SC2086,SC2046,SC2144 |
| 2313 | if rcctl get ${servicename} status; then |
| 2314 | echodebug "Service ${servicename} is enabled" |
| 2315 | return 0 |
| 2316 | else |
| 2317 | echodebug "Service ${servicename} is NOT enabled" |
| 2318 | return 1 |
| 2319 | fi |
| 2320 | } # ---------- end of function __check_services_openbsd ---------- |
| 2321 | |
| 2322 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 2323 | # NAME: __check_services_alpine |
| 2324 | # DESCRIPTION: Return 0 or 1 in case the service is enabled or not |
| 2325 | # PARAMETERS: servicename |
| 2326 | #---------------------------------------------------------------------------------------------------------------------- |
| 2327 | __check_services_alpine() { |
| 2328 | if [ $# -eq 0 ]; then |
| 2329 | echoerror "You need to pass a service name to check!" |
| 2330 | exit 1 |
| 2331 | elif [ $# -ne 1 ]; then |
| 2332 | echoerror "You need to pass a service name to check as the single argument to the function" |
| 2333 | fi |
| 2334 | |
| 2335 | servicename=$1 |
| 2336 | echodebug "Checking if service ${servicename} is enabled" |
| 2337 | |
| 2338 | # shellcheck disable=SC2086,SC2046,SC2144 |
| 2339 | if rc-status $(rc-status -r) | tail -n +2 | grep -q "\<$servicename\>"; then |
| 2340 | echodebug "Service ${servicename} is enabled" |
| 2341 | return 0 |
| 2342 | else |
| 2343 | echodebug "Service ${servicename} is NOT enabled" |
| 2344 | return 1 |
| 2345 | fi |
| 2346 | } # ---------- end of function __check_services_openbsd ---------- |
| 2347 | |
| 2348 | |
| 2349 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 2350 | # NAME: __create_virtualenv |
| 2351 | # DESCRIPTION: Return 0 or 1 depending on successful creation of virtualenv |
| 2352 | #---------------------------------------------------------------------------------------------------------------------- |
| 2353 | __create_virtualenv() { |
| 2354 | if [ ! -d "$_VIRTUALENV_DIR" ]; then |
| 2355 | echoinfo "Creating virtualenv ${_VIRTUALENV_DIR}" |
| 2356 | if [ $_PIP_ALL -eq $BS_TRUE ]; then |
| 2357 | virtualenv --no-site-packages "${_VIRTUALENV_DIR}" || return 1 |
| 2358 | else |
| 2359 | virtualenv --system-site-packages "${_VIRTUALENV_DIR}" || return 1 |
| 2360 | fi |
| 2361 | fi |
| 2362 | return 0 |
| 2363 | } # ---------- end of function __create_virtualenv ---------- |
| 2364 | |
| 2365 | |
| 2366 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 2367 | # NAME: __activate_virtualenv |
| 2368 | # DESCRIPTION: Return 0 or 1 depending on successful activation of virtualenv |
| 2369 | #---------------------------------------------------------------------------------------------------------------------- |
| 2370 | __activate_virtualenv() { |
| 2371 | set +o nounset |
| 2372 | # Is virtualenv empty |
| 2373 | if [ -z "$VIRTUAL_ENV" ]; then |
| 2374 | __create_virtualenv || return 1 |
| 2375 | # shellcheck source=/dev/null |
| 2376 | . "${_VIRTUALENV_DIR}/bin/activate" || return 1 |
| 2377 | echoinfo "Activated virtualenv ${_VIRTUALENV_DIR}" |
| 2378 | fi |
| 2379 | set -o nounset |
| 2380 | return 0 |
| 2381 | } # ---------- end of function __activate_virtualenv ---------- |
| 2382 | |
| 2383 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 2384 | # NAME: __install_pip_pkgs |
| 2385 | # DESCRIPTION: Return 0 or 1 if successfully able to install pip packages. Can provide a different python version to |
| 2386 | # install pip packages with. If $py_ver is not specified it will use the default python version. |
| 2387 | # PARAMETERS: pkgs, py_ver |
| 2388 | #---------------------------------------------------------------------------------------------------------------------- |
| 2389 | |
| 2390 | __install_pip_pkgs() { |
| 2391 | _pip_pkgs="$1" |
| 2392 | _py_exe="$2" |
| 2393 | _py_pkg=$(echo "$_py_exe" | sed -r "s/\.//g") |
| 2394 | _pip_cmd="${_py_exe} -m pip" |
| 2395 | |
| 2396 | if [ "${_py_exe}" = "" ]; then |
| 2397 | _py_exe='python' |
| 2398 | fi |
| 2399 | |
| 2400 | __check_pip_allowed |
| 2401 | |
| 2402 | # Install pip and pip dependencies |
| 2403 | if ! __check_command_exists "${_pip_cmd} --version"; then |
| 2404 | __PACKAGES="${_py_pkg}-setuptools ${_py_pkg}-pip gcc ${_py_pkg}-devel" |
| 2405 | # shellcheck disable=SC2086 |
| 2406 | __yum_install_noinput ${__PACKAGES} || return 1 |
| 2407 | fi |
| 2408 | |
| 2409 | echoinfo "Installing pip packages: ${_pip_pkgs} using ${_py_exe}" |
| 2410 | # shellcheck disable=SC2086 |
| 2411 | ${_pip_cmd} install ${_pip_pkgs} || return 1 |
| 2412 | } |
| 2413 | |
| 2414 | #--- FUNCTION ------------------------------------------------------------------------------------------------------- |
| 2415 | # NAME: __install_pip_deps |
| 2416 | # DESCRIPTION: Return 0 or 1 if successfully able to install pip packages via requirements file |
| 2417 | # PARAMETERS: requirements_file |
| 2418 | #---------------------------------------------------------------------------------------------------------------------- |
| 2419 | __install_pip_deps() { |
| 2420 | # Install virtualenv to system pip before activating virtualenv if thats going to be used |
| 2421 | # We assume pip pkg is installed since that is distro specific |
| 2422 | if [ "$_VIRTUALENV_DIR" != "null" ]; then |
| 2423 | if ! __check_command_exists pip; then |
| 2424 | echoerror "Pip not installed: required for -a installs" |
| 2425 | exit 1 |
| 2426 | fi |
| 2427 | pip install -U virtualenv |
| 2428 | __activate_virtualenv || return 1 |
| 2429 | else |
| 2430 | echoerror "Must have virtualenv dir specified for -a installs" |
| 2431 | fi |
| 2432 | |
| 2433 | requirements_file=$1 |
| 2434 | if [ ! -f "${requirements_file}" ]; then |
| 2435 | echoerror "Requirements file: ${requirements_file} cannot be found, needed for -a (pip pkg) installs" |
| 2436 | exit 1 |
| 2437 | fi |
| 2438 | |
| 2439 | __PIP_PACKAGES='' |
| 2440 | if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then |
| 2441 | # shellcheck disable=SC2089 |
| 2442 | __PIP_PACKAGES="${__PIP_PACKAGES} 'apache-libcloud>=$_LIBCLOUD_MIN_VERSION'" |
| 2443 | fi |
| 2444 | |
| 2445 | # shellcheck disable=SC2086,SC2090 |
| 2446 | pip install -U -r ${requirements_file} ${__PIP_PACKAGES} |
| 2447 | } # ---------- end of function __install_pip_deps ---------- |
| 2448 | |
| 2449 | |
| 2450 | ####################################################################################################################### |
| 2451 | # |
| 2452 | # Distribution install functions |
| 2453 | # |
| 2454 | # In order to install salt for a distribution you need to define: |
| 2455 | # |
| 2456 | # To Install Dependencies, which is required, one of: |
| 2457 | # 1. install_<distro>_<major_version>_<install_type>_deps |
| 2458 | # 2. install_<distro>_<major_version>_<minor_version>_<install_type>_deps |
| 2459 | # 3. install_<distro>_<major_version>_deps |
| 2460 | # 4 install_<distro>_<major_version>_<minor_version>_deps |
| 2461 | # 5. install_<distro>_<install_type>_deps |
| 2462 | # 6. install_<distro>_deps |
| 2463 | # |
| 2464 | # Optionally, define a salt configuration function, which will be called if |
| 2465 | # the -c (config-dir) option is passed. One of: |
| 2466 | # 1. config_<distro>_<major_version>_<install_type>_salt |
| 2467 | # 2. config_<distro>_<major_version>_<minor_version>_<install_type>_salt |
| 2468 | # 3. config_<distro>_<major_version>_salt |
| 2469 | # 4 config_<distro>_<major_version>_<minor_version>_salt |
| 2470 | # 5. config_<distro>_<install_type>_salt |
| 2471 | # 6. config_<distro>_salt |
| 2472 | # 7. config_salt [THIS ONE IS ALREADY DEFINED AS THE DEFAULT] |
| 2473 | # |
| 2474 | # Optionally, define a salt master pre-seed function, which will be called if |
| 2475 | # the -k (pre-seed master keys) option is passed. One of: |
| 2476 | # 1. preseed_<distro>_<major_version>_<install_type>_master |
| 2477 | # 2. preseed_<distro>_<major_version>_<minor_version>_<install_type>_master |
| 2478 | # 3. preseed_<distro>_<major_version>_master |
| 2479 | # 4 preseed_<distro>_<major_version>_<minor_version>_master |
| 2480 | # 5. preseed_<distro>_<install_type>_master |
| 2481 | # 6. preseed_<distro>_master |
| 2482 | # 7. preseed_master [THIS ONE IS ALREADY DEFINED AS THE DEFAULT] |
| 2483 | # |
| 2484 | # To install salt, which, of course, is required, one of: |
| 2485 | # 1. install_<distro>_<major_version>_<install_type> |
| 2486 | # 2. install_<distro>_<major_version>_<minor_version>_<install_type> |
| 2487 | # 3. install_<distro>_<install_type> |
| 2488 | # |
| 2489 | # Optionally, define a post install function, one of: |
| 2490 | # 1. install_<distro>_<major_version>_<install_type>_post |
| 2491 | # 2. install_<distro>_<major_version>_<minor_version>_<install_type>_post |
| 2492 | # 3. install_<distro>_<major_version>_post |
| 2493 | # 4 install_<distro>_<major_version>_<minor_version>_post |
| 2494 | # 5. install_<distro>_<install_type>_post |
| 2495 | # 6. install_<distro>_post |
| 2496 | # |
| 2497 | # Optionally, define a start daemons function, one of: |
| 2498 | # 1. install_<distro>_<major_version>_<install_type>_restart_daemons |
| 2499 | # 2. install_<distro>_<major_version>_<minor_version>_<install_type>_restart_daemons |
| 2500 | # 3. install_<distro>_<major_version>_restart_daemons |
| 2501 | # 4 install_<distro>_<major_version>_<minor_version>_restart_daemons |
| 2502 | # 5. install_<distro>_<install_type>_restart_daemons |
| 2503 | # 6. install_<distro>_restart_daemons |
| 2504 | # |
| 2505 | # NOTE: The start daemons function should be able to restart any daemons |
| 2506 | # which are running, or start if they're not running. |
| 2507 | # |
| 2508 | # Optionally, define a daemons running function, one of: |
| 2509 | # 1. daemons_running_<distro>_<major_version>_<install_type> |
| 2510 | # 2. daemons_running_<distro>_<major_version>_<minor_version>_<install_type> |
| 2511 | # 3. daemons_running_<distro>_<major_version> |
| 2512 | # 4 daemons_running_<distro>_<major_version>_<minor_version> |
| 2513 | # 5. daemons_running_<distro>_<install_type> |
| 2514 | # 6. daemons_running_<distro> |
| 2515 | # 7. daemons_running [THIS ONE IS ALREADY DEFINED AS THE DEFAULT] |
| 2516 | # |
| 2517 | # Optionally, check enabled Services: |
| 2518 | # 1. install_<distro>_<major_version>_<install_type>_check_services |
| 2519 | # 2. install_<distro>_<major_version>_<minor_version>_<install_type>_check_services |
| 2520 | # 3. install_<distro>_<major_version>_check_services |
| 2521 | # 4 install_<distro>_<major_version>_<minor_version>_check_services |
| 2522 | # 5. install_<distro>_<install_type>_check_services |
| 2523 | # 6. install_<distro>_check_services |
| 2524 | # |
| 2525 | ####################################################################################################################### |
| 2526 | |
| 2527 | |
| 2528 | ####################################################################################################################### |
| 2529 | # |
| 2530 | # Ubuntu Install Functions |
| 2531 | # |
| 2532 | __enable_universe_repository() { |
| 2533 | if [ "$(grep -R universe /etc/apt/sources.list /etc/apt/sources.list.d/ | grep -v '#')" != "" ]; then |
| 2534 | # The universe repository is already enabled |
| 2535 | return 0 |
| 2536 | fi |
| 2537 | |
| 2538 | echodebug "Enabling the universe repository" |
| 2539 | |
| 2540 | add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) universe" || return 1 |
| 2541 | |
| 2542 | return 0 |
| 2543 | } |
| 2544 | |
| 2545 | __install_saltstack_ubuntu_repository() { |
| 2546 | # Workaround for latest non-LTS ubuntu |
| 2547 | if [ "$DISTRO_VERSION" = "16.10" ] || [ "$DISTRO_MAJOR_VERSION" -gt 16 ]; then |
| 2548 | echowarn "Non-LTS Ubuntu detected, but stable packages requested. Trying packages from latest LTS release. You may experience problems." |
| 2549 | UBUNTU_VERSION=16.04 |
| 2550 | UBUNTU_CODENAME="xenial" |
| 2551 | else |
| 2552 | UBUNTU_VERSION=$DISTRO_VERSION |
| 2553 | UBUNTU_CODENAME=$DISTRO_CODENAME |
| 2554 | fi |
| 2555 | |
| 2556 | __PACKAGES='' |
| 2557 | |
| 2558 | # Install downloader backend for GPG keys fetching |
| 2559 | if [ "$DISTRO_VERSION" = "16.10" ] || [ "$DISTRO_MAJOR_VERSION" -gt 16 ]; then |
| 2560 | __PACKAGES="${__PACKAGES} gnupg2 dirmngr" |
| 2561 | else |
| 2562 | __PACKAGES="${__PACKAGES} gnupg-curl" |
| 2563 | fi |
| 2564 | |
| 2565 | # Make sure https transport is available |
| 2566 | if [ "$HTTP_VAL" = "https" ] ; then |
| 2567 | __PACKAGES="${__PACKAGES} apt-transport-https ca-certificates" |
| 2568 | fi |
| 2569 | |
| 2570 | # shellcheck disable=SC2086,SC2090 |
| 2571 | __apt_get_install_noinput ${__PACKAGES} || return 1 |
| 2572 | |
| 2573 | # SaltStack's stable Ubuntu repository: |
| 2574 | SALTSTACK_UBUNTU_URL="${HTTP_VAL}://${_REPO_URL}/apt/ubuntu/${UBUNTU_VERSION}/${__REPO_ARCH}/${STABLE_REV}" |
| 2575 | echo "deb $SALTSTACK_UBUNTU_URL $UBUNTU_CODENAME main" > /etc/apt/sources.list.d/saltstack.list |
| 2576 | |
| 2577 | __apt_key_fetch "$SALTSTACK_UBUNTU_URL/SALTSTACK-GPG-KEY.pub" || return 1 |
| 2578 | |
| 2579 | apt-get update |
| 2580 | } |
| 2581 | |
| 2582 | install_ubuntu_deps() { |
| 2583 | if [ $_DISABLE_REPOS -eq $BS_FALSE ]; then |
| 2584 | # Install add-apt-repository |
| 2585 | if ! __check_command_exists add-apt-repository; then |
| 2586 | __apt_get_install_noinput software-properties-common || return 1 |
| 2587 | fi |
| 2588 | |
| 2589 | __enable_universe_repository || return 1 |
| 2590 | |
| 2591 | apt-get update |
| 2592 | fi |
| 2593 | |
| 2594 | __PACKAGES='' |
| 2595 | |
| 2596 | if [ "$DISTRO_MAJOR_VERSION" -lt 16 ]; then |
| 2597 | # Minimal systems might not have upstart installed, install it |
| 2598 | __PACKAGES="upstart" |
| 2599 | fi |
| 2600 | |
| 2601 | if [ "$DISTRO_MAJOR_VERSION" -ge 16 ]; then |
| 2602 | __PACKAGES="${__PACKAGES} python2.7" |
| 2603 | fi |
| 2604 | |
| 2605 | if [ "$_VIRTUALENV_DIR" != "null" ]; then |
| 2606 | __PACKAGES="${__PACKAGES} python-virtualenv" |
| 2607 | fi |
| 2608 | # Need python-apt for managing packages via Salt |
| 2609 | __PACKAGES="${__PACKAGES} python-apt" |
| 2610 | |
| 2611 | # requests is still used by many salt modules |
| 2612 | __PACKAGES="${__PACKAGES} python-requests" |
| 2613 | |
| 2614 | # YAML module is used for generating custom master/minion configs |
| 2615 | __PACKAGES="${__PACKAGES} python-yaml" |
| 2616 | |
| 2617 | # Additionally install procps and pciutils which allows for Docker bootstraps. See 366#issuecomment-39666813 |
| 2618 | __PACKAGES="${__PACKAGES} procps pciutils" |
| 2619 | |
| 2620 | # shellcheck disable=SC2086,SC2090 |
| 2621 | __apt_get_install_noinput ${__PACKAGES} || return 1 |
| 2622 | |
| 2623 | if [ "${_EXTRA_PACKAGES}" != "" ]; then |
| 2624 | echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" |
| 2625 | # shellcheck disable=SC2086 |
| 2626 | __apt_get_install_noinput ${_EXTRA_PACKAGES} || return 1 |
| 2627 | fi |
| 2628 | |
| 2629 | return 0 |
| 2630 | } |
| 2631 | |
| 2632 | install_ubuntu_stable_deps() { |
| 2633 | if [ "${_SLEEP}" -eq "${__DEFAULT_SLEEP}" ] && [ "$DISTRO_MAJOR_VERSION" -lt 16 ]; then |
| 2634 | # The user did not pass a custom sleep value as an argument, let's increase the default value |
| 2635 | echodebug "On Ubuntu systems we increase the default sleep value to 10." |
| 2636 | echodebug "See https://github.com/saltstack/salt/issues/12248 for more info." |
| 2637 | _SLEEP=10 |
| 2638 | fi |
| 2639 | |
| 2640 | if [ $_START_DAEMONS -eq $BS_FALSE ]; then |
| 2641 | echowarn "Not starting daemons on Debian based distributions is not working mostly because starting them is the default behaviour." |
| 2642 | fi |
| 2643 | |
| 2644 | # No user interaction, libc6 restart services for example |
| 2645 | export DEBIAN_FRONTEND=noninteractive |
| 2646 | |
| 2647 | apt-get update |
| 2648 | |
| 2649 | if [ "${_UPGRADE_SYS}" -eq $BS_TRUE ]; then |
| 2650 | if [ "${_INSECURE_DL}" -eq $BS_TRUE ]; then |
| 2651 | __apt_get_install_noinput --allow-unauthenticated debian-archive-keyring && |
| 2652 | apt-key update && apt-get update |
| 2653 | fi |
| 2654 | |
| 2655 | __apt_get_upgrade_noinput || return 1 |
| 2656 | fi |
| 2657 | |
| 2658 | if [ "$_DISABLE_REPOS" -eq "$BS_FALSE" ] || [ "$_CUSTOM_REPO_URL" != "null" ]; then |
| 2659 | __check_dpkg_architecture || return 1 |
| 2660 | __install_saltstack_ubuntu_repository || return 1 |
| 2661 | fi |
| 2662 | |
| 2663 | install_ubuntu_deps || return 1 |
| 2664 | } |
| 2665 | |
| 2666 | install_ubuntu_daily_deps() { |
| 2667 | install_ubuntu_stable_deps || return 1 |
| 2668 | |
| 2669 | if [ $_DISABLE_REPOS -eq $BS_FALSE ]; then |
| 2670 | __enable_universe_repository || return 1 |
| 2671 | |
| 2672 | add-apt-repository -y ppa:saltstack/salt-daily || return 1 |
| 2673 | apt-get update |
| 2674 | fi |
| 2675 | |
| 2676 | if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then |
| 2677 | __apt_get_upgrade_noinput || return 1 |
| 2678 | fi |
| 2679 | |
| 2680 | return 0 |
| 2681 | } |
| 2682 | |
| 2683 | install_ubuntu_git_deps() { |
| 2684 | apt-get update |
| 2685 | |
| 2686 | if ! __check_command_exists git; then |
| 2687 | __apt_get_install_noinput git-core || return 1 |
| 2688 | fi |
| 2689 | |
| 2690 | if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then |
| 2691 | __apt_get_install_noinput ca-certificates |
| 2692 | fi |
| 2693 | |
| 2694 | __git_clone_and_checkout || return 1 |
| 2695 | |
| 2696 | __PACKAGES="" |
| 2697 | |
| 2698 | # See how we are installing packages |
| 2699 | if [ "${_PIP_ALL}" -eq $BS_TRUE ]; then |
| 2700 | __PACKAGES="${__PACKAGES} python-dev swig libssl-dev libzmq3 libzmq3-dev" |
| 2701 | |
| 2702 | if ! __check_command_exists pip; then |
| 2703 | __PACKAGES="${__PACKAGES} python-setuptools python-pip" |
| 2704 | fi |
| 2705 | |
| 2706 | # Get just the apt packages that are required to build all the pythons |
| 2707 | # shellcheck disable=SC2086 |
| 2708 | __apt_get_install_noinput ${__PACKAGES} || return 1 |
| 2709 | # Install the pythons from requirements (only zmq for now) |
| 2710 | __install_pip_deps "${_SALT_GIT_CHECKOUT_DIR}/requirements/zeromq.txt" || return 1 |
| 2711 | else |
| 2712 | install_ubuntu_stable_deps || return 1 |
| 2713 | |
| 2714 | __PACKAGES="${__PACKAGES} python-crypto python-jinja2 python-msgpack python-requests" |
| 2715 | __PACKAGES="${__PACKAGES} python-tornado python-yaml python-zmq" |
| 2716 | |
| 2717 | if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then |
| 2718 | # Install python-libcloud if asked to |
| 2719 | __PACKAGES="${__PACKAGES} python-libcloud" |
| 2720 | fi |
| 2721 | |
| 2722 | # shellcheck disable=SC2086 |
| 2723 | __apt_get_install_noinput ${__PACKAGES} || return 1 |
| 2724 | fi |
| 2725 | |
| 2726 | # Let's trigger config_salt() |
| 2727 | if [ "$_TEMP_CONFIG_DIR" = "null" ]; then |
| 2728 | _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" |
| 2729 | CONFIG_SALT_FUNC="config_salt" |
| 2730 | fi |
| 2731 | |
| 2732 | return 0 |
| 2733 | } |
| 2734 | |
| 2735 | install_ubuntu_stable() { |
| 2736 | __PACKAGES="" |
| 2737 | |
| 2738 | if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ];then |
| 2739 | __PACKAGES="${__PACKAGES} salt-cloud" |
| 2740 | fi |
| 2741 | if [ "$_INSTALL_MASTER" -eq $BS_TRUE ]; then |
| 2742 | __PACKAGES="${__PACKAGES} salt-master" |
| 2743 | fi |
| 2744 | if [ "$_INSTALL_MINION" -eq $BS_TRUE ]; then |
| 2745 | __PACKAGES="${__PACKAGES} salt-minion" |
| 2746 | fi |
| 2747 | if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ]; then |
| 2748 | __PACKAGES="${__PACKAGES} salt-syndic" |
| 2749 | fi |
| 2750 | |
| 2751 | # shellcheck disable=SC2086 |
| 2752 | __apt_get_install_noinput ${__PACKAGES} || return 1 |
| 2753 | |
| 2754 | return 0 |
| 2755 | } |
| 2756 | |
| 2757 | install_ubuntu_daily() { |
| 2758 | install_ubuntu_stable || return 1 |
| 2759 | |
| 2760 | return 0 |
| 2761 | } |
| 2762 | |
| 2763 | install_ubuntu_git() { |
| 2764 | # Activate virtualenv before install |
| 2765 | if [ "${_VIRTUALENV_DIR}" != "null" ]; then |
| 2766 | __activate_virtualenv || return 1 |
| 2767 | fi |
| 2768 | |
| 2769 | if [ -f "${_SALT_GIT_CHECKOUT_DIR}/salt/syspaths.py" ]; then |
| 2770 | python setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install --install-layout=deb || return 1 |
| 2771 | else |
| 2772 | python setup.py ${SETUP_PY_INSTALL_ARGS} install --install-layout=deb || return 1 |
| 2773 | fi |
| 2774 | |
| 2775 | return 0 |
| 2776 | } |
| 2777 | |
| 2778 | install_ubuntu_stable_post() { |
| 2779 | for fname in api master minion syndic; do |
| 2780 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 2781 | [ $fname = "api" ] && continue |
| 2782 | |
| 2783 | # Skip if not meant to be installed |
| 2784 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 2785 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 2786 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 2787 | |
| 2788 | if [ -f /bin/systemctl ]; then |
| 2789 | # Using systemd |
| 2790 | /bin/systemctl is-enabled salt-$fname.service > /dev/null 2>&1 || ( |
| 2791 | /bin/systemctl preset salt-$fname.service > /dev/null 2>&1 && |
| 2792 | /bin/systemctl enable salt-$fname.service > /dev/null 2>&1 |
| 2793 | ) |
| 2794 | sleep 0.1 |
| 2795 | /bin/systemctl daemon-reload |
| 2796 | elif [ -f /etc/init.d/salt-$fname ]; then |
| 2797 | update-rc.d salt-$fname defaults |
| 2798 | fi |
| 2799 | done |
| 2800 | |
| 2801 | return 0 |
| 2802 | } |
| 2803 | |
| 2804 | install_ubuntu_git_post() { |
| 2805 | for fname in api master minion syndic; do |
| 2806 | # Skip if not meant to be installed |
| 2807 | [ $fname = "api" ] && \ |
| 2808 | ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue |
| 2809 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 2810 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 2811 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 2812 | |
| 2813 | if [ -f /bin/systemctl ] && [ "$DISTRO_MAJOR_VERSION" -ge 16 ]; then |
| 2814 | __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.service" "/lib/systemd/system/salt-${fname}.service" |
| 2815 | |
| 2816 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 2817 | [ $fname = "api" ] && continue |
| 2818 | |
| 2819 | systemctl is-enabled salt-$fname.service || (systemctl preset salt-$fname.service && systemctl enable salt-$fname.service) |
| 2820 | sleep 0.1 |
| 2821 | systemctl daemon-reload |
| 2822 | elif [ -f /sbin/initctl ]; then |
| 2823 | _upstart_conf="/etc/init/salt-$fname.conf" |
| 2824 | # We have upstart support |
| 2825 | echodebug "There's upstart support" |
| 2826 | if [ ! -f $_upstart_conf ]; then |
| 2827 | # upstart does not know about our service, let's copy the proper file |
| 2828 | echowarn "Upstart does not appear to know about salt-$fname" |
| 2829 | echodebug "Copying ${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-$fname.upstart to $_upstart_conf" |
| 2830 | __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.upstart" "$_upstart_conf" |
| 2831 | # Set service to know about virtualenv |
| 2832 | if [ "${_VIRTUALENV_DIR}" != "null" ]; then |
| 2833 | echo "SALT_USE_VIRTUALENV=${_VIRTUALENV_DIR}" > /etc/default/salt-${fname} |
| 2834 | fi |
| 2835 | /sbin/initctl reload-configuration || return 1 |
| 2836 | fi |
| 2837 | # No upstart support in Ubuntu!? |
| 2838 | elif [ -f "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.init" ]; then |
| 2839 | echodebug "There's NO upstart support!?" |
| 2840 | echodebug "Copying ${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.init to /etc/init.d/salt-$fname" |
| 2841 | __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.init" "/etc/init.d/salt-$fname" |
| 2842 | chmod +x /etc/init.d/salt-$fname |
| 2843 | |
| 2844 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 2845 | [ $fname = "api" ] && continue |
| 2846 | |
| 2847 | update-rc.d salt-$fname defaults |
| 2848 | else |
| 2849 | echoerror "Neither upstart nor init.d was setup for salt-$fname" |
| 2850 | fi |
| 2851 | done |
| 2852 | |
| 2853 | return 0 |
| 2854 | } |
| 2855 | |
| 2856 | install_ubuntu_restart_daemons() { |
| 2857 | [ $_START_DAEMONS -eq $BS_FALSE ] && return |
| 2858 | |
| 2859 | # Ensure upstart configs / systemd units are loaded |
| 2860 | if [ -f /bin/systemctl ] && [ "$DISTRO_MAJOR_VERSION" -ge 16 ]; then |
| 2861 | systemctl daemon-reload |
| 2862 | elif [ -f /sbin/initctl ]; then |
| 2863 | /sbin/initctl reload-configuration |
| 2864 | fi |
| 2865 | |
| 2866 | for fname in api master minion syndic; do |
| 2867 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 2868 | [ $fname = "api" ] && continue |
| 2869 | |
| 2870 | # Skip if not meant to be installed |
| 2871 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 2872 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 2873 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 2874 | |
| 2875 | if [ -f /bin/systemctl ] && [ "$DISTRO_MAJOR_VERSION" -ge 16 ]; then |
| 2876 | echodebug "There's systemd support while checking salt-$fname" |
| 2877 | systemctl stop salt-$fname > /dev/null 2>&1 |
| 2878 | systemctl start salt-$fname.service |
| 2879 | [ $? -eq 0 ] && continue |
| 2880 | # We failed to start the service, let's test the SysV code below |
| 2881 | echodebug "Failed to start salt-$fname using systemd" |
| 2882 | fi |
| 2883 | |
| 2884 | if [ -f /sbin/initctl ]; then |
| 2885 | echodebug "There's upstart support while checking salt-$fname" |
| 2886 | |
| 2887 | status salt-$fname 2>/dev/null | grep -q running |
| 2888 | if [ $? -eq 0 ]; then |
| 2889 | stop salt-$fname || (echodebug "Failed to stop salt-$fname" && return 1) |
| 2890 | fi |
| 2891 | |
| 2892 | start salt-$fname |
| 2893 | [ $? -eq 0 ] && continue |
| 2894 | # We failed to start the service, let's test the SysV code below |
| 2895 | echodebug "Failed to start salt-$fname using Upstart" |
| 2896 | fi |
| 2897 | |
| 2898 | if [ ! -f /etc/init.d/salt-$fname ]; then |
| 2899 | echoerror "No init.d support for salt-$fname was found" |
| 2900 | return 1 |
| 2901 | fi |
| 2902 | |
| 2903 | /etc/init.d/salt-$fname stop > /dev/null 2>&1 |
| 2904 | /etc/init.d/salt-$fname start |
| 2905 | done |
| 2906 | |
| 2907 | return 0 |
| 2908 | } |
| 2909 | |
| 2910 | install_ubuntu_check_services() { |
| 2911 | for fname in api master minion syndic; do |
| 2912 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 2913 | [ $fname = "api" ] && continue |
| 2914 | |
| 2915 | # Skip if not meant to be installed |
| 2916 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 2917 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 2918 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 2919 | |
| 2920 | if [ -f /bin/systemctl ] && [ "$DISTRO_MAJOR_VERSION" -ge 16 ]; then |
| 2921 | __check_services_systemd salt-$fname || return 1 |
| 2922 | elif [ -f /sbin/initctl ] && [ -f /etc/init/salt-${fname}.conf ]; then |
| 2923 | __check_services_upstart salt-$fname || return 1 |
| 2924 | elif [ -f /etc/init.d/salt-$fname ]; then |
| 2925 | __check_services_debian salt-$fname || return 1 |
| 2926 | fi |
| 2927 | done |
| 2928 | |
| 2929 | return 0 |
| 2930 | } |
| 2931 | # |
| 2932 | # End of Ubuntu Install Functions |
| 2933 | # |
| 2934 | ####################################################################################################################### |
| 2935 | |
| 2936 | ####################################################################################################################### |
| 2937 | # |
| 2938 | # Debian Install Functions |
| 2939 | # |
| 2940 | __install_saltstack_debian_repository() { |
| 2941 | if [ "$DISTRO_MAJOR_VERSION" -eq 10 ]; then |
| 2942 | # Packages for Debian 10 at repo.saltstack.com are not yet available |
| 2943 | # Set up repository for Debian 9 for Debian 10 for now until support |
| 2944 | # is available at repo.saltstack.com for Debian 10. |
| 2945 | echowarn "Debian 10 distribution detected, but stable packages requested. Trying packages from Debian 9. You may experience problems." |
| 2946 | DEBIAN_RELEASE="9" |
| 2947 | DEBIAN_CODENAME="stretch" |
| 2948 | else |
| 2949 | DEBIAN_RELEASE="$DISTRO_MAJOR_VERSION" |
| 2950 | DEBIAN_CODENAME="$DISTRO_CODENAME" |
| 2951 | fi |
| 2952 | |
| 2953 | __PACKAGES='' |
| 2954 | |
| 2955 | # Install downloader backend for GPG keys fetching |
| 2956 | if [ "$DISTRO_MAJOR_VERSION" -ge 9 ]; then |
| 2957 | __PACKAGES="${__PACKAGES} gnupg2 dirmngr" |
| 2958 | else |
| 2959 | __PACKAGES="${__PACKAGES} gnupg-curl" |
| 2960 | fi |
| 2961 | |
| 2962 | # Make sure https transport is available |
| 2963 | if [ "$HTTP_VAL" = "https" ] ; then |
| 2964 | __PACKAGES="${__PACKAGES} apt-transport-https ca-certificates" |
| 2965 | fi |
| 2966 | |
| 2967 | # shellcheck disable=SC2086,SC2090 |
| 2968 | __apt_get_install_noinput ${__PACKAGES} || return 1 |
| 2969 | |
| 2970 | # amd64 is just a part of repository URI, 32-bit pkgs are hosted under the same location |
| 2971 | SALTSTACK_DEBIAN_URL="${HTTP_VAL}://${_REPO_URL}/apt/debian/${DEBIAN_RELEASE}/${__REPO_ARCH}/${STABLE_REV}" |
| 2972 | echo "deb $SALTSTACK_DEBIAN_URL $DEBIAN_CODENAME main" > "/etc/apt/sources.list.d/saltstack.list" |
| 2973 | |
| 2974 | __apt_key_fetch "$SALTSTACK_DEBIAN_URL/SALTSTACK-GPG-KEY.pub" || return 1 |
| 2975 | |
| 2976 | apt-get update |
| 2977 | } |
| 2978 | |
| 2979 | install_debian_deps() { |
| 2980 | if [ $_START_DAEMONS -eq $BS_FALSE ]; then |
| 2981 | echowarn "Not starting daemons on Debian based distributions is not working mostly because starting them is the default behaviour." |
| 2982 | fi |
| 2983 | |
| 2984 | # No user interaction, libc6 restart services for example |
| 2985 | export DEBIAN_FRONTEND=noninteractive |
| 2986 | |
| 2987 | apt-get update |
| 2988 | |
| 2989 | if [ "${_UPGRADE_SYS}" -eq $BS_TRUE ]; then |
| 2990 | # Try to update GPG keys first if allowed |
| 2991 | if [ "${_INSECURE_DL}" -eq $BS_TRUE ]; then |
| 2992 | __apt_get_install_noinput --allow-unauthenticated debian-archive-keyring && |
| 2993 | apt-key update && apt-get update |
| 2994 | fi |
| 2995 | |
| 2996 | __apt_get_upgrade_noinput || return 1 |
| 2997 | fi |
| 2998 | |
| 2999 | # Additionally install procps and pciutils which allows for Docker bootstraps. See 366#issuecomment-39666813 |
| 3000 | __PACKAGES='procps pciutils' |
| 3001 | |
| 3002 | # YAML module is used for generating custom master/minion configs |
| 3003 | __PACKAGES="${__PACKAGES} python-yaml" |
| 3004 | |
| 3005 | # shellcheck disable=SC2086 |
| 3006 | __apt_get_install_noinput ${__PACKAGES} || return 1 |
| 3007 | |
| 3008 | if [ "$_DISABLE_REPOS" -eq "$BS_FALSE" ] || [ "$_CUSTOM_REPO_URL" != "null" ]; then |
| 3009 | __check_dpkg_architecture || return 1 |
| 3010 | __install_saltstack_debian_repository || return 1 |
| 3011 | fi |
| 3012 | |
| 3013 | if [ "${_EXTRA_PACKAGES}" != "" ]; then |
| 3014 | echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" |
| 3015 | # shellcheck disable=SC2086 |
| 3016 | __apt_get_install_noinput ${_EXTRA_PACKAGES} || return 1 |
| 3017 | fi |
| 3018 | |
| 3019 | return 0 |
| 3020 | } |
| 3021 | |
| 3022 | install_debian_git_deps() { |
| 3023 | if ! __check_command_exists git; then |
| 3024 | __apt_get_install_noinput git || return 1 |
| 3025 | fi |
| 3026 | |
| 3027 | if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then |
| 3028 | __apt_get_install_noinput ca-certificates |
| 3029 | fi |
| 3030 | |
| 3031 | __git_clone_and_checkout || return 1 |
| 3032 | |
| 3033 | __PACKAGES="libzmq3 libzmq3-dev lsb-release python-apt python-backports.ssl-match-hostname python-crypto" |
| 3034 | __PACKAGES="${__PACKAGES} python-jinja2 python-msgpack python-requests" |
| 3035 | __PACKAGES="${__PACKAGES} python-tornado python-yaml python-zmq" |
| 3036 | |
| 3037 | if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then |
| 3038 | # Install python-libcloud if asked to |
| 3039 | __PACKAGES="${__PACKAGES} python-libcloud" |
| 3040 | fi |
| 3041 | |
| 3042 | # shellcheck disable=SC2086 |
| 3043 | __apt_get_install_noinput ${__PACKAGES} || return 1 |
| 3044 | |
| 3045 | # Let's trigger config_salt() |
| 3046 | if [ "$_TEMP_CONFIG_DIR" = "null" ]; then |
| 3047 | _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" |
| 3048 | CONFIG_SALT_FUNC="config_salt" |
| 3049 | fi |
| 3050 | |
| 3051 | return 0 |
| 3052 | } |
| 3053 | |
| 3054 | install_debian_7_git_deps() { |
| 3055 | install_debian_deps || return 1 |
| 3056 | install_debian_git_deps || return 1 |
| 3057 | |
| 3058 | return 0 |
| 3059 | } |
| 3060 | |
| 3061 | install_debian_8_git_deps() { |
| 3062 | install_debian_deps || return 1 |
| 3063 | |
| 3064 | if ! __check_command_exists git; then |
| 3065 | __apt_get_install_noinput git || return 1 |
| 3066 | fi |
| 3067 | |
| 3068 | if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then |
| 3069 | __apt_get_install_noinput ca-certificates |
| 3070 | fi |
| 3071 | |
| 3072 | __git_clone_and_checkout || return 1 |
| 3073 | |
| 3074 | __PACKAGES="libzmq3 libzmq3-dev lsb-release python-apt python-crypto python-jinja2 python-msgpack" |
| 3075 | __PACKAGES="${__PACKAGES} python-requests python-systemd python-yaml python-zmq" |
| 3076 | |
| 3077 | if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then |
| 3078 | # Install python-libcloud if asked to |
| 3079 | __PACKAGES="${__PACKAGES} python-libcloud" |
| 3080 | fi |
| 3081 | |
| 3082 | __PIP_PACKAGES='' |
| 3083 | if (__check_pip_allowed >/dev/null 2>&1); then |
| 3084 | __PIP_PACKAGES='tornado' |
| 3085 | # Install development environment for building tornado Python module |
| 3086 | __PACKAGES="${__PACKAGES} build-essential python-dev" |
| 3087 | |
| 3088 | if ! __check_command_exists pip; then |
| 3089 | __PACKAGES="${__PACKAGES} python-pip" |
| 3090 | fi |
| 3091 | # Attempt to configure backports repo on non-x86_64 system |
| 3092 | elif [ $_DISABLE_REPOS -eq $BS_FALSE ] && [ "$DPKG_ARCHITECTURE" != "amd64" ]; then |
| 3093 | # Check if Debian Backports repo already configured |
| 3094 | if ! apt-cache policy | grep -q 'Debian Backports'; then |
| 3095 | echo 'deb http://httpredir.debian.org/debian jessie-backports main' > \ |
| 3096 | /etc/apt/sources.list.d/backports.list |
| 3097 | fi |
| 3098 | |
| 3099 | apt-get update || return 1 |
| 3100 | |
| 3101 | # python-tornado package should be installed from backports repo |
| 3102 | __PACKAGES="${__PACKAGES} python-backports.ssl-match-hostname python-tornado/jessie-backports" |
| 3103 | else |
| 3104 | __PACKAGES="${__PACKAGES} python-backports.ssl-match-hostname python-tornado" |
| 3105 | fi |
| 3106 | |
| 3107 | # shellcheck disable=SC2086 |
| 3108 | __apt_get_install_noinput ${__PACKAGES} || return 1 |
| 3109 | |
| 3110 | if [ "${__PIP_PACKAGES}" != "" ]; then |
| 3111 | # shellcheck disable=SC2086,SC2090 |
| 3112 | pip install -U ${__PIP_PACKAGES} || return 1 |
| 3113 | fi |
| 3114 | |
| 3115 | # Let's trigger config_salt() |
| 3116 | if [ "$_TEMP_CONFIG_DIR" = "null" ]; then |
| 3117 | _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" |
| 3118 | CONFIG_SALT_FUNC="config_salt" |
| 3119 | fi |
| 3120 | |
| 3121 | return 0 |
| 3122 | } |
| 3123 | |
| 3124 | install_debian_9_git_deps() { |
| 3125 | install_debian_deps || return 1 |
| 3126 | |
| 3127 | if ! __check_command_exists git; then |
| 3128 | __apt_get_install_noinput git || return 1 |
| 3129 | fi |
| 3130 | |
| 3131 | if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then |
| 3132 | __apt_get_install_noinput ca-certificates |
| 3133 | fi |
| 3134 | |
| 3135 | __git_clone_and_checkout || return 1 |
| 3136 | |
| 3137 | __PACKAGES="libzmq5 lsb-release python-apt python-backports-abc python-crypto" |
| 3138 | __PACKAGES="${__PACKAGES} python-jinja2 python-msgpack python-requests python-systemd" |
| 3139 | __PACKAGES="${__PACKAGES} python-tornado python-yaml python-zmq" |
| 3140 | |
| 3141 | if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then |
| 3142 | # Install python-libcloud if asked to |
| 3143 | __PACKAGES="${__PACKAGES} python-libcloud" |
| 3144 | fi |
| 3145 | |
| 3146 | # shellcheck disable=SC2086 |
| 3147 | __apt_get_install_noinput ${__PACKAGES} || return 1 |
| 3148 | |
| 3149 | # Let's trigger config_salt() |
| 3150 | if [ "$_TEMP_CONFIG_DIR" = "null" ]; then |
| 3151 | _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" |
| 3152 | CONFIG_SALT_FUNC="config_salt" |
| 3153 | fi |
| 3154 | |
| 3155 | return 0 |
| 3156 | } |
| 3157 | |
| 3158 | install_debian_10_git_deps() { |
| 3159 | install_debian_9_git_deps || return 1 |
| 3160 | return 0 |
| 3161 | } |
| 3162 | |
| 3163 | install_debian_stable() { |
| 3164 | __PACKAGES="" |
| 3165 | |
| 3166 | if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ];then |
| 3167 | __PACKAGES="${__PACKAGES} salt-cloud" |
| 3168 | fi |
| 3169 | if [ "$_INSTALL_MASTER" -eq $BS_TRUE ]; then |
| 3170 | __PACKAGES="${__PACKAGES} salt-master" |
| 3171 | fi |
| 3172 | if [ "$_INSTALL_MINION" -eq $BS_TRUE ]; then |
| 3173 | __PACKAGES="${__PACKAGES} salt-minion" |
| 3174 | fi |
| 3175 | if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ]; then |
| 3176 | __PACKAGES="${__PACKAGES} salt-syndic" |
| 3177 | fi |
| 3178 | |
| 3179 | # shellcheck disable=SC2086 |
| 3180 | __apt_get_install_noinput ${__PACKAGES} || return 1 |
| 3181 | |
| 3182 | return 0 |
| 3183 | } |
| 3184 | |
| 3185 | install_debian_7_stable() { |
| 3186 | install_debian_stable || return 1 |
| 3187 | return 0 |
| 3188 | } |
| 3189 | |
| 3190 | install_debian_8_stable() { |
| 3191 | install_debian_stable || return 1 |
| 3192 | return 0 |
| 3193 | } |
| 3194 | |
| 3195 | install_debian_9_stable() { |
| 3196 | install_debian_stable || return 1 |
| 3197 | return 0 |
| 3198 | } |
| 3199 | |
| 3200 | install_debian_git() { |
| 3201 | if [ -f "${_SALT_GIT_CHECKOUT_DIR}/salt/syspaths.py" ]; then |
| 3202 | python setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install --install-layout=deb || return 1 |
| 3203 | else |
| 3204 | python setup.py ${SETUP_PY_INSTALL_ARGS} install --install-layout=deb || return 1 |
| 3205 | fi |
| 3206 | } |
| 3207 | |
| 3208 | install_debian_7_git() { |
| 3209 | install_debian_git || return 1 |
| 3210 | return 0 |
| 3211 | } |
| 3212 | |
| 3213 | install_debian_8_git() { |
| 3214 | install_debian_git || return 1 |
| 3215 | return 0 |
| 3216 | } |
| 3217 | |
| 3218 | install_debian_9_git() { |
| 3219 | install_debian_git || return 1 |
| 3220 | return 0 |
| 3221 | } |
| 3222 | |
| 3223 | install_debian_git_post() { |
| 3224 | for fname in api master minion syndic; do |
| 3225 | # Skip if not meant to be installed |
| 3226 | [ "$fname" = "api" ] && \ |
| 3227 | ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue |
| 3228 | [ "$fname" = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 3229 | [ "$fname" = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 3230 | [ "$fname" = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 3231 | |
| 3232 | # Configure SystemD for Debian 8 "Jessie" and later |
| 3233 | if [ -f /bin/systemctl ]; then |
| 3234 | if [ ! -f /lib/systemd/system/salt-${fname}.service ] || \ |
| 3235 | ([ -f /lib/systemd/system/salt-${fname}.service ] && [ $_FORCE_OVERWRITE -eq $BS_TRUE ]); then |
| 3236 | if [ -f "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.service" ]; then |
| 3237 | __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.service" /lib/systemd/system |
| 3238 | __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.environment" "/etc/default/salt-${fname}" |
| 3239 | else |
| 3240 | # workaround before adding Debian-specific unit files to the Salt main repo |
| 3241 | __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.service" /lib/systemd/system |
| 3242 | sed -i -e '/^Type/ s/notify/simple/' /lib/systemd/system/salt-${fname}.service |
| 3243 | fi |
| 3244 | fi |
| 3245 | |
| 3246 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 3247 | [ "$fname" = "api" ] && continue |
| 3248 | |
| 3249 | /bin/systemctl enable "salt-${fname}.service" |
| 3250 | SYSTEMD_RELOAD=$BS_TRUE |
| 3251 | |
| 3252 | # Install initscripts for Debian 7 "Wheezy" |
| 3253 | elif [ ! -f "/etc/init.d/salt-$fname" ] || \ |
| 3254 | ([ -f "/etc/init.d/salt-$fname" ] && [ "$_FORCE_OVERWRITE" -eq $BS_TRUE ]); then |
| 3255 | if [ -f "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-$fname.init" ]; then |
| 3256 | __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.init" "/etc/init.d/salt-${fname}" |
| 3257 | __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.environment" "/etc/default/salt-${fname}" |
| 3258 | else |
| 3259 | # Make sure wget is available |
| 3260 | __check_command_exists wget || __apt_get_install_noinput wget || return 1 |
| 3261 | __fetch_url "/etc/init.d/salt-${fname}" "${HTTP_VAL}://anonscm.debian.org/cgit/pkg-salt/salt.git/plain/debian/salt-${fname}.init" |
| 3262 | fi |
| 3263 | |
| 3264 | if [ ! -f "/etc/init.d/salt-${fname}" ]; then |
| 3265 | echowarn "The init script for salt-${fname} was not found, skipping it..." |
| 3266 | continue |
| 3267 | fi |
| 3268 | |
| 3269 | chmod +x "/etc/init.d/salt-${fname}" |
| 3270 | |
| 3271 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 3272 | [ "$fname" = "api" ] && continue |
| 3273 | |
| 3274 | update-rc.d "salt-${fname}" defaults |
| 3275 | fi |
| 3276 | done |
| 3277 | } |
| 3278 | |
| 3279 | install_debian_restart_daemons() { |
| 3280 | [ "$_START_DAEMONS" -eq $BS_FALSE ] && return 0 |
| 3281 | |
| 3282 | for fname in api master minion syndic; do |
| 3283 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 3284 | [ $fname = "api" ] && continue |
| 3285 | |
| 3286 | # Skip if not meant to be installed |
| 3287 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 3288 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 3289 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 3290 | |
| 3291 | if [ -f /bin/systemctl ]; then |
| 3292 | # Debian 8 uses systemd |
| 3293 | /bin/systemctl stop salt-$fname > /dev/null 2>&1 |
| 3294 | /bin/systemctl start salt-$fname.service |
| 3295 | elif [ -f /etc/init.d/salt-$fname ]; then |
| 3296 | # Still in SysV init |
| 3297 | /etc/init.d/salt-$fname stop > /dev/null 2>&1 |
| 3298 | /etc/init.d/salt-$fname start |
| 3299 | fi |
| 3300 | done |
| 3301 | } |
| 3302 | |
| 3303 | install_debian_check_services() { |
| 3304 | for fname in api master minion syndic; do |
| 3305 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 3306 | [ $fname = "api" ] && continue |
| 3307 | |
| 3308 | # Skip if not meant to be installed |
| 3309 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 3310 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 3311 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 3312 | |
| 3313 | if [ -f /bin/systemctl ]; then |
| 3314 | __check_services_systemd salt-$fname || return 1 |
| 3315 | elif [ -f /etc/init.d/salt-$fname ]; then |
| 3316 | __check_services_debian salt-$fname || return 1 |
| 3317 | fi |
| 3318 | done |
| 3319 | return 0 |
| 3320 | } |
| 3321 | # |
| 3322 | # Ended Debian Install Functions |
| 3323 | # |
| 3324 | ####################################################################################################################### |
| 3325 | |
| 3326 | ####################################################################################################################### |
| 3327 | # |
| 3328 | # Fedora Install Functions |
| 3329 | # |
| 3330 | |
| 3331 | install_fedora_deps() { |
| 3332 | |
| 3333 | if [ $_DISABLE_REPOS -eq $BS_FALSE ]; then |
| 3334 | if [ "$_ENABLE_EXTERNAL_ZMQ_REPOS" -eq $BS_TRUE ]; then |
| 3335 | __install_saltstack_copr_zeromq_repository || return 1 |
| 3336 | fi |
| 3337 | |
| 3338 | __install_saltstack_copr_salt_repository || return 1 |
| 3339 | fi |
| 3340 | |
| 3341 | __PACKAGES="PyYAML libyaml python-crypto python-jinja2 python-zmq python2-msgpack python2-requests" |
| 3342 | |
| 3343 | if [ "$DISTRO_MAJOR_VERSION" -lt 26 ]; then |
| 3344 | __PACKAGES="${__PACKAGES} yum-utils" |
| 3345 | else |
| 3346 | __PACKAGES="${__PACKAGES} dnf-utils" |
| 3347 | fi |
| 3348 | |
| 3349 | # shellcheck disable=SC2086 |
| 3350 | dnf install -y ${__PACKAGES} || return 1 |
| 3351 | |
| 3352 | if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then |
| 3353 | dnf -y update || return 1 |
| 3354 | fi |
| 3355 | |
| 3356 | if [ "${_EXTRA_PACKAGES}" != "" ]; then |
| 3357 | echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" |
| 3358 | # shellcheck disable=SC2086 |
| 3359 | dnf install -y ${_EXTRA_PACKAGES} || return 1 |
| 3360 | fi |
| 3361 | |
| 3362 | return 0 |
| 3363 | } |
| 3364 | |
| 3365 | install_fedora_stable() { |
| 3366 | __PACKAGES="" |
| 3367 | |
| 3368 | if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ];then |
| 3369 | __PACKAGES="${__PACKAGES} salt-cloud" |
| 3370 | fi |
| 3371 | if [ "$_INSTALL_MASTER" -eq $BS_TRUE ]; then |
| 3372 | __PACKAGES="${__PACKAGES} salt-master" |
| 3373 | fi |
| 3374 | if [ "$_INSTALL_MINION" -eq $BS_TRUE ]; then |
| 3375 | __PACKAGES="${__PACKAGES} salt-minion" |
| 3376 | fi |
| 3377 | if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ]; then |
| 3378 | __PACKAGES="${__PACKAGES} salt-syndic" |
| 3379 | fi |
| 3380 | |
| 3381 | # shellcheck disable=SC2086 |
| 3382 | dnf install -y ${__PACKAGES} || return 1 |
| 3383 | |
| 3384 | return 0 |
| 3385 | } |
| 3386 | |
| 3387 | install_fedora_stable_post() { |
| 3388 | for fname in api master minion syndic; do |
| 3389 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 3390 | [ $fname = "api" ] && continue |
| 3391 | |
| 3392 | # Skip if not meant to be installed |
| 3393 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 3394 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 3395 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 3396 | |
| 3397 | systemctl is-enabled salt-$fname.service || (systemctl preset salt-$fname.service && systemctl enable salt-$fname.service) |
| 3398 | sleep 0.1 |
| 3399 | systemctl daemon-reload |
| 3400 | done |
| 3401 | } |
| 3402 | |
| 3403 | install_fedora_git_deps() { |
| 3404 | |
| 3405 | if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then |
| 3406 | dnf install -y ca-certificates || return 1 |
| 3407 | fi |
| 3408 | |
| 3409 | install_fedora_deps || return 1 |
| 3410 | |
| 3411 | if ! __check_command_exists git; then |
| 3412 | dnf install -y git || return 1 |
| 3413 | fi |
| 3414 | |
| 3415 | __git_clone_and_checkout || return 1 |
| 3416 | |
| 3417 | __PACKAGES="python2-tornado systemd-python" |
| 3418 | |
| 3419 | if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then |
| 3420 | __PACKAGES="${__PACKAGES} python-libcloud python-netaddr" |
| 3421 | fi |
| 3422 | |
| 3423 | # shellcheck disable=SC2086 |
| 3424 | dnf install -y ${__PACKAGES} || return 1 |
| 3425 | |
| 3426 | # Let's trigger config_salt() |
| 3427 | if [ "$_TEMP_CONFIG_DIR" = "null" ]; then |
| 3428 | _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" |
| 3429 | CONFIG_SALT_FUNC="config_salt" |
| 3430 | fi |
| 3431 | |
| 3432 | return 0 |
| 3433 | } |
| 3434 | |
| 3435 | install_fedora_git() { |
| 3436 | if [ -f "${_SALT_GIT_CHECKOUT_DIR}/salt/syspaths.py" ]; then |
| 3437 | python setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install || return 1 |
| 3438 | else |
| 3439 | python setup.py ${SETUP_PY_INSTALL_ARGS} install || return 1 |
| 3440 | fi |
| 3441 | return 0 |
| 3442 | } |
| 3443 | |
| 3444 | install_fedora_git_post() { |
| 3445 | for fname in api master minion syndic; do |
| 3446 | # Skip if not meant to be installed |
| 3447 | [ $fname = "api" ] && \ |
| 3448 | ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue |
| 3449 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 3450 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 3451 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 3452 | |
| 3453 | __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-${fname}.service" "/lib/systemd/system/salt-${fname}.service" |
| 3454 | |
| 3455 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 3456 | [ $fname = "api" ] && continue |
| 3457 | |
| 3458 | systemctl is-enabled salt-$fname.service || (systemctl preset salt-$fname.service && systemctl enable salt-$fname.service) |
| 3459 | sleep 0.1 |
| 3460 | systemctl daemon-reload |
| 3461 | done |
| 3462 | } |
| 3463 | |
| 3464 | install_fedora_restart_daemons() { |
| 3465 | [ $_START_DAEMONS -eq $BS_FALSE ] && return |
| 3466 | |
| 3467 | for fname in api master minion syndic; do |
| 3468 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 3469 | [ $fname = "api" ] && continue |
| 3470 | |
| 3471 | # Skip if not meant to be installed |
| 3472 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 3473 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 3474 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 3475 | |
| 3476 | systemctl stop salt-$fname > /dev/null 2>&1 |
| 3477 | systemctl start salt-$fname.service |
| 3478 | done |
| 3479 | } |
| 3480 | |
| 3481 | install_fedora_check_services() { |
| 3482 | for fname in api master minion syndic; do |
| 3483 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 3484 | [ $fname = "api" ] && continue |
| 3485 | |
| 3486 | # Skip if not meant to be installed |
| 3487 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 3488 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 3489 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 3490 | |
| 3491 | __check_services_systemd salt-$fname || return 1 |
| 3492 | done |
| 3493 | |
| 3494 | return 0 |
| 3495 | } |
| 3496 | # |
| 3497 | # Ended Fedora Install Functions |
| 3498 | # |
| 3499 | ####################################################################################################################### |
| 3500 | |
| 3501 | ####################################################################################################################### |
| 3502 | # |
| 3503 | # CentOS Install Functions |
| 3504 | # |
| 3505 | __install_epel_repository() { |
| 3506 | if [ ${_EPEL_REPOS_INSTALLED} -eq $BS_TRUE ]; then |
| 3507 | return 0 |
| 3508 | fi |
| 3509 | |
| 3510 | # Check if epel repo is already enabled and flag it accordingly |
| 3511 | yum repolist | grep -q "^[!]\?${_EPEL_REPO}/" |
| 3512 | if [ $? -eq 0 ]; then |
| 3513 | _EPEL_REPOS_INSTALLED=$BS_TRUE |
| 3514 | return 0 |
| 3515 | fi |
| 3516 | |
| 3517 | # Download latest 'epel-release' package for the distro version directly |
| 3518 | epel_repo_url="${HTTP_VAL}://dl.fedoraproject.org/pub/epel/epel-release-latest-${DISTRO_MAJOR_VERSION}.noarch.rpm" |
| 3519 | rpm -Uvh --force "$epel_repo_url" || return 1 |
| 3520 | |
| 3521 | _EPEL_REPOS_INSTALLED=$BS_TRUE |
| 3522 | |
| 3523 | return 0 |
| 3524 | } |
| 3525 | |
| 3526 | __install_saltstack_copr_zeromq_repository() { |
| 3527 | echoinfo "Installing Zeromq >=4 and PyZMQ>=14 from SaltStack's COPR repository" |
| 3528 | if [ ! -s /etc/yum.repos.d/saltstack-zeromq4.repo ]; then |
| 3529 | if [ "${DISTRO_NAME_L}" = "fedora" ]; then |
| 3530 | __REPOTYPE="${DISTRO_NAME_L}" |
| 3531 | else |
| 3532 | __REPOTYPE="epel" |
| 3533 | fi |
| 3534 | __fetch_url /etc/yum.repos.d/saltstack-zeromq4.repo \ |
| 3535 | "${HTTP_VAL}://copr.fedorainfracloud.org/coprs/saltstack/zeromq4/repo/${__REPOTYPE}-${DISTRO_MAJOR_VERSION}/saltstack-zeromq4-${__REPOTYPE}-${DISTRO_MAJOR_VERSION}.repo" || return 1 |
| 3536 | fi |
| 3537 | return 0 |
| 3538 | } |
| 3539 | |
| 3540 | __install_saltstack_rhel_repository() { |
| 3541 | if [ "$ITYPE" = "stable" ]; then |
| 3542 | repo_rev="$STABLE_REV" |
| 3543 | else |
| 3544 | repo_rev="latest" |
| 3545 | fi |
| 3546 | |
| 3547 | # Avoid using '$releasever' variable for yum. |
| 3548 | # Instead, this should work correctly on all RHEL variants. |
| 3549 | base_url="${HTTP_VAL}://${_REPO_URL}/yum/redhat/${DISTRO_MAJOR_VERSION}/\$basearch/${repo_rev}/" |
| 3550 | gpg_key="SALTSTACK-GPG-KEY.pub" |
| 3551 | repo_file="/etc/yum.repos.d/saltstack.repo" |
| 3552 | |
| 3553 | if [ ! -s "$repo_file" ]; then |
| 3554 | cat <<_eof > "$repo_file" |
| 3555 | [saltstack] |
| 3556 | name=SaltStack ${repo_rev} Release Channel for RHEL/CentOS \$releasever |
| 3557 | baseurl=${base_url} |
| 3558 | skip_if_unavailable=True |
| 3559 | gpgcheck=1 |
| 3560 | gpgkey=${base_url}${gpg_key} |
| 3561 | enabled=1 |
| 3562 | enabled_metadata=1 |
| 3563 | _eof |
| 3564 | |
| 3565 | fetch_url="${HTTP_VAL}://${_REPO_URL}/yum/redhat/${DISTRO_MAJOR_VERSION}/${CPU_ARCH_L}/${repo_rev}/" |
| 3566 | __rpm_import_gpg "${fetch_url}${gpg_key}" || return 1 |
| 3567 | fi |
| 3568 | |
| 3569 | return 0 |
| 3570 | } |
| 3571 | |
| 3572 | __install_saltstack_copr_salt_repository() { |
| 3573 | echoinfo "Adding SaltStack's COPR repository" |
| 3574 | |
| 3575 | if [ "${DISTRO_NAME_L}" = "fedora" ]; then |
| 3576 | [ "$DISTRO_MAJOR_VERSION" -ge 22 ] && return 0 |
| 3577 | __REPOTYPE="${DISTRO_NAME_L}" |
| 3578 | else |
| 3579 | __REPOTYPE="epel" |
| 3580 | fi |
| 3581 | |
| 3582 | __REPO_FILENAME="saltstack-salt-${__REPOTYPE}-${DISTRO_MAJOR_VERSION}.repo" |
| 3583 | |
| 3584 | if [ ! -s "/etc/yum.repos.d/${__REPO_FILENAME}" ]; then |
| 3585 | __fetch_url "/etc/yum.repos.d/${__REPO_FILENAME}" \ |
| 3586 | "${HTTP_VAL}://copr.fedorainfracloud.org/coprs/saltstack/salt/repo/${__REPOTYPE}-${DISTRO_MAJOR_VERSION}/${__REPO_FILENAME}" || return 1 |
| 3587 | fi |
| 3588 | |
| 3589 | return 0 |
| 3590 | } |
| 3591 | |
| 3592 | install_centos_stable_deps() { |
| 3593 | if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then |
| 3594 | yum -y update || return 1 |
| 3595 | fi |
| 3596 | |
| 3597 | if [ $_DISABLE_REPOS -eq $BS_FALSE ]; then |
| 3598 | __install_epel_repository || return 1 |
| 3599 | __install_saltstack_rhel_repository || return 1 |
| 3600 | fi |
| 3601 | |
| 3602 | # If -R was passed, we need to configure custom repo url with rsync-ed packages |
| 3603 | # Which is still handled in __install_saltstack_rhel_repository. This call has |
| 3604 | # its own check in case -r was passed without -R. |
| 3605 | if [ "$_CUSTOM_REPO_URL" != "null" ]; then |
| 3606 | __install_saltstack_rhel_repository || return 1 |
| 3607 | fi |
| 3608 | |
| 3609 | # YAML module is used for generating custom master/minion configs |
| 3610 | __PACKAGES="yum-utils chkconfig PyYAML" |
| 3611 | |
| 3612 | # shellcheck disable=SC2086 |
| 3613 | __yum_install_noinput ${__PACKAGES} || return 1 |
| 3614 | |
| 3615 | if [ "${_EXTRA_PACKAGES}" != "" ]; then |
| 3616 | echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" |
| 3617 | # shellcheck disable=SC2086 |
| 3618 | __yum_install_noinput ${_EXTRA_PACKAGES} || return 1 |
| 3619 | fi |
| 3620 | |
| 3621 | |
| 3622 | return 0 |
| 3623 | } |
| 3624 | |
| 3625 | install_centos_stable() { |
| 3626 | __PACKAGES="" |
| 3627 | |
| 3628 | if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ];then |
| 3629 | __PACKAGES="${__PACKAGES} salt-cloud" |
| 3630 | fi |
| 3631 | if [ "$_INSTALL_MASTER" -eq $BS_TRUE ];then |
| 3632 | __PACKAGES="${__PACKAGES} salt-master" |
| 3633 | fi |
| 3634 | if [ "$_INSTALL_MINION" -eq $BS_TRUE ]; then |
| 3635 | __PACKAGES="${__PACKAGES} salt-minion" |
| 3636 | fi |
| 3637 | if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ];then |
| 3638 | __PACKAGES="${__PACKAGES} salt-syndic" |
| 3639 | fi |
| 3640 | |
| 3641 | # shellcheck disable=SC2086 |
| 3642 | __yum_install_noinput ${__PACKAGES} || return 1 |
| 3643 | |
| 3644 | return 0 |
| 3645 | } |
| 3646 | |
| 3647 | install_centos_stable_post() { |
| 3648 | SYSTEMD_RELOAD=$BS_FALSE |
| 3649 | |
| 3650 | for fname in api master minion syndic; do |
| 3651 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 3652 | [ $fname = "api" ] && continue |
| 3653 | |
| 3654 | # Skip if not meant to be installed |
| 3655 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 3656 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 3657 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 3658 | |
| 3659 | if [ -f /bin/systemctl ]; then |
| 3660 | /bin/systemctl is-enabled salt-${fname}.service > /dev/null 2>&1 || ( |
| 3661 | /bin/systemctl preset salt-${fname}.service > /dev/null 2>&1 && |
| 3662 | /bin/systemctl enable salt-${fname}.service > /dev/null 2>&1 |
| 3663 | ) |
| 3664 | |
| 3665 | SYSTEMD_RELOAD=$BS_TRUE |
| 3666 | elif [ -f "/etc/init.d/salt-${fname}" ]; then |
| 3667 | /sbin/chkconfig salt-${fname} on |
| 3668 | fi |
| 3669 | done |
| 3670 | |
| 3671 | if [ "$SYSTEMD_RELOAD" -eq $BS_TRUE ]; then |
| 3672 | /bin/systemctl daemon-reload |
| 3673 | fi |
| 3674 | |
| 3675 | return 0 |
| 3676 | } |
| 3677 | |
| 3678 | install_centos_git_deps() { |
| 3679 | install_centos_stable_deps || return 1 |
| 3680 | |
| 3681 | if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then |
| 3682 | __yum_install_noinput ca-certificates || return 1 |
| 3683 | fi |
| 3684 | |
| 3685 | if ! __check_command_exists git; then |
| 3686 | __yum_install_noinput git || return 1 |
| 3687 | fi |
| 3688 | |
| 3689 | __git_clone_and_checkout || return 1 |
| 3690 | |
| 3691 | __PACKAGES="python-crypto python-futures python-msgpack python-zmq python-jinja2 python-requests python-tornado" |
| 3692 | |
| 3693 | if [ "$DISTRO_MAJOR_VERSION" -ge 7 ]; then |
| 3694 | __PACKAGES="${__PACKAGES} systemd-python" |
| 3695 | fi |
| 3696 | |
| 3697 | if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then |
| 3698 | __PACKAGES="${__PACKAGES} python-libcloud" |
| 3699 | fi |
| 3700 | |
| 3701 | if [ "${_INSTALL_PY}" -eq "${BS_TRUE}" ]; then |
| 3702 | # Install Python if "-y" was passed in. |
| 3703 | __install_python || return 1 |
| 3704 | fi |
| 3705 | |
| 3706 | if [ "${_PY_EXE}" != "" ]; then |
| 3707 | # If "-x" is defined, install dependencies with pip based on the Python version given. |
| 3708 | _PIP_PACKAGES="jinja2 msgpack-python pycrypto PyYAML tornado zmq" |
| 3709 | |
| 3710 | if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then |
| 3711 | for SINGLE_PACKAGE in $_PIP_PACKAGES; do |
| 3712 | __REQUIRED_VERSION="$(grep "${SINGLE_PACKAGE}" "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" |
| 3713 | if [ "${__REQUIRED_VERSION}" != "" ]; then |
| 3714 | _PIP_PACKAGES=$(echo "$_PIP_PACKAGES" | sed "s/${SINGLE_PACKAGE}/${__REQUIRED_VERSION}/") |
| 3715 | fi |
| 3716 | done |
| 3717 | fi |
| 3718 | |
| 3719 | if [ "$_INSTALL_CLOUD" -eq "${BS_TRUE}" ]; then |
| 3720 | _PIP_PACKAGES="${_PIP_PACKAGES} apache-libcloud" |
| 3721 | fi |
| 3722 | |
| 3723 | __install_pip_pkgs "${_PIP_PACKAGES}" "${_PY_EXE}" || return 1 |
| 3724 | else |
| 3725 | # shellcheck disable=SC2086 |
| 3726 | __yum_install_noinput ${__PACKAGES} || return 1 |
| 3727 | fi |
| 3728 | |
| 3729 | # Let's trigger config_salt() |
| 3730 | if [ "$_TEMP_CONFIG_DIR" = "null" ]; then |
| 3731 | _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" |
| 3732 | CONFIG_SALT_FUNC="config_salt" |
| 3733 | fi |
| 3734 | |
| 3735 | return 0 |
| 3736 | } |
| 3737 | |
| 3738 | install_centos_git() { |
| 3739 | if [ "${_PY_EXE}" != "" ]; then |
| 3740 | _PYEXE=${_PY_EXE} |
| 3741 | echoinfo "Using the following python version: ${_PY_EXE} to install salt" |
| 3742 | else |
| 3743 | _PYEXE='python2' |
| 3744 | fi |
| 3745 | |
| 3746 | if [ -f "${_SALT_GIT_CHECKOUT_DIR}/salt/syspaths.py" ]; then |
| 3747 | $_PYEXE setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install --prefix=/usr || return 1 |
| 3748 | else |
| 3749 | $_PYEXE setup.py ${SETUP_PY_INSTALL_ARGS} install --prefix=/usr || return 1 |
| 3750 | fi |
| 3751 | |
| 3752 | return 0 |
| 3753 | } |
| 3754 | |
| 3755 | install_centos_git_post() { |
| 3756 | SYSTEMD_RELOAD=$BS_FALSE |
| 3757 | |
| 3758 | for fname in api master minion syndic; do |
| 3759 | # Skip if not meant to be installed |
| 3760 | [ $fname = "api" ] && \ |
| 3761 | ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue |
| 3762 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 3763 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 3764 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 3765 | |
| 3766 | if [ -f /bin/systemctl ]; then |
| 3767 | if [ ! -f "/usr/lib/systemd/system/salt-${fname}.service" ] || \ |
| 3768 | ([ -f "/usr/lib/systemd/system/salt-${fname}.service" ] && [ "$_FORCE_OVERWRITE" -eq $BS_TRUE ]); then |
| 3769 | __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-${fname}.service" /usr/lib/systemd/system |
| 3770 | fi |
| 3771 | |
| 3772 | SYSTEMD_RELOAD=$BS_TRUE |
| 3773 | elif [ ! -f "/etc/init.d/salt-$fname" ] || \ |
| 3774 | ([ -f "/etc/init.d/salt-$fname" ] && [ "$_FORCE_OVERWRITE" -eq $BS_TRUE ]); then |
| 3775 | __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-${fname}" /etc/init.d |
| 3776 | chmod +x /etc/init.d/salt-${fname} |
| 3777 | fi |
| 3778 | done |
| 3779 | |
| 3780 | if [ "$SYSTEMD_RELOAD" -eq $BS_TRUE ]; then |
| 3781 | /bin/systemctl daemon-reload |
| 3782 | fi |
| 3783 | |
| 3784 | install_centos_stable_post || return 1 |
| 3785 | |
| 3786 | return 0 |
| 3787 | } |
| 3788 | |
| 3789 | install_centos_restart_daemons() { |
| 3790 | [ $_START_DAEMONS -eq $BS_FALSE ] && return |
| 3791 | |
| 3792 | for fname in api master minion syndic; do |
| 3793 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 3794 | [ $fname = "api" ] && continue |
| 3795 | |
| 3796 | # Skip if not meant to be installed |
| 3797 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 3798 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 3799 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 3800 | |
| 3801 | if [ -f /sbin/initctl ] && [ -f /etc/init/salt-${fname}.conf ]; then |
| 3802 | # We have upstart support and upstart knows about our service |
| 3803 | /sbin/initctl status salt-$fname > /dev/null 2>&1 |
| 3804 | if [ $? -ne 0 ]; then |
| 3805 | # Everything is in place and upstart gave us an error code? Fail! |
| 3806 | return 1 |
| 3807 | fi |
| 3808 | |
| 3809 | # upstart knows about this service. |
| 3810 | # Let's try to stop it, and then start it |
| 3811 | /sbin/initctl stop salt-$fname > /dev/null 2>&1 |
| 3812 | /sbin/initctl start salt-$fname > /dev/null 2>&1 |
| 3813 | # Restart service |
| 3814 | if [ $? -ne 0 ]; then |
| 3815 | # Failed the restart?! |
| 3816 | return 1 |
| 3817 | fi |
| 3818 | elif [ -f /etc/init.d/salt-$fname ]; then |
| 3819 | # Disable stdin to fix shell session hang on killing tee pipe |
| 3820 | service salt-$fname stop < /dev/null > /dev/null 2>&1 |
| 3821 | service salt-$fname start < /dev/null |
| 3822 | elif [ -f /usr/bin/systemctl ]; then |
| 3823 | # CentOS 7 uses systemd |
| 3824 | /usr/bin/systemctl stop salt-$fname > /dev/null 2>&1 |
| 3825 | /usr/bin/systemctl start salt-$fname.service |
| 3826 | fi |
| 3827 | done |
| 3828 | } |
| 3829 | |
| 3830 | install_centos_testing_deps() { |
| 3831 | install_centos_stable_deps || return 1 |
| 3832 | return 0 |
| 3833 | } |
| 3834 | |
| 3835 | install_centos_testing() { |
| 3836 | install_centos_stable || return 1 |
| 3837 | return 0 |
| 3838 | } |
| 3839 | |
| 3840 | install_centos_testing_post() { |
| 3841 | install_centos_stable_post || return 1 |
| 3842 | return 0 |
| 3843 | } |
| 3844 | |
| 3845 | install_centos_check_services() { |
| 3846 | for fname in api master minion syndic; do |
| 3847 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 3848 | [ $fname = "api" ] && continue |
| 3849 | |
| 3850 | # Skip if not meant to be installed |
| 3851 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 3852 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 3853 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 3854 | |
| 3855 | if [ -f /sbin/initctl ] && [ -f /etc/init/salt-${fname}.conf ]; then |
| 3856 | __check_services_upstart salt-$fname || return 1 |
| 3857 | elif [ -f /etc/init.d/salt-$fname ]; then |
| 3858 | __check_services_sysvinit salt-$fname || return 1 |
| 3859 | elif [ -f /usr/bin/systemctl ]; then |
| 3860 | __check_services_systemd salt-$fname || return 1 |
| 3861 | fi |
| 3862 | done |
| 3863 | |
| 3864 | return 0 |
| 3865 | } |
| 3866 | # |
| 3867 | # Ended CentOS Install Functions |
| 3868 | # |
| 3869 | ####################################################################################################################### |
| 3870 | |
| 3871 | ####################################################################################################################### |
| 3872 | # |
| 3873 | # RedHat Install Functions |
| 3874 | # |
| 3875 | install_red_hat_linux_stable_deps() { |
| 3876 | install_centos_stable_deps || return 1 |
| 3877 | return 0 |
| 3878 | } |
| 3879 | |
| 3880 | install_red_hat_linux_git_deps() { |
| 3881 | install_centos_git_deps || return 1 |
| 3882 | return 0 |
| 3883 | } |
| 3884 | |
| 3885 | install_red_hat_enterprise_linux_stable_deps() { |
| 3886 | install_red_hat_linux_stable_deps || return 1 |
| 3887 | return 0 |
| 3888 | } |
| 3889 | |
| 3890 | install_red_hat_enterprise_linux_git_deps() { |
| 3891 | install_red_hat_linux_git_deps || return 1 |
| 3892 | return 0 |
| 3893 | } |
| 3894 | |
| 3895 | install_red_hat_enterprise_server_stable_deps() { |
| 3896 | install_red_hat_linux_stable_deps || return 1 |
| 3897 | return 0 |
| 3898 | } |
| 3899 | |
| 3900 | install_red_hat_enterprise_server_git_deps() { |
| 3901 | install_red_hat_linux_git_deps || return 1 |
| 3902 | return 0 |
| 3903 | } |
| 3904 | |
| 3905 | install_red_hat_enterprise_workstation_stable_deps() { |
| 3906 | install_red_hat_linux_stable_deps || return 1 |
| 3907 | return 0 |
| 3908 | } |
| 3909 | |
| 3910 | install_red_hat_enterprise_workstation_git_deps() { |
| 3911 | install_red_hat_linux_git_deps || return 1 |
| 3912 | return 0 |
| 3913 | } |
| 3914 | |
| 3915 | install_red_hat_linux_stable() { |
| 3916 | install_centos_stable || return 1 |
| 3917 | return 0 |
| 3918 | } |
| 3919 | |
| 3920 | install_red_hat_linux_git() { |
| 3921 | install_centos_git || return 1 |
| 3922 | return 0 |
| 3923 | } |
| 3924 | |
| 3925 | install_red_hat_enterprise_linux_stable() { |
| 3926 | install_red_hat_linux_stable || return 1 |
| 3927 | return 0 |
| 3928 | } |
| 3929 | |
| 3930 | install_red_hat_enterprise_linux_git() { |
| 3931 | install_red_hat_linux_git || return 1 |
| 3932 | return 0 |
| 3933 | } |
| 3934 | |
| 3935 | install_red_hat_enterprise_server_stable() { |
| 3936 | install_red_hat_linux_stable || return 1 |
| 3937 | return 0 |
| 3938 | } |
| 3939 | |
| 3940 | install_red_hat_enterprise_server_git() { |
| 3941 | install_red_hat_linux_git || return 1 |
| 3942 | return 0 |
| 3943 | } |
| 3944 | |
| 3945 | install_red_hat_enterprise_workstation_stable() { |
| 3946 | install_red_hat_linux_stable || return 1 |
| 3947 | return 0 |
| 3948 | } |
| 3949 | |
| 3950 | install_red_hat_enterprise_workstation_git() { |
| 3951 | install_red_hat_linux_git || return 1 |
| 3952 | return 0 |
| 3953 | } |
| 3954 | |
| 3955 | install_red_hat_linux_stable_post() { |
| 3956 | install_centos_stable_post || return 1 |
| 3957 | return 0 |
| 3958 | } |
| 3959 | |
| 3960 | install_red_hat_linux_restart_daemons() { |
| 3961 | install_centos_restart_daemons || return 1 |
| 3962 | return 0 |
| 3963 | } |
| 3964 | |
| 3965 | install_red_hat_linux_git_post() { |
| 3966 | install_centos_git_post || return 1 |
| 3967 | return 0 |
| 3968 | } |
| 3969 | |
| 3970 | install_red_hat_enterprise_linux_stable_post() { |
| 3971 | install_red_hat_linux_stable_post || return 1 |
| 3972 | return 0 |
| 3973 | } |
| 3974 | |
| 3975 | install_red_hat_enterprise_linux_restart_daemons() { |
| 3976 | install_red_hat_linux_restart_daemons || return 1 |
| 3977 | return 0 |
| 3978 | } |
| 3979 | |
| 3980 | install_red_hat_enterprise_linux_git_post() { |
| 3981 | install_red_hat_linux_git_post || return 1 |
| 3982 | return 0 |
| 3983 | } |
| 3984 | |
| 3985 | install_red_hat_enterprise_server_stable_post() { |
| 3986 | install_red_hat_linux_stable_post || return 1 |
| 3987 | return 0 |
| 3988 | } |
| 3989 | |
| 3990 | install_red_hat_enterprise_server_restart_daemons() { |
| 3991 | install_red_hat_linux_restart_daemons || return 1 |
| 3992 | return 0 |
| 3993 | } |
| 3994 | |
| 3995 | install_red_hat_enterprise_server_git_post() { |
| 3996 | install_red_hat_linux_git_post || return 1 |
| 3997 | return 0 |
| 3998 | } |
| 3999 | |
| 4000 | install_red_hat_enterprise_workstation_stable_post() { |
| 4001 | install_red_hat_linux_stable_post || return 1 |
| 4002 | return 0 |
| 4003 | } |
| 4004 | |
| 4005 | install_red_hat_enterprise_workstation_restart_daemons() { |
| 4006 | install_red_hat_linux_restart_daemons || return 1 |
| 4007 | return 0 |
| 4008 | } |
| 4009 | |
| 4010 | install_red_hat_enterprise_workstation_git_post() { |
| 4011 | install_red_hat_linux_git_post || return 1 |
| 4012 | return 0 |
| 4013 | } |
| 4014 | |
| 4015 | install_red_hat_linux_testing_deps() { |
| 4016 | install_centos_testing_deps || return 1 |
| 4017 | return 0 |
| 4018 | } |
| 4019 | |
| 4020 | install_red_hat_linux_testing() { |
| 4021 | install_centos_testing || return 1 |
| 4022 | return 0 |
| 4023 | } |
| 4024 | |
| 4025 | install_red_hat_linux_testing_post() { |
| 4026 | install_centos_testing_post || return 1 |
| 4027 | return 0 |
| 4028 | } |
| 4029 | |
| 4030 | install_red_hat_enterprise_server_testing_deps() { |
| 4031 | install_centos_testing_deps || return 1 |
| 4032 | return 0 |
| 4033 | } |
| 4034 | |
| 4035 | install_red_hat_enterprise_server_testing() { |
| 4036 | install_centos_testing || return 1 |
| 4037 | return 0 |
| 4038 | } |
| 4039 | |
| 4040 | install_red_hat_enterprise_server_testing_post() { |
| 4041 | install_centos_testing_post || return 1 |
| 4042 | return 0 |
| 4043 | } |
| 4044 | |
| 4045 | install_red_hat_enterprise_workstation_testing_deps() { |
| 4046 | install_centos_testing_deps || return 1 |
| 4047 | return 0 |
| 4048 | } |
| 4049 | |
| 4050 | install_red_hat_enterprise_workstation_testing() { |
| 4051 | install_centos_testing || return 1 |
| 4052 | return 0 |
| 4053 | } |
| 4054 | |
| 4055 | install_red_hat_enterprise_workstation_testing_post() { |
| 4056 | install_centos_testing_post || return 1 |
| 4057 | return 0 |
| 4058 | } |
| 4059 | # |
| 4060 | # Ended RedHat Install Functions |
| 4061 | # |
| 4062 | ####################################################################################################################### |
| 4063 | |
| 4064 | ####################################################################################################################### |
| 4065 | # |
| 4066 | # Oracle Linux Install Functions |
| 4067 | # |
| 4068 | install_oracle_linux_stable_deps() { |
| 4069 | install_centos_stable_deps || return 1 |
| 4070 | return 0 |
| 4071 | } |
| 4072 | |
| 4073 | install_oracle_linux_git_deps() { |
| 4074 | install_centos_git_deps || return 1 |
| 4075 | return 0 |
| 4076 | } |
| 4077 | |
| 4078 | install_oracle_linux_testing_deps() { |
| 4079 | install_centos_testing_deps || return 1 |
| 4080 | return 0 |
| 4081 | } |
| 4082 | |
| 4083 | install_oracle_linux_stable() { |
| 4084 | install_centos_stable || return 1 |
| 4085 | return 0 |
| 4086 | } |
| 4087 | |
| 4088 | install_oracle_linux_git() { |
| 4089 | install_centos_git || return 1 |
| 4090 | return 0 |
| 4091 | } |
| 4092 | |
| 4093 | install_oracle_linux_testing() { |
| 4094 | install_centos_testing || return 1 |
| 4095 | return 0 |
| 4096 | } |
| 4097 | |
| 4098 | install_oracle_linux_stable_post() { |
| 4099 | install_centos_stable_post || return 1 |
| 4100 | return 0 |
| 4101 | } |
| 4102 | |
| 4103 | install_oracle_linux_git_post() { |
| 4104 | install_centos_git_post || return 1 |
| 4105 | return 0 |
| 4106 | } |
| 4107 | |
| 4108 | install_oracle_linux_testing_post() { |
| 4109 | install_centos_testing_post || return 1 |
| 4110 | return 0 |
| 4111 | } |
| 4112 | |
| 4113 | install_oracle_linux_restart_daemons() { |
| 4114 | install_centos_restart_daemons || return 1 |
| 4115 | return 0 |
| 4116 | } |
| 4117 | |
| 4118 | install_oracle_linux_check_services() { |
| 4119 | install_centos_check_services || return 1 |
| 4120 | return 0 |
| 4121 | } |
| 4122 | # |
| 4123 | # Ended Oracle Linux Install Functions |
| 4124 | # |
| 4125 | ####################################################################################################################### |
| 4126 | |
| 4127 | ####################################################################################################################### |
| 4128 | # |
| 4129 | # Scientific Linux Install Functions |
| 4130 | # |
| 4131 | install_scientific_linux_stable_deps() { |
| 4132 | install_centos_stable_deps || return 1 |
| 4133 | return 0 |
| 4134 | } |
| 4135 | |
| 4136 | install_scientific_linux_git_deps() { |
| 4137 | install_centos_git_deps || return 1 |
| 4138 | return 0 |
| 4139 | } |
| 4140 | |
| 4141 | install_scientific_linux_testing_deps() { |
| 4142 | install_centos_testing_deps || return 1 |
| 4143 | return 0 |
| 4144 | } |
| 4145 | |
| 4146 | install_scientific_linux_stable() { |
| 4147 | install_centos_stable || return 1 |
| 4148 | return 0 |
| 4149 | } |
| 4150 | |
| 4151 | install_scientific_linux_git() { |
| 4152 | install_centos_git || return 1 |
| 4153 | return 0 |
| 4154 | } |
| 4155 | |
| 4156 | install_scientific_linux_testing() { |
| 4157 | install_centos_testing || return 1 |
| 4158 | return 0 |
| 4159 | } |
| 4160 | |
| 4161 | install_scientific_linux_stable_post() { |
| 4162 | install_centos_stable_post || return 1 |
| 4163 | return 0 |
| 4164 | } |
| 4165 | |
| 4166 | install_scientific_linux_git_post() { |
| 4167 | install_centos_git_post || return 1 |
| 4168 | return 0 |
| 4169 | } |
| 4170 | |
| 4171 | install_scientific_linux_testing_post() { |
| 4172 | install_centos_testing_post || return 1 |
| 4173 | return 0 |
| 4174 | } |
| 4175 | |
| 4176 | install_scientific_linux_restart_daemons() { |
| 4177 | install_centos_restart_daemons || return 1 |
| 4178 | return 0 |
| 4179 | } |
| 4180 | |
| 4181 | install_scientific_linux_check_services() { |
| 4182 | install_centos_check_services || return 1 |
| 4183 | return 0 |
| 4184 | } |
| 4185 | # |
| 4186 | # Ended Scientific Linux Install Functions |
| 4187 | # |
| 4188 | ####################################################################################################################### |
| 4189 | |
| 4190 | ####################################################################################################################### |
| 4191 | # |
| 4192 | # CloudLinux Install Functions |
| 4193 | # |
| 4194 | install_cloud_linux_stable_deps() { |
| 4195 | install_centos_stable_deps || return 1 |
| 4196 | return 0 |
| 4197 | } |
| 4198 | |
| 4199 | install_cloud_linux_git_deps() { |
| 4200 | install_centos_git_deps || return 1 |
| 4201 | return 0 |
| 4202 | } |
| 4203 | |
| 4204 | install_cloud_linux_testing_deps() { |
| 4205 | install_centos_testing_deps || return 1 |
| 4206 | return 0 |
| 4207 | } |
| 4208 | |
| 4209 | install_cloud_linux_stable() { |
| 4210 | install_centos_stable || return 1 |
| 4211 | return 0 |
| 4212 | } |
| 4213 | |
| 4214 | install_cloud_linux_git() { |
| 4215 | install_centos_git || return 1 |
| 4216 | return 0 |
| 4217 | } |
| 4218 | |
| 4219 | install_cloud_linux_testing() { |
| 4220 | install_centos_testing || return 1 |
| 4221 | return 0 |
| 4222 | } |
| 4223 | |
| 4224 | install_cloud_linux_stable_post() { |
| 4225 | install_centos_stable_post || return 1 |
| 4226 | return 0 |
| 4227 | } |
| 4228 | |
| 4229 | install_cloud_linux_git_post() { |
| 4230 | install_centos_git_post || return 1 |
| 4231 | return 0 |
| 4232 | } |
| 4233 | |
| 4234 | install_cloud_linux_testing_post() { |
| 4235 | install_centos_testing_post || return 1 |
| 4236 | return 0 |
| 4237 | } |
| 4238 | |
| 4239 | install_cloud_linux_restart_daemons() { |
| 4240 | install_centos_restart_daemons || return 1 |
| 4241 | return 0 |
| 4242 | } |
| 4243 | |
| 4244 | install_cloud_linux_check_services() { |
| 4245 | install_centos_check_services || return 1 |
| 4246 | return 0 |
| 4247 | } |
| 4248 | # |
| 4249 | # End of CloudLinux Install Functions |
| 4250 | # |
| 4251 | ####################################################################################################################### |
| 4252 | |
| 4253 | ####################################################################################################################### |
| 4254 | # |
| 4255 | # Alpine Linux Install Functions |
| 4256 | # |
| 4257 | install_alpine_linux_stable_deps() { |
| 4258 | if ! grep -q '^[^#].\+alpine/.\+/community' /etc/apk/repositories; then |
| 4259 | # Add community repository entry based on the "main" repo URL |
| 4260 | __REPO=$(grep '^[^#].\+alpine/.\+/main\>' /etc/apk/repositories) |
| 4261 | echo "${__REPO}" | sed -e 's/main/community/' >> /etc/apk/repositories |
| 4262 | fi |
| 4263 | |
| 4264 | apk update |
| 4265 | |
| 4266 | # Get latest root CA certs |
| 4267 | apk -U add ca-certificates |
| 4268 | |
| 4269 | if ! __check_command_exists openssl; then |
| 4270 | # Install OpenSSL to be able to pull from https:// URLs |
| 4271 | apk -U add openssl |
| 4272 | fi |
| 4273 | } |
| 4274 | |
| 4275 | install_alpine_linux_git_deps() { |
| 4276 | install_alpine_linux_stable_deps || return 1 |
| 4277 | |
| 4278 | apk -U add python2 py-virtualenv py2-crypto py2-setuptools \ |
| 4279 | py2-jinja2 py2-yaml py2-markupsafe py2-msgpack py2-psutil \ |
| 4280 | py2-zmq zeromq py2-requests || return 1 |
| 4281 | |
| 4282 | if ! __check_command_exists git; then |
| 4283 | apk -U add git || return 1 |
| 4284 | fi |
| 4285 | |
| 4286 | __git_clone_and_checkout || return 1 |
| 4287 | |
| 4288 | if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then |
| 4289 | # We're on the develop branch, install whichever tornado is on the requirements file |
| 4290 | __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" |
| 4291 | if [ "${__REQUIRED_TORNADO}" != "" ]; then |
| 4292 | apk -U add py2-tornado || return 1 |
| 4293 | fi |
| 4294 | fi |
| 4295 | |
| 4296 | # Let's trigger config_salt() |
| 4297 | if [ "$_TEMP_CONFIG_DIR" = "null" ]; then |
| 4298 | _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" |
| 4299 | CONFIG_SALT_FUNC="config_salt" |
| 4300 | fi |
| 4301 | } |
| 4302 | |
| 4303 | install_alpine_linux_stable() { |
| 4304 | __PACKAGES="salt" |
| 4305 | |
| 4306 | if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ];then |
| 4307 | __PACKAGES="${__PACKAGES} salt-cloud" |
| 4308 | fi |
| 4309 | if [ "$_INSTALL_MASTER" -eq $BS_TRUE ]; then |
| 4310 | __PACKAGES="${__PACKAGES} salt-master" |
| 4311 | fi |
| 4312 | if [ "$_INSTALL_MINION" -eq $BS_TRUE ]; then |
| 4313 | __PACKAGES="${__PACKAGES} salt-minion" |
| 4314 | fi |
| 4315 | if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ]; then |
| 4316 | __PACKAGES="${__PACKAGES} salt-syndic" |
| 4317 | fi |
| 4318 | |
| 4319 | # shellcheck disable=SC2086 |
| 4320 | apk -U add ${__PACKAGES} || return 1 |
| 4321 | return 0 |
| 4322 | } |
| 4323 | |
| 4324 | install_alpine_linux_git() { |
| 4325 | if [ -f "${_SALT_GIT_CHECKOUT_DIR}/salt/syspaths.py" ]; then |
| 4326 | python2 setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install || return 1 |
| 4327 | else |
| 4328 | python2 setup.py ${SETUP_PY_INSTALL_ARGS} install || return 1 |
| 4329 | fi |
| 4330 | } |
| 4331 | |
| 4332 | install_alpine_linux_post() { |
| 4333 | for fname in api master minion syndic; do |
| 4334 | # Skip if not meant to be installed |
| 4335 | [ $fname = "api" ] && \ |
| 4336 | ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue |
| 4337 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 4338 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 4339 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 4340 | |
| 4341 | if [ -f /sbin/rc-update ]; then |
| 4342 | script_url="${_SALTSTACK_REPO_URL%.git}/raw/develop/pkg/alpine/salt-$fname" |
| 4343 | [ -f "/etc/init.d/salt-$fname" ] || __fetch_url "/etc/init.d/salt-$fname" "$script_url" |
| 4344 | |
| 4345 | if [ $? -eq 0 ]; then |
| 4346 | chmod +x "/etc/init.d/salt-$fname" |
| 4347 | else |
| 4348 | echoerror "Failed to get OpenRC init script for $OS_NAME from $script_url." |
| 4349 | return 1 |
| 4350 | fi |
| 4351 | |
| 4352 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 4353 | [ $fname = "api" ] && continue |
| 4354 | |
| 4355 | /sbin/rc-update add "salt-$fname" > /dev/null 2>&1 || return 1 |
| 4356 | fi |
| 4357 | done |
| 4358 | } |
| 4359 | |
| 4360 | install_alpine_linux_restart_daemons() { |
| 4361 | [ "${_START_DAEMONS}" -eq $BS_FALSE ] && return |
| 4362 | |
| 4363 | for fname in api master minion syndic; do |
| 4364 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 4365 | [ $fname = "api" ] && continue |
| 4366 | |
| 4367 | # Skip if not meant to be installed |
| 4368 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 4369 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 4370 | |
| 4371 | # Disable stdin to fix shell session hang on killing tee pipe |
| 4372 | /sbin/rc-service salt-$fname stop < /dev/null > /dev/null 2>&1 |
| 4373 | /sbin/rc-service salt-$fname start < /dev/null || return 1 |
| 4374 | done |
| 4375 | } |
| 4376 | |
| 4377 | install_alpine_linux_check_services() { |
| 4378 | for fname in api master minion syndic; do |
| 4379 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 4380 | [ $fname = "api" ] && continue |
| 4381 | |
| 4382 | # Skip if not meant to be installed |
| 4383 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 4384 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 4385 | |
| 4386 | __check_services_alpine salt-$fname || return 1 |
| 4387 | done |
| 4388 | |
| 4389 | return 0 |
| 4390 | } |
| 4391 | |
| 4392 | daemons_running_alpine_linux() { |
| 4393 | [ "${_START_DAEMONS}" -eq $BS_FALSE ] && return |
| 4394 | |
| 4395 | FAILED_DAEMONS=0 |
| 4396 | for fname in api master minion syndic; do |
| 4397 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 4398 | [ $fname = "api" ] && continue |
| 4399 | |
| 4400 | # Skip if not meant to be installed |
| 4401 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 4402 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 4403 | |
| 4404 | # shellcheck disable=SC2009 |
| 4405 | if [ "$(ps wwwaux | grep -v grep | grep salt-$fname)" = "" ]; then |
| 4406 | echoerror "salt-$fname was not found running" |
| 4407 | FAILED_DAEMONS=$((FAILED_DAEMONS + 1)) |
| 4408 | fi |
| 4409 | done |
| 4410 | |
| 4411 | return $FAILED_DAEMONS |
| 4412 | } |
| 4413 | |
| 4414 | # |
| 4415 | # Ended Alpine Linux Install Functions |
| 4416 | # |
| 4417 | ####################################################################################################################### |
| 4418 | |
| 4419 | |
| 4420 | ####################################################################################################################### |
| 4421 | # |
| 4422 | # Amazon Linux AMI Install Functions |
| 4423 | # |
| 4424 | |
| 4425 | install_amazon_linux_ami_deps() { |
| 4426 | # Shim to figure out if we're using old (rhel) or new (aws) rpms. |
| 4427 | _USEAWS=$BS_FALSE |
| 4428 | pkg_append="python" |
| 4429 | |
| 4430 | repo_rev="$(echo "${STABLE_REV}" | sed 's|.*\/||g')" |
| 4431 | |
| 4432 | if echo "$repo_rev" | egrep -q '^(latest|2016\.11)$' || \ |
| 4433 | [ "$(echo "$repo_rev" | cut -c1-4)" -gt 2016 ]; then |
| 4434 | _USEAWS=$BS_TRUE |
| 4435 | pkg_append="python27" |
| 4436 | fi |
| 4437 | |
| 4438 | # We need to install yum-utils before doing anything else when installing on |
| 4439 | # Amazon Linux ECS-optimized images. See issue #974. |
| 4440 | __yum_install_noinput yum-utils |
| 4441 | |
| 4442 | # Do upgrade early |
| 4443 | if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then |
| 4444 | yum -y update || return 1 |
| 4445 | fi |
| 4446 | |
| 4447 | if [ $_DISABLE_REPOS -eq $BS_FALSE ] || [ "$_CUSTOM_REPO_URL" != "null" ]; then |
| 4448 | __REPO_FILENAME="saltstack-repo.repo" |
| 4449 | |
| 4450 | # Set a few vars to make life easier. |
| 4451 | if [ $_USEAWS -eq $BS_TRUE ]; then |
| 4452 | base_url="$HTTP_VAL://${_REPO_URL}/yum/amazon/latest/\$basearch/$repo_rev/" |
| 4453 | gpg_key="${base_url}SALTSTACK-GPG-KEY.pub" |
| 4454 | repo_name="SaltStack repo for Amazon Linux" |
| 4455 | else |
| 4456 | base_url="$HTTP_VAL://${_REPO_URL}/yum/redhat/6/\$basearch/$repo_rev/" |
| 4457 | gpg_key="${base_url}SALTSTACK-GPG-KEY.pub" |
| 4458 | repo_name="SaltStack repo for RHEL/CentOS 6" |
| 4459 | fi |
| 4460 | |
| 4461 | # This should prob be refactored to use __install_saltstack_rhel_repository() |
| 4462 | # With args passed in to do the right thing. Reformatted to be more like the |
| 4463 | # amazon linux yum file. |
| 4464 | if [ ! -s "/etc/yum.repos.d/${__REPO_FILENAME}" ]; then |
| 4465 | cat <<_eof > "/etc/yum.repos.d/${__REPO_FILENAME}" |
| 4466 | [saltstack-repo] |
| 4467 | name=$repo_name |
| 4468 | failovermethod=priority |
| 4469 | priority=10 |
| 4470 | gpgcheck=1 |
| 4471 | gpgkey=$gpg_key |
| 4472 | baseurl=$base_url |
| 4473 | _eof |
| 4474 | fi |
| 4475 | |
| 4476 | fi |
| 4477 | |
| 4478 | # Package python-ordereddict-1.1-2.el6.noarch is obsoleted by python26-2.6.9-2.88.amzn1.x86_64 |
| 4479 | # which is already installed |
| 4480 | __PACKAGES="${pkg_append}-PyYAML ${pkg_append}-crypto ${pkg_append}-msgpack ${pkg_append}-zmq ${pkg_append}-jinja2 ${pkg_append}-requests" |
| 4481 | |
| 4482 | # shellcheck disable=SC2086 |
| 4483 | __yum_install_noinput ${__PACKAGES} || return 1 |
| 4484 | |
| 4485 | if [ "${_EXTRA_PACKAGES}" != "" ]; then |
| 4486 | echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" |
| 4487 | # shellcheck disable=SC2086 |
| 4488 | __yum_install_noinput ${_EXTRA_PACKAGES} || return 1 |
| 4489 | fi |
| 4490 | } |
| 4491 | |
| 4492 | install_amazon_linux_ami_git_deps() { |
| 4493 | if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then |
| 4494 | yum -y install ca-certificates || return 1 |
| 4495 | fi |
| 4496 | |
| 4497 | PIP_EXE='pip' |
| 4498 | if __check_command_exists python2.7; then |
| 4499 | if ! __check_command_exists pip2.7; then |
| 4500 | /usr/bin/easy_install-2.7 pip || return 1 |
| 4501 | fi |
| 4502 | PIP_EXE='/usr/local/bin/pip2.7' |
| 4503 | _PY_EXE='python2.7' |
| 4504 | fi |
| 4505 | |
| 4506 | install_amazon_linux_ami_deps || return 1 |
| 4507 | |
| 4508 | if ! __check_command_exists git; then |
| 4509 | __yum_install_noinput git || return 1 |
| 4510 | fi |
| 4511 | |
| 4512 | __git_clone_and_checkout || return 1 |
| 4513 | |
| 4514 | __PACKAGES="" |
| 4515 | __PIP_PACKAGES="" |
| 4516 | |
| 4517 | if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then |
| 4518 | __check_pip_allowed "You need to allow pip based installations (-P) in order to install apache-libcloud" |
| 4519 | __PACKAGES="${__PACKAGES} python-pip" |
| 4520 | __PIP_PACKAGES="${__PIP_PACKAGES} apache-libcloud>=$_LIBCLOUD_MIN_VERSION" |
| 4521 | fi |
| 4522 | |
| 4523 | if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then |
| 4524 | # We're on the develop branch, install whichever tornado is on the requirements file |
| 4525 | __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" |
| 4526 | if [ "${__REQUIRED_TORNADO}" != "" ]; then |
| 4527 | __PACKAGES="${__PACKAGES} ${pkg_append}-tornado" |
| 4528 | fi |
| 4529 | fi |
| 4530 | |
| 4531 | if [ "${__PACKAGES}" != "" ]; then |
| 4532 | # shellcheck disable=SC2086 |
| 4533 | __yum_install_noinput ${__PACKAGES} || return 1 |
| 4534 | fi |
| 4535 | |
| 4536 | if [ "${__PIP_PACKAGES}" != "" ]; then |
| 4537 | # shellcheck disable=SC2086 |
| 4538 | ${PIP_EXE} install ${__PIP_PACKAGES} || return 1 |
| 4539 | fi |
| 4540 | |
| 4541 | # Let's trigger config_salt() |
| 4542 | if [ "$_TEMP_CONFIG_DIR" = "null" ]; then |
| 4543 | _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" |
| 4544 | CONFIG_SALT_FUNC="config_salt" |
| 4545 | fi |
| 4546 | |
| 4547 | return 0 |
| 4548 | } |
| 4549 | |
| 4550 | install_amazon_linux_ami_stable() { |
| 4551 | install_centos_stable || return 1 |
| 4552 | return 0 |
| 4553 | } |
| 4554 | |
| 4555 | install_amazon_linux_ami_stable_post() { |
| 4556 | install_centos_stable_post || return 1 |
| 4557 | return 0 |
| 4558 | } |
| 4559 | |
| 4560 | install_amazon_linux_ami_restart_daemons() { |
| 4561 | install_centos_restart_daemons || return 1 |
| 4562 | return 0 |
| 4563 | } |
| 4564 | |
| 4565 | install_amazon_linux_ami_git() { |
| 4566 | install_centos_git || return 1 |
| 4567 | return 0 |
| 4568 | } |
| 4569 | |
| 4570 | install_amazon_linux_ami_git_post() { |
| 4571 | install_centos_git_post || return 1 |
| 4572 | return 0 |
| 4573 | } |
| 4574 | |
| 4575 | install_amazon_linux_ami_testing() { |
| 4576 | install_centos_testing || return 1 |
| 4577 | return 0 |
| 4578 | } |
| 4579 | |
| 4580 | install_amazon_linux_ami_testing_post() { |
| 4581 | install_centos_testing_post || return 1 |
| 4582 | return 0 |
| 4583 | } |
| 4584 | # |
| 4585 | # Ended Amazon Linux AMI Install Functions |
| 4586 | # |
| 4587 | ####################################################################################################################### |
| 4588 | |
| 4589 | ####################################################################################################################### |
| 4590 | # |
| 4591 | # Arch Install Functions |
| 4592 | # |
| 4593 | install_arch_linux_stable_deps() { |
| 4594 | if [ ! -f /etc/pacman.d/gnupg ]; then |
| 4595 | pacman-key --init && pacman-key --populate archlinux || return 1 |
| 4596 | fi |
| 4597 | |
| 4598 | # Pacman does not resolve dependencies on outdated versions |
| 4599 | # They always need to be updated |
| 4600 | pacman -Syy --noconfirm |
| 4601 | |
| 4602 | pacman -S --noconfirm --needed archlinux-keyring || return 1 |
| 4603 | |
| 4604 | pacman -Su --noconfirm --needed pacman || return 1 |
| 4605 | |
| 4606 | if __check_command_exists pacman-db-upgrade; then |
| 4607 | pacman-db-upgrade || return 1 |
| 4608 | fi |
| 4609 | |
| 4610 | # YAML module is used for generating custom master/minion configs |
| 4611 | pacman -Su --noconfirm --needed python2-yaml |
| 4612 | |
| 4613 | if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then |
| 4614 | pacman -Su --noconfirm --needed python2-apache-libcloud || return 1 |
| 4615 | fi |
| 4616 | |
| 4617 | if [ "${_EXTRA_PACKAGES}" != "" ]; then |
| 4618 | echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" |
| 4619 | # shellcheck disable=SC2086 |
| 4620 | pacman -Su --noconfirm --needed ${_EXTRA_PACKAGES} || return 1 |
| 4621 | fi |
| 4622 | } |
| 4623 | |
| 4624 | install_arch_linux_git_deps() { |
| 4625 | install_arch_linux_stable_deps |
| 4626 | |
| 4627 | # Don't fail if un-installing python2-distribute threw an error |
| 4628 | if ! __check_command_exists git; then |
| 4629 | pacman -Sy --noconfirm --needed git || return 1 |
| 4630 | fi |
| 4631 | pacman -R --noconfirm python2-distribute |
| 4632 | pacman -Su --noconfirm --needed python2-crypto python2-setuptools python2-jinja \ |
| 4633 | python2-markupsafe python2-msgpack python2-psutil \ |
| 4634 | python2-pyzmq zeromq python2-requests python2-systemd || return 1 |
| 4635 | |
| 4636 | __git_clone_and_checkout || return 1 |
| 4637 | |
| 4638 | if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then |
| 4639 | # We're on the develop branch, install whichever tornado is on the requirements file |
| 4640 | __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" |
| 4641 | if [ "${__REQUIRED_TORNADO}" != "" ]; then |
| 4642 | pacman -Su --noconfirm --needed python2-tornado |
| 4643 | fi |
| 4644 | fi |
| 4645 | |
| 4646 | |
| 4647 | # Let's trigger config_salt() |
| 4648 | if [ "$_TEMP_CONFIG_DIR" = "null" ]; then |
| 4649 | _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" |
| 4650 | CONFIG_SALT_FUNC="config_salt" |
| 4651 | fi |
| 4652 | |
| 4653 | return 0 |
| 4654 | } |
| 4655 | |
| 4656 | install_arch_linux_stable() { |
| 4657 | # Pacman does not resolve dependencies on outdated versions |
| 4658 | # They always need to be updated |
| 4659 | pacman -Syy --noconfirm |
| 4660 | |
| 4661 | pacman -Su --noconfirm --needed pacman || return 1 |
| 4662 | # See https://mailman.archlinux.org/pipermail/arch-dev-public/2013-June/025043.html |
| 4663 | # to know why we're ignoring below. |
| 4664 | pacman -Syu --noconfirm --ignore filesystem,bash || return 1 |
| 4665 | pacman -S --noconfirm --needed bash || return 1 |
| 4666 | pacman -Su --noconfirm || return 1 |
| 4667 | # We can now resume regular salt update |
| 4668 | pacman -Syu --noconfirm salt || return 1 |
| 4669 | return 0 |
| 4670 | } |
| 4671 | |
| 4672 | install_arch_linux_git() { |
| 4673 | if [ -f "${_SALT_GIT_CHECKOUT_DIR}/salt/syspaths.py" ]; then |
| 4674 | python2 setup.py --salt-config-dir="$_SALT_ETC_DIR" --salt-cache-dir="${_SALT_CACHE_DIR}" ${SETUP_PY_INSTALL_ARGS} install || return 1 |
| 4675 | else |
| 4676 | python2 setup.py ${SETUP_PY_INSTALL_ARGS} install || return 1 |
| 4677 | fi |
| 4678 | return 0 |
| 4679 | } |
| 4680 | |
| 4681 | install_arch_linux_post() { |
| 4682 | for fname in api master minion syndic; do |
| 4683 | # Skip if not meant to be installed |
| 4684 | [ $fname = "api" ] && \ |
| 4685 | ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue |
| 4686 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 4687 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 4688 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 4689 | |
| 4690 | # Since Arch's pacman renames configuration files |
| 4691 | if [ "$_TEMP_CONFIG_DIR" != "null" ] && [ -f "$_SALT_ETC_DIR/$fname.pacorig" ]; then |
| 4692 | # Since a configuration directory was provided, it also means that any |
| 4693 | # configuration file copied was renamed by Arch, see: |
| 4694 | # https://wiki.archlinux.org/index.php/Pacnew_and_Pacsave_Files#.pacorig |
| 4695 | __copyfile "$_SALT_ETC_DIR/$fname.pacorig" "$_SALT_ETC_DIR/$fname" $BS_TRUE |
| 4696 | fi |
| 4697 | |
| 4698 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 4699 | [ $fname = "api" ] && continue |
| 4700 | |
| 4701 | if [ -f /usr/bin/systemctl ]; then |
| 4702 | # Using systemd |
| 4703 | /usr/bin/systemctl is-enabled salt-$fname.service > /dev/null 2>&1 || ( |
| 4704 | /usr/bin/systemctl preset salt-$fname.service > /dev/null 2>&1 && |
| 4705 | /usr/bin/systemctl enable salt-$fname.service > /dev/null 2>&1 |
| 4706 | ) |
| 4707 | sleep 0.1 |
| 4708 | /usr/bin/systemctl daemon-reload |
| 4709 | continue |
| 4710 | fi |
| 4711 | |
| 4712 | # XXX: How do we enable old Arch init.d scripts? |
| 4713 | done |
| 4714 | } |
| 4715 | |
| 4716 | install_arch_linux_git_post() { |
| 4717 | for fname in api master minion syndic; do |
| 4718 | # Skip if not meant to be installed |
| 4719 | [ $fname = "api" ] && \ |
| 4720 | ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue |
| 4721 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 4722 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 4723 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 4724 | |
| 4725 | if [ -f /usr/bin/systemctl ]; then |
| 4726 | __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-${fname}.service" "/lib/systemd/system/salt-${fname}.service" |
| 4727 | |
| 4728 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 4729 | [ $fname = "api" ] && continue |
| 4730 | |
| 4731 | /usr/bin/systemctl is-enabled salt-${fname}.service > /dev/null 2>&1 || ( |
| 4732 | /usr/bin/systemctl preset salt-${fname}.service > /dev/null 2>&1 && |
| 4733 | /usr/bin/systemctl enable salt-${fname}.service > /dev/null 2>&1 |
| 4734 | ) |
| 4735 | sleep 0.1 |
| 4736 | /usr/bin/systemctl daemon-reload |
| 4737 | continue |
| 4738 | fi |
| 4739 | |
| 4740 | # SysV init!? |
| 4741 | __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-$fname" "/etc/rc.d/init.d/salt-$fname" |
| 4742 | chmod +x /etc/rc.d/init.d/salt-$fname |
| 4743 | done |
| 4744 | } |
| 4745 | |
| 4746 | install_arch_linux_restart_daemons() { |
| 4747 | [ $_START_DAEMONS -eq $BS_FALSE ] && return |
| 4748 | |
| 4749 | for fname in api master minion syndic; do |
| 4750 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 4751 | [ $fname = "api" ] && continue |
| 4752 | |
| 4753 | # Skip if not meant to be installed |
| 4754 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 4755 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 4756 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 4757 | |
| 4758 | if [ -f /usr/bin/systemctl ]; then |
| 4759 | /usr/bin/systemctl stop salt-$fname.service > /dev/null 2>&1 |
| 4760 | /usr/bin/systemctl start salt-$fname.service |
| 4761 | continue |
| 4762 | fi |
| 4763 | |
| 4764 | /etc/rc.d/salt-$fname stop > /dev/null 2>&1 |
| 4765 | /etc/rc.d/salt-$fname start |
| 4766 | done |
| 4767 | } |
| 4768 | |
| 4769 | install_arch_check_services() { |
| 4770 | if [ ! -f /usr/bin/systemctl ]; then |
| 4771 | # Not running systemd!? Don't check! |
| 4772 | return 0 |
| 4773 | fi |
| 4774 | |
| 4775 | for fname in api master minion syndic; do |
| 4776 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 4777 | [ $fname = "api" ] && continue |
| 4778 | |
| 4779 | # Skip if not meant to be installed |
| 4780 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 4781 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 4782 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 4783 | |
| 4784 | __check_services_systemd salt-$fname || return 1 |
| 4785 | done |
| 4786 | |
| 4787 | return 0 |
| 4788 | } |
| 4789 | # |
| 4790 | # Ended Arch Install Functions |
| 4791 | # |
| 4792 | ####################################################################################################################### |
| 4793 | |
| 4794 | ####################################################################################################################### |
| 4795 | # |
| 4796 | # FreeBSD Install Functions |
| 4797 | # |
| 4798 | |
| 4799 | __freebsd_get_packagesite() { |
| 4800 | if [ "$CPU_ARCH_L" = "amd64" ]; then |
| 4801 | BSD_ARCH="x86:64" |
| 4802 | elif [ "$CPU_ARCH_L" = "x86_64" ]; then |
| 4803 | BSD_ARCH="x86:64" |
| 4804 | elif [ "$CPU_ARCH_L" = "i386" ]; then |
| 4805 | BSD_ARCH="x86:32" |
| 4806 | elif [ "$CPU_ARCH_L" = "i686" ]; then |
| 4807 | BSD_ARCH="x86:32" |
| 4808 | fi |
| 4809 | |
| 4810 | # Since the variable might not be set, don't, momentarily treat it as a |
| 4811 | # failure |
| 4812 | set +o nounset |
| 4813 | |
| 4814 | # ABI is a std format for identifying release / architecture combos |
| 4815 | ABI="freebsd:${DISTRO_MAJOR_VERSION}:${BSD_ARCH}" |
| 4816 | _PACKAGESITE="http://pkg.freebsd.org/${ABI}/latest" |
| 4817 | # Awkwardly, we want the `${ABI}` to be in conf file without escaping |
| 4818 | PKGCONFURL="pkg+http://pkg.freebsd.org/\${ABI}/latest" |
| 4819 | SALTPKGCONFURL="http://repo.saltstack.com/freebsd/\${ABI}/" |
| 4820 | |
| 4821 | # Treat unset variables as errors once more |
| 4822 | set -o nounset |
| 4823 | } |
| 4824 | |
| 4825 | # Using a separate conf step to head for idempotent install... |
| 4826 | __configure_freebsd_pkg_details() { |
| 4827 | ## pkg.conf is deprecated. |
| 4828 | ## We use conf files in /usr/local or /etc instead |
| 4829 | mkdir -p /usr/local/etc/pkg/repos/ |
| 4830 | mkdir -p /etc/pkg/ |
| 4831 | |
| 4832 | ## Use new JSON-like format for pkg repo configs |
| 4833 | ## check if /etc/pkg/FreeBSD.conf is already in place |
| 4834 | if [ ! -f /etc/pkg/FreeBSD.conf ]; then |
| 4835 | conf_file=/usr/local/etc/pkg/repos/freebsd.conf |
| 4836 | { |
| 4837 | echo "FreeBSD:{" |
| 4838 | echo " url: \"${PKGCONFURL}\"," |
| 4839 | echo " mirror_type: \"srv\"," |
| 4840 | echo " signature_type: \"fingerprints\"," |
| 4841 | echo " fingerprints: \"/usr/share/keys/pkg\"," |
| 4842 | echo " enabled: true" |
| 4843 | echo "}" |
| 4844 | } > $conf_file |
| 4845 | __copyfile $conf_file /etc/pkg/FreeBSD.conf |
| 4846 | fi |
| 4847 | FROM_FREEBSD="-r FreeBSD" |
| 4848 | |
| 4849 | ## add saltstack freebsd repo |
| 4850 | salt_conf_file=/usr/local/etc/pkg/repos/saltstack.conf |
| 4851 | { |
| 4852 | echo "SaltStack:{" |
| 4853 | echo " url: \"${SALTPKGCONFURL}\"," |
| 4854 | echo " mirror_type: \"http\"," |
| 4855 | echo " enabled: true" |
| 4856 | echo " priority: 10" |
| 4857 | echo "}" |
| 4858 | } > $salt_conf_file |
| 4859 | FROM_SALTSTACK="-r SaltStack" |
| 4860 | |
| 4861 | ## ensure future ports builds use pkgng |
| 4862 | echo "WITH_PKGNG= yes" >> /etc/make.conf |
| 4863 | |
| 4864 | /usr/local/sbin/pkg update -f || return 1 |
| 4865 | } |
| 4866 | |
| 4867 | install_freebsd_9_stable_deps() { |
| 4868 | _SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/usr/local/etc/salt} |
| 4869 | _PKI_DIR=${_SALT_ETC_DIR}/pki |
| 4870 | |
| 4871 | if [ $_DISABLE_REPOS -eq $BS_FALSE ]; then |
| 4872 | #make variables available even if pkg already installed |
| 4873 | __freebsd_get_packagesite |
| 4874 | |
| 4875 | if [ ! -x /usr/local/sbin/pkg ]; then |
| 4876 | |
| 4877 | # install new `pkg` code from its own tarball. |
| 4878 | fetch "${_PACKAGESITE}/Latest/pkg.txz" || return 1 |
| 4879 | tar xf ./pkg.txz -s ",/.*/,,g" "*/pkg-static" || return 1 |
| 4880 | ./pkg-static add ./pkg.txz || return 1 |
| 4881 | /usr/local/sbin/pkg2ng || return 1 |
| 4882 | fi |
| 4883 | |
| 4884 | # Configure the pkg repository using new approach |
| 4885 | __configure_freebsd_pkg_details || return 1 |
| 4886 | fi |
| 4887 | |
| 4888 | # Now install swig |
| 4889 | # shellcheck disable=SC2086 |
| 4890 | /usr/local/sbin/pkg install ${FROM_FREEBSD} -y swig || return 1 |
| 4891 | |
| 4892 | # YAML module is used for generating custom master/minion configs |
| 4893 | # shellcheck disable=SC2086 |
| 4894 | /usr/local/sbin/pkg install ${FROM_FREEBSD} -y py27-yaml || return 1 |
| 4895 | |
| 4896 | if [ "${_EXTRA_PACKAGES}" != "" ]; then |
| 4897 | echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" |
| 4898 | # shellcheck disable=SC2086 |
| 4899 | /usr/local/sbin/pkg install ${FROM_FREEBSD} -y ${_EXTRA_PACKAGES} || return 1 |
| 4900 | fi |
| 4901 | |
| 4902 | if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then |
| 4903 | pkg upgrade -y || return 1 |
| 4904 | fi |
| 4905 | |
| 4906 | return 0 |
| 4907 | } |
| 4908 | |
| 4909 | install_freebsd_10_stable_deps() { |
| 4910 | install_freebsd_9_stable_deps |
| 4911 | } |
| 4912 | |
| 4913 | install_freebsd_11_stable_deps() { |
| 4914 | install_freebsd_9_stable_deps |
| 4915 | } |
| 4916 | |
| 4917 | install_freebsd_git_deps() { |
| 4918 | install_freebsd_9_stable_deps || return 1 |
| 4919 | |
| 4920 | # shellcheck disable=SC2086 |
| 4921 | 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' ' ') |
| 4922 | # shellcheck disable=SC2086 |
| 4923 | /usr/local/sbin/pkg install ${FROM_FREEBSD} -y ${SALT_DEPENDENCIES} || return 1 |
| 4924 | |
| 4925 | if ! __check_command_exists git; then |
| 4926 | /usr/local/sbin/pkg install -y git || return 1 |
| 4927 | fi |
| 4928 | |
| 4929 | /usr/local/sbin/pkg install -y www/py-requests || return 1 |
| 4930 | |
| 4931 | __git_clone_and_checkout || return 1 |
| 4932 | |
| 4933 | if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then |
| 4934 | # We're on the develop branch, install whichever tornado is on the requirements file |
| 4935 | __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" |
| 4936 | if [ "${__REQUIRED_TORNADO}" != "" ]; then |
| 4937 | /usr/local/sbin/pkg install -y www/py-tornado || return 1 |
| 4938 | fi |
| 4939 | fi |
| 4940 | |
| 4941 | echodebug "Adapting paths to FreeBSD" |
| 4942 | # The list of files was taken from Salt's BSD port Makefile |
| 4943 | for file in doc/man/salt-key.1 doc/man/salt-cp.1 doc/man/salt-minion.1 \ |
| 4944 | doc/man/salt-syndic.1 doc/man/salt-master.1 doc/man/salt-run.1 \ |
| 4945 | doc/man/salt.7 doc/man/salt.1 doc/man/salt-call.1; do |
| 4946 | [ ! -f $file ] && continue |
| 4947 | echodebug "Patching ${file}" |
| 4948 | sed -in -e "s|/etc/salt|${_SALT_ETC_DIR}|" \ |
| 4949 | -e "s|/srv/salt|${_SALT_ETC_DIR}/states|" \ |
| 4950 | -e "s|/srv/pillar|${_SALT_ETC_DIR}/pillar|" ${file} |
| 4951 | done |
| 4952 | if [ ! -f salt/syspaths.py ]; then |
| 4953 | # We still can't provide the system paths, salt 0.16.x |
| 4954 | # Let's patch salt's source and adapt paths to what's expected on FreeBSD |
| 4955 | echodebug "Replacing occurrences of '/etc/salt' with \'${_SALT_ETC_DIR}\'" |
| 4956 | # The list of files was taken from Salt's BSD port Makefile |
| 4957 | for file in conf/minion conf/master salt/config.py salt/client.py \ |
| 4958 | salt/modules/mysql.py salt/utils/parsers.py salt/modules/tls.py \ |
| 4959 | salt/modules/postgres.py salt/utils/migrations.py; do |
| 4960 | [ ! -f $file ] && continue |
| 4961 | echodebug "Patching ${file}" |
| 4962 | sed -in -e "s|/etc/salt|${_SALT_ETC_DIR}|" \ |
| 4963 | -e "s|/srv/salt|${_SALT_ETC_DIR}/states|" \ |
| 4964 | -e "s|/srv/pillar|${_SALT_ETC_DIR}/pillar|" ${file} |
| 4965 | done |
| 4966 | fi |
| 4967 | echodebug "Finished patching" |
| 4968 | |
| 4969 | # Let's trigger config_salt() |
| 4970 | if [ "$_TEMP_CONFIG_DIR" = "null" ]; then |
| 4971 | _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" |
| 4972 | CONFIG_SALT_FUNC="config_salt" |
| 4973 | |
| 4974 | fi |
| 4975 | |
| 4976 | return 0 |
| 4977 | } |
| 4978 | |
| 4979 | install_freebsd_9_stable() { |
| 4980 | # shellcheck disable=SC2086 |
| 4981 | /usr/local/sbin/pkg install ${FROM_SALTSTACK} -y sysutils/py-salt || return 1 |
| 4982 | return 0 |
| 4983 | } |
| 4984 | |
| 4985 | install_freebsd_10_stable() { |
| 4986 | # shellcheck disable=SC2086 |
| 4987 | /usr/local/sbin/pkg install ${FROM_FREEBSD} -y sysutils/py-salt || return 1 |
| 4988 | return 0 |
| 4989 | } |
| 4990 | |
| 4991 | install_freebsd_11_stable() { |
| 4992 | # |
| 4993 | # installing latest version of salt from FreeBSD CURRENT ports repo |
| 4994 | # |
| 4995 | # shellcheck disable=SC2086 |
| 4996 | /usr/local/sbin/pkg install ${FROM_FREEBSD} -y sysutils/py-salt || return 1 |
| 4997 | |
| 4998 | return 0 |
| 4999 | } |
| 5000 | |
| 5001 | install_freebsd_git() { |
| 5002 | |
| 5003 | # /usr/local/bin/python2 in FreeBSD is a symlink to /usr/local/bin/python2.7 |
| 5004 | __PYTHON_PATH=$(readlink -f "$(which python2)") |
| 5005 | __ESCAPED_PYTHON_PATH=$(echo "${__PYTHON_PATH}" | sed 's/\//\\\//g') |
| 5006 | |
| 5007 | # Install from git |
| 5008 | if [ ! -f salt/syspaths.py ]; then |
| 5009 | # We still can't provide the system paths, salt 0.16.x |
| 5010 | ${__PYTHON_PATH} setup.py ${SETUP_PY_INSTALL_ARGS} install || return 1 |
| 5011 | else |
| 5012 | ${__PYTHON_PATH} setup.py \ |
| 5013 | --salt-root-dir=/ \ |
| 5014 | --salt-config-dir="${_SALT_ETC_DIR}" \ |
| 5015 | --salt-cache-dir="${_SALT_CACHE_DIR}" \ |
| 5016 | --salt-sock-dir=/var/run/salt \ |
| 5017 | --salt-srv-root-dir="${_SALT_ETC_DIR}" \ |
| 5018 | --salt-base-file-roots-dir="${_SALT_ETC_DIR}/states" \ |
| 5019 | --salt-base-pillar-roots-dir="${_SALT_ETC_DIR}/pillar" \ |
| 5020 | --salt-base-master-roots-dir="${_SALT_ETC_DIR}/salt-master" \ |
| 5021 | --salt-logs-dir=/var/log/salt \ |
| 5022 | --salt-pidfile-dir=/var/run \ |
| 5023 | ${SETUP_PY_INSTALL_ARGS} install \ |
| 5024 | || return 1 |
| 5025 | fi |
| 5026 | |
| 5027 | for script in salt_api salt_master salt_minion salt_proxy salt_syndic; do |
| 5028 | __fetch_url "/usr/local/etc/rc.d/${script}" "https://raw.githubusercontent.com/freebsd/freebsd-ports/master/sysutils/py-salt/files/${script}.in" || return 1 |
| 5029 | sed -i '' 's/%%PREFIX%%/\/usr\/local/g' /usr/local/etc/rc.d/${script} |
| 5030 | sed -i '' "s/%%PYTHON_CMD%%/${__ESCAPED_PYTHON_PATH}/g" /usr/local/etc/rc.d/${script} |
| 5031 | chmod +x /usr/local/etc/rc.d/${script} || return 1 |
| 5032 | done |
| 5033 | |
| 5034 | # And we're good to go |
| 5035 | return 0 |
| 5036 | } |
| 5037 | |
| 5038 | install_freebsd_9_stable_post() { |
| 5039 | for fname in api master minion syndic; do |
| 5040 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 5041 | [ $fname = "api" ] && continue |
| 5042 | |
| 5043 | # Skip if not meant to be installed |
| 5044 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 5045 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 5046 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 5047 | |
| 5048 | enable_string="salt_${fname}_enable=\"YES\"" |
| 5049 | grep "$enable_string" /etc/rc.conf >/dev/null 2>&1 |
| 5050 | [ $? -eq 1 ] && echo "$enable_string" >> /etc/rc.conf |
| 5051 | |
| 5052 | if [ $fname = "minion" ] ; then |
| 5053 | grep "salt_minion_paths" /etc/rc.conf >/dev/null 2>&1 |
| 5054 | [ $? -eq 1 ] && echo "salt_minion_paths=\"/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin\"" >> /etc/rc.conf |
| 5055 | fi |
| 5056 | done |
| 5057 | } |
| 5058 | |
| 5059 | install_freebsd_10_stable_post() { |
| 5060 | install_freebsd_9_stable_post |
| 5061 | } |
| 5062 | |
| 5063 | install_freebsd_11_stable_post() { |
| 5064 | install_freebsd_9_stable_post |
| 5065 | } |
| 5066 | |
| 5067 | install_freebsd_git_post() { |
| 5068 | if [ -f $salt_conf_file ]; then |
| 5069 | rm -f $salt_conf_file |
| 5070 | fi |
| 5071 | install_freebsd_9_stable_post || return 1 |
| 5072 | return 0 |
| 5073 | } |
| 5074 | |
| 5075 | install_freebsd_restart_daemons() { |
| 5076 | [ $_START_DAEMONS -eq $BS_FALSE ] && return |
| 5077 | |
| 5078 | for fname in api master minion syndic; do |
| 5079 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 5080 | [ $fname = "api" ] && continue |
| 5081 | |
| 5082 | # Skip if not meant to be installed |
| 5083 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 5084 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 5085 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 5086 | |
| 5087 | service salt_$fname stop > /dev/null 2>&1 |
| 5088 | service salt_$fname start |
| 5089 | done |
| 5090 | } |
| 5091 | # |
| 5092 | # Ended FreeBSD Install Functions |
| 5093 | # |
| 5094 | ####################################################################################################################### |
| 5095 | |
| 5096 | ####################################################################################################################### |
| 5097 | # |
| 5098 | # OpenBSD Install Functions |
| 5099 | # |
| 5100 | |
| 5101 | __choose_openbsd_mirror() { |
| 5102 | OPENBSD_REPO='' |
| 5103 | MINTIME='' |
| 5104 | MIRROR_LIST=$(ftp -w 15 -Vao - 'https://ftp.openbsd.org/cgi-bin/ftplist.cgi?dbversion=1' | awk '/^http/ {print $1}') |
| 5105 | |
| 5106 | for MIRROR in $MIRROR_LIST; do |
| 5107 | MIRROR_HOST=$(echo "$MIRROR" | sed -e 's|.*//||' -e 's|+*/.*$||') |
| 5108 | TIME=$(ping -c 1 -w 1 -q "$MIRROR_HOST" | awk -F/ '/round-trip/ { print $5 }') |
| 5109 | [ -z "$TIME" ] && continue |
| 5110 | |
| 5111 | echodebug "ping time for $MIRROR_HOST is $TIME" |
| 5112 | if [ -z "$MINTIME" ]; then |
| 5113 | FASTER_MIRROR=1 |
| 5114 | else |
| 5115 | FASTER_MIRROR=$(echo "$TIME < $MINTIME" | bc) |
| 5116 | fi |
| 5117 | if [ "$FASTER_MIRROR" -eq 1 ]; then |
| 5118 | MINTIME=$TIME |
| 5119 | OPENBSD_REPO="$MIRROR" |
| 5120 | fi |
| 5121 | done |
| 5122 | } |
| 5123 | |
| 5124 | install_openbsd_deps() { |
| 5125 | if [ $_DISABLE_REPOS -eq $BS_FALSE ]; then |
| 5126 | __choose_openbsd_mirror || return 1 |
| 5127 | echoinfo "setting package repository to $OPENBSD_REPO with ping time of $MINTIME" |
| 5128 | [ -n "$OPENBSD_REPO" ] || return 1 |
| 5129 | echo "${OPENBSD_REPO}" >>/etc/installurl || return 1 |
| 5130 | fi |
| 5131 | |
| 5132 | if [ "${_EXTRA_PACKAGES}" != "" ]; then |
| 5133 | echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" |
| 5134 | # shellcheck disable=SC2086 |
| 5135 | pkg_add -I -v ${_EXTRA_PACKAGES} || return 1 |
| 5136 | fi |
| 5137 | return 0 |
| 5138 | } |
| 5139 | |
| 5140 | install_openbsd_git_deps() { |
| 5141 | install_openbsd_deps || return 1 |
| 5142 | pkg_add -I -v git || return 1 |
| 5143 | __git_clone_and_checkout || return 1 |
| 5144 | # |
| 5145 | # Let's trigger config_salt() |
| 5146 | # |
| 5147 | if [ "$_TEMP_CONFIG_DIR" = "null" ]; then |
| 5148 | _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" |
| 5149 | CONFIG_SALT_FUNC="config_salt" |
| 5150 | fi |
| 5151 | return 0 |
| 5152 | } |
| 5153 | |
| 5154 | install_openbsd_git() { |
| 5155 | # |
| 5156 | # Install from git |
| 5157 | # |
| 5158 | if [ ! -f salt/syspaths.py ]; then |
| 5159 | # We still can't provide the system paths, salt 0.16.x |
| 5160 | /usr/local/bin/python2.7 setup.py ${SETUP_PY_INSTALL_ARGS} install || return 1 |
| 5161 | fi |
| 5162 | return 0 |
| 5163 | } |
| 5164 | |
| 5165 | install_openbsd_stable() { |
| 5166 | pkg_add -r -I -v salt || return 1 |
| 5167 | return 0 |
| 5168 | } |
| 5169 | |
| 5170 | install_openbsd_post() { |
| 5171 | for fname in api master minion syndic; do |
| 5172 | [ $fname = "api" ] && continue |
| 5173 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 5174 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 5175 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 5176 | |
| 5177 | rcctl enable salt_$fname |
| 5178 | done |
| 5179 | |
| 5180 | return 0 |
| 5181 | } |
| 5182 | |
| 5183 | install_openbsd_check_services() { |
| 5184 | for fname in api master minion syndic; do |
| 5185 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 5186 | [ $fname = "api" ] && continue |
| 5187 | |
| 5188 | # Skip if not meant to be installed |
| 5189 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 5190 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 5191 | [ $fname = "syndic" ] && continue |
| 5192 | |
| 5193 | if [ -f /etc/rc.d/salt_${fname} ]; then |
| 5194 | __check_services_openbsd salt_${fname} || return 1 |
| 5195 | fi |
| 5196 | done |
| 5197 | |
| 5198 | return 0 |
| 5199 | } |
| 5200 | |
| 5201 | install_openbsd_restart_daemons() { |
| 5202 | [ $_START_DAEMONS -eq $BS_FALSE ] && return |
| 5203 | |
| 5204 | for fname in api master minion syndic; do |
| 5205 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 5206 | [ $fname = "api" ] && continue |
| 5207 | |
| 5208 | # Skip if not meant to be installed |
| 5209 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 5210 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 5211 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 5212 | |
| 5213 | rcctl restart salt_${fname} |
| 5214 | done |
| 5215 | |
| 5216 | return 0 |
| 5217 | } |
| 5218 | |
| 5219 | # |
| 5220 | # Ended OpenBSD Install Functions |
| 5221 | # |
| 5222 | ####################################################################################################################### |
| 5223 | |
| 5224 | ####################################################################################################################### |
| 5225 | # |
| 5226 | # SmartOS Install Functions |
| 5227 | # |
| 5228 | install_smartos_deps() { |
| 5229 | pkgin -y install zeromq py27-crypto py27-msgpack py27-yaml py27-jinja2 py27-zmq py27-requests || return 1 |
| 5230 | |
| 5231 | # Set _SALT_ETC_DIR to SmartOS default if they didn't specify |
| 5232 | _SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/opt/local/etc/salt} |
| 5233 | # We also need to redefine the PKI directory |
| 5234 | _PKI_DIR=${_SALT_ETC_DIR}/pki |
| 5235 | |
| 5236 | # Let's trigger config_salt() |
| 5237 | if [ "$_TEMP_CONFIG_DIR" = "null" ]; then |
| 5238 | # Let's set the configuration directory to /tmp |
| 5239 | _TEMP_CONFIG_DIR="/tmp" |
| 5240 | CONFIG_SALT_FUNC="config_salt" |
| 5241 | |
| 5242 | # Let's download, since they were not provided, the default configuration files |
| 5243 | if [ ! -f "$_SALT_ETC_DIR/minion" ] && [ ! -f "$_TEMP_CONFIG_DIR/minion" ]; then |
| 5244 | # shellcheck disable=SC2086 |
| 5245 | curl $_CURL_ARGS -s -o "$_TEMP_CONFIG_DIR/minion" -L \ |
| 5246 | https://raw.githubusercontent.com/saltstack/salt/develop/conf/minion || return 1 |
| 5247 | fi |
| 5248 | if [ ! -f "$_SALT_ETC_DIR/master" ] && [ ! -f $_TEMP_CONFIG_DIR/master ]; then |
| 5249 | # shellcheck disable=SC2086 |
| 5250 | curl $_CURL_ARGS -s -o "$_TEMP_CONFIG_DIR/master" -L \ |
| 5251 | https://raw.githubusercontent.com/saltstack/salt/develop/conf/master || return 1 |
| 5252 | fi |
| 5253 | fi |
| 5254 | |
| 5255 | if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then |
| 5256 | pkgin -y install py27-apache-libcloud || return 1 |
| 5257 | fi |
| 5258 | |
| 5259 | if [ "${_EXTRA_PACKAGES}" != "" ]; then |
| 5260 | echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" |
| 5261 | # shellcheck disable=SC2086 |
| 5262 | pkgin -y install ${_EXTRA_PACKAGES} || return 1 |
| 5263 | fi |
| 5264 | |
| 5265 | return 0 |
| 5266 | } |
| 5267 | |
| 5268 | install_smartos_git_deps() { |
| 5269 | install_smartos_deps || return 1 |
| 5270 | |
| 5271 | if ! __check_command_exists git; then |
| 5272 | pkgin -y install git || return 1 |
| 5273 | fi |
| 5274 | |
| 5275 | if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then |
| 5276 | # Install whichever tornado is in the requirements file |
| 5277 | __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" |
| 5278 | __check_pip_allowed "You need to allow pip based installations (-P) in order to install the python package '${__REQUIRED_TORNADO}'" |
| 5279 | |
| 5280 | # Install whichever futures is in the requirements file |
| 5281 | __REQUIRED_FUTURES="$(grep futures "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" |
| 5282 | __check_pip_allowed "You need to allow pip based installations (-P) in order to install the python package '${__REQUIRED_FUTURES}'" |
| 5283 | |
| 5284 | if [ "${__REQUIRED_TORNADO}" != "" ]; then |
| 5285 | if ! __check_command_exists pip; then |
| 5286 | pkgin -y install py27-pip |
| 5287 | fi |
| 5288 | pip install -U "${__REQUIRED_TORNADO}" |
| 5289 | fi |
| 5290 | |
| 5291 | if [ "${__REQUIRED_FUTURES}" != "" ]; then |
| 5292 | if ! __check_command_exists pip; then |
| 5293 | pkgin -y install py27-pip |
| 5294 | fi |
| 5295 | pip install -U "${__REQUIRED_FUTURES}" |
| 5296 | fi |
| 5297 | fi |
| 5298 | |
| 5299 | __git_clone_and_checkout || return 1 |
| 5300 | # Let's trigger config_salt() |
| 5301 | if [ "$_TEMP_CONFIG_DIR" = "null" ]; then |
| 5302 | _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" |
| 5303 | CONFIG_SALT_FUNC="config_salt" |
| 5304 | fi |
| 5305 | |
| 5306 | return 0 |
| 5307 | } |
| 5308 | |
| 5309 | install_smartos_stable() { |
| 5310 | pkgin -y install salt || return 1 |
| 5311 | return 0 |
| 5312 | } |
| 5313 | |
| 5314 | install_smartos_git() { |
| 5315 | # Use setuptools in order to also install dependencies |
| 5316 | # lets force our config path on the setup for now, since salt/syspaths.py only got fixed in 2015.5.0 |
| 5317 | 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 |
| 5318 | return 0 |
| 5319 | } |
| 5320 | |
| 5321 | install_smartos_post() { |
| 5322 | smf_dir="/opt/custom/smf" |
| 5323 | |
| 5324 | # Install manifest files if needed. |
| 5325 | for fname in api master minion syndic; do |
| 5326 | # Skip if not meant to be installed |
| 5327 | [ $fname = "api" ] && \ |
| 5328 | ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue |
| 5329 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 5330 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 5331 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 5332 | |
| 5333 | svcs network/salt-$fname > /dev/null 2>&1 |
| 5334 | if [ $? -eq 1 ]; then |
| 5335 | if [ ! -f "$_TEMP_CONFIG_DIR/salt-$fname.xml" ]; then |
| 5336 | # shellcheck disable=SC2086 |
| 5337 | curl $_CURL_ARGS -s -o "$_TEMP_CONFIG_DIR/salt-$fname.xml" -L \ |
| 5338 | "https://raw.githubusercontent.com/saltstack/salt/develop/pkg/smartos/salt-$fname.xml" |
| 5339 | fi |
| 5340 | svccfg import "$_TEMP_CONFIG_DIR/salt-$fname.xml" |
| 5341 | if [ "${VIRTUAL_TYPE}" = "global" ]; then |
| 5342 | if [ ! -d "$smf_dir" ]; then |
| 5343 | mkdir -p "$smf_dir" || return 1 |
| 5344 | fi |
| 5345 | if [ ! -f "$smf_dir/salt-$fname.xml" ]; then |
| 5346 | __copyfile "$_TEMP_CONFIG_DIR/salt-$fname.xml" "$smf_dir/" || return 1 |
| 5347 | fi |
| 5348 | fi |
| 5349 | fi |
| 5350 | done |
| 5351 | |
| 5352 | return 0 |
| 5353 | } |
| 5354 | |
| 5355 | install_smartos_git_post() { |
| 5356 | smf_dir="/opt/custom/smf" |
| 5357 | |
| 5358 | # Install manifest files if needed. |
| 5359 | for fname in api master minion syndic; do |
| 5360 | # Skip if not meant to be installed |
| 5361 | [ $fname = "api" ] && \ |
| 5362 | ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue |
| 5363 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 5364 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 5365 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 5366 | |
| 5367 | svcs "network/salt-$fname" > /dev/null 2>&1 |
| 5368 | if [ $? -eq 1 ]; then |
| 5369 | svccfg import "${_SALT_GIT_CHECKOUT_DIR}/pkg/smartos/salt-$fname.xml" |
| 5370 | if [ "${VIRTUAL_TYPE}" = "global" ]; then |
| 5371 | if [ ! -d $smf_dir ]; then |
| 5372 | mkdir -p "$smf_dir" |
| 5373 | fi |
| 5374 | if [ ! -f "$smf_dir/salt-$fname.xml" ]; then |
| 5375 | __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/smartos/salt-$fname.xml" "$smf_dir/" |
| 5376 | fi |
| 5377 | fi |
| 5378 | fi |
| 5379 | done |
| 5380 | |
| 5381 | return 0 |
| 5382 | } |
| 5383 | |
| 5384 | install_smartos_restart_daemons() { |
| 5385 | [ $_START_DAEMONS -eq $BS_FALSE ] && return |
| 5386 | |
| 5387 | for fname in api master minion syndic; do |
| 5388 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 5389 | [ $fname = "api" ] && continue |
| 5390 | |
| 5391 | # Skip if not meant to be installed |
| 5392 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 5393 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 5394 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 5395 | |
| 5396 | # Stop if running && Start service |
| 5397 | svcadm disable salt-$fname > /dev/null 2>&1 |
| 5398 | svcadm enable salt-$fname |
| 5399 | done |
| 5400 | |
| 5401 | return 0 |
| 5402 | } |
| 5403 | # |
| 5404 | # Ended SmartOS Install Functions |
| 5405 | # |
| 5406 | ####################################################################################################################### |
| 5407 | |
| 5408 | ####################################################################################################################### |
| 5409 | # |
| 5410 | # openSUSE Install Functions. |
| 5411 | # |
| 5412 | __ZYPPER_REQUIRES_REPLACE_FILES=-1 |
| 5413 | |
| 5414 | __set_suse_pkg_repo() { |
| 5415 | |
| 5416 | # Set distro repo variable |
| 5417 | if [ "${DISTRO_MAJOR_VERSION}" -gt 2015 ]; then |
| 5418 | DISTRO_REPO="openSUSE_Tumbleweed" |
| 5419 | elif [ "${DISTRO_MAJOR_VERSION}" -ge 42 ]; then |
| 5420 | DISTRO_REPO="openSUSE_Leap_${DISTRO_MAJOR_VERSION}.${DISTRO_MINOR_VERSION}" |
| 5421 | elif [ "${DISTRO_MAJOR_VERSION}" -lt 42 ]; then |
| 5422 | DISTRO_REPO="SLE_${DISTRO_MAJOR_VERSION}_SP${SUSE_PATCHLEVEL}" |
| 5423 | fi |
| 5424 | |
| 5425 | if [ "$_DOWNSTREAM_PKG_REPO" -eq $BS_TRUE ]; then |
| 5426 | suse_pkg_url_base="https://download.opensuse.org/repositories/systemsmanagement:/saltstack" |
| 5427 | suse_pkg_url_path="${DISTRO_REPO}/systemsmanagement:saltstack.repo" |
| 5428 | else |
| 5429 | suse_pkg_url_base="${HTTP_VAL}://repo.saltstack.com/opensuse" |
| 5430 | suse_pkg_url_path="${DISTRO_REPO}/systemsmanagement:saltstack:products.repo" |
| 5431 | fi |
| 5432 | SUSE_PKG_URL="$suse_pkg_url_base/$suse_pkg_url_path" |
| 5433 | } |
| 5434 | |
| 5435 | __check_and_refresh_suse_pkg_repo() { |
| 5436 | # Check to see if systemsmanagement_saltstack exists |
| 5437 | __zypper repos | grep -q systemsmanagement_saltstack |
| 5438 | |
| 5439 | if [ $? -eq 1 ]; then |
| 5440 | # zypper does not yet know anything about systemsmanagement_saltstack |
| 5441 | __zypper addrepo --refresh "${SUSE_PKG_URL}" || return 1 |
| 5442 | fi |
| 5443 | } |
| 5444 | |
| 5445 | __version_lte() { |
| 5446 | if ! __check_command_exists python; then |
| 5447 | zypper zypper --non-interactive install --replacefiles --auto-agree-with-licenses python || \ |
| 5448 | zypper zypper --non-interactive install --auto-agree-with-licenses python || return 1 |
| 5449 | fi |
| 5450 | |
| 5451 | 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 |
| 5452 | __ZYPPER_REQUIRES_REPLACE_FILES=${BS_TRUE} |
| 5453 | else |
| 5454 | __ZYPPER_REQUIRES_REPLACE_FILES=${BS_FALSE} |
| 5455 | fi |
| 5456 | } |
| 5457 | |
| 5458 | __zypper() { |
| 5459 | zypper --non-interactive "${@}"; return $? |
| 5460 | } |
| 5461 | |
| 5462 | __zypper_install() { |
| 5463 | if [ "${__ZYPPER_REQUIRES_REPLACE_FILES}" = "-1" ]; then |
| 5464 | __version_lte "1.10.4" "$(zypper --version | awk '{ print $2 }')" |
| 5465 | fi |
| 5466 | if [ "${__ZYPPER_REQUIRES_REPLACE_FILES}" = "${BS_TRUE}" ]; then |
| 5467 | # In case of file conflicts replace old files. |
| 5468 | # Option present in zypper 1.10.4 and newer: |
| 5469 | # https://github.com/openSUSE/zypper/blob/95655728d26d6d5aef7796b675f4cc69bc0c05c0/package/zypper.changes#L253 |
| 5470 | __zypper install --auto-agree-with-licenses --replacefiles "${@}"; return $? |
| 5471 | else |
| 5472 | __zypper install --auto-agree-with-licenses "${@}"; return $? |
| 5473 | fi |
| 5474 | } |
| 5475 | |
| 5476 | install_opensuse_stable_deps() { |
| 5477 | if [ $_DISABLE_REPOS -eq $BS_FALSE ]; then |
| 5478 | # Is the repository already known |
| 5479 | __set_suse_pkg_repo |
| 5480 | # Check zypper repos and refresh if necessary |
| 5481 | __check_and_refresh_suse_pkg_repo |
| 5482 | fi |
| 5483 | |
| 5484 | __zypper --gpg-auto-import-keys refresh |
| 5485 | if [ $? -ne 0 ] && [ $? -ne 4 ]; then |
| 5486 | # If the exit code is not 0, and it's not 4 (failed to update a |
| 5487 | # repository) return a failure. Otherwise continue. |
| 5488 | return 1 |
| 5489 | fi |
| 5490 | |
| 5491 | if [ "$DISTRO_MAJOR_VERSION" -eq 12 ] && [ "$DISTRO_MINOR_VERSION" -eq 3 ]; then |
| 5492 | # Because patterns-openSUSE-minimal_base-conflicts conflicts with python, lets remove the first one |
| 5493 | __zypper remove patterns-openSUSE-minimal_base-conflicts |
| 5494 | fi |
| 5495 | |
| 5496 | if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then |
| 5497 | __zypper --gpg-auto-import-keys update || return 1 |
| 5498 | fi |
| 5499 | |
| 5500 | # YAML module is used for generating custom master/minion configs |
| 5501 | # requests is still used by many salt modules |
| 5502 | # Salt needs python-zypp installed in order to use the zypper module |
| 5503 | __PACKAGES="python-PyYAML python-requests python-zypp" |
| 5504 | |
| 5505 | # shellcheck disable=SC2086 |
| 5506 | __zypper_install ${__PACKAGES} || return 1 |
| 5507 | |
| 5508 | if [ "${_EXTRA_PACKAGES}" != "" ]; then |
| 5509 | echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" |
| 5510 | # shellcheck disable=SC2086 |
| 5511 | __zypper_install ${_EXTRA_PACKAGES} || return 1 |
| 5512 | fi |
| 5513 | |
| 5514 | return 0 |
| 5515 | } |
| 5516 | |
| 5517 | install_opensuse_git_deps() { |
| 5518 | if [ "$_INSECURE_DL" -eq $BS_FALSE ] && [ "${_SALT_REPO_URL%%://*}" = "https" ]; then |
| 5519 | __zypper_install ca-certificates || return 1 |
| 5520 | fi |
| 5521 | |
| 5522 | install_opensuse_stable_deps || return 1 |
| 5523 | |
| 5524 | if ! __check_command_exists git; then |
| 5525 | __zypper_install git || return 1 |
| 5526 | fi |
| 5527 | |
| 5528 | __zypper_install patch || return 1 |
| 5529 | |
| 5530 | __git_clone_and_checkout || return 1 |
| 5531 | |
| 5532 | __PACKAGES="libzmq5 python-Jinja2 python-msgpack-python python-pycrypto python-pyzmq python-xml" |
| 5533 | |
| 5534 | if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then |
| 5535 | # We're on the develop branch, install whichever tornado is on the requirements file |
| 5536 | __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" |
| 5537 | if [ "${__REQUIRED_TORNADO}" != "" ]; then |
| 5538 | __PACKAGES="${__PACKAGES} python-tornado" |
| 5539 | fi |
| 5540 | fi |
| 5541 | |
| 5542 | if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then |
| 5543 | __PACKAGES="${__PACKAGES} python-apache-libcloud" |
| 5544 | fi |
| 5545 | |
| 5546 | # shellcheck disable=SC2086 |
| 5547 | __zypper_install ${__PACKAGES} || return 1 |
| 5548 | |
| 5549 | # Let's trigger config_salt() |
| 5550 | if [ "$_TEMP_CONFIG_DIR" = "null" ]; then |
| 5551 | _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" |
| 5552 | CONFIG_SALT_FUNC="config_salt" |
| 5553 | fi |
| 5554 | |
| 5555 | return 0 |
| 5556 | } |
| 5557 | |
| 5558 | install_opensuse_stable() { |
| 5559 | __PACKAGES="" |
| 5560 | |
| 5561 | if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ];then |
| 5562 | __PACKAGES="${__PACKAGES} salt-cloud" |
| 5563 | fi |
| 5564 | if [ "$_INSTALL_MASTER" -eq $BS_TRUE ]; then |
| 5565 | __PACKAGES="${__PACKAGES} salt-master" |
| 5566 | fi |
| 5567 | if [ "$_INSTALL_MINION" -eq $BS_TRUE ]; then |
| 5568 | __PACKAGES="${__PACKAGES} salt-minion" |
| 5569 | fi |
| 5570 | if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ]; then |
| 5571 | __PACKAGES="${__PACKAGES} salt-syndic" |
| 5572 | fi |
| 5573 | |
| 5574 | # shellcheck disable=SC2086 |
| 5575 | __zypper_install $__PACKAGES || return 1 |
| 5576 | |
| 5577 | return 0 |
| 5578 | } |
| 5579 | |
| 5580 | install_opensuse_git() { |
| 5581 | python setup.py ${SETUP_PY_INSTALL_ARGS} install --prefix=/usr || return 1 |
| 5582 | return 0 |
| 5583 | } |
| 5584 | |
| 5585 | install_opensuse_stable_post() { |
| 5586 | for fname in api master minion syndic; do |
| 5587 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 5588 | [ $fname = "api" ] && continue |
| 5589 | |
| 5590 | # Skip if not meant to be installed |
| 5591 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 5592 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 5593 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 5594 | |
| 5595 | if [ -f /bin/systemctl ]; then |
| 5596 | systemctl is-enabled salt-$fname.service || (systemctl preset salt-$fname.service && systemctl enable salt-$fname.service) |
| 5597 | sleep 0.1 |
| 5598 | systemctl daemon-reload |
| 5599 | continue |
| 5600 | fi |
| 5601 | |
| 5602 | /sbin/chkconfig --add salt-$fname |
| 5603 | /sbin/chkconfig salt-$fname on |
| 5604 | done |
| 5605 | |
| 5606 | return 0 |
| 5607 | } |
| 5608 | |
| 5609 | install_opensuse_git_post() { |
| 5610 | for fname in api master minion syndic; do |
| 5611 | # Skip if not meant to be installed |
| 5612 | [ $fname = "api" ] && \ |
| 5613 | ([ "$_INSTALL_MASTER" -eq $BS_FALSE ] || ! __check_command_exists "salt-${fname}") && continue |
| 5614 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 5615 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 5616 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 5617 | |
| 5618 | if [ -f /bin/systemctl ]; then |
| 5619 | use_usr_lib=$BS_FALSE |
| 5620 | |
| 5621 | if [ "${DISTRO_MAJOR_VERSION}" -gt 13 ] || ([ "${DISTRO_MAJOR_VERSION}" -eq 13 ] && [ "${DISTRO_MINOR_VERSION}" -ge 2 ]); then |
| 5622 | use_usr_lib=$BS_TRUE |
| 5623 | fi |
| 5624 | |
| 5625 | if [ "${DISTRO_MAJOR_VERSION}" -eq 12 ] && [ -d "/usr/lib/systemd/" ]; then |
| 5626 | use_usr_lib=$BS_TRUE |
| 5627 | fi |
| 5628 | |
| 5629 | if [ "${use_usr_lib}" -eq $BS_TRUE ]; then |
| 5630 | __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.service" "/usr/lib/systemd/system/salt-${fname}.service" |
| 5631 | else |
| 5632 | __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/salt-${fname}.service" "/lib/systemd/system/salt-${fname}.service" |
| 5633 | fi |
| 5634 | |
| 5635 | continue |
| 5636 | fi |
| 5637 | |
| 5638 | __copyfile "${_SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-$fname" "/etc/init.d/salt-$fname" |
| 5639 | chmod +x /etc/init.d/salt-$fname |
| 5640 | done |
| 5641 | |
| 5642 | install_opensuse_stable_post || return 1 |
| 5643 | |
| 5644 | return 0 |
| 5645 | } |
| 5646 | |
| 5647 | install_opensuse_restart_daemons() { |
| 5648 | [ $_START_DAEMONS -eq $BS_FALSE ] && return |
| 5649 | |
| 5650 | for fname in api master minion syndic; do |
| 5651 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 5652 | [ $fname = "api" ] && continue |
| 5653 | |
| 5654 | # Skip if not meant to be installed |
| 5655 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 5656 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 5657 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 5658 | |
| 5659 | if [ -f /bin/systemctl ]; then |
| 5660 | systemctl stop salt-$fname > /dev/null 2>&1 |
| 5661 | systemctl start salt-$fname.service |
| 5662 | continue |
| 5663 | fi |
| 5664 | |
| 5665 | service salt-$fname stop > /dev/null 2>&1 |
| 5666 | service salt-$fname start |
| 5667 | done |
| 5668 | } |
| 5669 | |
| 5670 | install_opensuse_check_services() { |
| 5671 | if [ ! -f /bin/systemctl ]; then |
| 5672 | # Not running systemd!? Don't check! |
| 5673 | return 0 |
| 5674 | fi |
| 5675 | |
| 5676 | for fname in api master minion syndic; do |
| 5677 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 5678 | [ $fname = "api" ] && continue |
| 5679 | |
| 5680 | # Skip if not meant to be installed |
| 5681 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 5682 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 5683 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 5684 | |
| 5685 | __check_services_systemd salt-$fname > /dev/null 2>&1 || __check_services_systemd salt-$fname.service > /dev/null 2>&1 || return 1 |
| 5686 | done |
| 5687 | |
| 5688 | return 0 |
| 5689 | } |
| 5690 | # |
| 5691 | # End of openSUSE Install Functions. |
| 5692 | # |
| 5693 | ####################################################################################################################### |
| 5694 | |
| 5695 | ####################################################################################################################### |
| 5696 | # |
| 5697 | # SUSE Enterprise 12 |
| 5698 | # |
| 5699 | |
| 5700 | install_suse_12_stable_deps() { |
| 5701 | if [ $_DISABLE_REPOS -eq $BS_FALSE ]; then |
| 5702 | # Is the repository already known |
| 5703 | __set_suse_pkg_repo |
| 5704 | # Check zypper repos and refresh if necessary |
| 5705 | __check_and_refresh_suse_pkg_repo |
| 5706 | fi |
| 5707 | |
| 5708 | __zypper --gpg-auto-import-keys refresh || return 1 |
| 5709 | |
| 5710 | if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then |
| 5711 | __zypper --gpg-auto-import-keys update || return 1 |
| 5712 | fi |
| 5713 | |
| 5714 | # YAML module is used for generating custom master/minion configs |
| 5715 | # requests is still used by many salt modules |
| 5716 | # Salt needs python-zypp installed in order to use the zypper module |
| 5717 | __PACKAGES="python-PyYAML python-requests python-zypp" |
| 5718 | |
| 5719 | if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then |
| 5720 | __PACKAGES="${__PACKAGES} python-apache-libcloud" |
| 5721 | fi |
| 5722 | |
| 5723 | # shellcheck disable=SC2086,SC2090 |
| 5724 | __zypper_install ${__PACKAGES} || return 1 |
| 5725 | |
| 5726 | if [ "${_EXTRA_PACKAGES}" != "" ]; then |
| 5727 | echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" |
| 5728 | # shellcheck disable=SC2086 |
| 5729 | __zypper_install ${_EXTRA_PACKAGES} || return 1 |
| 5730 | fi |
| 5731 | |
| 5732 | return 0 |
| 5733 | } |
| 5734 | |
| 5735 | install_suse_12_git_deps() { |
| 5736 | install_suse_12_stable_deps || return 1 |
| 5737 | |
| 5738 | if ! __check_command_exists git; then |
| 5739 | __zypper_install git || return 1 |
| 5740 | fi |
| 5741 | |
| 5742 | __git_clone_and_checkout || return 1 |
| 5743 | |
| 5744 | __PACKAGES="" |
| 5745 | # shellcheck disable=SC2089 |
| 5746 | __PACKAGES="${__PACKAGES} libzmq3 python-Jinja2 python-msgpack-python python-pycrypto" |
| 5747 | __PACKAGES="${__PACKAGES} python-pyzmq python-xml" |
| 5748 | |
| 5749 | if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then |
| 5750 | # We're on the develop branch, install whichever tornado is on the requirements file |
| 5751 | __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" |
| 5752 | if [ "${__REQUIRED_TORNADO}" != "" ]; then |
| 5753 | __PACKAGES="${__PACKAGES} python-tornado" |
| 5754 | fi |
| 5755 | fi |
| 5756 | |
| 5757 | if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then |
| 5758 | __PACKAGES="${__PACKAGES} python-apache-libcloud" |
| 5759 | fi |
| 5760 | |
| 5761 | # shellcheck disable=SC2086 |
| 5762 | __zypper_install ${__PACKAGES} || return 1 |
| 5763 | |
| 5764 | # Let's trigger config_salt() |
| 5765 | if [ "$_TEMP_CONFIG_DIR" = "null" ]; then |
| 5766 | _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" |
| 5767 | CONFIG_SALT_FUNC="config_salt" |
| 5768 | fi |
| 5769 | |
| 5770 | return 0 |
| 5771 | } |
| 5772 | |
| 5773 | install_suse_12_stable() { |
| 5774 | install_opensuse_stable || return 1 |
| 5775 | return 0 |
| 5776 | } |
| 5777 | |
| 5778 | install_suse_12_git() { |
| 5779 | install_opensuse_git || return 1 |
| 5780 | return 0 |
| 5781 | } |
| 5782 | |
| 5783 | install_suse_12_stable_post() { |
| 5784 | install_opensuse_stable_post || return 1 |
| 5785 | return 0 |
| 5786 | } |
| 5787 | |
| 5788 | install_suse_12_git_post() { |
| 5789 | install_opensuse_git_post || return 1 |
| 5790 | return 0 |
| 5791 | } |
| 5792 | |
| 5793 | install_suse_12_restart_daemons() { |
| 5794 | install_opensuse_restart_daemons || return 1 |
| 5795 | return 0 |
| 5796 | } |
| 5797 | |
| 5798 | # |
| 5799 | # End of SUSE Enterprise 12 |
| 5800 | # |
| 5801 | ####################################################################################################################### |
| 5802 | |
| 5803 | ####################################################################################################################### |
| 5804 | # |
| 5805 | # SUSE Enterprise 11 |
| 5806 | # |
| 5807 | |
| 5808 | install_suse_11_stable_deps() { |
| 5809 | if [ $_DISABLE_REPOS -eq $BS_FALSE ]; then |
| 5810 | # Is the repository already known |
| 5811 | __set_suse_pkg_repo |
| 5812 | # Check zypper repos and refresh if necessary |
| 5813 | __check_and_refresh_suse_pkg_repo |
| 5814 | fi |
| 5815 | |
| 5816 | __zypper --gpg-auto-import-keys refresh || return 1 |
| 5817 | |
| 5818 | if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then |
| 5819 | __zypper --gpg-auto-import-keys update || return 1 |
| 5820 | fi |
| 5821 | |
| 5822 | # YAML module is used for generating custom master/minion configs |
| 5823 | __PACKAGES="python-PyYAML" |
| 5824 | |
| 5825 | # shellcheck disable=SC2086,SC2090 |
| 5826 | __zypper_install ${__PACKAGES} || return 1 |
| 5827 | |
| 5828 | if [ "${_EXTRA_PACKAGES}" != "" ]; then |
| 5829 | echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" |
| 5830 | # shellcheck disable=SC2086 |
| 5831 | __zypper_install ${_EXTRA_PACKAGES} || return 1 |
| 5832 | fi |
| 5833 | |
| 5834 | return 0 |
| 5835 | } |
| 5836 | |
| 5837 | install_suse_11_git_deps() { |
| 5838 | install_suse_11_stable_deps || return 1 |
| 5839 | |
| 5840 | if ! __check_command_exists git; then |
| 5841 | __zypper_install git || return 1 |
| 5842 | fi |
| 5843 | |
| 5844 | __git_clone_and_checkout || return 1 |
| 5845 | |
| 5846 | __PACKAGES="" |
| 5847 | # shellcheck disable=SC2089 |
| 5848 | __PACKAGES="${__PACKAGES} libzmq4 python-Jinja2 python-msgpack-python python-pycrypto" |
| 5849 | __PACKAGES="${__PACKAGES} python-pyzmq python-xml python-zypp" |
| 5850 | |
| 5851 | if [ -f "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt" ]; then |
| 5852 | # We're on the develop branch, install whichever tornado is on the requirements file |
| 5853 | __REQUIRED_TORNADO="$(grep tornado "${_SALT_GIT_CHECKOUT_DIR}/requirements/base.txt")" |
| 5854 | if [ "${__REQUIRED_TORNADO}" != "" ]; then |
| 5855 | __PACKAGES="${__PACKAGES} python-tornado" |
| 5856 | fi |
| 5857 | fi |
| 5858 | |
| 5859 | if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then |
| 5860 | __PACKAGES="${__PACKAGES} python-apache-libcloud" |
| 5861 | fi |
| 5862 | |
| 5863 | # shellcheck disable=SC2086 |
| 5864 | __zypper_install ${__PACKAGES} || return 1 |
| 5865 | |
| 5866 | # Let's trigger config_salt() |
| 5867 | if [ "$_TEMP_CONFIG_DIR" = "null" ]; then |
| 5868 | _TEMP_CONFIG_DIR="${_SALT_GIT_CHECKOUT_DIR}/conf/" |
| 5869 | CONFIG_SALT_FUNC="config_salt" |
| 5870 | fi |
| 5871 | |
| 5872 | return 0 |
| 5873 | } |
| 5874 | |
| 5875 | install_suse_11_stable() { |
| 5876 | install_opensuse_stable || return 1 |
| 5877 | return 0 |
| 5878 | } |
| 5879 | |
| 5880 | install_suse_11_git() { |
| 5881 | install_opensuse_git || return 1 |
| 5882 | return 0 |
| 5883 | } |
| 5884 | |
| 5885 | install_suse_11_stable_post() { |
| 5886 | install_opensuse_stable_post || return 1 |
| 5887 | return 0 |
| 5888 | } |
| 5889 | |
| 5890 | install_suse_11_git_post() { |
| 5891 | install_opensuse_git_post || return 1 |
| 5892 | return 0 |
| 5893 | } |
| 5894 | |
| 5895 | install_suse_11_restart_daemons() { |
| 5896 | install_opensuse_restart_daemons || return 1 |
| 5897 | return 0 |
| 5898 | } |
| 5899 | |
| 5900 | |
| 5901 | # |
| 5902 | # End of SUSE Enterprise 11 |
| 5903 | # |
| 5904 | ####################################################################################################################### |
| 5905 | |
| 5906 | ####################################################################################################################### |
| 5907 | # |
| 5908 | # SUSE Enterprise General Functions |
| 5909 | # |
| 5910 | |
| 5911 | # Used for both SLE 11 and 12 |
| 5912 | install_suse_check_services() { |
| 5913 | if [ ! -f /bin/systemctl ]; then |
| 5914 | # Not running systemd!? Don't check! |
| 5915 | return 0 |
| 5916 | fi |
| 5917 | |
| 5918 | for fname in api master minion syndic; do |
| 5919 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 5920 | [ $fname = "api" ] && continue |
| 5921 | |
| 5922 | # Skip if not meant to be installed |
| 5923 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 5924 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 5925 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 5926 | |
| 5927 | __check_services_systemd salt-$fname || return 1 |
| 5928 | done |
| 5929 | |
| 5930 | return 0 |
| 5931 | } |
| 5932 | |
| 5933 | # |
| 5934 | # End of SUSE Enterprise General Functions |
| 5935 | # |
| 5936 | ####################################################################################################################### |
| 5937 | |
| 5938 | ####################################################################################################################### |
| 5939 | # |
| 5940 | # Gentoo Install Functions. |
| 5941 | # |
| 5942 | __autounmask() { |
| 5943 | emerge --autounmask-write --autounmask-only "${@}"; return $? |
| 5944 | } |
| 5945 | |
| 5946 | __emerge() { |
| 5947 | if [ "$_GENTOO_USE_BINHOST" -eq $BS_TRUE ]; then |
| 5948 | emerge --getbinpkg "${@}"; return $? |
| 5949 | fi |
| 5950 | emerge "${@}"; return $? |
| 5951 | } |
| 5952 | |
| 5953 | __gentoo_config_protection() { |
| 5954 | # usually it's a good thing to have config files protected by portage, but |
| 5955 | # in this case this would require to interrupt the bootstrapping script at |
| 5956 | # this point, manually merge the changes using etc-update/dispatch-conf/ |
| 5957 | # cfg-update and then restart the bootstrapping script, so instead we allow |
| 5958 | # at this point to modify certain config files directly |
| 5959 | 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" |
| 5960 | |
| 5961 | # emerge currently won't write to files that aren't there, so we need to ensure their presence |
| 5962 | touch /etc/portage/package.accept_keywords /etc/portage/package.keywords /etc/portage/package.license /etc/portage/package.unmask /etc/portage/package.use |
| 5963 | } |
| 5964 | |
| 5965 | __gentoo_pre_dep() { |
| 5966 | if [ "$_ECHO_DEBUG" -eq $BS_TRUE ]; then |
| 5967 | if __check_command_exists eix; then |
| 5968 | eix-sync |
| 5969 | else |
| 5970 | emerge --sync |
| 5971 | fi |
| 5972 | else |
| 5973 | if __check_command_exists eix; then |
| 5974 | eix-sync -q |
| 5975 | else |
| 5976 | emerge --sync --quiet |
| 5977 | fi |
| 5978 | fi |
| 5979 | if [ ! -d /etc/portage ]; then |
| 5980 | mkdir /etc/portage |
| 5981 | fi |
| 5982 | } |
| 5983 | |
| 5984 | __gentoo_post_dep() { |
| 5985 | # ensures dev-lib/crypto++ compiles happily |
| 5986 | __emerge --oneshot 'sys-devel/libtool' |
| 5987 | # the -o option asks it to emerge the deps but not the package. |
| 5988 | __gentoo_config_protection |
| 5989 | |
| 5990 | if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then |
| 5991 | __autounmask 'dev-python/libcloud' |
| 5992 | __emerge -v 'dev-python/libcloud' |
| 5993 | fi |
| 5994 | |
| 5995 | __autounmask 'dev-python/requests' |
| 5996 | __autounmask 'app-admin/salt' |
| 5997 | |
| 5998 | __emerge -vo 'dev-python/requests' |
| 5999 | __emerge -vo 'app-admin/salt' |
| 6000 | |
| 6001 | if [ "${_EXTRA_PACKAGES}" != "" ]; then |
| 6002 | echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" |
| 6003 | # shellcheck disable=SC2086 |
| 6004 | __autounmask ${_EXTRA_PACKAGES} || return 1 |
| 6005 | # shellcheck disable=SC2086 |
| 6006 | __emerge -v ${_EXTRA_PACKAGES} || return 1 |
| 6007 | fi |
| 6008 | } |
| 6009 | |
| 6010 | install_gentoo_deps() { |
| 6011 | __gentoo_pre_dep || return 1 |
| 6012 | __gentoo_post_dep || return 1 |
| 6013 | } |
| 6014 | |
| 6015 | install_gentoo_git_deps() { |
| 6016 | __gentoo_pre_dep || return 1 |
| 6017 | __gentoo_post_dep || return 1 |
| 6018 | } |
| 6019 | |
| 6020 | install_gentoo_stable() { |
| 6021 | __gentoo_config_protection |
| 6022 | __emerge -v 'app-admin/salt' || return 1 |
| 6023 | } |
| 6024 | |
| 6025 | install_gentoo_git() { |
| 6026 | __gentoo_config_protection |
| 6027 | __emerge -v '=app-admin/salt-9999' || return 1 |
| 6028 | } |
| 6029 | |
| 6030 | install_gentoo_post() { |
| 6031 | for fname in api master minion syndic; do |
| 6032 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 6033 | [ $fname = "api" ] && continue |
| 6034 | |
| 6035 | # Skip if not meant to be installed |
| 6036 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 6037 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 6038 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 6039 | |
| 6040 | if [ -d "/run/systemd/system" ]; then |
| 6041 | systemctl enable salt-$fname.service |
| 6042 | systemctl start salt-$fname.service |
| 6043 | else |
| 6044 | rc-update add salt-$fname default |
| 6045 | /etc/init.d/salt-$fname start |
| 6046 | fi |
| 6047 | done |
| 6048 | } |
| 6049 | |
| 6050 | install_gentoo_restart_daemons() { |
| 6051 | [ $_START_DAEMONS -eq $BS_FALSE ] && return |
| 6052 | |
| 6053 | for fname in api master minion syndic; do |
| 6054 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 6055 | [ $fname = "api" ] && continue |
| 6056 | |
| 6057 | # Skip if not meant to be installed |
| 6058 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 6059 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 6060 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 6061 | |
| 6062 | if [ -d "/run/systemd/system" ]; then |
| 6063 | systemctl stop salt-$fname > /dev/null 2>&1 |
| 6064 | systemctl start salt-$fname.service |
| 6065 | else |
| 6066 | /etc/init.d/salt-$fname stop > /dev/null 2>&1 |
| 6067 | /etc/init.d/salt-$fname start |
| 6068 | fi |
| 6069 | done |
| 6070 | } |
| 6071 | |
| 6072 | install_gentoo_check_services() { |
| 6073 | if [ ! -d "/run/systemd/system" ]; then |
| 6074 | # Not running systemd!? Don't check! |
| 6075 | return 0 |
| 6076 | fi |
| 6077 | |
| 6078 | for fname in api master minion syndic; do |
| 6079 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 6080 | [ $fname = "api" ] && continue |
| 6081 | |
| 6082 | # Skip if not meant to be installed |
| 6083 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 6084 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 6085 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 6086 | |
| 6087 | __check_services_systemd salt-$fname || return 1 |
| 6088 | done |
| 6089 | |
| 6090 | return 0 |
| 6091 | } |
| 6092 | # |
| 6093 | # End of Gentoo Install Functions. |
| 6094 | # |
| 6095 | ####################################################################################################################### |
| 6096 | |
| 6097 | ####################################################################################################################### |
| 6098 | # |
| 6099 | # VoidLinux Install Functions |
| 6100 | # |
| 6101 | install_voidlinux_stable_deps() { |
| 6102 | if [ "$_UPGRADE_SYS" -eq $BS_TRUE ]; then |
| 6103 | xbps-install -Suy || return 1 |
| 6104 | fi |
| 6105 | |
| 6106 | if [ "${_EXTRA_PACKAGES}" != "" ]; then |
| 6107 | echoinfo "Installing the following extra packages as requested: ${_EXTRA_PACKAGES}" |
| 6108 | xbps-install -Suy "${_EXTRA_PACKAGES}" || return 1 |
| 6109 | fi |
| 6110 | |
| 6111 | return 0 |
| 6112 | } |
| 6113 | |
| 6114 | install_voidlinux_stable() { |
| 6115 | xbps-install -Suy salt || return 1 |
| 6116 | return 0 |
| 6117 | } |
| 6118 | |
| 6119 | install_voidlinux_stable_post() { |
| 6120 | for fname in master minion syndic; do |
| 6121 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 6122 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 6123 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 6124 | |
| 6125 | ln -s /etc/sv/salt-$fname /var/service/. |
| 6126 | done |
| 6127 | } |
| 6128 | |
| 6129 | install_voidlinux_restart_daemons() { |
| 6130 | [ $_START_DAEMONS -eq $BS_FALSE ] && return |
| 6131 | |
| 6132 | for fname in master minion syndic; do |
| 6133 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 6134 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 6135 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 6136 | |
| 6137 | sv restart salt-$fname |
| 6138 | done |
| 6139 | } |
| 6140 | |
| 6141 | install_voidlinux_check_services() { |
| 6142 | for fname in master minion syndic; do |
| 6143 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 6144 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 6145 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 6146 | |
| 6147 | [ -e /var/service/salt-$fname ] || return 1 |
| 6148 | done |
| 6149 | |
| 6150 | return 0 |
| 6151 | } |
| 6152 | |
| 6153 | daemons_running_voidlinux() { |
| 6154 | [ "$_START_DAEMONS" -eq $BS_FALSE ] && return 0 |
| 6155 | |
| 6156 | FAILED_DAEMONS=0 |
| 6157 | for fname in master minion syndic; do |
| 6158 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 6159 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 6160 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 6161 | |
| 6162 | if [ "$(sv status salt-$fname | grep run)" = "" ]; then |
| 6163 | echoerror "salt-$fname was not found running" |
| 6164 | FAILED_DAEMONS=$((FAILED_DAEMONS + 1)) |
| 6165 | fi |
| 6166 | done |
| 6167 | |
| 6168 | return $FAILED_DAEMONS |
| 6169 | } |
| 6170 | # |
| 6171 | # Ended VoidLinux Install Functions |
| 6172 | # |
| 6173 | ####################################################################################################################### |
| 6174 | |
| 6175 | ####################################################################################################################### |
| 6176 | # |
| 6177 | # Default minion configuration function. Matches ANY distribution as long as |
| 6178 | # the -c options is passed. |
| 6179 | # |
| 6180 | config_salt() { |
| 6181 | # If the configuration directory is not passed, return |
| 6182 | [ "$_TEMP_CONFIG_DIR" = "null" ] && return |
| 6183 | |
| 6184 | if [ "$_CONFIG_ONLY" -eq $BS_TRUE ]; then |
| 6185 | echowarn "Passing -C (config only) option implies -F (forced overwrite)." |
| 6186 | |
| 6187 | if [ "$_FORCE_OVERWRITE" -ne $BS_TRUE ]; then |
| 6188 | echowarn "Overwriting configs in 11 seconds!" |
| 6189 | sleep 11 |
| 6190 | _FORCE_OVERWRITE=$BS_TRUE |
| 6191 | fi |
| 6192 | fi |
| 6193 | |
| 6194 | # Let's create the necessary directories |
| 6195 | [ -d "$_SALT_ETC_DIR" ] || mkdir "$_SALT_ETC_DIR" || return 1 |
| 6196 | [ -d "$_PKI_DIR" ] || (mkdir -p "$_PKI_DIR" && chmod 700 "$_PKI_DIR") || return 1 |
| 6197 | |
| 6198 | # If -C or -F was passed, we don't need a .bak file for the config we're updating |
| 6199 | # This is used in the custom master/minion config file checks below |
| 6200 | CREATE_BAK=$BS_TRUE |
| 6201 | if [ "$_FORCE_OVERWRITE" -eq $BS_TRUE ]; then |
| 6202 | CREATE_BAK=$BS_FALSE |
| 6203 | fi |
| 6204 | |
| 6205 | CONFIGURED_ANYTHING=$BS_FALSE |
| 6206 | |
| 6207 | # Copy the grains file if found |
| 6208 | if [ -f "$_TEMP_CONFIG_DIR/grains" ]; then |
| 6209 | echodebug "Moving provided grains file from $_TEMP_CONFIG_DIR/grains to $_SALT_ETC_DIR/grains" |
| 6210 | __movefile "$_TEMP_CONFIG_DIR/grains" "$_SALT_ETC_DIR/grains" || return 1 |
| 6211 | CONFIGURED_ANYTHING=$BS_TRUE |
| 6212 | fi |
| 6213 | |
| 6214 | if [ "$_INSTALL_MINION" -eq $BS_TRUE ] || \ |
| 6215 | [ "$_CONFIG_ONLY" -eq $BS_TRUE ] || [ "$_CUSTOM_MINION_CONFIG" != "null" ]; then |
| 6216 | # Create the PKI directory |
| 6217 | [ -d "$_PKI_DIR/minion" ] || (mkdir -p "$_PKI_DIR/minion" && chmod 700 "$_PKI_DIR/minion") || return 1 |
| 6218 | |
| 6219 | # Check to see if a custom minion config json dict was provided |
| 6220 | if [ "$_CUSTOM_MINION_CONFIG" != "null" ]; then |
| 6221 | |
| 6222 | # Check if a minion config file already exists and move to .bak if needed |
| 6223 | if [ -f "$_SALT_ETC_DIR/minion" ] && [ "$CREATE_BAK" -eq "$BS_TRUE" ]; then |
| 6224 | __movefile "$_SALT_ETC_DIR/minion" "$_SALT_ETC_DIR/minion.bak" $BS_TRUE || return 1 |
| 6225 | CONFIGURED_ANYTHING=$BS_TRUE |
| 6226 | fi |
| 6227 | |
| 6228 | # Overwrite/create the config file with the yaml string |
| 6229 | __overwriteconfig "$_SALT_ETC_DIR/minion" "$_CUSTOM_MINION_CONFIG" || return 1 |
| 6230 | CONFIGURED_ANYTHING=$BS_TRUE |
| 6231 | |
| 6232 | # Copy the minions configuration if found |
| 6233 | # Explicitly check for custom master config to avoid moving the minion config |
| 6234 | elif [ -f "$_TEMP_CONFIG_DIR/minion" ] && [ "$_CUSTOM_MASTER_CONFIG" = "null" ]; then |
| 6235 | __movefile "$_TEMP_CONFIG_DIR/minion" "$_SALT_ETC_DIR" "$_FORCE_OVERWRITE" || return 1 |
| 6236 | CONFIGURED_ANYTHING=$BS_TRUE |
| 6237 | fi |
| 6238 | |
| 6239 | # Copy the minion's keys if found |
| 6240 | if [ -f "$_TEMP_CONFIG_DIR/minion.pem" ]; then |
| 6241 | __movefile "$_TEMP_CONFIG_DIR/minion.pem" "$_PKI_DIR/minion/" "$_FORCE_OVERWRITE" || return 1 |
| 6242 | chmod 400 "$_PKI_DIR/minion/minion.pem" || return 1 |
| 6243 | CONFIGURED_ANYTHING=$BS_TRUE |
| 6244 | fi |
| 6245 | if [ -f "$_TEMP_CONFIG_DIR/minion.pub" ]; then |
| 6246 | __movefile "$_TEMP_CONFIG_DIR/minion.pub" "$_PKI_DIR/minion/" "$_FORCE_OVERWRITE" || return 1 |
| 6247 | chmod 664 "$_PKI_DIR/minion/minion.pub" || return 1 |
| 6248 | CONFIGURED_ANYTHING=$BS_TRUE |
| 6249 | fi |
| 6250 | # For multi-master-pki, copy the master_sign public key if found |
| 6251 | if [ -f "$_TEMP_CONFIG_DIR/master_sign.pub" ]; then |
| 6252 | __movefile "$_TEMP_CONFIG_DIR/master_sign.pub" "$_PKI_DIR/minion/" || return 1 |
| 6253 | chmod 664 "$_PKI_DIR/minion/master_sign.pub" || return 1 |
| 6254 | CONFIGURED_ANYTHING=$BS_TRUE |
| 6255 | fi |
| 6256 | fi |
| 6257 | |
| 6258 | # only (re)place master or syndic configs if -M (install master) or -S |
| 6259 | # (install syndic) specified |
| 6260 | OVERWRITE_MASTER_CONFIGS=$BS_FALSE |
| 6261 | if [ "$_INSTALL_MASTER" -eq $BS_TRUE ] && [ "$_CONFIG_ONLY" -eq $BS_TRUE ]; then |
| 6262 | OVERWRITE_MASTER_CONFIGS=$BS_TRUE |
| 6263 | fi |
| 6264 | if [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ] && [ "$_CONFIG_ONLY" -eq $BS_TRUE ]; then |
| 6265 | OVERWRITE_MASTER_CONFIGS=$BS_TRUE |
| 6266 | fi |
| 6267 | |
| 6268 | if [ "$_INSTALL_MASTER" -eq $BS_TRUE ] || [ "$_INSTALL_SYNDIC" -eq $BS_TRUE ] || [ "$OVERWRITE_MASTER_CONFIGS" -eq $BS_TRUE ] || [ "$_CUSTOM_MASTER_CONFIG" != "null" ]; then |
| 6269 | # Create the PKI directory |
| 6270 | [ -d "$_PKI_DIR/master" ] || (mkdir -p "$_PKI_DIR/master" && chmod 700 "$_PKI_DIR/master") || return 1 |
| 6271 | |
| 6272 | # Check to see if a custom master config json dict was provided |
| 6273 | if [ "$_CUSTOM_MASTER_CONFIG" != "null" ]; then |
| 6274 | |
| 6275 | # Check if a master config file already exists and move to .bak if needed |
| 6276 | if [ -f "$_SALT_ETC_DIR/master" ] && [ "$CREATE_BAK" -eq "$BS_TRUE" ]; then |
| 6277 | __movefile "$_SALT_ETC_DIR/master" "$_SALT_ETC_DIR/master.bak" $BS_TRUE || return 1 |
| 6278 | CONFIGURED_ANYTHING=$BS_TRUE |
| 6279 | fi |
| 6280 | |
| 6281 | # Overwrite/create the config file with the yaml string |
| 6282 | __overwriteconfig "$_SALT_ETC_DIR/master" "$_CUSTOM_MASTER_CONFIG" || return 1 |
| 6283 | CONFIGURED_ANYTHING=$BS_TRUE |
| 6284 | |
| 6285 | # Copy the masters configuration if found |
| 6286 | elif [ -f "$_TEMP_CONFIG_DIR/master" ]; then |
| 6287 | __movefile "$_TEMP_CONFIG_DIR/master" "$_SALT_ETC_DIR" || return 1 |
| 6288 | CONFIGURED_ANYTHING=$BS_TRUE |
| 6289 | fi |
| 6290 | |
| 6291 | # Copy the master's keys if found |
| 6292 | if [ -f "$_TEMP_CONFIG_DIR/master.pem" ]; then |
| 6293 | __movefile "$_TEMP_CONFIG_DIR/master.pem" "$_PKI_DIR/master/" || return 1 |
| 6294 | chmod 400 "$_PKI_DIR/master/master.pem" || return 1 |
| 6295 | CONFIGURED_ANYTHING=$BS_TRUE |
| 6296 | fi |
| 6297 | if [ -f "$_TEMP_CONFIG_DIR/master.pub" ]; then |
| 6298 | __movefile "$_TEMP_CONFIG_DIR/master.pub" "$_PKI_DIR/master/" || return 1 |
| 6299 | chmod 664 "$_PKI_DIR/master/master.pub" || return 1 |
| 6300 | CONFIGURED_ANYTHING=$BS_TRUE |
| 6301 | fi |
| 6302 | fi |
| 6303 | |
| 6304 | if [ "$_INSTALL_CLOUD" -eq $BS_TRUE ]; then |
| 6305 | # Recursively copy salt-cloud configs with overwriting if necessary |
| 6306 | for file in "$_TEMP_CONFIG_DIR"/cloud*; do |
| 6307 | if [ -f "$file" ]; then |
| 6308 | __copyfile "$file" "$_SALT_ETC_DIR" || return 1 |
| 6309 | elif [ -d "$file" ]; then |
| 6310 | subdir="$(basename "$file")" |
| 6311 | mkdir -p "$_SALT_ETC_DIR/$subdir" |
| 6312 | for file_d in "$_TEMP_CONFIG_DIR/$subdir"/*; do |
| 6313 | if [ -f "$file_d" ]; then |
| 6314 | __copyfile "$file_d" "$_SALT_ETC_DIR/$subdir" || return 1 |
| 6315 | fi |
| 6316 | done |
| 6317 | fi |
| 6318 | done |
| 6319 | fi |
| 6320 | |
| 6321 | if [ "$_CONFIG_ONLY" -eq $BS_TRUE ] && [ $CONFIGURED_ANYTHING -eq $BS_FALSE ]; then |
| 6322 | echowarn "No configuration or keys were copied over. No configuration was done!" |
| 6323 | exit 0 |
| 6324 | fi |
| 6325 | |
| 6326 | return 0 |
| 6327 | } |
| 6328 | # |
| 6329 | # Ended Default Configuration function |
| 6330 | # |
| 6331 | ####################################################################################################################### |
| 6332 | |
| 6333 | ####################################################################################################################### |
| 6334 | # |
| 6335 | # Default salt master minion keys pre-seed function. Matches ANY distribution |
| 6336 | # as long as the -k option is passed. |
| 6337 | # |
| 6338 | preseed_master() { |
| 6339 | # Create the PKI directory |
| 6340 | |
| 6341 | if [ "$(find "$_TEMP_KEYS_DIR" -maxdepth 1 -type f | wc -l)" -lt 1 ]; then |
| 6342 | echoerror "No minion keys were uploaded. Unable to pre-seed master" |
| 6343 | return 1 |
| 6344 | fi |
| 6345 | |
| 6346 | SEED_DEST="$_PKI_DIR/master/minions" |
| 6347 | [ -d "$SEED_DEST" ] || (mkdir -p "$SEED_DEST" && chmod 700 "$SEED_DEST") || return 1 |
| 6348 | |
| 6349 | for keyfile in $_TEMP_KEYS_DIR/*; do |
| 6350 | keyfile=$(basename "${keyfile}") |
| 6351 | src_keyfile="${_TEMP_KEYS_DIR}/${keyfile}" |
| 6352 | dst_keyfile="${SEED_DEST}/${keyfile}" |
| 6353 | |
| 6354 | # If it's not a file, skip to the next |
| 6355 | [ ! -f "$src_keyfile" ] && continue |
| 6356 | |
| 6357 | __movefile "$src_keyfile" "$dst_keyfile" || return 1 |
| 6358 | chmod 664 "$dst_keyfile" || return 1 |
| 6359 | done |
| 6360 | |
| 6361 | return 0 |
| 6362 | } |
| 6363 | # |
| 6364 | # Ended Default Salt Master Pre-Seed minion keys function |
| 6365 | # |
| 6366 | ####################################################################################################################### |
| 6367 | |
| 6368 | ####################################################################################################################### |
| 6369 | # |
| 6370 | # This function checks if all of the installed daemons are running or not. |
| 6371 | # |
| 6372 | daemons_running() { |
| 6373 | [ "$_START_DAEMONS" -eq $BS_FALSE ] && return 0 |
| 6374 | |
| 6375 | FAILED_DAEMONS=0 |
| 6376 | for fname in api master minion syndic; do |
| 6377 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 6378 | [ $fname = "api" ] && continue |
| 6379 | |
| 6380 | # Skip if not meant to be installed |
| 6381 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 6382 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 6383 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 6384 | |
| 6385 | # shellcheck disable=SC2009 |
| 6386 | if [ "${DISTRO_NAME}" = "SmartOS" ]; then |
| 6387 | if [ "$(svcs -Ho STA salt-$fname)" != "ON" ]; then |
| 6388 | echoerror "salt-$fname was not found running" |
| 6389 | FAILED_DAEMONS=$((FAILED_DAEMONS + 1)) |
| 6390 | fi |
| 6391 | elif [ "$(ps wwwaux | grep -v grep | grep salt-$fname)" = "" ]; then |
| 6392 | echoerror "salt-$fname was not found running" |
| 6393 | FAILED_DAEMONS=$((FAILED_DAEMONS + 1)) |
| 6394 | fi |
| 6395 | done |
| 6396 | |
| 6397 | return $FAILED_DAEMONS |
| 6398 | } |
| 6399 | # |
| 6400 | # Ended daemons running check function |
| 6401 | # |
| 6402 | ####################################################################################################################### |
| 6403 | |
| 6404 | #====================================================================================================================== |
| 6405 | # LET'S PROCEED WITH OUR INSTALLATION |
| 6406 | #====================================================================================================================== |
| 6407 | |
| 6408 | # Let's get the dependencies install function |
| 6409 | if [ ${_NO_DEPS} -eq $BS_FALSE ]; then |
| 6410 | DEP_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_deps" |
| 6411 | DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_deps" |
| 6412 | DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_deps" |
| 6413 | DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_deps" |
| 6414 | DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}_deps" |
| 6415 | DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}_deps" |
| 6416 | elif [ "${ITYPE}" = "git" ]; then |
| 6417 | DEP_FUNC_NAMES="__git_clone_and_checkout" |
| 6418 | else |
| 6419 | DEP_FUNC_NAMES="" |
| 6420 | fi |
| 6421 | |
| 6422 | DEPS_INSTALL_FUNC="null" |
| 6423 | for FUNC_NAME in $(__strip_duplicates "$DEP_FUNC_NAMES"); do |
| 6424 | if __function_defined "$FUNC_NAME"; then |
| 6425 | DEPS_INSTALL_FUNC="$FUNC_NAME" |
| 6426 | break |
| 6427 | fi |
| 6428 | done |
| 6429 | echodebug "DEPS_INSTALL_FUNC=${DEPS_INSTALL_FUNC}" |
| 6430 | |
| 6431 | # Let's get the Salt config function |
| 6432 | CONFIG_FUNC_NAMES="config_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_salt" |
| 6433 | CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_salt" |
| 6434 | CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_salt" |
| 6435 | CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_salt" |
| 6436 | CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}_${ITYPE}_salt" |
| 6437 | CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}_salt" |
| 6438 | CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_salt" |
| 6439 | |
| 6440 | CONFIG_SALT_FUNC="null" |
| 6441 | for FUNC_NAME in $(__strip_duplicates "$CONFIG_FUNC_NAMES"); do |
| 6442 | if __function_defined "$FUNC_NAME"; then |
| 6443 | CONFIG_SALT_FUNC="$FUNC_NAME" |
| 6444 | break |
| 6445 | fi |
| 6446 | done |
| 6447 | echodebug "CONFIG_SALT_FUNC=${CONFIG_SALT_FUNC}" |
| 6448 | |
| 6449 | # Let's get the pre-seed master function |
| 6450 | PRESEED_FUNC_NAMES="preseed_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_master" |
| 6451 | PRESEED_FUNC_NAMES="$PRESEED_FUNC_NAMES preseed_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_master" |
| 6452 | PRESEED_FUNC_NAMES="$PRESEED_FUNC_NAMES preseed_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_master" |
| 6453 | PRESEED_FUNC_NAMES="$PRESEED_FUNC_NAMES preseed_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_master" |
| 6454 | PRESEED_FUNC_NAMES="$PRESEED_FUNC_NAMES preseed_${DISTRO_NAME_L}_${ITYPE}_master" |
| 6455 | PRESEED_FUNC_NAMES="$PRESEED_FUNC_NAMES preseed_${DISTRO_NAME_L}_master" |
| 6456 | PRESEED_FUNC_NAMES="$PRESEED_FUNC_NAMES preseed_master" |
| 6457 | |
| 6458 | PRESEED_MASTER_FUNC="null" |
| 6459 | for FUNC_NAME in $(__strip_duplicates "$PRESEED_FUNC_NAMES"); do |
| 6460 | if __function_defined "$FUNC_NAME"; then |
| 6461 | PRESEED_MASTER_FUNC="$FUNC_NAME" |
| 6462 | break |
| 6463 | fi |
| 6464 | done |
| 6465 | echodebug "PRESEED_MASTER_FUNC=${PRESEED_MASTER_FUNC}" |
| 6466 | |
| 6467 | # Let's get the install function |
| 6468 | INSTALL_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}" |
| 6469 | INSTALL_FUNC_NAMES="$INSTALL_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}" |
| 6470 | INSTALL_FUNC_NAMES="$INSTALL_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}" |
| 6471 | |
| 6472 | INSTALL_FUNC="null" |
| 6473 | for FUNC_NAME in $(__strip_duplicates "$INSTALL_FUNC_NAMES"); do |
| 6474 | if __function_defined "$FUNC_NAME"; then |
| 6475 | INSTALL_FUNC="$FUNC_NAME" |
| 6476 | break |
| 6477 | fi |
| 6478 | done |
| 6479 | echodebug "INSTALL_FUNC=${INSTALL_FUNC}" |
| 6480 | |
| 6481 | # Let's get the post install function |
| 6482 | POST_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_post" |
| 6483 | POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_post" |
| 6484 | POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_post" |
| 6485 | POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_post" |
| 6486 | POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}_post" |
| 6487 | POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}_post" |
| 6488 | |
| 6489 | POST_INSTALL_FUNC="null" |
| 6490 | for FUNC_NAME in $(__strip_duplicates "$POST_FUNC_NAMES"); do |
| 6491 | if __function_defined "$FUNC_NAME"; then |
| 6492 | POST_INSTALL_FUNC="$FUNC_NAME" |
| 6493 | break |
| 6494 | fi |
| 6495 | done |
| 6496 | echodebug "POST_INSTALL_FUNC=${POST_INSTALL_FUNC}" |
| 6497 | |
| 6498 | # Let's get the start daemons install function |
| 6499 | STARTDAEMONS_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_restart_daemons" |
| 6500 | STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_restart_daemons" |
| 6501 | STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_restart_daemons" |
| 6502 | STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_restart_daemons" |
| 6503 | STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}_restart_daemons" |
| 6504 | STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}_restart_daemons" |
| 6505 | |
| 6506 | STARTDAEMONS_INSTALL_FUNC="null" |
| 6507 | for FUNC_NAME in $(__strip_duplicates "$STARTDAEMONS_FUNC_NAMES"); do |
| 6508 | if __function_defined "$FUNC_NAME"; then |
| 6509 | STARTDAEMONS_INSTALL_FUNC="$FUNC_NAME" |
| 6510 | break |
| 6511 | fi |
| 6512 | done |
| 6513 | echodebug "STARTDAEMONS_INSTALL_FUNC=${STARTDAEMONS_INSTALL_FUNC}" |
| 6514 | |
| 6515 | # Let's get the daemons running check function. |
| 6516 | DAEMONS_RUNNING_FUNC_NAMES="daemons_running_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}" |
| 6517 | DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}" |
| 6518 | DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}" |
| 6519 | DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}" |
| 6520 | DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running_${DISTRO_NAME_L}_${ITYPE}" |
| 6521 | DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running_${DISTRO_NAME_L}" |
| 6522 | DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running" |
| 6523 | |
| 6524 | DAEMONS_RUNNING_FUNC="null" |
| 6525 | for FUNC_NAME in $(__strip_duplicates "$DAEMONS_RUNNING_FUNC_NAMES"); do |
| 6526 | if __function_defined "$FUNC_NAME"; then |
| 6527 | DAEMONS_RUNNING_FUNC="$FUNC_NAME" |
| 6528 | break |
| 6529 | fi |
| 6530 | done |
| 6531 | echodebug "DAEMONS_RUNNING_FUNC=${DAEMONS_RUNNING_FUNC}" |
| 6532 | |
| 6533 | # Let's get the check services function |
| 6534 | if [ ${_DISABLE_SALT_CHECKS} -eq $BS_FALSE ]; then |
| 6535 | CHECK_SERVICES_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_check_services" |
| 6536 | CHECK_SERVICES_FUNC_NAMES="$CHECK_SERVICES_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_check_services" |
| 6537 | CHECK_SERVICES_FUNC_NAMES="$CHECK_SERVICES_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_check_services" |
| 6538 | CHECK_SERVICES_FUNC_NAMES="$CHECK_SERVICES_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_check_services" |
| 6539 | CHECK_SERVICES_FUNC_NAMES="$CHECK_SERVICES_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}_check_services" |
| 6540 | CHECK_SERVICES_FUNC_NAMES="$CHECK_SERVICES_FUNC_NAMES install_${DISTRO_NAME_L}_check_services" |
| 6541 | else |
| 6542 | CHECK_SERVICES_FUNC_NAMES="" |
| 6543 | fi |
| 6544 | |
| 6545 | CHECK_SERVICES_FUNC="null" |
| 6546 | for FUNC_NAME in $(__strip_duplicates "$CHECK_SERVICES_FUNC_NAMES"); do |
| 6547 | if __function_defined "$FUNC_NAME"; then |
| 6548 | CHECK_SERVICES_FUNC="$FUNC_NAME" |
| 6549 | break |
| 6550 | fi |
| 6551 | done |
| 6552 | echodebug "CHECK_SERVICES_FUNC=${CHECK_SERVICES_FUNC}" |
| 6553 | |
| 6554 | if [ ${_NO_DEPS} -eq $BS_FALSE ] && [ "$DEPS_INSTALL_FUNC" = "null" ]; then |
| 6555 | echoerror "No dependencies installation function found. Exiting..." |
| 6556 | exit 1 |
| 6557 | fi |
| 6558 | |
| 6559 | if [ "$INSTALL_FUNC" = "null" ]; then |
| 6560 | echoerror "No installation function found. Exiting..." |
| 6561 | exit 1 |
| 6562 | fi |
| 6563 | |
| 6564 | # Install dependencies |
| 6565 | if [ ${_NO_DEPS} -eq $BS_FALSE ] && [ $_CONFIG_ONLY -eq $BS_FALSE ]; then |
| 6566 | # Only execute function is not in config mode only |
| 6567 | echoinfo "Running ${DEPS_INSTALL_FUNC}()" |
| 6568 | $DEPS_INSTALL_FUNC |
| 6569 | if [ $? -ne 0 ]; then |
| 6570 | echoerror "Failed to run ${DEPS_INSTALL_FUNC}()!!!" |
| 6571 | exit 1 |
| 6572 | fi |
| 6573 | fi |
| 6574 | |
| 6575 | # Triggering config_salt() if overwriting master or minion configs |
| 6576 | if [ "$_CUSTOM_MASTER_CONFIG" != "null" ] || [ "$_CUSTOM_MINION_CONFIG" != "null" ]; then |
| 6577 | if [ "$_TEMP_CONFIG_DIR" = "null" ]; then |
| 6578 | _TEMP_CONFIG_DIR="$_SALT_ETC_DIR" |
| 6579 | fi |
| 6580 | |
| 6581 | if [ ${_NO_DEPS} -eq $BS_FALSE ] && [ $_CONFIG_ONLY -eq $BS_TRUE ]; then |
| 6582 | # Execute function to satisfy dependencies for configuration step |
| 6583 | echoinfo "Running ${DEPS_INSTALL_FUNC}()" |
| 6584 | $DEPS_INSTALL_FUNC |
| 6585 | if [ $? -ne 0 ]; then |
| 6586 | echoerror "Failed to run ${DEPS_INSTALL_FUNC}()!!!" |
| 6587 | exit 1 |
| 6588 | fi |
| 6589 | fi |
| 6590 | fi |
| 6591 | |
| 6592 | # Configure Salt |
| 6593 | if [ "$CONFIG_SALT_FUNC" != "null" ] && [ "$_TEMP_CONFIG_DIR" != "null" ]; then |
| 6594 | echoinfo "Running ${CONFIG_SALT_FUNC}()" |
| 6595 | $CONFIG_SALT_FUNC |
| 6596 | if [ $? -ne 0 ]; then |
| 6597 | echoerror "Failed to run ${CONFIG_SALT_FUNC}()!!!" |
| 6598 | exit 1 |
| 6599 | fi |
| 6600 | fi |
| 6601 | |
| 6602 | # Drop the master address if passed |
| 6603 | if [ "$_SALT_MASTER_ADDRESS" != "null" ]; then |
| 6604 | [ ! -d "$_SALT_ETC_DIR/minion.d" ] && mkdir -p "$_SALT_ETC_DIR/minion.d" |
| 6605 | cat <<_eof > $_SALT_ETC_DIR/minion.d/99-master-address.conf |
| 6606 | master: $_SALT_MASTER_ADDRESS |
| 6607 | _eof |
| 6608 | fi |
| 6609 | |
| 6610 | # Drop the minion id if passed |
| 6611 | if [ "$_SALT_MINION_ID" != "null" ]; then |
| 6612 | [ ! -d "$_SALT_ETC_DIR" ] && mkdir -p "$_SALT_ETC_DIR" |
| 6613 | echo "$_SALT_MINION_ID" > "$_SALT_ETC_DIR/minion_id" |
| 6614 | fi |
| 6615 | |
| 6616 | # Pre-seed master keys |
| 6617 | if [ "$PRESEED_MASTER_FUNC" != "null" ] && [ "$_TEMP_KEYS_DIR" != "null" ]; then |
| 6618 | echoinfo "Running ${PRESEED_MASTER_FUNC}()" |
| 6619 | $PRESEED_MASTER_FUNC |
| 6620 | if [ $? -ne 0 ]; then |
| 6621 | echoerror "Failed to run ${PRESEED_MASTER_FUNC}()!!!" |
| 6622 | exit 1 |
| 6623 | fi |
| 6624 | fi |
| 6625 | |
| 6626 | # Install Salt |
| 6627 | if [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then |
| 6628 | # Only execute function is not in config mode only |
| 6629 | echoinfo "Running ${INSTALL_FUNC}()" |
| 6630 | $INSTALL_FUNC |
| 6631 | if [ $? -ne 0 ]; then |
| 6632 | echoerror "Failed to run ${INSTALL_FUNC}()!!!" |
| 6633 | exit 1 |
| 6634 | fi |
| 6635 | fi |
| 6636 | |
| 6637 | # Run any post install function. Only execute function if not in config mode only |
| 6638 | if [ "$POST_INSTALL_FUNC" != "null" ] && [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then |
| 6639 | echoinfo "Running ${POST_INSTALL_FUNC}()" |
| 6640 | $POST_INSTALL_FUNC |
| 6641 | if [ $? -ne 0 ]; then |
| 6642 | echoerror "Failed to run ${POST_INSTALL_FUNC}()!!!" |
| 6643 | exit 1 |
| 6644 | fi |
| 6645 | fi |
| 6646 | |
| 6647 | # Run any check services function, Only execute function if not in config mode only |
| 6648 | if [ "$CHECK_SERVICES_FUNC" != "null" ] && [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then |
| 6649 | echoinfo "Running ${CHECK_SERVICES_FUNC}()" |
| 6650 | $CHECK_SERVICES_FUNC |
| 6651 | if [ $? -ne 0 ]; then |
| 6652 | echoerror "Failed to run ${CHECK_SERVICES_FUNC}()!!!" |
| 6653 | exit 1 |
| 6654 | fi |
| 6655 | fi |
| 6656 | |
| 6657 | # Run any start daemons function |
| 6658 | if [ "$STARTDAEMONS_INSTALL_FUNC" != "null" ] && [ ${_START_DAEMONS} -eq $BS_TRUE ]; then |
| 6659 | echoinfo "Running ${STARTDAEMONS_INSTALL_FUNC}()" |
| 6660 | echodebug "Waiting ${_SLEEP} seconds for processes to settle before checking for them" |
| 6661 | sleep ${_SLEEP} |
| 6662 | $STARTDAEMONS_INSTALL_FUNC |
| 6663 | if [ $? -ne 0 ]; then |
| 6664 | echoerror "Failed to run ${STARTDAEMONS_INSTALL_FUNC}()!!!" |
| 6665 | exit 1 |
| 6666 | fi |
| 6667 | fi |
| 6668 | |
| 6669 | # Check if the installed daemons are running or not |
| 6670 | if [ "$DAEMONS_RUNNING_FUNC" != "null" ] && [ ${_START_DAEMONS} -eq $BS_TRUE ]; then |
| 6671 | echoinfo "Running ${DAEMONS_RUNNING_FUNC}()" |
| 6672 | echodebug "Waiting ${_SLEEP} seconds for processes to settle before checking for them" |
| 6673 | sleep ${_SLEEP} # Sleep a little bit to let daemons start |
| 6674 | $DAEMONS_RUNNING_FUNC |
| 6675 | if [ $? -ne 0 ]; then |
| 6676 | echoerror "Failed to run ${DAEMONS_RUNNING_FUNC}()!!!" |
| 6677 | |
| 6678 | for fname in api master minion syndic; do |
| 6679 | # Skip salt-api since the service should be opt-in and not necessarily started on boot |
| 6680 | [ $fname = "api" ] && continue |
| 6681 | |
| 6682 | # Skip if not meant to be installed |
| 6683 | [ $fname = "master" ] && [ "$_INSTALL_MASTER" -eq $BS_FALSE ] && continue |
| 6684 | [ $fname = "minion" ] && [ "$_INSTALL_MINION" -eq $BS_FALSE ] && continue |
| 6685 | [ $fname = "syndic" ] && [ "$_INSTALL_SYNDIC" -eq $BS_FALSE ] && continue |
| 6686 | |
| 6687 | if [ "$_ECHO_DEBUG" -eq $BS_FALSE ]; then |
| 6688 | echoerror "salt-$fname was not found running. Pass '-D' to ${__ScriptName} when bootstrapping for additional debugging information..." |
| 6689 | continue |
| 6690 | fi |
| 6691 | |
| 6692 | [ ! -f "$_SALT_ETC_DIR/$fname" ] && [ $fname != "syndic" ] && echodebug "$_SALT_ETC_DIR/$fname does not exist" |
| 6693 | |
| 6694 | echodebug "Running salt-$fname by hand outputs: $(nohup salt-$fname -l debug)" |
| 6695 | |
| 6696 | [ ! -f /var/log/salt/$fname ] && echodebug "/var/log/salt/$fname does not exist. Can't cat its contents!" && continue |
| 6697 | |
| 6698 | echodebug "DAEMON LOGS for $fname:" |
| 6699 | echodebug "$(cat /var/log/salt/$fname)" |
| 6700 | echo |
| 6701 | done |
| 6702 | |
| 6703 | echodebug "Running Processes:" |
| 6704 | echodebug "$(ps auxwww)" |
| 6705 | |
| 6706 | exit 1 |
| 6707 | fi |
| 6708 | fi |
| 6709 | |
| 6710 | # Done! |
| 6711 | if [ "$_CONFIG_ONLY" -eq $BS_FALSE ]; then |
| 6712 | echoinfo "Salt installed!" |
| 6713 | else |
| 6714 | echoinfo "Salt configured!" |
| 6715 | fi |
| 6716 | |
| 6717 | exit 0 |