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