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