vagrant-salt 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/README.rst +131 -170
  2. data/example/complete/Vagrantfile +67 -0
  3. data/example/complete/salt/custom-bootstrap-salt.sh +2425 -0
  4. data/example/complete/salt/key/master.pem +30 -0
  5. data/example/complete/salt/key/master.pub +14 -0
  6. data/example/complete/salt/key/minion.pem +30 -0
  7. data/example/complete/salt/key/minion.pub +14 -0
  8. data/example/complete/salt/master +459 -0
  9. data/example/{salt/minion.conf → complete/salt/minion} +1 -2
  10. data/example/{salt → complete/salt}/roots/pillar/top.sls +0 -0
  11. data/example/complete/salt/roots/salt/nginx.sls +5 -0
  12. data/example/complete/salt/roots/salt/top.sls +3 -0
  13. data/example/masterless/Vagrantfile +18 -0
  14. data/example/masterless/salt/minion +219 -0
  15. data/example/{salt/roots/salt → masterless/salt/roots/pillar}/top.sls +0 -0
  16. data/example/masterless/salt/roots/salt/nginx.sls +5 -0
  17. data/example/masterless/salt/roots/salt/top.sls +3 -0
  18. data/lib/vagrant-salt.rb +16 -3
  19. data/lib/vagrant-salt/config.rb +103 -0
  20. data/lib/vagrant-salt/errors.rb +11 -0
  21. data/lib/vagrant-salt/plugin.rb +31 -0
  22. data/lib/vagrant-salt/provisioner.rb +211 -104
  23. data/lib/vagrant-salt/version.rb +5 -0
  24. data/scripts/.travis.yml +16 -0
  25. data/scripts/ChangeLog +39 -0
  26. data/scripts/LICENSE +16 -0
  27. data/scripts/README.rst +124 -35
  28. data/scripts/bootstrap-salt-minion.sh +1815 -381
  29. data/scripts/bootstrap-salt.sh +2425 -0
  30. data/scripts/salt-bootstrap.sh +2425 -0
  31. data/scripts/tests/README.rst +38 -0
  32. data/scripts/tests/bootstrap/__init__.py +11 -0
  33. data/{example/salt/key/KEYPAIR_GOES_HERE → scripts/tests/bootstrap/ext/__init__.py} +0 -0
  34. data/scripts/tests/bootstrap/ext/console.py +100 -0
  35. data/scripts/tests/bootstrap/ext/os_data.py +199 -0
  36. data/scripts/tests/bootstrap/test_install.py +586 -0
  37. data/scripts/tests/bootstrap/test_lint.py +27 -0
  38. data/scripts/tests/bootstrap/test_usage.py +28 -0
  39. data/scripts/tests/bootstrap/unittesting.py +216 -0
  40. data/scripts/tests/ext/checkbashisms +640 -0
  41. data/scripts/tests/install-testsuite-deps.py +99 -0
  42. data/scripts/tests/runtests.py +207 -0
  43. data/templates/locales/en.yml +14 -0
  44. data/vagrant-salt.gemspec +2 -2
  45. metadata +43 -10
  46. data/example/Vagrantfile +0 -26
  47. data/lib/vagrant_init.rb +0 -1
data/README.rst CHANGED
@@ -8,35 +8,29 @@ or the `salt-users mailing list`_.
8
8
 
9
9
  .. _`Vagrant`: http://www.vagrantup.com/
10
10
  .. _`Saltstack`: http://saltstack.org/
11
+ .. _`bootstrap`: https://github.com/saltstack/salt-bootstrap
11
12
  .. _`Salt`: http://saltstack.org/
12
13
  .. _`salt-users mailing list`: https://groups.google.com/forum/#!forum/salt-users
13
14
 
14
15
  Introduction
15
16
  ============
16
17
 
17
- Just like Chef or Puppet, Salt can be used as a provisioning tool.
18
- `Salty Vagrant`_ lets you use your salt state tree and a your minion config
19
- file to automatically build your dev environment the same way you use salt
20
- to deploy for other environments.
18
+ `Salty Vagrant`_ is a plugin for Vagrant which lets you use salt as a
19
+ provisioning tool. You can use your existing salt formulas and configs
20
+ to build up development environments.
21
21
 
22
22
  .. _`Salty Vagrant`: https://github.com/saltstack/salty-vagrant
23
23
 
24
- There are two different ways to use `Salty Vagrant`_. The simplest way uses
25
- the salt minion in a masterless configuration. With this option you distribute
26
- your state tree along with your Vagrantfile and a minion config. The
27
- minion will bootstrap itself and apply all necessary states.
28
-
29
- The second method lets you specify a remote salt master, which assures that
30
- the vagrant minion will always be able to fetch your most up to date state
31
- tree. If you use a salt master, you will either need to manually accept
32
- new vagrant minions on the master, or distribute preseeded keys along with
33
- your vagrant files.
24
+ The simplest way to use `Salty Vagrant`_ is by configuring it for
25
+ masterless mode. With this setup, you use a standalone minion along
26
+ with your file_roots and/or pillar_roots. See the ``examples/`` folder
27
+ for more details.
34
28
 
35
29
  Masterless (Quick Start)
36
30
  ========================
37
31
 
38
32
  1. Install `Vagrant`_
39
- 2. Install `Salty Vagrant`_ (``vagrant gem install vagrant-salt``)
33
+ 2. Install `Salty Vagrant`_ (``vagrant plugin install vagrant-salt``)
40
34
  3. Get the Ubuntu 12.04 base box: ``vagrant box add precise64 http://files.vagrantup.com/precise64.box``
41
35
  4. Create/Update your ``Vagrantfile`` (Detailed in `Configuration`_) [#shared_folders]_
42
36
  5. Place your minion config in ``salt/minion`` [#file_client]_
@@ -45,202 +39,113 @@ Masterless (Quick Start)
45
39
  .. [#file_client] Make sure your minion config sets ``file_client: local`` for masterless
46
40
  .. [#shared_folders] Don't forget to create a shared folder for your salt file root
47
41
 
48
- Using Remote Salt Master
49
- ========================
50
42
 
51
- If you are already using `Salt`_ for deployment, you can use your existing
52
- master to provision your vagrant boxes as well. You will need to do one of the
53
- following:
43
+ Configuration
44
+ =============
54
45
 
55
- #. Manually accept the vagrant's minion key after it boots. [#accept_key]_
56
- #. Preseed the Vagrant box with minion keys pre-generated on the master
46
+ Here is an extremely simple ``Vagrantfile``, to be used with
47
+ the above masterless setup::
57
48
 
58
- .. [#accept_key] This is not recommended. If your developers need to destroy and rebuild their VM, you will have to repeat the process.
49
+ Vagrant.configure("2") do |config|
50
+ ## Chose your base box
51
+ config.vm.box = "precise64"
59
52
 
60
- Preseeding Vagrant Minion Keys
61
- ------------------------------
53
+ ## For masterless, mount your salt file root
54
+ config.vm.synced_folder "salt/roots/", "/srv/"
62
55
 
63
- On the master, create the keypair and add the public key to the accepted minions
64
- folder::
56
+ ## Use all the defaults:
57
+ config.vm.provision :salt do |salt|
65
58
 
66
- root@saltmaster# salt-key --gen-keys=[minion_id]
67
- root@saltmaster# cp [minion_id].pub /etc/salt/pki/minions/[minion_id]
59
+ salt.run_highstate = true
68
60
 
69
- Replace ``[minion_id]`` with the id you would like to assign the minion.
61
+ end
62
+ end
70
63
 
71
- Next you want to bundle the key pair along with your Vagrantfile,
72
- the salt_provisioner.rb, and your minion config. The directory should look
73
- something like this::
64
+ Actions
65
+ -------
74
66
 
75
- myvagrant/
76
- Vagrantfile
77
- salt/
78
- minion.conf
79
- key/
80
- minion.pem
81
- minion.pub
67
+ run_highstate (true/false)
68
+ Executes ``state.highstate`` on vagrant up
82
69
 
83
- You will need to determine your own secure method of transferring this
84
- package. Leaking the minion's private key poses a security risk to your salt
85
- network.
70
+ accept_keys (true/false)
71
+ Accept all keys if running a master
86
72
 
87
- The are two required settings for your ``minion.conf`` file::
88
73
 
89
- master: [master_fqdn]
90
- id: [minion_id]
74
+ Install Options
75
+ ---------------
91
76
 
92
- Make sure you use the same ``[minion_id]`` that you used on the master or
93
- it will not match with the key.
77
+ install_master (true/false)
78
+ Install the salt-master
94
79
 
95
- Create/Update your ``Vagrantfile`` per the example provided in the `Configuration`_ section.
80
+ no_minion (true/false)
81
+ Don't install the minion
96
82
 
97
- Finally, you should be able to run ``vagrant up`` and the salt should put your
98
- vagrant minion in state.highstate.
83
+ install_syndic (true/false)
84
+ Install the salt-syndic
99
85
 
86
+ install_type (stable | git | daily)
87
+ Whether to install from a distribution's stable package manager, a
88
+ daily ppa, or git treeish.
100
89
 
101
- Configuration
102
- =============
90
+ install_args (develop)
91
+ When performing a git install, you can specify a branch, tag, or
92
+ any treeish.
103
93
 
104
- Your ``Vagrantfile`` should look roughly like this::
94
+ always_install (true/false)
95
+ Installs salt binaries even if they are already detected
105
96
 
106
- Vagrant::Config.run do |config|
107
- ## Chose your base box
108
- config.vm.box = "precise64"
109
97
 
110
- ## For masterless, mount your salt file root
111
- config.vm.share_folder "salt_file_root", "/srv", "/path/to/salt_file_root"
98
+ Minion Options
99
+ --------------
112
100
 
101
+ minion_config (salt/minion)
102
+ Path to a custom salt minion config file.
113
103
 
114
- ## Use all the defaults:
115
- config.vm.provision :salt do |salt|
116
- salt.run_highstate = true
104
+ minion_key (salt/key/minion.pem)
105
+ Path to your minion key
117
106
 
118
- ## Optional Settings:
119
- # salt.minion_config = "salt/minion.conf"
120
- # salt.temp_config_dir = "/existing/folder/on/basebox/"
121
- # salt.salt_install_type = "git"
122
- # salt.salt_install_args = "develop"
107
+ minion_pub (salt/key/minion.pub)
108
+ Path to your minion public key
123
109
 
124
- ## If you have a remote master setup, you can add
125
- ## your preseeded minion key
126
- # salt.minion_key = "salt/key/minion.pem"
127
- # salt.minion_pub = "salt/key/minion.pub"
128
- end
129
- end
130
110
 
131
- Inside of your Vagrantfile, there are a few parameters you can assign
132
- depending on whether you are running masterless or with a remote master.
111
+ Master Options
112
+ --------------
133
113
 
134
- minion_config : "salt/minion.conf"
135
- Path to your minion configuration file.
114
+ master_config (salt/minion)
115
+ Path to a custom salt master config file
136
116
 
137
- temp_config_dir : "/tmp"
138
- Path on the guest box that the minion files will be copied to before
139
- placing in the salt directories. (Not all distros support "/tmp")
117
+ master_key (salt/key/master.pem)
118
+ Path to your master key
140
119
 
141
- minion_key : false
142
- String path to your minion key. Only useful with ``master=true``
120
+ master_pub (salt/key/master.pub)
121
+ Path to your master public key
143
122
 
144
- minion_pub : false
145
- String path to your minion public key. Only useful with ``master=true``
146
123
 
147
- salt_install_type : "stable" : "daily" : "git"
148
- Whether to install from a distribution's stable package manager, a
149
- daily ppa, or git treeish.
124
+ Other
125
+ -----
126
+ bootstrap_script (salt/bootstrap_salt.sh)
127
+ Path to a custom `bootstrap`_ script
150
128
 
151
- salt_install_args : ""
152
- When performing a git install, you can specify a branch, tag, or
153
- any treeish.
129
+ temp_config_dir (/tmp)
130
+ Path on the guest box that config and bootstrap files will be copied
131
+ to before placing in the salt directories
154
132
 
133
+ verbose (true/false)
134
+ Prints bootstrap script output to screen
155
135
 
156
- Bootstrapping Salt
157
- ==================
158
136
 
159
- Before `Salt`_ can be used for provisioning on the target virtual box, the
160
- binaries need to be installed. Since `Vagrant`_ and `Salt`_ support many
161
- different distributions and versions of operating systems, the `Salt`_
162
- installation process is handled by the shell script
163
- ``scripts/bootstrap-salt-minion.sh``. This script runs through a series of
164
- checks to determine operating system type and version to then install the
165
- `Salt`_ binaries using the appropriate methods.
166
-
167
- Adding support for other operating systems
168
- ------------------------------------------
169
- In order to install salt for a distribution you need to define:
170
-
171
- To Install Dependencies, which is required, one of:
172
- 1. install_<distro>_<distro_version>_<install_type>_deps
173
- 2. install_<distro>_<distro_version>_deps
174
- 3. install_<distro>_<install_type>_deps
175
- 4. install_<distro>_deps
176
-
177
-
178
- To install salt, which, of course, is required, one of:
179
- 1. install_<distro>_<distro_version>_<install_type>
180
- 2. install_<distro>_<install_type>
181
-
182
- Optionally, define a minion configuration function, which will be called if
183
- the -c|config-dir option is passed. One of:
184
- 1. config_<distro>_<distro_version>_<install_type>_minion
185
- 2. config_<distro>_<distro_version>_minion
186
- 3. config_<distro>_<install_type>_minion
187
- 4. config_<distro>_minion
188
- 5. config_minion [THIS ONE IS ALREADY DEFINED AS THE DEFAULT]
189
-
190
- Also optionally, define a post install function, one of:
191
- 1. install_<distro>_<distro_versions>_<install_type>_post
192
- 2. install_<distro>_<distro_versions>_post
193
- 3. install_<distro>_<install_type>_post
194
- 4. install_<distro>_post
195
-
196
- Below is an example for Ubuntu Oneiric:
197
-
198
- install_ubuntu_1110_deps() {
199
- apt-get update
200
- apt-get -y install python-software-properties
201
- add-apt-repository -y 'deb http://us.archive.ubuntu.com/ubuntu/ oneiric universe'
202
- add-apt-repository -y ppa:saltstack/salt
203
- }
204
-
205
- install_ubuntu_1110_post() {
206
- add-apt-repository -y --remove 'deb http://us.archive.ubuntu.com/ubuntu/ oneiric universe'
207
- }
208
-
209
- install_ubuntu_stable() {
210
- apt-get -y install salt-minion
211
- }
212
-
213
- Since there is no ``install_ubuntu_1110_stable()`` it defaults to the
214
- unspecified version script.
215
-
216
- The bootstrapping script must be plain POSIX sh only, **not** bash or another
217
- shell script. By design the targeting for each operating system and version is
218
- very specific. Assumptions of supported versions or variants should not be
219
- made, to avoid failed or broken installations.
137
+ Installation Notes
138
+ ==================
220
139
 
221
140
  Supported Operating Systems
222
141
  ---------------------------
223
142
  - Ubuntu 10.x/11.x/12.x
224
- - Debian 6.x
143
+ - Debian 6.x/7.x
225
144
  - CentOS 6.3
226
145
  - Fedora
227
146
  - Arch
228
147
  - FreeBSD 9.0
229
148
 
230
- Installation Notes
231
- ==================
232
- Ubuntu & Debian
233
- ---------------
234
-
235
- Users have reported that vagrant plugins do not work with the debian packaged vagrant
236
- (such as Ubuntu repository). Installing vagrant with gem should work.
237
-
238
- 1. ``sudo apt-get remove vagrant``
239
- 2. ``sudo gem install vagrant``
240
- 3. ``vagrant gem install vagrant-salt``
241
-
242
- That should get you up and running.
243
-
244
149
  Installing from source
245
150
  ----------------------
246
151
 
@@ -250,6 +155,62 @@ Installing from source
250
155
  4. ``git submodule init``
251
156
  5. ``git submodule update``
252
157
  6. ``gem build vagrant-salt.gemspec``
253
- 7. ``vagrant gem install vagrant-salt-[version].gem``
158
+ 7. ``vagrant plugin install vagrant-salt-[version].gem``
159
+
160
+
161
+ Miscellaneous
162
+ =============
163
+
164
+ Using Remote Salt Master
165
+ ------------------------
166
+
167
+ If you are already using `Salt`_ for deployment, you can use your existing
168
+ master to provision your vagrant boxes as well. You will need to do one of the
169
+ following:
170
+
171
+ #. Manually accept the vagrant's minion key after it boots. [#accept_key]_
172
+ #. Preseed the Vagrant box with minion keys pre-generated on the master
173
+
174
+ .. [#accept_key] This is not recommended. If your developers need to destroy and rebuild their VM, you will have to repeat the process.
175
+
176
+ Preseeding Vagrant Minion Keys
177
+ ------------------------------
178
+
179
+ On the master, create the keypair and add the public key to the accepted minions
180
+ folder::
181
+
182
+ root@saltmaster# salt-key --gen-keys=[minion_id]
183
+ root@saltmaster# cp [minion_id].pub /etc/salt/pki/master/minions/[minion_id]
184
+
185
+ Replace ``[minion_id]`` with the id you would like to assign the minion.
186
+
187
+ Next you want to bundle the key pair along with your Vagrantfile,
188
+ the salt_provisioner.rb, and your minion config. The directory should look
189
+ something like this::
190
+
191
+ myvagrant/
192
+ Vagrantfile
193
+ salt/
194
+ minion.conf
195
+ key/
196
+ minion.pem
197
+ minion.pub
198
+
199
+ You will need to determine your own secure method of transferring this
200
+ package. Leaking the minion's private key poses a security risk to your salt
201
+ network.
202
+
203
+ The are two required settings for your ``minion.conf`` file::
204
+
205
+ master: [master_fqdn]
206
+ id: [minion_id]
207
+
208
+ Make sure you use the same ``[minion_id]`` that you used on the master or
209
+ it will not match with the key.
210
+
211
+ Create/Update your ``Vagrantfile`` per the example provided in the `Configuration`_ section.
212
+
213
+ Finally, you should be able to run ``vagrant up`` and the salt should put your
214
+ vagrant minion in state.highstate.
215
+
254
216
 
255
- .. vim: fenc=utf-8 spell spl=en cc=80 tw=79 fo=want sts=2 sw=2 et
@@ -0,0 +1,67 @@
1
+ Vagrant.configure("2") do |config|
2
+ ## Chose your base box
3
+ config.vm.box = "precise64"
4
+
5
+ ## For local master, mount your file_roots
6
+ config.vm.synced_folder "salt/roots/", "/srv/"
7
+
8
+ config.vm.provision :salt do |salt|
9
+
10
+ # Config Options
11
+ salt.minion_config = "salt/minion"
12
+ salt.master_config = "salt/master"
13
+
14
+ # These are more useful when connecting to a remote master
15
+ # and you want to use pre-seeded keys (already accepted on master)
16
+ ## !! Please do not use these keys in production!
17
+ salt.minion_key = "salt/key/minion.pem"
18
+ salt.minion_pub = "salt/key/minion.pub"
19
+
20
+ # Good for multi-vm setups where live minions are expecting
21
+ # existing master
22
+ ## !! Please do not use these keys in production!
23
+ salt.master_key = "salt/key/master.pem"
24
+ salt.master_pub = "salt/key/master.pub"
25
+
26
+ # Bootstrap Options Below
27
+ # See options here:
28
+ # http://bootstrap.saltstack.org
29
+
30
+ # If you need bleeding edge salt
31
+ salt.install_type = "git"
32
+ salt.install_args = "develop"
33
+
34
+ # Install a master on this machine
35
+ salt.install_master = true
36
+
37
+ # Can also install syndic:
38
+ # salt.install_syndic = true
39
+
40
+ # Minion is on by default, but can be disabled:
41
+ # salt.no_minion = true
42
+
43
+ # Actions
44
+ # Normally we want to run state.highstate to provision the machine
45
+ salt.run_highstate = true
46
+
47
+ # If you are using a master with minion setup, you need to accept keys
48
+ salt.accept_keys = true
49
+
50
+ # Default will not install / update salt binaries if they are present
51
+ # Use this option to always install
52
+ salt.always_install = true
53
+
54
+ # Gives more output, such as fromt bootstrap script
55
+ salt.verbose = true
56
+
57
+ # If you need an updated bootstrap script, or a custom one
58
+ salt.bootstrap_script = "salt/custom-bootstrap-salt.sh"
59
+
60
+ # Pass extra flags to bootstrap script
61
+ salt.bootstrap_options = "-D"
62
+
63
+ # If your distro does not use /tmp, you can use another dir
64
+ salt.temp_config_dir = "/tmp"
65
+
66
+ end
67
+ end
@@ -0,0 +1,2425 @@
1
+ #!/bin/sh -
2
+ #===============================================================================
3
+ # vim: softtabstop=4 shiftwidth=4 expandtab fenc=utf-8 spell spelllang=en
4
+ #===============================================================================
5
+ #
6
+ # FILE: bootstrap-salt.sh
7
+ #
8
+ # DESCRIPTION: Bootstrap salt installation for various systems/distributions
9
+ #
10
+ # BUGS: https://github.com/saltstack/salty-vagrant/issues
11
+ # AUTHOR: Pedro Algarvio (s0undt3ch), pedro@algarvio.me
12
+ # Alec Koumjian (akoumjian), akoumjian@gmail.com
13
+ # Geoff Garside (geoffgarside), geoff@geoffgarside.co.uk
14
+ # LICENSE: Apache 2.0
15
+ # ORGANIZATION: Salt Stack (saltstack.org)
16
+ # CREATED: 10/15/2012 09:49:37 PM WEST
17
+ #===============================================================================
18
+ set -o nounset # Treat unset variables as an error
19
+ ScriptVersion="1.5.2"
20
+ ScriptName="bootstrap-salt.sh"
21
+ echo "Running a custom bootstrap script!"
22
+ #===============================================================================
23
+ # Environment variables taken into account.
24
+ #-------------------------------------------------------------------------------
25
+ # * BS_COLORS: If 0 disables colour support
26
+ # * BS_PIP_ALLOWED: If 1 enable pip based installations(if needed)
27
+ # * BS_ECHO_DEBUG: If 1 enable debug echo which can also be set by -D
28
+ # * BS_SALT_ETC_DIR: Defaults to /etc/salt
29
+ # * BS_FORCE_OVERWRITE: Force overriding copied files(config, init.d, etc)
30
+ #===============================================================================
31
+
32
+
33
+ #===============================================================================
34
+ # LET THE BLACK MAGIC BEGIN!!!!
35
+ #===============================================================================
36
+
37
+
38
+ # Bootstrap script truth values
39
+ BS_TRUE=1
40
+ BS_FALSE=0
41
+
42
+ #--- FUNCTION ----------------------------------------------------------------
43
+ # NAME: __detect_color_support
44
+ # DESCRIPTION: Try to detect color support.
45
+ #-------------------------------------------------------------------------------
46
+ COLORS=${BS_COLORS:-$(tput colors 2>/dev/null || echo 0)}
47
+ __detect_color_support() {
48
+ if [ $? -eq 0 ] && [ "$COLORS" -gt 2 ]; then
49
+ RC="\033[1;31m"
50
+ GC="\033[1;32m"
51
+ BC="\033[1;34m"
52
+ YC="\033[1;33m"
53
+ EC="\033[0m"
54
+ else
55
+ RC=""
56
+ GC=""
57
+ BC=""
58
+ YC=""
59
+ EC=""
60
+ fi
61
+ }
62
+ __detect_color_support
63
+
64
+
65
+ #--- FUNCTION ----------------------------------------------------------------
66
+ # NAME: echoerr
67
+ # DESCRIPTION: Echo errors to stderr.
68
+ #-------------------------------------------------------------------------------
69
+ echoerror() {
70
+ printf "${RC} * ERROR${EC}: $@\n" 1>&2;
71
+ }
72
+
73
+ #--- FUNCTION ----------------------------------------------------------------
74
+ # NAME: echoinfo
75
+ # DESCRIPTION: Echo information to stdout.
76
+ #-------------------------------------------------------------------------------
77
+ echoinfo() {
78
+ printf "${GC} * INFO${EC}: %s\n" "$@";
79
+ }
80
+
81
+ #--- FUNCTION ----------------------------------------------------------------
82
+ # NAME: echowarn
83
+ # DESCRIPTION: Echo warning informations to stdout.
84
+ #-------------------------------------------------------------------------------
85
+ echowarn() {
86
+ printf "${YC} * WARN${EC}: %s\n" "$@";
87
+ }
88
+
89
+ #--- FUNCTION ----------------------------------------------------------------
90
+ # NAME: echodebug
91
+ # DESCRIPTION: Echo debug information to stdout.
92
+ #-------------------------------------------------------------------------------
93
+ echodebug() {
94
+ if [ $ECHO_DEBUG -eq $BS_TRUE ]; then
95
+ printf "${BC} * DEBUG${EC}: %s\n" "$@";
96
+ fi
97
+ }
98
+
99
+ #--- FUNCTION ----------------------------------------------------------------
100
+ # NAME: pip_not_allowed
101
+ # DESCRIPTION: Simple function to let the users know that -P needs to be
102
+ # used.
103
+ #-------------------------------------------------------------------------------
104
+ pip_not_allowed() {
105
+ echoerror "pip based installations were not allowed. Retry using '-P'"
106
+ usage
107
+ exit 1
108
+ }
109
+
110
+ #=== FUNCTION ================================================================
111
+ # NAME: usage
112
+ # DESCRIPTION: Display usage information.
113
+ #===============================================================================
114
+ usage() {
115
+ cat << EOT
116
+
117
+ Usage : ${ScriptName} [options] <install-type> <install-type-args>
118
+
119
+ Installation types:
120
+ - stable (default)
121
+ - daily (ubuntu specific)
122
+ - git
123
+
124
+ Examples:
125
+ $ ${ScriptName}
126
+ $ ${ScriptName} stable
127
+ $ ${ScriptName} daily
128
+ $ ${ScriptName} git
129
+ $ ${ScriptName} git develop
130
+ $ ${ScriptName} git 8c3fadf15ec183e5ce8c63739850d543617e4357
131
+
132
+ Options:
133
+ -h Display this message
134
+ -v Display script version
135
+ -n No colours.
136
+ -D Show debug output.
137
+ -c Temporary configuration directory
138
+ -M Also install salt-master
139
+ -S Also install salt-syndic
140
+ -N Do not install salt-minion
141
+ -C Only run the configuration function. This option automaticaly
142
+ bypasses any installation.
143
+ -P Allow pip based installations. On some distributions the required salt
144
+ packages or it's dependencies are not available as a package for that
145
+ distribution. Using this flag allows the script to use pip as a last
146
+ resort method. NOTE: This works for functions which actually implement
147
+ pip based installations.
148
+ -F Allow copied files to overwrite existing(config, init.d, etc)
149
+
150
+ EOT
151
+ } # ---------- end of function usage ----------
152
+
153
+ #-----------------------------------------------------------------------
154
+ # Handle command line arguments
155
+ #-----------------------------------------------------------------------
156
+ TEMP_CONFIG_DIR="null"
157
+ INSTALL_MASTER=$BS_FALSE
158
+ INSTALL_SYNDIC=$BS_FALSE
159
+ INSTALL_MINION=$BS_TRUE
160
+ ECHO_DEBUG=${BS_ECHO_DEBUG:-$BS_FALSE}
161
+ CONFIG_ONLY=$BS_FALSE
162
+ PIP_ALLOWED=${BS_PIP_ALLOWED:-$BS_FALSE}
163
+ SALT_ETC_DIR=${BS_SALT_ETC_DIR:-/etc/salt}
164
+ FORCE_OVERWRITE=${BS_FORCE_OVERWRITE:-$BS_FALSE}
165
+
166
+ while getopts ":hvnDc:MSNCP" opt
167
+ do
168
+ case "${opt}" in
169
+
170
+ h ) usage; exit 0 ;;
171
+
172
+ v ) echo "$0 -- Version $ScriptVersion"; exit 0 ;;
173
+ n ) COLORS=0; __detect_color_support ;;
174
+ D ) ECHO_DEBUG=$BS_TRUE ;;
175
+ c ) TEMP_CONFIG_DIR="$OPTARG"
176
+ # If the configuration directory does not exist, error out
177
+ if [ ! -d "$TEMP_CONFIG_DIR" ]; then
178
+ echoerror "The configuration directory ${TEMP_CONFIG_DIR} does not exist."
179
+ exit 1
180
+ fi
181
+ ;;
182
+ M ) INSTALL_MASTER=$BS_TRUE ;;
183
+ S ) INSTALL_SYNDIC=$BS_TRUE ;;
184
+ N ) INSTALL_MINION=$BS_FALSE ;;
185
+ C ) CONFIG_ONLY=$BS_TRUE ;;
186
+ P ) PIP_ALLOWED=$BS_TRUE ;;
187
+ F ) FORCE_OVERWRITE=$BS_TRUE ;;
188
+
189
+ \?) echo
190
+ echoerror "Option does not exist : $OPTARG"
191
+ usage
192
+ exit 1
193
+ ;;
194
+
195
+ esac # --- end of case ---
196
+ done
197
+ shift $(($OPTIND-1))
198
+
199
+
200
+ __check_unparsed_options() {
201
+ shellopts="$1"
202
+ unparsed_options=$( echo "$shellopts" | grep -E '[-]+[[:alnum:]]' )
203
+ if [ "x$unparsed_options" != "x" ]; then
204
+ usage
205
+ echo
206
+ echoerror "options are only allowed before install arguments"
207
+ echo
208
+ exit 1
209
+ fi
210
+ }
211
+
212
+
213
+ # Check that we're actually installing one of minion/master/syndic
214
+ if [ $INSTALL_MINION -eq $BS_FALSE ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && [ $CONFIG_ONLY -eq $BS_FALSE ]; then
215
+ echowarn "Nothing to install or configure"
216
+ exit 0
217
+ fi
218
+
219
+ if [ $CONFIG_ONLY -eq $BS_TRUE ] && [ "$TEMP_CONFIG_DIR" = "null" ]; then
220
+ echoerror "In order to run the script in configuration only mode you also need to provide the configuration directory."
221
+ exit 1
222
+ fi
223
+
224
+ # Define installation type
225
+ if [ "$#" -eq 0 ];then
226
+ ITYPE="stable"
227
+ else
228
+ __check_unparsed_options "$*"
229
+ ITYPE=$1
230
+ shift
231
+ fi
232
+
233
+ # Check installation type
234
+ if [ "$ITYPE" != "stable" ] && [ "$ITYPE" != "daily" ] && [ "$ITYPE" != "git" ]; then
235
+ echoerror "Installation type \"$ITYPE\" is not known..."
236
+ exit 1
237
+ fi
238
+
239
+ # If doing a git install, check what branch/tag/sha will be checked out
240
+ if [ $ITYPE = "git" ]; then
241
+ if [ "$#" -eq 0 ];then
242
+ GIT_REV="master"
243
+ else
244
+ __check_unparsed_options "$*"
245
+ GIT_REV="$1"
246
+ shift
247
+ fi
248
+ fi
249
+
250
+ # Check for any unparsed arguments. Should be an error.
251
+ if [ "$#" -gt 0 ]; then
252
+ __check_unparsed_options "$*"
253
+ usage
254
+ echo
255
+ echoerror "Too many arguments."
256
+ exit 1
257
+ fi
258
+
259
+ # Root permissions are required to run this script
260
+ if [ $(whoami) != "root" ] ; then
261
+ echoerror "Salt requires root privileges to install. Please re-run this script as root."
262
+ exit 1
263
+ fi
264
+
265
+ CALLER=$(echo `ps -a -o pid,args | grep $$ | grep -v grep | tr -s ' '` | cut -d ' ' -f 2)
266
+ if [ "${CALLER}x" = "${0}x" ]; then
267
+ CALLER="PIPED THROUGH"
268
+ fi
269
+ echoinfo "${CALLER} ${0} -- Version ${ScriptVersion}"
270
+ #echowarn "Running the unstable version of ${ScriptName}"
271
+
272
+
273
+ #--- FUNCTION ----------------------------------------------------------------
274
+ # NAME: __exit_cleanup
275
+ # DESCRIPTION: Cleanup any leftovers after script has ended
276
+ #
277
+ #
278
+ # http://www.unix.com/man-page/POSIX/1posix/trap/
279
+ #
280
+ # Signal Number Signal Name
281
+ # 1 SIGHUP
282
+ # 2 SIGINT
283
+ # 3 SIGQUIT
284
+ # 6 SIGABRT
285
+ # 9 SIGKILL
286
+ # 14 SIGALRM
287
+ # 15 SIGTERM
288
+ #-------------------------------------------------------------------------------
289
+ __exit_cleanup() {
290
+ EXIT_CODE=$?
291
+
292
+ # Remove the logging pipe when the script exits
293
+ echodebug "Removing the logging pipe $LOGPIPE"
294
+ rm -f $LOGPIPE
295
+
296
+ # Kill tee when exiting, CentOS, at least requires this
297
+ TEE_PID=$(ps ax | grep tee | grep $LOGFILE | awk '{print $1}')
298
+
299
+ [ "x$TEE_PID" = "x" ] && exit $EXIT_CODE
300
+
301
+ echodebug "Killing logging pipe tee's with pid(s): $TEE_PID"
302
+
303
+ # We need to trap errors since killing tee will cause a 127 errno
304
+ # We also do this as late as possible so we don't "mis-catch" other errors
305
+ __trap_errors() {
306
+ echoinfo "Errors Trapped: $EXIT_CODE"
307
+ # Exit with the "original" exit code, not the trapped code
308
+ exit $EXIT_CODE
309
+ }
310
+ trap "__trap_errors" INT QUIT ABRT KILL QUIT TERM
311
+
312
+ # Now we're "good" to kill tee
313
+ kill -s TERM $TEE_PID
314
+
315
+ # In case the 127 errno is not triggered, exit with the "original" exit code
316
+ exit $EXIT_CODE
317
+ }
318
+ trap "__exit_cleanup" EXIT INT
319
+
320
+
321
+ # Define our logging file and pipe paths
322
+ LOGFILE="/tmp/$( echo $ScriptName | sed s/.sh/.log/g )"
323
+ LOGPIPE="/tmp/$( echo $ScriptName | sed s/.sh/.logpipe/g )"
324
+
325
+ # Create our logging pipe
326
+ # On FreeBSD we have to use mkfifo instead of mknod
327
+ mknod $LOGPIPE p >/dev/null 2>&1 || mkfifo $LOGPIPE >/dev/null 2>&1
328
+ if [ $? -ne 0 ]; then
329
+ echoerror "Failed to create the named pipe required to log"
330
+ exit 1
331
+ fi
332
+
333
+ # What ever is written to the logpipe gets written to the logfile
334
+ tee < $LOGPIPE $LOGFILE &
335
+
336
+ # Close STDOUT, reopen it directing it to the logpipe
337
+ exec 1>&-
338
+ exec 1>$LOGPIPE
339
+ # Close STDERR, reopen it directing it to the logpipe
340
+ exec 2>&-
341
+ exec 2>$LOGPIPE
342
+
343
+
344
+ #--- FUNCTION ----------------------------------------------------------------
345
+ # NAME: __gather_hardware_info
346
+ # DESCRIPTION: Discover hardware information
347
+ #-------------------------------------------------------------------------------
348
+ __gather_hardware_info() {
349
+ if [ -f /proc/cpuinfo ]; then
350
+ CPU_VENDOR_ID=$(cat /proc/cpuinfo | grep -E 'vendor_id|Processor' | head -n 1 | awk '{print $3}' | cut -d '-' -f1 )
351
+ elif [ -f /usr/bin/kstat ]; then
352
+ # SmartOS.
353
+ # Solaris!?
354
+ # This has only been tested for a GenuineIntel CPU
355
+ CPU_VENDOR_ID=$(/usr/bin/kstat -p cpu_info:0:cpu_info0:vendor_id | awk '{print $2}')
356
+ else
357
+ CPU_VENDOR_ID=$( sysctl -n hw.model )
358
+ fi
359
+ CPU_VENDOR_ID_L=$( echo $CPU_VENDOR_ID | tr '[:upper:]' '[:lower:]' )
360
+ CPU_ARCH=$(uname -m 2>/dev/null || uname -p 2>/dev/null || echo "unknown")
361
+ CPU_ARCH_L=$( echo $CPU_ARCH | tr '[:upper:]' '[:lower:]' )
362
+
363
+ }
364
+ __gather_hardware_info
365
+
366
+
367
+ #--- FUNCTION ----------------------------------------------------------------
368
+ # NAME: __gather_os_info
369
+ # DESCRIPTION: Discover operating system information
370
+ #-------------------------------------------------------------------------------
371
+ __gather_os_info() {
372
+ OS_NAME=$(uname -s 2>/dev/null)
373
+ OS_NAME_L=$( echo $OS_NAME | tr '[:upper:]' '[:lower:]' )
374
+ OS_VERSION=$(uname -r)
375
+ OS_VERSION_L=$( echo $OS_VERSION | tr '[:upper:]' '[:lower:]' )
376
+ }
377
+ __gather_os_info
378
+
379
+
380
+ #--- FUNCTION ----------------------------------------------------------------
381
+ # NAME: __parse_version_string
382
+ # DESCRIPTION: Parse version strings ignoring the revision.
383
+ # MAJOR.MINOR.REVISION becomes MAJOR.MINOR
384
+ #-------------------------------------------------------------------------------
385
+ __parse_version_string() {
386
+ VERSION_STRING="$1"
387
+ PARSED_VERSION=$(
388
+ echo $VERSION_STRING |
389
+ sed -e 's/^/#/' \
390
+ -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\)\(\.[0-9][0-9]*\).*$/\1/' \
391
+ -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
392
+ -e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \
393
+ -e 's/^#.*$//'
394
+ )
395
+ echo $PARSED_VERSION
396
+ }
397
+
398
+
399
+ #--- FUNCTION ----------------------------------------------------------------
400
+ # NAME: __unquote_string
401
+ # DESCRIPTION: Strip single or double quotes from the provided string.
402
+ #-------------------------------------------------------------------------------
403
+ __unquote_string() {
404
+ echo $@ | sed "s/^\([\"']\)\(.*\)\1\$/\2/g"
405
+ }
406
+
407
+ #--- FUNCTION ----------------------------------------------------------------
408
+ # NAME: __camelcase_split
409
+ # DESCRIPTION: Convert CamelCased strings to Camel_Cased
410
+ #-------------------------------------------------------------------------------
411
+ __camelcase_split() {
412
+ echo $@ | sed -r 's/([^A-Z-])([A-Z])/\1 \2/g'
413
+ }
414
+
415
+ #--- FUNCTION ----------------------------------------------------------------
416
+ # NAME: __strip_duplicates
417
+ # DESCRIPTION: Strip duplicate strings
418
+ #-------------------------------------------------------------------------------
419
+ __strip_duplicates() {
420
+ echo $@ | tr -s '[:space:]' '\n' | awk '!x[$0]++'
421
+ }
422
+
423
+ #--- FUNCTION ----------------------------------------------------------------
424
+ # NAME: __sort_release_files
425
+ # DESCRIPTION: Custom sort function. Alphabetical or numerical sort is not
426
+ # enough.
427
+ #-------------------------------------------------------------------------------
428
+ __sort_release_files() {
429
+ KNOWN_RELEASE_FILES=$(echo "(arch|centos|debian|ubuntu|fedora|redhat|suse|\
430
+ mandrake|mandriva|gentoo|slackware|turbolinux|unitedlinux|lsb|system|\
431
+ os)(-|_)(release|version)" | sed -r 's:[[:space:]]::g')
432
+ primary_release_files=""
433
+ secondary_release_files=""
434
+ # Sort know VS un-known files first
435
+ for release_file in $(echo $@ | sed -r 's:[[:space:]]:\n:g' | sort --unique --ignore-case); do
436
+ match=$(echo $release_file | egrep -i ${KNOWN_RELEASE_FILES})
437
+ if [ "x${match}" != "x" ]; then
438
+ primary_release_files="${primary_release_files} ${release_file}"
439
+ else
440
+ secondary_release_files="${secondary_release_files} ${release_file}"
441
+ fi
442
+ done
443
+
444
+ # Now let's sort by know files importance, max important goes last in the max_prio list
445
+ max_prio="redhat-release centos-release"
446
+ for entry in $max_prio; do
447
+ if [ "x$(echo ${primary_release_files} | grep $entry)" != "x" ]; then
448
+ primary_release_files=$(echo ${primary_release_files} | sed -e "s:\(.*\)\($entry\)\(.*\):\2 \1 \3:g")
449
+ fi
450
+ done
451
+ # Now, least important goes last in the min_prio list
452
+ min_prio="lsb-release"
453
+ for entry in $max_prio; do
454
+ if [ "x$(echo ${primary_release_files} | grep $entry)" != "x" ]; then
455
+ primary_release_files=$(echo ${primary_release_files} | sed -e "s:\(.*\)\($entry\)\(.*\):\1 \3 \2:g")
456
+ fi
457
+ done
458
+
459
+ # Echo the results collapsing multiple white-space into a single white-space
460
+ echo "${primary_release_files} ${secondary_release_files}" | sed -r 's:[[:space:]]:\n:g'
461
+ }
462
+
463
+
464
+ #--- FUNCTION ----------------------------------------------------------------
465
+ # NAME: __gather_linux_system_info
466
+ # DESCRIPTION: Discover Linux system information
467
+ #-------------------------------------------------------------------------------
468
+ __gather_linux_system_info() {
469
+ DISTRO_NAME=""
470
+ DISTRO_VERSION=""
471
+
472
+ # Let's test if the lsb_release binary is available
473
+ rv=$(lsb_release >/dev/null 2>&1)
474
+ if [ $? -eq 0 ]; then
475
+ DISTRO_NAME=$(lsb_release -si)
476
+ if [ "x$(echo "$DISTRO_NAME" | grep RedHat)" != "x" ]; then
477
+ # Let's convert CamelCase to Camel Case
478
+ DISTRO_NAME=$(__camelcase_split "$DISTRO_NAME")
479
+ fi
480
+ rv=$(lsb_release -sr)
481
+ [ "${rv}x" != "x" ] && DISTRO_VERSION=$(__parse_version_string "$rv")
482
+ elif [ -f /etc/lsb-release ]; then
483
+ # We don't have the lsb_release binary, though, we do have the file it parses
484
+ DISTRO_NAME=$(grep DISTRIB_ID /etc/lsb-release | sed -e 's/.*=//')
485
+ rv=$(grep DISTRIB_RELEASE /etc/lsb-release | sed -e 's/.*=//')
486
+ [ "${rv}x" != "x" ] && DISTRO_VERSION=$(__parse_version_string "$rv")
487
+ fi
488
+
489
+ if [ "x$DISTRO_NAME" != "x" ] && [ "x$DISTRO_VERSION" != "x" ]; then
490
+ # We already have the distribution name and version
491
+ return
492
+ fi
493
+
494
+ for rsource in $(__sort_release_files $(
495
+ cd /etc && /bin/ls *[_-]release *[_-]version 2>/dev/null | env -i sort | \
496
+ sed -e '/^redhat-release$/d' -e '/^lsb-release$/d'; \
497
+ echo redhat-release lsb-release
498
+ )); do
499
+
500
+ [ -L "/etc/${rsource}" ] && continue # Don't follow symlinks
501
+ [ ! -f "/etc/${rsource}" ] && continue # Does not exist
502
+
503
+ n=$(echo ${rsource} | sed -e 's/[_-]release$//' -e 's/[_-]version$//')
504
+ rv=$( (grep VERSION /etc/${rsource}; cat /etc/${rsource}) | grep '[0-9]' | sed -e 'q' )
505
+ [ "${rv}x" = "x" ] && continue # There's no version information. Continue to next rsource
506
+ v=$(__parse_version_string "$rv")
507
+ case $(echo ${n} | tr '[:upper:]' '[:lower:]') in
508
+ redhat )
509
+ if [ ".$(egrep 'CentOS' /etc/${rsource})" != . ]; then
510
+ n="CentOS"
511
+ elif [ ".$(egrep 'Red Hat Enterprise Linux' /etc/${rsource})" != . ]; then
512
+ n="<R>ed <H>at <E>nterprise <L>inux"
513
+ else
514
+ n="<R>ed <H>at <L>inux"
515
+ fi
516
+ ;;
517
+ arch ) n="Arch Linux" ;;
518
+ centos ) n="CentOS" ;;
519
+ debian ) n="Debian" ;;
520
+ ubuntu ) n="Ubuntu" ;;
521
+ fedora ) n="Fedora" ;;
522
+ suse ) n="SUSE" ;;
523
+ mandrake*|mandriva ) n="Mandriva" ;;
524
+ gentoo ) n="Gentoo" ;;
525
+ slackware ) n="Slackware" ;;
526
+ turbolinux ) n="TurboLinux" ;;
527
+ unitedlinux ) n="UnitedLinux" ;;
528
+ system )
529
+ while read -r line; do
530
+ [ "${n}x" != "systemx" ] && break
531
+ case "$line" in
532
+ *Amazon*Linux*AMI*)
533
+ n="Amazon Linux AMI"
534
+ break
535
+ esac
536
+ done < /etc/${rsource}
537
+ ;;
538
+ os )
539
+ n=$(__unquote_string $(grep '^NAME=' /etc/os-release | sed -e 's/^NAME=\(.*\)$/\1/g'))
540
+ [ "${n}" = "Arch Linux" ] && v="" # Arch Linux does not provide a version.
541
+ ;;
542
+ * ) n="${n}" ;
543
+ esac
544
+ DISTRO_NAME=$n
545
+ DISTRO_VERSION=$v
546
+ break
547
+ done
548
+ }
549
+
550
+
551
+ #--- FUNCTION ----------------------------------------------------------------
552
+ # NAME: __gather_sunos_system_info
553
+ # DESCRIPTION: Discover SunOS system info
554
+ #-------------------------------------------------------------------------------
555
+ __gather_sunos_system_info() {
556
+ if [ -f /sbin/uname ]; then
557
+ DISTRO_VERSION=$(/sbin/uname -X | grep -i kernelid | awk '{ print $3}')
558
+ fi
559
+
560
+ DISTRO_NAME=""
561
+ if [ -f /etc/release ]; then
562
+ while read -r line; do
563
+ [ "${DISTRO_NAME}x" != "x" ] && break
564
+ case "$line" in
565
+ *OpenIndiana*oi_[0-9]*)
566
+ DISTRO_NAME="OpenIndiana"
567
+ DISTRO_VERSION=$(echo "$line" | sed -nr "s/OpenIndiana(.*)oi_([[:digit:]]+)(.*)/\2/p")
568
+ break
569
+ ;;
570
+ *OpenSolaris*snv_[0-9]*)
571
+ DISTRO_NAME="OpenSolaris"
572
+ DISTRO_VERSION=$(echo "$line" | sed -nr "s/OpenSolaris(.*)snv_([[:digit:]]+)(.*)/\2/p")
573
+ break
574
+ ;;
575
+ *Oracle*Solaris*[0-9]*)
576
+ DISTRO_NAME="Oracle Solaris"
577
+ DISTRO_VERSION=$(echo "$line" | sed -nr "s/(Oracle Solaris) ([[:digit:]]+)(.*)/\2/p")
578
+ break
579
+ ;;
580
+ *Solaris*)
581
+ DISTRO_NAME="Solaris"
582
+ break
583
+ ;;
584
+ *NexentaCore*)
585
+ DISTRO_NAME="Nexenta Core"
586
+ break
587
+ ;;
588
+ *SmartOS*)
589
+ DISTRO_NAME="SmartOS"
590
+ break
591
+ ;;
592
+ esac
593
+ done < /etc/release
594
+ fi
595
+
596
+ if [ "${DISTRO_NAME}x" = "x" ]; then
597
+ DISTRO_NAME="Solaris"
598
+ DISTRO_VERSION=$(
599
+ echo "${OS_VERSION}" |
600
+ sed -e 's;^4\.;1.;' \
601
+ -e 's;^5\.\([0-6]\)[^0-9]*$;2.\1;' \
602
+ -e 's;^5\.\([0-9][0-9]*\).*;\1;'
603
+ )
604
+ fi
605
+ }
606
+
607
+
608
+ #--- FUNCTION ----------------------------------------------------------------
609
+ # NAME: __gather_bsd_system_info
610
+ # DESCRIPTION: Discover OpenBSD, NetBSD and FreeBSD systems information
611
+ #-------------------------------------------------------------------------------
612
+ __gather_bsd_system_info() {
613
+ DISTRO_NAME=${OS_NAME}
614
+ DISTRO_VERSION=$(echo "${OS_VERSION}" | sed -e 's;[()];;' -e 's/-.*$//')
615
+ }
616
+
617
+
618
+ #--- FUNCTION ----------------------------------------------------------------
619
+ # NAME: __gather_system_info
620
+ # DESCRIPTION: Discover which system and distribution we are running.
621
+ #-------------------------------------------------------------------------------
622
+ __gather_system_info() {
623
+ case ${OS_NAME_L} in
624
+ linux )
625
+ __gather_linux_system_info
626
+ ;;
627
+ sunos )
628
+ __gather_sunos_system_info
629
+ ;;
630
+ openbsd|freebsd|netbsd )
631
+ __gather_bsd_system_info
632
+ ;;
633
+ * )
634
+ echoerror "${OS_NAME} not supported.";
635
+ exit 1
636
+ ;;
637
+ esac
638
+
639
+ }
640
+ __gather_system_info
641
+
642
+
643
+ echo
644
+ echoinfo "System Information:"
645
+ echoinfo " CPU: ${CPU_VENDOR_ID}"
646
+ echoinfo " CPU Arch: ${CPU_ARCH}"
647
+ echoinfo " OS Name: ${OS_NAME}"
648
+ echoinfo " OS Version: ${OS_VERSION}"
649
+ echoinfo " Distribution: ${DISTRO_NAME} ${DISTRO_VERSION}"
650
+ echo
651
+
652
+ # Let users know what's going to be installed/configured
653
+ if [ $INSTALL_MINION -eq $BS_TRUE ]; then
654
+ if [ $CONFIG_ONLY -eq $BS_FALSE ]; then
655
+ echoinfo "Installing minion"
656
+ else
657
+ echoinfo "Configuring minion"
658
+ fi
659
+ fi
660
+
661
+ if [ $INSTALL_MASTER -eq $BS_TRUE ]; then
662
+ if [ $CONFIG_ONLY -eq $BS_FALSE ]; then
663
+ echoinfo "Installing master"
664
+ else
665
+ echoinfo "Configuring master"
666
+ fi
667
+ fi
668
+
669
+ if [ $INSTALL_SYNDIC -eq $BS_TRUE ]; then
670
+ if [ $CONFIG_ONLY -eq $BS_FALSE ]; then
671
+ echoinfo "Installing syndic"
672
+ else
673
+ echoinfo "Configuring syndic"
674
+ fi
675
+ fi
676
+
677
+ # Simplify version naming on functions
678
+ if [ "x${DISTRO_VERSION}" = "x" ]; then
679
+ DISTRO_MAJOR_VERSION=""
680
+ DISTRO_MINOR_VERSION=""
681
+ PREFIXED_DISTRO_MAJOR_VERSION=""
682
+ PREFIXED_DISTRO_MINOR_VERSION=""
683
+ else
684
+ DISTRO_MAJOR_VERSION="$(echo $DISTRO_VERSION | sed 's/^\([0-9]*\).*/\1/g')"
685
+ DISTRO_MINOR_VERSION="$(echo $DISTRO_VERSION | sed 's/^\([0-9]*\).\([0-9]*\).*/\2/g')"
686
+ PREFIXED_DISTRO_MAJOR_VERSION="_${DISTRO_MAJOR_VERSION}"
687
+ if [ "${PREFIXED_DISTRO_MAJOR_VERSION}" = "_" ]; then
688
+ PREFIXED_DISTRO_MAJOR_VERSION=""
689
+ fi
690
+ PREFIXED_DISTRO_MINOR_VERSION="_${DISTRO_MINOR_VERSION}"
691
+ if [ "${PREFIXED_DISTRO_MINOR_VERSION}" = "_" ]; then
692
+ PREFIXED_DISTRO_MINOR_VERSION=""
693
+ fi
694
+ fi
695
+ # Simplify distro name naming on functions
696
+ DISTRO_NAME_L=$(echo $DISTRO_NAME | tr '[:upper:]' '[:lower:]' | sed 's/[^a-zA-Z0-9_ ]//g' | sed -re 's/([[:space:]])+/_/g')
697
+
698
+
699
+ # Only Ubuntu has daily packages, let's let users know about that
700
+ if ([ "${DISTRO_NAME_L}" != "ubuntu" ] && [ $ITYPE = "daily" ]) && \
701
+ ([ "${DISTRO_NAME_L}" != "trisquel" ] && [ $ITYPE = "daily" ]); then
702
+ echoerror "${DISTRO_NAME} does not have daily packages support"
703
+ exit 1
704
+ fi
705
+
706
+
707
+ #--- FUNCTION ----------------------------------------------------------------
708
+ # NAME: __function_defined
709
+ # DESCRIPTION: Checks if a function is defined within this scripts scope
710
+ # PARAMETERS: function name
711
+ # RETURNS: 0 or 1 as in defined or not defined
712
+ #-------------------------------------------------------------------------------
713
+ __function_defined() {
714
+ FUNC_NAME=$1
715
+ if [ "$(command -v $FUNC_NAME)x" != "x" ]; then
716
+ echoinfo "Found function $FUNC_NAME"
717
+ return 0
718
+ fi
719
+ echodebug "$FUNC_NAME not found...."
720
+ return 1
721
+ }
722
+
723
+
724
+ #--- FUNCTION ----------------------------------------------------------------
725
+ # NAME: __git_clone_and_checkout
726
+ # DESCRIPTION: (DRY) Helper function to clone and checkout salt to a
727
+ # specific revision.
728
+ #-------------------------------------------------------------------------------
729
+ __git_clone_and_checkout() {
730
+ SALT_GIT_CHECKOUT_DIR=/tmp/git/salt
731
+ [ -d /tmp/git ] || mkdir /tmp/git
732
+ cd /tmp/git
733
+ if [ -d $SALT_GIT_CHECKOUT_DIR ]; then
734
+ cd $SALT_GIT_CHECKOUT_DIR
735
+ git fetch || return 1
736
+ # Tags are needed because of salt's versioning, also fetch that
737
+ git fetch --tags || return 1
738
+ git reset --hard $GIT_REV || return 1
739
+
740
+ # Just calling `git reset --hard $GIT_REV` on a branch name that has
741
+ # already been checked out will not update that branch to the upstream
742
+ # HEAD; instead it will simply reset to itself. Check the ref to see
743
+ # if it is a branch name, check out the branch, and pull in the
744
+ # changes.
745
+ git branch -a | grep -q ${GIT_REV}
746
+ if [ $? -eq 0 ]; then
747
+ git pull --rebase || return 1
748
+ fi
749
+ else
750
+ git clone https://github.com/saltstack/salt.git salt || return 1
751
+ cd $SALT_GIT_CHECKOUT_DIR
752
+ git checkout $GIT_REV || return 1
753
+ fi
754
+ return 0
755
+ }
756
+
757
+
758
+ #--- FUNCTION ----------------------------------------------------------------
759
+ # NAME: __apt_get_noinput
760
+ # DESCRIPTION: (DRY) apt-get install with noinput options
761
+ #-------------------------------------------------------------------------------
762
+ __apt_get_noinput() {
763
+ apt-get install -y -o DPkg::Options::=--force-confold $@; return $?
764
+ }
765
+
766
+
767
+ #--- FUNCTION ----------------------------------------------------------------
768
+ # NAME: copyfile
769
+ # DESCRIPTION: Simple function to copy files. Overrides if asked.
770
+ #-------------------------------------------------------------------------------
771
+ copyfile() {
772
+ overwrite=$FORCE_OVERWRITE
773
+ if [ $# -eq 2 ]; then
774
+ sfile=$1
775
+ dfile=$2
776
+ elif [ $# -eq 3 ]; then
777
+ sfile=$1
778
+ dfile=$2
779
+ overwrite=$3
780
+ else
781
+ echoerror "Wrong number of arguments for copyfile()"
782
+ echoinfo "USAGE: copyfile <source> <dest> OR copyfile <source> <dest> <overwrite>"
783
+ exit 1
784
+ fi
785
+
786
+ # Does the source file exist?
787
+ if [ ! -f "$sfile" ]; then
788
+ echowarn "$sfile does not exist!"
789
+ return 1
790
+ fi
791
+
792
+ if [ ! -f "$dfile" ]; then
793
+ # The destination file does not exist, copy
794
+ echodebug "Copying $sfile to $dfile"
795
+ cp "$sfile" "$dfile"
796
+ elif [ -f "$dfile" ] && [ $overwrite -eq $BS_TRUE ]; then
797
+ # The destination exist and we're overwriting
798
+ echodebug "Overriding $dfile with $sfile"
799
+ cp -f "$sfile" "$dfile"
800
+ elif [ -f "$dfile" ] && [ $overwrite -ne $BS_TRUE ]; then
801
+ echodebug "Not overriding $dfile with $sfile"
802
+ fi
803
+ return 0
804
+ }
805
+
806
+
807
+ ##############################################################################
808
+ #
809
+ # Distribution install functions
810
+ #
811
+ # In order to install salt for a distribution you need to define:
812
+ #
813
+ # To Install Dependencies, which is required, one of:
814
+ # 1. install_<distro>_<major_version>_<install_type>_deps
815
+ # 2. install_<distro>_<major_version>_<minor_version>_<install_type>_deps
816
+ # 3. install_<distro>_<major_version>_deps
817
+ # 4 install_<distro>_<major_version>_<minor_version>_deps
818
+ # 5. install_<distro>_<install_type>_deps
819
+ # 6. install_<distro>_deps
820
+ #
821
+ # Optionally, define a salt configuration function, which will be called if
822
+ # the -c|config-dir option is passed. One of:
823
+ # 1. config_<distro>_<major_version>_<install_type>_salt
824
+ # 2. config_<distro>_<major_version>_<minor_version>_<install_type>_salt
825
+ # 3. config_<distro>_<major_version>_salt
826
+ # 4 config_<distro>_<major_version>_<minor_version>_salt
827
+ # 5. config_<distro>_<install_type>_salt
828
+ # 6. config_<distro>_salt
829
+ # 7. config_salt [THIS ONE IS ALREADY DEFINED AS THE DEFAULT]
830
+ #
831
+ # To install salt, which, of course, is required, one of:
832
+ # 1. install_<distro>_<major_version>_<install_type>
833
+ # 2. install_<distro>_<major_version>_<minor_version>_<install_type>
834
+ # 3. install_<distro>_<install_type>
835
+ #
836
+ # Optionally, define a post install function, one of:
837
+ # 1. install_<distro>_<major_version>_<install_type>_post
838
+ # 2. install_<distro>_<major_version>_<minor_version>_<install_type>_post
839
+ # 3. install_<distro>_<major_version>_post
840
+ # 4 install_<distro>_<major_version>_<minor_version>_post
841
+ # 5. install_<distro>_<install_type>_post
842
+ # 6. install_<distro>_post
843
+ #
844
+ # Optionally, define a start daemons function, one of:
845
+ # 1. install_<distro>_<major_version>_<install_type>_restart_daemons
846
+ # 2. install_<distro>_<major_version>_<minor_version>_<install_type>_restart_daemons
847
+ # 3. install_<distro>_<major_version>_restart_daemons
848
+ # 4 install_<distro>_<major_version>_<minor_version>_restart_daemons
849
+ # 5. install_<distro>_<install_type>_restart_daemons
850
+ # 6. install_<distro>_restart_daemons
851
+ #
852
+ # NOTE: The start daemons function should be able to restart any daemons
853
+ # which are running, or start if they're not running.
854
+ #
855
+ ##############################################################################
856
+
857
+
858
+ ##############################################################################
859
+ #
860
+ # Ubuntu Install Functions
861
+ #
862
+ install_ubuntu_deps() {
863
+ apt-get update
864
+ if [ $DISTRO_MAJOR_VERSION -eq 12 ] && [ $DISTRO_MINOR_VERSION -gt 04 ] || [ $DISTRO_MAJOR_VERSION -gt 12 ]; then
865
+ # Above Ubuntu 12.04 add-apt-repository is in a different package
866
+ __apt_get_noinput software-properties-common
867
+ else
868
+ __apt_get_noinput python-software-properties
869
+ fi
870
+ if [ $DISTRO_MAJOR_VERSION -lt 11 ] && [ $DISTRO_MINOR_VERSION -lt 10 ]; then
871
+ add-apt-repository ppa:saltstack/salt
872
+ else
873
+ add-apt-repository -y ppa:saltstack/salt
874
+ fi
875
+ apt-get update
876
+ }
877
+
878
+ install_ubuntu_daily_deps() {
879
+ apt-get update
880
+ if [ $DISTRO_MAJOR_VERSION -eq 12 ] && [ $DISTRO_MINOR_VERSION -gt 04 ] || [ $DISTRO_MAJOR_VERSION -gt 12 ]; then
881
+ # Above Ubuntu 12.04 add-apt-repository is in a different package
882
+ __apt_get_noinput software-properties-common
883
+ else
884
+ __apt_get_noinput python-software-properties
885
+ fi
886
+ if [ $DISTRO_MAJOR_VERSION -lt 11 ] && [ $DISTRO_MINOR_VERSION -lt 10 ]; then
887
+ add-apt-repository ppa:saltstack/salt-daily
888
+ else
889
+ add-apt-repository -y ppa:saltstack/salt-daily
890
+ fi
891
+ apt-get update
892
+ }
893
+
894
+ install_ubuntu_11_10_deps() {
895
+ apt-get update
896
+ __apt_get_noinput python-software-properties
897
+ add-apt-repository -y 'deb http://us.archive.ubuntu.com/ubuntu/ oneiric universe'
898
+ add-apt-repository -y ppa:saltstack/salt
899
+ apt-get update
900
+ }
901
+
902
+ install_ubuntu_git_deps() {
903
+ install_ubuntu_deps
904
+ __apt_get_noinput git-core python-yaml python-m2crypto python-crypto msgpack-python python-zmq python-jinja2
905
+
906
+ __git_clone_and_checkout || return 1
907
+
908
+ # Let's trigger config_salt()
909
+ if [ "$TEMP_CONFIG_DIR" = "null" ]; then
910
+ TEMP_CONFIG_DIR="${SALT_GIT_CHECKOUT_DIR}/conf/"
911
+ CONFIG_SALT_FUNC="config_salt"
912
+ fi
913
+
914
+ return 0
915
+ }
916
+
917
+ install_ubuntu_11_10_post() {
918
+ add-apt-repository -y --remove 'deb http://us.archive.ubuntu.com/ubuntu/ oneiric universe'
919
+ }
920
+
921
+ install_ubuntu_stable() {
922
+ packages=""
923
+ if [ $INSTALL_MINION -eq $BS_TRUE ]; then
924
+ packages="${packages} salt-minion"
925
+ fi
926
+ if [ $INSTALL_MASTER -eq $BS_TRUE ]; then
927
+ packages="${packages} salt-master"
928
+ fi
929
+ if [ $INSTALL_SYNDIC -eq $BS_TRUE ]; then
930
+ packages="${packages} salt-syndic"
931
+ fi
932
+ __apt_get_noinput ${packages}
933
+ }
934
+
935
+ install_ubuntu_daily() {
936
+ install_ubuntu_stable
937
+ }
938
+
939
+ install_ubuntu_git() {
940
+ python setup.py install --install-layout=deb
941
+ }
942
+
943
+ install_ubuntu_git_post() {
944
+ for fname in minion master syndic; do
945
+
946
+ # Skip if not meant to be installed
947
+ [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
948
+ [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
949
+ [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
950
+
951
+ if [ -f /sbin/initctl ]; then
952
+ # We have upstart support
953
+ echodebug "There's upstart support"
954
+ /sbin/initctl status salt-$fname > /dev/null 2>&1
955
+
956
+ if [ $? -eq 1 ]; then
957
+ # upstart does not know about our service, let's copy the proper file
958
+ echowarn "Upstart does not apparently know anything about salt-$fname"
959
+ echodebug "Copying ${SALT_GIT_CHECKOUT_DIR}/pkg/salt-$fname.upstart to /etc/init/salt-$fname.conf"
960
+ copyfile ${SALT_GIT_CHECKOUT_DIR}/pkg/salt-$fname.upstart /etc/init/salt-$fname.conf
961
+ fi
962
+ # No upstart support in Ubuntu!?
963
+ elif [ -f ${SALT_GIT_CHECKOUT_DIR}/debian/salt-$fname.init ]; then
964
+ echodebug "There's NO upstart support!?"
965
+ echodebug "Copying ${SALT_GIT_CHECKOUT_DIR}/debian/salt-$fname.init to /etc/init.d/salt-$fname"
966
+ copyfile ${SALT_GIT_CHECKOUT_DIR}/debian/salt-$fname.init /etc/init.d/salt-$fname
967
+ chmod +x /etc/init.d/salt-$fname
968
+ update-rc.d salt-$fname defaults
969
+ else
970
+ echoerror "Neither upstart not init.d was setup for salt-$fname"
971
+ fi
972
+ done
973
+ }
974
+
975
+ install_ubuntu_restart_daemons() {
976
+ for fname in minion master syndic; do
977
+
978
+ # Skip if not meant to be installed
979
+ [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
980
+ [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
981
+ [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
982
+
983
+ if [ -f /sbin/initctl ]; then
984
+ echodebug "There's upstart support"
985
+ /sbin/initctl status salt-$fname || \
986
+ echowarn "Upstart does not apparently know anything about salt-$fname"
987
+ if [ $? -eq 0 ]; then
988
+ echodebug "Upstart apparently knows about salt-$fname"
989
+ # upstart knows about this service, let's stop and start it.
990
+ # We could restart but earlier versions of the upstart script
991
+ # did not support restart, so, it's safer this way
992
+ /sbin/initctl stop salt-$fname || echodebug "Failed to stop salt-$fname"
993
+ /sbin/initctl start salt-$fname
994
+ [ $? -eq 0 ] && continue
995
+ # We failed to start the service, let's test the SysV code bellow
996
+ echodebug "Failed to start salt-$fname"
997
+ fi
998
+ fi
999
+
1000
+ if [ ! -f /etc/init.d/salt-$fname ]; then
1001
+ echoerror "No init.d support for salt-$fname was found"
1002
+ return 1
1003
+ fi
1004
+
1005
+ /etc/init.d/salt-$fname stop > /dev/null 2>&1
1006
+ /etc/init.d/salt-$fname start
1007
+ done
1008
+ return 0
1009
+ }
1010
+ #
1011
+ # End of Ubuntu Install Functions
1012
+ #
1013
+ ##############################################################################
1014
+
1015
+ ##############################################################################
1016
+ #
1017
+ # Trisquel(Ubuntu) Install Functions
1018
+ #
1019
+ # Trisquel 6.0 is based on Ubuntu 12.04
1020
+ #
1021
+ install_trisquel_6_stable_deps() {
1022
+ apt-get update
1023
+ __apt_get_noinput python-software-properties
1024
+ add-apt-repository -y ppa:saltstack/salt
1025
+ apt-get update
1026
+ }
1027
+
1028
+ install_trisquel_6_daily_deps() {
1029
+ apt-get update
1030
+ __apt_get_noinput python-software-properties
1031
+ add-apt-repository -y ppa:saltstack/salt-daily
1032
+ apt-get update
1033
+ }
1034
+
1035
+ install_trisquel_6_git_deps() {
1036
+ install_trisquel_6_stable_deps
1037
+ __apt_get_noinput git-core python-yaml python-m2crypto python-crypto \
1038
+ msgpack-python python-zmq python-jinja2
1039
+
1040
+ __git_clone_and_checkout || return 1
1041
+
1042
+ # Let's trigger config_salt()
1043
+ if [ "$TEMP_CONFIG_DIR" = "null" ]; then
1044
+ TEMP_CONFIG_DIR="${SALT_GIT_CHECKOUT_DIR}/conf/"
1045
+ CONFIG_SALT_FUNC="config_salt"
1046
+ fi
1047
+
1048
+ return 0
1049
+ }
1050
+
1051
+ install_trisquel_6_stable() {
1052
+ install_ubuntu_stable
1053
+ }
1054
+
1055
+ install_trisquel_6_daily() {
1056
+ install_ubuntu_daily
1057
+ }
1058
+
1059
+ install_trisquel_6_git() {
1060
+ install_ubuntu_git
1061
+ }
1062
+
1063
+ install_trisquel_git_post() {
1064
+ install_ubuntu_git_post
1065
+ }
1066
+
1067
+ install_trisquel_restart_daemons() {
1068
+ install_ubuntu_restart_daemons
1069
+ }
1070
+ #
1071
+ # End of Tristel(Ubuntu) Install Functions
1072
+ #
1073
+ ##############################################################################
1074
+
1075
+ ##############################################################################
1076
+ #
1077
+ # Debian Install Functions
1078
+ #
1079
+ install_debian_deps() {
1080
+ apt-get update
1081
+ }
1082
+
1083
+ install_debian_6_0_deps() {
1084
+ [ $PIP_ALLOWED -eq $BS_FALSE ] && pip_not_allowed
1085
+ echowarn "PyZMQ will be installed from PyPi in order to compile it against ZMQ3"
1086
+ echowarn "This is required for long term stable minion connections to the master."
1087
+
1088
+ # No user interaction, libc6 restart services for example
1089
+ export DEBIAN_FRONTEND=noninteractive
1090
+
1091
+ if [ "x$(grep -R 'backports.debian.org' /etc/apt)" = "x" ]; then
1092
+ echo "deb http://backports.debian.org/debian-backports squeeze-backports main" >> \
1093
+ /etc/apt/sources.list.d/backports.list
1094
+ fi
1095
+
1096
+ if [ ! -f /etc/apt/preferences.d/local-salt-backport.pref ]; then
1097
+ # Add madduck's repo since squeeze packages have been deprecated
1098
+ for fname in salt-common salt-master salt-minion salt-syndic salt-doc; do
1099
+ echo "Package: $fname"
1100
+ echo "Pin: release a=squeeze-backports"
1101
+ echo "Pin-Priority: 600"
1102
+ echo
1103
+ done > /etc/apt/preferences.d/local-salt-backport.pref
1104
+
1105
+ cat <<_eof > /etc/apt/sources.list.d/local-madduck-backports.list
1106
+ deb http://debian.madduck.net/repo squeeze-backports main
1107
+ deb-src http://debian.madduck.net/repo squeeze-backports main
1108
+ _eof
1109
+
1110
+ wget -q http://debian.madduck.net/repo/gpg/archive.key -O - | apt-key add -
1111
+ fi
1112
+
1113
+ if [ ! -f /etc/apt/sources.list.d/debian-experimental.list ]; then
1114
+ cat <<_eof > /etc/apt/sources.list.d/debian-experimental.list
1115
+ deb http://ftp.debian.org/debian experimental main
1116
+ deb-src http://ftp.debian.org/debian experimental main
1117
+ _eof
1118
+
1119
+ cat <<_eof > /etc/apt/preferences.d/libzmq3-debian-experimental.pref
1120
+ Package: libzmq3
1121
+ Pin: release a=experimental
1122
+ Pin-Priority: 800
1123
+
1124
+ Package: libzmq3-dev
1125
+ Pin: release a=experimental
1126
+ Pin-Priority: 800
1127
+ _eof
1128
+ fi
1129
+
1130
+ apt-get update
1131
+ __apt_get_noinput -t experimental libzmq3 libzmq3-dev
1132
+ __apt_get_noinput build-essential python-dev python-pip
1133
+ }
1134
+
1135
+ install_debian_git_deps() {
1136
+ [ $PIP_ALLOWED -eq $BS_FALSE ] && pip_not_allowed
1137
+ echowarn "PyZMQ will be installed from PyPi in order to compile it against ZMQ3"
1138
+ echowarn "This is required for long term stable minion connections to the master."
1139
+
1140
+ # No user interaction, libc6 restart services for example
1141
+ export DEBIAN_FRONTEND=noninteractive
1142
+
1143
+ apt-get update
1144
+ __apt_get_noinput lsb-release python python-pkg-resources python-crypto \
1145
+ python-jinja2 python-m2crypto python-yaml msgpack-python python-pip git
1146
+
1147
+ __git_clone_and_checkout || return 1
1148
+
1149
+ # Let's trigger config_salt()
1150
+ if [ "$TEMP_CONFIG_DIR" = "null" ]; then
1151
+ TEMP_CONFIG_DIR="${SALT_GIT_CHECKOUT_DIR}/conf/"
1152
+ CONFIG_SALT_FUNC="config_salt"
1153
+ fi
1154
+
1155
+ return 0
1156
+ }
1157
+
1158
+ install_debian_6_0_git_deps() {
1159
+ install_debian_6_0_deps # Add backports
1160
+ install_debian_git_deps # Grab the actual deps
1161
+ }
1162
+
1163
+ install_debian_stable() {
1164
+ packages=""
1165
+ if [ $INSTALL_MINION -eq $BS_TRUE ]; then
1166
+ packages="${packages} salt-minion"
1167
+ fi
1168
+ if [ $INSTALL_MASTER -eq $BS_TRUE ]; then
1169
+ packages="${packages} salt-master"
1170
+ fi
1171
+ if [ $INSTALL_SYNDIC -eq $BS_TRUE ]; then
1172
+ packages="${packages} salt-syndic"
1173
+ fi
1174
+ __apt_get_noinput ${packages}
1175
+
1176
+ # Building pyzmq from source to build it against libzmq3.
1177
+ # Should override current installation
1178
+ pip install -U pyzmq
1179
+ }
1180
+
1181
+
1182
+ install_debian_6_0() {
1183
+ install_debian_stable
1184
+ }
1185
+
1186
+ install_debian_git() {
1187
+ python setup.py install --install-layout=deb
1188
+
1189
+ # Building pyzmq from source to build it against libzmq3.
1190
+ # Should override current installation
1191
+ pip install -U pyzmq
1192
+ }
1193
+
1194
+ install_debian_6_0_git() {
1195
+ install_debian_git
1196
+ }
1197
+
1198
+ install_debian_git_post() {
1199
+ for fname in minion master syndic; do
1200
+
1201
+ # Skip if not meant to be installed
1202
+ [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
1203
+ [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
1204
+ [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
1205
+
1206
+ if [ -f ${SALT_GIT_CHECKOUT_DIR}/debian/salt-$fname.init ]; then
1207
+ copyfile ${SALT_GIT_CHECKOUT_DIR}/debian/salt-$fname.init /etc/init.d/salt-$fname
1208
+ fi
1209
+ chmod +x /etc/init.d/salt-$fname
1210
+ update-rc.d salt-$fname defaults
1211
+ done
1212
+ }
1213
+
1214
+ install_debian_restart_daemons() {
1215
+ for fname in minion master syndic; do
1216
+
1217
+ # Skip if not meant to be installed
1218
+ [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
1219
+ [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
1220
+ [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
1221
+
1222
+ /etc/init.d/salt-$fname stop > /dev/null 2>&1
1223
+ /etc/init.d/salt-$fname start
1224
+ done
1225
+ }
1226
+ #
1227
+ # Ended Debian Install Functions
1228
+ #
1229
+ ##############################################################################
1230
+
1231
+ ##############################################################################
1232
+ #
1233
+ # Fedora Install Functions
1234
+ #
1235
+ install_fedora_deps() {
1236
+ yum install -y PyYAML libyaml m2crypto python-crypto python-jinja2 python-msgpack python-zmq
1237
+ }
1238
+
1239
+ install_fedora_stable() {
1240
+ packages=""
1241
+ if [ $INSTALL_MINION -eq $BS_TRUE ]; then
1242
+ packages="${packages} salt-minion"
1243
+ fi
1244
+ if [ $INSTALL_MASTER -eq $BS_TRUE ] || [ $INSTALL_SYNDIC -eq $BS_TRUE ]; then
1245
+ packages="${packages} salt-master"
1246
+ fi
1247
+ yum install -y ${packages}
1248
+ }
1249
+
1250
+ install_fedora_git_deps() {
1251
+ install_fedora_deps
1252
+ yum install -y git
1253
+
1254
+ __git_clone_and_checkout || return 1
1255
+
1256
+ # Let's trigger config_salt()
1257
+ if [ "$TEMP_CONFIG_DIR" = "null" ]; then
1258
+ TEMP_CONFIG_DIR="${SALT_GIT_CHECKOUT_DIR}/conf/"
1259
+ CONFIG_SALT_FUNC="config_salt"
1260
+ fi
1261
+
1262
+ return 0
1263
+ }
1264
+
1265
+ install_fedora_git() {
1266
+ python setup.py install
1267
+ }
1268
+
1269
+ install_fedora_git_post() {
1270
+ for fname in minion master syndic; do
1271
+
1272
+ # Skip if not meant to be installed
1273
+ [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
1274
+ [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
1275
+ [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
1276
+
1277
+ copyfile ${SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-$fname.service /lib/systemd/system/salt-$fname.service
1278
+
1279
+ systemctl is-enabled salt-$fname.service || (systemctl preset salt-$fname.service && systemctl enable salt-$fname.service)
1280
+ sleep 0.1
1281
+ systemctl daemon-reload
1282
+ done
1283
+ }
1284
+
1285
+ install_fedora_restart_daemons() {
1286
+ for fname in minion master syndic; do
1287
+
1288
+ # Skip if not meant to be installed
1289
+ [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
1290
+ [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
1291
+ [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
1292
+
1293
+ systemctl stop salt-$fname > /dev/null 2>&1
1294
+ systemctl start salt-$fname.service
1295
+ done
1296
+ }
1297
+ #
1298
+ # Ended Fedora Install Functions
1299
+ #
1300
+ ##############################################################################
1301
+
1302
+ ##############################################################################
1303
+ #
1304
+ # CentOS Install Functions
1305
+ #
1306
+ install_centos_stable_deps() {
1307
+ if [ $CPU_ARCH_L = "i686" ]; then
1308
+ EPEL_ARCH="i386"
1309
+ else
1310
+ EPEL_ARCH=$CPU_ARCH_L
1311
+ fi
1312
+ if [ $DISTRO_MAJOR_VERSION -eq 5 ]; then
1313
+ rpm -Uvh --force http://mirrors.kernel.org/fedora-epel/5/${EPEL_ARCH}/epel-release-5-4.noarch.rpm
1314
+ elif [ $DISTRO_MAJOR_VERSION -eq 6 ]; then
1315
+ rpm -Uvh --force http://mirrors.kernel.org/fedora-epel/6/${EPEL_ARCH}/epel-release-6-8.noarch.rpm
1316
+ else
1317
+ echoerror "Failed add EPEL repository support."
1318
+ exit 1
1319
+ fi
1320
+
1321
+ yum -y update
1322
+
1323
+ if [ $DISTRO_MAJOR_VERSION -eq 5 ]; then
1324
+ yum -y install PyYAML python26-m2crypto m2crypto python26 python26-crypto \
1325
+ python26-msgpack python26-zmq python26-jinja2 --enablerepo=epel-testing
1326
+ else
1327
+ yum -y install PyYAML m2crypto python-crypto python-msgpack python-zmq \
1328
+ python-jinja2 --enablerepo=epel-testing
1329
+ fi
1330
+ }
1331
+
1332
+ install_centos_stable() {
1333
+ packages=""
1334
+ if [ $INSTALL_MINION -eq $BS_TRUE ]; then
1335
+ packages="${packages} salt-minion"
1336
+ fi
1337
+ if [ $INSTALL_MASTER -eq $BS_TRUE ] || [ $INSTALL_SYNDIC -eq $BS_TRUE ]; then
1338
+ packages="${packages} salt-master"
1339
+ fi
1340
+ yum -y install ${packages} --enablerepo=epel-testing
1341
+ }
1342
+
1343
+ install_centos_stable_post() {
1344
+ for fname in minion master syndic; do
1345
+ # Skip if not meant to be installed
1346
+ [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
1347
+ [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
1348
+ [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
1349
+
1350
+ if [ ! -f /sbin/initctl ] && [ -f /etc/init.d/salt-$fname ]; then
1351
+ # Still in SysV init!?
1352
+ /sbin/chkconfig salt-$fname on
1353
+ fi
1354
+ done
1355
+ }
1356
+
1357
+ install_centos_git_deps() {
1358
+ install_centos_stable_deps
1359
+ yum -y install git --enablerepo=epel-testing
1360
+
1361
+ __git_clone_and_checkout || return 1
1362
+
1363
+ # Let's trigger config_salt()
1364
+ if [ "$TEMP_CONFIG_DIR" = "null" ]; then
1365
+ TEMP_CONFIG_DIR="${SALT_GIT_CHECKOUT_DIR}/conf/"
1366
+ CONFIG_SALT_FUNC="config_salt"
1367
+ fi
1368
+
1369
+ return 0
1370
+ }
1371
+
1372
+ install_centos_git() {
1373
+ if [ $DISTRO_MAJOR_VERSION -eq 5 ]; then
1374
+ python2.6 setup.py install
1375
+ else
1376
+ python2 setup.py install
1377
+ fi
1378
+ }
1379
+
1380
+ install_centos_git_post() {
1381
+ for fname in master minion syndic; do
1382
+
1383
+ # Skip if not meant to be installed
1384
+ [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
1385
+ [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
1386
+ [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
1387
+
1388
+ if [ -f /sbin/initctl ]; then
1389
+ # We have upstart support
1390
+ /sbin/initctl status salt-$fname > /dev/null 2>&1
1391
+ if [ $? -eq 1 ]; then
1392
+ # upstart does not know about our service, let's copy the proper file
1393
+ copyfile ${SALT_GIT_CHECKOUT_DIR}/pkg/salt-$fname.upstart /etc/init/salt-$fname.conf
1394
+ fi
1395
+ # Still in SysV init?!
1396
+ elif [ ! -f /etc/init.d/salt-$fname ]; then
1397
+ copyfile ${SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-${fname} /etc/init.d/
1398
+ chmod +x /etc/init.d/salt-${fname}
1399
+ /sbin/chkconfig salt-${fname} on
1400
+ fi
1401
+ done
1402
+ }
1403
+
1404
+ install_centos_restart_daemons() {
1405
+ for fname in minion master syndic; do
1406
+ # Skip if not meant to be installed
1407
+ [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
1408
+ [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
1409
+ [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
1410
+
1411
+ if [ -f /sbin/initctl ]; then
1412
+ # We have upstart support
1413
+ /sbin/initctl status salt-$fname > /dev/null 2>&1
1414
+ if [ $? -eq 0 ]; then
1415
+ # upstart knows about this service.
1416
+ # Let's try to stop it, and then start it
1417
+ /sbin/initctl stop salt-$fname > /dev/null 2>&1
1418
+ /sbin/initctl start salt-$fname > /dev/null 2>&1
1419
+ # Restart service
1420
+ [ $? -eq 0 ] && continue
1421
+ # We failed to start the service, let's test the SysV code bellow
1422
+ fi
1423
+ fi
1424
+
1425
+ if [ -f /etc/init.d/salt-$fname ]; then
1426
+ # Still in SysV init!?
1427
+ /etc/init.d/salt-$fname stop > /dev/null 2>&1
1428
+ /etc/init.d/salt-$fname start
1429
+ fi
1430
+ done
1431
+ }
1432
+ #
1433
+ # Ended CentOS Install Functions
1434
+ #
1435
+ ##############################################################################
1436
+
1437
+ ##############################################################################
1438
+ #
1439
+ # RedHat Install Functions
1440
+ #
1441
+ install_red_hat_linux_stable_deps() {
1442
+ install_centos_stable_deps
1443
+ }
1444
+
1445
+ install_red_hat_linux_git_deps() {
1446
+ install_centos_git_deps
1447
+ }
1448
+
1449
+ install_red_hat_enterprise_linux_stable_deps() {
1450
+ install_red_hat_linux_stable_deps
1451
+ }
1452
+
1453
+ install_red_hat_enterprise_linux_git_deps() {
1454
+ install_red_hat_linux_git_deps
1455
+ }
1456
+
1457
+ install_red_hat_enterprise_server_stable_deps() {
1458
+ install_red_hat_linux_stable_deps
1459
+ }
1460
+
1461
+ install_red_hat_enterprise_server_git_deps() {
1462
+ install_red_hat_linux_git_deps
1463
+ }
1464
+
1465
+ install_red_hat_linux_stable() {
1466
+ install_centos_stable
1467
+ }
1468
+
1469
+ install_red_hat_linux_git() {
1470
+ install_centos_git
1471
+ }
1472
+
1473
+ install_red_hat_enterprise_linux_stable() {
1474
+ install_red_hat_linux_stable
1475
+ }
1476
+
1477
+ install_red_hat_enterprise_linux_git() {
1478
+ install_red_hat_linux_git
1479
+ }
1480
+
1481
+ install_red_hat_enterprise_server_stable() {
1482
+ install_red_hat_linux_stable
1483
+ }
1484
+
1485
+ install_red_hat_enterprise_server_git() {
1486
+ install_red_hat_linux_git
1487
+ }
1488
+
1489
+ install_red_hat_linux_stable_post() {
1490
+ install_centos_stable_post
1491
+ }
1492
+
1493
+ install_red_hat_linux_restart_daemons() {
1494
+ install_centos_restart_daemons
1495
+ }
1496
+
1497
+ install_red_hat_linux_git_post() {
1498
+ install_centos_git_post
1499
+ }
1500
+
1501
+ install_red_hat_enterprise_linux_stable_post() {
1502
+ install_red_hat_linux_stable_post
1503
+ }
1504
+
1505
+ install_red_hat_enterprise_linux_restart_daemons() {
1506
+ install_red_hat_linux_restart_daemons
1507
+ }
1508
+
1509
+ install_red_hat_enterprise_linux_git_post() {
1510
+ install_red_hat_linux_git_post
1511
+ }
1512
+
1513
+ install_red_hat_enterprise_server_stable_post() {
1514
+ install_red_hat_linux_stable_post
1515
+ }
1516
+
1517
+ install_red_hat_enterprise_server_restart_daemons() {
1518
+ install_red_hat_linux_restart_daemons
1519
+ }
1520
+
1521
+ install_red_hat_enterprise_server_git_post() {
1522
+ install_red_hat_linux_git_post
1523
+ }
1524
+ #
1525
+ # Ended RedHat Install Functions
1526
+ #
1527
+ ##############################################################################
1528
+
1529
+ ##############################################################################
1530
+ #
1531
+ # Amazon Linux AMI Install Functions
1532
+ #
1533
+ install_amazon_linux_ami_deps() {
1534
+ # Acording to http://aws.amazon.com/amazon-linux-ami/faqs/#epel we should
1535
+ # enable the EPEL 6 repo
1536
+ if [ $CPU_ARCH_L = "i686" ]; then
1537
+ EPEL_ARCH="i386"
1538
+ else
1539
+ EPEL_ARCH=$CPU_ARCH_L
1540
+ fi
1541
+ rpm -Uvh --force http://mirrors.kernel.org/fedora-epel/6/${EPEL_ARCH}/epel-release-6-8.noarch.rpm
1542
+ yum -y update
1543
+ yum -y install PyYAML m2crypto python-crypto python-msgpack python-zmq \
1544
+ python-ordereddict python-jinja2 --enablerepo=epel-testing
1545
+ }
1546
+
1547
+ install_amazon_linux_ami_git_deps() {
1548
+ install_amazon_linux_ami_deps
1549
+ yum -y install git --enablerepo=epel-testing
1550
+
1551
+ __git_clone_and_checkout || return 1
1552
+
1553
+ # Let's trigger config_salt()
1554
+ if [ "$TEMP_CONFIG_DIR" = "null" ]; then
1555
+ TEMP_CONFIG_DIR="${SALT_GIT_CHECKOUT_DIR}/conf/"
1556
+ CONFIG_SALT_FUNC="config_salt"
1557
+ fi
1558
+
1559
+ return 0
1560
+ }
1561
+
1562
+ install_amazon_linux_ami_stable() {
1563
+ install_centos_stable
1564
+ }
1565
+
1566
+ install_amazon_linux_ami_stable_post() {
1567
+ install_centos_stable_post
1568
+ }
1569
+
1570
+ install_amazon_linux_ami_restart_daemons() {
1571
+ install_centos_restart_daemons
1572
+ }
1573
+
1574
+ install_amazon_linux_ami_git() {
1575
+ install_centos_git
1576
+ }
1577
+
1578
+ install_amazon_linux_ami_git_post() {
1579
+ install_centos_git_post
1580
+ }
1581
+ #
1582
+ # Ended Amazon Linux AMI Install Functions
1583
+ #
1584
+ ##############################################################################
1585
+
1586
+ ##############################################################################
1587
+ #
1588
+ # Arch Install Functions
1589
+ #
1590
+ install_arch_linux_stable_deps() {
1591
+ grep '\[salt\]' /etc/pacman.conf >/dev/null 2>&1 || echo '[salt]
1592
+ Server = http://intothesaltmine.org/archlinux
1593
+ ' >> /etc/pacman.conf
1594
+ }
1595
+
1596
+ install_arch_linux_git_deps() {
1597
+ grep '\[salt\]' /etc/pacman.conf >/dev/null 2>&1 || echo '[salt]
1598
+ Server = http://intothesaltmine.org/archlinux
1599
+ ' >> /etc/pacman.conf
1600
+
1601
+ pacman -Sy --noconfirm pacman
1602
+ pacman -Sy --noconfirm git python2-crypto python2-distribute \
1603
+ python2-jinja python2-m2crypto python2-markupsafe python2-msgpack \
1604
+ python2-psutil python2-yaml python2-pyzmq zeromq
1605
+
1606
+ __git_clone_and_checkout || return 1
1607
+
1608
+ # Let's trigger config_salt()
1609
+ if [ "$TEMP_CONFIG_DIR" = "null" ]; then
1610
+ TEMP_CONFIG_DIR="${SALT_GIT_CHECKOUT_DIR}/conf/"
1611
+ CONFIG_SALT_FUNC="config_salt"
1612
+ fi
1613
+
1614
+ return 0
1615
+ }
1616
+
1617
+ install_arch_linux_stable() {
1618
+ pacman -Sy --noconfirm pacman
1619
+ pacman -Syu --noconfirm salt
1620
+ }
1621
+
1622
+ install_arch_linux_git() {
1623
+ python2 setup.py install
1624
+ }
1625
+
1626
+ install_arch_linux_post() {
1627
+ for fname in minion master syndic; do
1628
+
1629
+ # Skip if not meant to be installed
1630
+ [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
1631
+ [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
1632
+ [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
1633
+
1634
+ if [ -f /usr/bin/systemctl ]; then
1635
+ # Using systemd
1636
+ /usr/bin/systemctl is-enabled salt-$fname.service > /dev/null 2>&1 || (
1637
+ /usr/bin/systemctl preset salt-$fname.service > /dev/null 2>&1 &&
1638
+ /usr/bin/systemctl enable salt-$fname.service > /dev/null 2>&1
1639
+ )
1640
+ sleep 0.1
1641
+ /usr/bin/systemctl daemon-reload
1642
+ continue
1643
+ fi
1644
+
1645
+ # XXX: How do we enable old Arch init.d scripts?
1646
+ done
1647
+ }
1648
+
1649
+ install_arch_linux_git_post() {
1650
+ for fname in minion master syndic; do
1651
+
1652
+ # Skip if not meant to be installed
1653
+ [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
1654
+ [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
1655
+ [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
1656
+
1657
+ if [ -f /usr/bin/systemctl ]; then
1658
+ copyfile ${SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-$fname.service /lib/systemd/system/salt-$fname.service
1659
+
1660
+ /usr/bin/systemctl is-enabled salt-$fname.service > /dev/null 2>&1 || (
1661
+ /usr/bin/systemctl preset salt-$fname.service > /dev/null 2>&1 &&
1662
+ /usr/bin/systemctl enable salt-$fname.service > /dev/null 2>&1
1663
+ )
1664
+ sleep 0.1
1665
+ /usr/bin/systemctl daemon-reload
1666
+ continue
1667
+ fi
1668
+
1669
+ # SysV init!?
1670
+ copyfile ${SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-$fname /etc/rc.d/init.d/salt-$fname
1671
+ chmod +x /etc/rc.d/init.d/salt-$fname
1672
+ done
1673
+ }
1674
+
1675
+ install_arch_linux_restart_daemons() {
1676
+ for fname in minion master syndic; do
1677
+
1678
+ # Skip if not meant to be installed
1679
+ [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
1680
+ [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
1681
+ [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
1682
+
1683
+ if [ -f /usr/bin/systemctl ]; then
1684
+ /usr/bin/systemctl stop salt-$fname.service > /dev/null 2>&1
1685
+ /usr/bin/systemctl start salt-$fname.service
1686
+ continue
1687
+ fi
1688
+ /etc/rc.d/salt-$fname stop > /dev/null 2>&1
1689
+ /etc/rc.d/salt-$fname start
1690
+ done
1691
+ }
1692
+ #
1693
+ # Ended Arch Install Functions
1694
+ #
1695
+ ##############################################################################
1696
+
1697
+ ##############################################################################
1698
+ #
1699
+ # FreeBSD Install Functions
1700
+ #
1701
+ __freebsd_get_packagesite() {
1702
+ if [ $CPU_ARCH_L = "amd64" ]; then
1703
+ BSD_ARCH="x86:64"
1704
+ elif [ $CPU_ARCH_L = "x86_64" ]; then
1705
+ BSD_ARCH="x86:64"
1706
+ elif [ $CPU_ARCH_L = "i386" ]; then
1707
+ BSD_ARCH="x86:32"
1708
+ elif [ $CPU_ARCH_L = "i686" ]; then
1709
+ BSD_ARCH="x86:32"
1710
+ fi
1711
+
1712
+ if [ "x${PACKAGESITE}" = "x" ]; then
1713
+ echowarn "The environment variable PACKAGESITE is not set."
1714
+ echowarn "The installation will, most likely fail since pkgbeta.freebsd.org does not yet contain any packages"
1715
+ fi
1716
+ BS_PACKAGESITE=${PACKAGESITE:-"http://pkgbeta.freebsd.org/freebsd:${DISTRO_MAJOR_VERSION}:${BSD_ARCH}/latest"}
1717
+ }
1718
+
1719
+ install_freebsd_9_stable_deps() {
1720
+ __freebsd_get_packagesite
1721
+
1722
+ fetch "${BS_PACKAGESITE}/Latest/pkg.txz"
1723
+ tar xf ./pkg.txz -s ",/.*/,,g" "*/pkg-static"
1724
+ ./pkg-static add ./pkg.txz
1725
+ /usr/local/sbin/pkg2ng
1726
+ echo "PACKAGESITE: ${BS_PACKAGESITE}" > /usr/local/etc/pkg.conf
1727
+
1728
+ /usr/local/sbin/pkg install -y swig
1729
+ }
1730
+
1731
+ install_freebsd_git_deps() {
1732
+ __freebsd_get_packagesite
1733
+
1734
+ fetch "${BS_PACKAGESITE}/Latest/pkg.txz"
1735
+ tar xf ./pkg.txz -s ",/.*/,,g" "*/pkg-static"
1736
+ ./pkg-static add ./pkg.txz
1737
+ /usr/local/sbin/pkg2ng
1738
+ echo "PACKAGESITE: ${BS_PACKAGESITE}" > /usr/local/etc/pkg.conf
1739
+
1740
+ /usr/local/sbin/pkg install -y swig
1741
+
1742
+ __git_clone_and_checkout || return 1
1743
+ # Let's trigger config_salt()
1744
+ if [ "$TEMP_CONFIG_DIR" = "null" ]; then
1745
+ TEMP_CONFIG_DIR="${SALT_GIT_CHECKOUT_DIR}/conf/"
1746
+ CONFIG_SALT_FUNC="config_salt"
1747
+ fi
1748
+
1749
+ return 0
1750
+ }
1751
+
1752
+ install_freebsd_9_stable() {
1753
+ /usr/local/sbin/pkg install -y sysutils/py-salt
1754
+ }
1755
+
1756
+ install_freebsd_git() {
1757
+ /usr/local/sbin/pkg install -y git sysutils/py-salt
1758
+ /usr/local/sbin/pkg delete -y sysutils/py-salt
1759
+
1760
+ /usr/local/bin/python setup.py install
1761
+ }
1762
+
1763
+ install_freebsd_9_stable_post() {
1764
+ for fname in minion master syndic; do
1765
+
1766
+ # Skip if not meant to be installed
1767
+ [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
1768
+ [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
1769
+ [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
1770
+
1771
+ enable_string="salt_${fname}_enable=\"YES\""
1772
+ grep "$enable_string" /etc/rc.conf >/dev/null 2>&1
1773
+ [ $? -eq 1 ] && echo "$enable_string" >> /etc/rc.conf
1774
+
1775
+ [ -f /usr/local/etc/salt/${fname}.sample ] && copyfile /usr/local/etc/salt/${fname}.sample /usr/local/etc/salt/${fname}
1776
+
1777
+ if [ $fname = "minion" ] ; then
1778
+ grep "salt_minion_paths" /etc/rc.conf >/dev/null 2>&1
1779
+ [ $? -eq 1 ] && echo "salt_minion_paths=\"/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin\"" >> /etc/rc.conf
1780
+ fi
1781
+
1782
+ done
1783
+ }
1784
+
1785
+ install_freebsd_git_post() {
1786
+ install_freebsd_9_stable_post
1787
+ }
1788
+
1789
+ install_freebsd_restart_daemons() {
1790
+ for fname in minion master syndic; do
1791
+
1792
+ # Skip if not meant to be installed
1793
+ [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
1794
+ [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
1795
+ [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
1796
+
1797
+ service salt_$fname stop > /dev/null 2>&1
1798
+ service salt_$fname start
1799
+ done
1800
+ }
1801
+ #
1802
+ # Ended FreeBSD Install Functions
1803
+ #
1804
+ ##############################################################################
1805
+
1806
+ ##############################################################################
1807
+ #
1808
+ # SmartOS Install Functions
1809
+ #
1810
+ install_smartos_deps() {
1811
+ [ $PIP_ALLOWED -eq $BS_FALSE ] && pip_not_allowed
1812
+ echowarn "PyZMQ will be installed using pip"
1813
+
1814
+ ZEROMQ_VERSION='3.2.2'
1815
+ pkgin -y in libtool-base autoconf automake libuuid gcc-compiler gmake \
1816
+ python27 py27-pip py27-setuptools py27-yaml py27-crypto swig
1817
+ [ -d zeromq-${ZEROMQ_VERSION} ] || (
1818
+ wget http://download.zeromq.org/zeromq-${ZEROMQ_VERSION}.tar.gz &&
1819
+ tar -xvf zeromq-${ZEROMQ_VERSION}.tar.gz
1820
+ )
1821
+ cd zeromq-${ZEROMQ_VERSION}
1822
+ ./configure
1823
+ make
1824
+ make install
1825
+
1826
+ pip-2.7 install pyzmq
1827
+
1828
+ # Let's trigger config_salt()
1829
+ if [ "$TEMP_CONFIG_DIR" = "null" ]; then
1830
+ # Let's set the configuration directory to /tmp
1831
+ TEMP_CONFIG_DIR="/tmp"
1832
+ CONFIG_SALT_FUNC="config_salt"
1833
+
1834
+ # Let's download, since they were not provided, the default configuration files
1835
+ if [ ! -f /etc/salt/minion ] && [ ! -f $TEMP_CONFIG_DIR/minion ]; then
1836
+ curl -sk -o $TEMP_CONFIG_DIR/minion -L https://raw.github.com/saltstack/salt/blob/develop/conf/minion
1837
+ fi
1838
+ if [ ! -f /etc/salt/master ] && [ ! -f $TEMP_CONFIG_DIR/master ]; then
1839
+ curl -sk -o $TEMP_CONFIG_DIR/master -L https://raw.github.com/saltstack/salt/blob/develop/conf/master
1840
+ fi
1841
+ fi
1842
+
1843
+ }
1844
+
1845
+ install_smartos_git_deps() {
1846
+ install_smartos_deps
1847
+ pkgin -y in scmgit
1848
+
1849
+ __git_clone_and_checkout || return 1
1850
+ # Let's trigger config_salt()
1851
+ if [ "$TEMP_CONFIG_DIR" = "null" ]; then
1852
+ TEMP_CONFIG_DIR="${SALT_GIT_CHECKOUT_DIR}/conf/"
1853
+ CONFIG_SALT_FUNC="config_salt"
1854
+ fi
1855
+
1856
+ return 0
1857
+ }
1858
+
1859
+ install_smartos_stable() {
1860
+ USE_SETUPTOOLS=1 pip-2.7 install salt
1861
+ }
1862
+
1863
+ install_smartos_git() {
1864
+ # Use setuptools in order to also install dependencies
1865
+ USE_SETUPTOOLS=1 /opt/local/bin/python setup.py install
1866
+ }
1867
+
1868
+ install_smartos_post() {
1869
+ # Install manifest files if needed.
1870
+ for fname in minion master syndic; do
1871
+ svcs network/salt-$fname > /dev/null 2>&1
1872
+ if [ $? -eq 1 ]; then
1873
+ if [ ! -f $TEMP_CONFIG_DIR/salt-$fname.xml ]; then
1874
+ curl -sk -o $TEMP_CONFIG_DIR/salt-$fname.xml -L https://raw.github.com/saltstack/salt/develop/pkg/solaris/salt-$fname.xml
1875
+ fi
1876
+ svccfg import $TEMP_CONFIG_DIR/salt-$fname.xml
1877
+ fi
1878
+ done
1879
+ }
1880
+
1881
+ install_smartos_git_post() {
1882
+ # Install manifest files if needed.
1883
+ for fname in minion master syndic; do
1884
+ svcs network/salt-$fname > /dev/null 2>&1
1885
+ if [ $? -eq 1 ]; then
1886
+ svccfg import ${SALT_GIT_CHECKOUT_DIR}/pkg/solaris/salt-$fname.xml
1887
+ fi
1888
+ done
1889
+ }
1890
+
1891
+ install_smartos_restart_daemons() {
1892
+ for fname in minion master syndic; do
1893
+
1894
+ # Skip if not meant to be installed
1895
+ [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
1896
+ [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
1897
+ [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
1898
+
1899
+ # Stop if running && Start service
1900
+ svcadm disable salt-$fname > /dev/null 2>&1
1901
+ svcadm enable salt-$fname
1902
+ done
1903
+ }
1904
+ #
1905
+ # Ended SmartOS Install Functions
1906
+ #
1907
+ ##############################################################################
1908
+
1909
+ ##############################################################################
1910
+ #
1911
+ # openSUSE Install Functions.
1912
+ #
1913
+ install_opensuse_stable_deps() {
1914
+ DISTRO_REPO="openSUSE_${DISTRO_MAJOR_VERSION}.${DISTRO_MINOR_VERSION}"
1915
+ zypper --non-interactive addrepo --refresh \
1916
+ http://download.opensuse.org/repositories/devel:/languages:/python/${DISTRO_REPO}/devel:languages:python.repo
1917
+ zypper --gpg-auto-import-keys --non-interactive refresh
1918
+ zypper --non-interactive install --auto-agree-with-licenses libzmq3 python \
1919
+ python-Jinja2 python-M2Crypto python-PyYAML python-msgpack-python \
1920
+ python-pycrypto python-pyzmq
1921
+ }
1922
+
1923
+ install_opensuse_git_deps() {
1924
+ install_opensuse_stable_deps
1925
+ zypper --non-interactive install --auto-agree-with-licenses git
1926
+
1927
+ __git_clone_and_checkout || return 1
1928
+
1929
+ # Let's trigger config_salt()
1930
+ if [ "$TEMP_CONFIG_DIR" = "null" ]; then
1931
+ TEMP_CONFIG_DIR="${SALT_GIT_CHECKOUT_DIR}/conf/"
1932
+ CONFIG_SALT_FUNC="config_salt"
1933
+ fi
1934
+
1935
+ return 0
1936
+ }
1937
+
1938
+ install_opensuse_stable() {
1939
+ packages=""
1940
+ if [ $INSTALL_MINION -eq $BS_TRUE ]; then
1941
+ packages="${packages} salt-minion"
1942
+ fi
1943
+ if [ $INSTALL_MASTER -eq $BS_TRUE ]; then
1944
+ packages="${packages} salt-master"
1945
+ fi
1946
+ if [ $INSTALL_SYNDIC -eq $BS_TRUE ]; then
1947
+ packages="${packages} salt-syndic"
1948
+ fi
1949
+ zypper --non-interactive install --auto-agree-with-licenses $packages
1950
+ }
1951
+
1952
+ install_opensuse_git() {
1953
+ python setup.py install --prefix=/usr
1954
+ }
1955
+
1956
+ install_opensuse_stable_post() {
1957
+ for fname in minion master syndic; do
1958
+
1959
+ # Skip if not meant to be installed
1960
+ [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
1961
+ [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
1962
+ [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
1963
+
1964
+ if [ -f /bin/systemctl ]; then
1965
+ systemctl is-enabled salt-$fname.service || (systemctl preset salt-$fname.service && systemctl enable salt-$fname.service)
1966
+ sleep 0.1
1967
+ systemctl daemon-reload
1968
+ continue
1969
+ fi
1970
+
1971
+ /sbin/chkconfig --add salt-$fname
1972
+ /sbin/chkconfig salt-$fname on
1973
+
1974
+ done
1975
+ }
1976
+
1977
+ install_opensuse_git_post() {
1978
+ for fname in minion master syndic; do
1979
+
1980
+ # Skip if not meant to be installed
1981
+ [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
1982
+ [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
1983
+ [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
1984
+
1985
+ if [ -f /bin/systemctl ]; then
1986
+ copyfile ${SALT_GIT_CHECKOUT_DIR}/pkg/salt-$fname.service /lib/systemd/system/salt-$fname.service
1987
+ continue
1988
+ fi
1989
+
1990
+ copyfile ${SALT_GIT_CHECKOUT_DIR}/pkg/rpm/salt-$fname /etc/init.d/salt-$fname
1991
+ chmod +x /etc/init.d/salt-$fname
1992
+
1993
+ done
1994
+
1995
+ install_opensuse_stable_post
1996
+ }
1997
+
1998
+ install_opensuse_restart_daemons() {
1999
+ for fname in minion master syndic; do
2000
+
2001
+ # Skip if not meant to be installed
2002
+ [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
2003
+ [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
2004
+ [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
2005
+
2006
+ if [ -f /bin/systemctl ]; then
2007
+ systemctl stop salt-$fname > /dev/null 2>&1
2008
+ systemctl start salt-$fname.service
2009
+ continue
2010
+ fi
2011
+
2012
+ service salt-$fname stop > /dev/null 2>&1
2013
+ service salt-$fname start
2014
+
2015
+ done
2016
+ }
2017
+ #
2018
+ # End of openSUSE Install Functions.
2019
+ #
2020
+ ##############################################################################
2021
+
2022
+ ##############################################################################
2023
+ #
2024
+ # SuSE Install Functions.
2025
+ #
2026
+ install_suse_11_stable_deps() {
2027
+ SUSE_PATCHLEVEL=$(grep PATCHLEVEL /etc/SuSE-release | awk '{print $3}')
2028
+ if [ "x${SUSE_PATCHLEVEL}" != "x" ]; then
2029
+ DISTRO_PATCHLEVEL="_SP${SUSE_PATCHLEVEL}"
2030
+ fi
2031
+ DISTRO_REPO="SLE_${DISTRO_MAJOR_VERSION}${DISTRO_PATCHLEVEL}"
2032
+
2033
+ zypper --non-interactive addrepo --refresh \
2034
+ http://download.opensuse.org/repositories/devel:/languages:/python/${DISTRO_REPO}/devel:languages:python.repo
2035
+ zypper --gpg-auto-import-keys --non-interactive refresh
2036
+ if [ $SUSE_PATCHLEVEL -eq 1 ]; then
2037
+ [ $PIP_ALLOWED -eq $BS_FALSE ] && pip_not_allowed
2038
+ echowarn "PyYaml will be installed using pip"
2039
+ zypper --non-interactive install --auto-agree-with-licenses libzmq3 python \
2040
+ python-Jinja2 'python-M2Crypto>=0.21' python-msgpack-python \
2041
+ python-pycrypto python-pyzmq python-pip
2042
+ # There's no python-PyYaml in SP1, let's install it using pip
2043
+ pip install PyYaml
2044
+ else
2045
+ zypper --non-interactive install --auto-agree-with-licenses libzmq3 python \
2046
+ python-Jinja2 'python-M2Crypto>=0.21' python-PyYAML python-msgpack-python \
2047
+ python-pycrypto python-pyzmq
2048
+ fi
2049
+ }
2050
+
2051
+ install_suse_11_git_deps() {
2052
+ install_suse_11_stable_deps
2053
+ zypper --non-interactive install --auto-agree-with-licenses git
2054
+
2055
+ __git_clone_and_checkout || return 1
2056
+
2057
+ # Let's trigger config_salt()
2058
+ if [ "$TEMP_CONFIG_DIR" = "null" ]; then
2059
+ TEMP_CONFIG_DIR="${SALT_GIT_CHECKOUT_DIR}/conf/"
2060
+ CONFIG_SALT_FUNC="config_salt"
2061
+ fi
2062
+
2063
+ return 0
2064
+ }
2065
+
2066
+ install_suse_11_stable() {
2067
+ if [ $SUSE_PATCHLEVEL -gt 1 ]; then
2068
+ install_opensuse_stable
2069
+ else
2070
+ # USE_SETUPTOOLS=1 To work around
2071
+ # error: option --single-version-externally-managed not recognized
2072
+ USE_SETUPTOOLS=1 pip install salt
2073
+ fi
2074
+ }
2075
+
2076
+ install_suse_11_git() {
2077
+ install_opensuse_git
2078
+ }
2079
+
2080
+ install_suse_11_stable_post() {
2081
+ if [ $SUSE_PATCHLEVEL -gt 1 ]; then
2082
+ install_opensuse_stable_post
2083
+ else
2084
+ for fname in minion master syndic; do
2085
+
2086
+ # Skip if not meant to be installed
2087
+ [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
2088
+ [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
2089
+ [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
2090
+
2091
+ if [ -f /bin/systemctl ]; then
2092
+ curl -k -L https://github.com/saltstack/salt/raw/develop/pkg/salt-$fname.service \
2093
+ -o /lib/systemd/system/salt-$fname.service
2094
+ continue
2095
+ fi
2096
+
2097
+ curl -k -L https://github.com/saltstack/salt/raw/develop/pkg/rpm/salt-$fname \
2098
+ -o /etc/init.d/salt-$fname
2099
+ chmod +x /etc/init.d/salt-$fname
2100
+
2101
+ done
2102
+ fi
2103
+ }
2104
+
2105
+ install_suse_11_git_post() {
2106
+ install_opensuse_git_post
2107
+ }
2108
+
2109
+ install_suse_11_restart_daemons() {
2110
+ install_opensuse_restart_daemons
2111
+ }
2112
+ #
2113
+ # End of SuSE Install Functions.
2114
+ #
2115
+ ##############################################################################
2116
+
2117
+ ##############################################################################
2118
+ #
2119
+ # Default minion configuration function. Matches ANY distribution as long as
2120
+ # the -c options is passed.
2121
+ #
2122
+ config_salt() {
2123
+ # If the configuration directory is not passed, return
2124
+ [ "$TEMP_CONFIG_DIR" = "null" ] && return
2125
+
2126
+ CONFIGURED_ANYTHING=$BS_FALSE
2127
+
2128
+ PKI_DIR=$SALT_ETC_DIR/pki
2129
+
2130
+ # Let's create the necessary directories
2131
+ [ -d $SALT_ETC_DIR ] || mkdir $SALT_ETC_DIR
2132
+ [ -d $PKI_DIR ] || mkdir -p $PKI_DIR && chmod 700 $PKI_DIR
2133
+
2134
+ if [ $INSTALL_MINION -eq $BS_TRUE ]; then
2135
+ # Create the PKI directory
2136
+ [ -d $PKI_DIR/minion ] || mkdir -p $PKI_DIR/minion && chmod 700 $PKI_DIR/minion
2137
+
2138
+ # Copy the minions configuration if found
2139
+ [ -f "$TEMP_CONFIG_DIR/minion" ] && mv "$TEMP_CONFIG_DIR/minion" /etc/salt && CONFIGURED_ANYTHING=$BS_TRUE
2140
+
2141
+ # Copy the minion's keys if found
2142
+ if [ -f "$TEMP_CONFIG_DIR/minion.pem" ]; then
2143
+ mv "$TEMP_CONFIG_DIR/minion.pem" $PKI_DIR/minion/
2144
+ chmod 400 $PKI_DIR/minion/minion.pem
2145
+ CONFIGURED_ANYTHING=$BS_TRUE
2146
+ fi
2147
+ if [ -f "$TEMP_CONFIG_DIR/minion.pub" ]; then
2148
+ mv "$TEMP_CONFIG_DIR/minion.pub" $PKI_DIR/minion/
2149
+ chmod 664 $PKI_DIR/minion/minion.pub
2150
+ CONFIGURED_ANYTHING=$BS_TRUE
2151
+ fi
2152
+ fi
2153
+
2154
+
2155
+ if [ $INSTALL_MASTER -eq $BS_TRUE ] || [ $INSTALL_SYNDIC -eq $BS_TRUE ]; then
2156
+ # Create the PKI directory
2157
+ [ -d $PKI_DIR/master ] || mkdir -p $PKI_DIR/master && chmod 700 $PKI_DIR/master
2158
+
2159
+ # Copy the masters configuration if found
2160
+ [ -f "$TEMP_CONFIG_DIR/master" ] && mv "$TEMP_CONFIG_DIR/master" /etc/salt && CONFIGURED_ANYTHING=$BS_TRUE
2161
+
2162
+ # Copy the master's keys if found
2163
+ if [ -f "$TEMP_CONFIG_DIR/master.pem" ]; then
2164
+ mv "$TEMP_CONFIG_DIR/master.pem" $PKI_DIR/master/
2165
+ chmod 400 $PKI_DIR/master/master.pem
2166
+ CONFIGURED_ANYTHING=$BS_TRUE
2167
+ fi
2168
+ if [ -f "$TEMP_CONFIG_DIR/master.pub" ]; then
2169
+ mv "$TEMP_CONFIG_DIR/master.pub" $PKI_DIR/master/
2170
+ chmod 664 $PKI_DIR/master/master.pub
2171
+ CONFIGURED_ANYTHING=$BS_TRUE
2172
+ fi
2173
+ fi
2174
+
2175
+ if [ $CONFIG_ONLY -eq $BS_TRUE ] && [ $CONFIGURED_ANYTHING -eq $BS_FALSE ]; then
2176
+ echowarn "No configuration or keys were copied over. No configuration was done!"
2177
+ exit 0
2178
+ fi
2179
+ }
2180
+ #
2181
+ # Ended Default Configuration function
2182
+ #
2183
+ ##############################################################################
2184
+
2185
+
2186
+ ##############################################################################
2187
+ #
2188
+ # This function checks if all of the installed daemons are running or not.
2189
+ #
2190
+ daemons_running() {
2191
+ FAILED_DAEMONS=0
2192
+ for fname in minion master syndic; do
2193
+
2194
+ # Skip if not meant to be installed
2195
+ [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
2196
+ [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
2197
+ [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
2198
+
2199
+ if [ "x$(ps aux | grep -v grep | grep salt-$fname)" = "x" ]; then
2200
+ echoerror "salt-$fname was not found running"
2201
+ FAILED_DAEMONS=$(expr $FAILED_DAEMONS + 1)
2202
+ fi
2203
+ done
2204
+ return $FAILED_DAEMONS
2205
+ }
2206
+ #
2207
+ # Ended daemons running check function
2208
+ #
2209
+ ##############################################################################
2210
+
2211
+
2212
+ #=============================================================================
2213
+ # LET'S PROCEED WITH OUR INSTALLATION
2214
+ #=============================================================================
2215
+ # Let's get the dependencies install function
2216
+ DEP_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_deps"
2217
+ DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_deps"
2218
+ DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_deps"
2219
+ DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_deps"
2220
+ DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}_deps"
2221
+ DEP_FUNC_NAMES="$DEP_FUNC_NAMES install_${DISTRO_NAME_L}_deps"
2222
+
2223
+ DEPS_INSTALL_FUNC="null"
2224
+ for DEP_FUNC_NAME in $(__strip_duplicates $DEP_FUNC_NAMES); do
2225
+ if __function_defined $DEP_FUNC_NAME; then
2226
+ DEPS_INSTALL_FUNC=$DEP_FUNC_NAME
2227
+ break
2228
+ fi
2229
+ done
2230
+
2231
+
2232
+ # Let's get the minion config function
2233
+ CONFIG_SALT_FUNC="null"
2234
+ if [ "$TEMP_CONFIG_DIR" != "null" ]; then
2235
+
2236
+ CONFIG_FUNC_NAMES="config_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_salt"
2237
+ CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_salt"
2238
+ CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_salt"
2239
+ CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_salt"
2240
+ CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}_${ITYPE}_salt"
2241
+ CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_${DISTRO_NAME_L}_salt"
2242
+ CONFIG_FUNC_NAMES="$CONFIG_FUNC_NAMES config_salt"
2243
+
2244
+ for FUNC_NAME in $(__strip_duplicates $CONFIG_FUNC_NAMES); do
2245
+ if __function_defined $FUNC_NAME; then
2246
+ CONFIG_SALT_FUNC=$FUNC_NAME
2247
+ break
2248
+ fi
2249
+ done
2250
+ fi
2251
+
2252
+
2253
+ # Let's get the install function
2254
+ INSTALL_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}"
2255
+ INSTALL_FUNC_NAMES="$INSTALL_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}"
2256
+ INSTALL_FUNC_NAMES="$INSTALL_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}"
2257
+
2258
+ INSTALL_FUNC="null"
2259
+ for FUNC_NAME in $(__strip_duplicates $INSTALL_FUNC_NAMES); do
2260
+ if __function_defined $FUNC_NAME; then
2261
+ INSTALL_FUNC=$FUNC_NAME
2262
+ break
2263
+ fi
2264
+ done
2265
+
2266
+
2267
+ # Let's get the post install function
2268
+ POST_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_post"
2269
+ POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_post"
2270
+ POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_post"
2271
+ POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_post"
2272
+ POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}_post"
2273
+ POST_FUNC_NAMES="$POST_FUNC_NAMES install_${DISTRO_NAME_L}_post"
2274
+
2275
+
2276
+ POST_INSTALL_FUNC="null"
2277
+ for FUNC_NAME in $(__strip_duplicates $POST_FUNC_NAMES); do
2278
+ if __function_defined $FUNC_NAME; then
2279
+ POST_INSTALL_FUNC=$FUNC_NAME
2280
+ break
2281
+ fi
2282
+ done
2283
+
2284
+
2285
+ # Let's get the start daemons install function
2286
+ STARTDAEMONS_FUNC_NAMES="install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}_restart_daemons"
2287
+ STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}_restart_daemons"
2288
+ STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_restart_daemons"
2289
+ STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_restart_daemons"
2290
+ STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}_${ITYPE}_restart_daemons"
2291
+ STARTDAEMONS_FUNC_NAMES="$STARTDAEMONS_FUNC_NAMES install_${DISTRO_NAME_L}_restart_daemons"
2292
+
2293
+ STARTDAEMONS_INSTALL_FUNC="null"
2294
+ for FUNC_NAME in $(__strip_duplicates $STARTDAEMONS_FUNC_NAMES); do
2295
+ if __function_defined $FUNC_NAME; then
2296
+ STARTDAEMONS_INSTALL_FUNC=$FUNC_NAME
2297
+ break
2298
+ fi
2299
+ done
2300
+
2301
+
2302
+ # Let's get the daemons running check function.
2303
+ DAEMONS_RUNNING_FUNC="null"
2304
+ DAEMONS_RUNNING_FUNC_NAMES="daemons_running_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}_${ITYPE}"
2305
+ DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}_${ITYPE}"
2306
+ DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}"
2307
+ DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running_${DISTRO_NAME_L}${PREFIXED_DISTRO_MAJOR_VERSION}${PREFIXED_DISTRO_MINOR_VERSION}"
2308
+ DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running_${DISTRO_NAME_L}_${ITYPE}"
2309
+ DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running_${DISTRO_NAME_L}"
2310
+ DAEMONS_RUNNING_FUNC_NAMES="$DAEMONS_RUNNING_FUNC_NAMES daemons_running"
2311
+
2312
+ for FUNC_NAME in $(__strip_duplicates $DAEMONS_RUNNING_FUNC_NAMES); do
2313
+ if __function_defined $FUNC_NAME; then
2314
+ DAEMONS_RUNNING_FUNC=$FUNC_NAME
2315
+ break
2316
+ fi
2317
+ done
2318
+
2319
+
2320
+
2321
+ if [ $DEPS_INSTALL_FUNC = "null" ]; then
2322
+ echoerror "No dependencies installation function found. Exiting..."
2323
+ exit 1
2324
+ fi
2325
+
2326
+ if [ $INSTALL_FUNC = "null" ]; then
2327
+ echoerror "No installation function found. Exiting..."
2328
+ exit 1
2329
+ fi
2330
+
2331
+
2332
+ # Install dependencies
2333
+ if [ $CONFIG_ONLY -eq $BS_FALSE ]; then
2334
+ # Only execute function is not in config mode only
2335
+ echoinfo "Running ${DEPS_INSTALL_FUNC}()"
2336
+ $DEPS_INSTALL_FUNC
2337
+ if [ $? -ne 0 ]; then
2338
+ echoerror "Failed to run ${DEPS_INSTALL_FUNC}()!!!"
2339
+ exit 1
2340
+ fi
2341
+ fi
2342
+
2343
+
2344
+ # Configure Salt
2345
+ if [ "$TEMP_CONFIG_DIR" != "null" ] && [ "$CONFIG_SALT_FUNC" != "null" ]; then
2346
+ echoinfo "Running ${CONFIG_SALT_FUNC}()"
2347
+ $CONFIG_SALT_FUNC
2348
+ if [ $? -ne 0 ]; then
2349
+ echoerror "Failed to run ${CONFIG_SALT_FUNC}()!!!"
2350
+ exit 1
2351
+ fi
2352
+ fi
2353
+
2354
+
2355
+ # Install Salt
2356
+ if [ $CONFIG_ONLY -eq $BS_FALSE ]; then
2357
+ # Only execute function is not in config mode only
2358
+ echoinfo "Running ${INSTALL_FUNC}()"
2359
+ $INSTALL_FUNC
2360
+ if [ $? -ne 0 ]; then
2361
+ echoerror "Failed to run ${INSTALL_FUNC}()!!!"
2362
+ exit 1
2363
+ fi
2364
+ fi
2365
+
2366
+
2367
+ # Run any post install function, Only execute function is not in config mode only
2368
+ if [ $CONFIG_ONLY -eq $BS_FALSE ] && [ "$POST_INSTALL_FUNC" != "null" ]; then
2369
+ echoinfo "Running ${POST_INSTALL_FUNC}()"
2370
+ $POST_INSTALL_FUNC
2371
+ if [ $? -ne 0 ]; then
2372
+ echoerror "Failed to run ${POST_INSTALL_FUNC}()!!!"
2373
+ exit 1
2374
+ fi
2375
+ fi
2376
+
2377
+
2378
+ # Run any start daemons function
2379
+ if [ "$STARTDAEMONS_INSTALL_FUNC" != "null" ]; then
2380
+ echoinfo "Running ${STARTDAEMONS_INSTALL_FUNC}()"
2381
+ $STARTDAEMONS_INSTALL_FUNC
2382
+ if [ $? -ne 0 ]; then
2383
+ echoerror "Failed to run ${STARTDAEMONS_INSTALL_FUNC}()!!!"
2384
+ exit 1
2385
+ fi
2386
+ fi
2387
+
2388
+ # Check if the installed daemons are running or not
2389
+ if [ "$DAEMONS_RUNNING_FUNC" != "null" ]; then
2390
+ sleep 3 # Sleep a little bit to let daemons start
2391
+ echoinfo "Running ${DAEMONS_RUNNING_FUNC}()"
2392
+ $DAEMONS_RUNNING_FUNC
2393
+ if [ $? -ne 0 ]; then
2394
+ echoerror "Failed to run ${DAEMONS_RUNNING_FUNC}()!!!"
2395
+ echodebug "Running Processes:"
2396
+ echodebug "$(ps auxwww)"
2397
+
2398
+ for fname in minion master syndic; do
2399
+ # Skip if not meant to be installed
2400
+ [ $fname = "minion" ] && [ $INSTALL_MINION -eq $BS_FALSE ] && continue
2401
+ [ $fname = "master" ] && [ $INSTALL_MASTER -eq $BS_FALSE ] && continue
2402
+ [ $fname = "syndic" ] && [ $INSTALL_SYNDIC -eq $BS_FALSE ] && continue
2403
+
2404
+ [ ! $SALT_ETC_DIR/$fname ] && [ $fname != "syndic" ] && echodebug "$SALT_ETC_DIR/$fname does not exist"
2405
+
2406
+ echodebug "Running salt-$fname by hand outputs: $(salt-$fname -l debug)"
2407
+
2408
+ [ ! -f /var/log/salt/$fname ] && echodebug "/var/log/salt/$fname does not exist. Can't cat its contents!" && continue
2409
+
2410
+ echodebug "DEAMON LOGS for $fname:"
2411
+ echodebug "$(cat /var/log/salt/$fname)"
2412
+ echo
2413
+ done
2414
+ exit 1
2415
+ fi
2416
+ fi
2417
+
2418
+
2419
+ # Done!
2420
+ if [ $CONFIG_ONLY -eq $BS_FALSE ]; then
2421
+ echoinfo "Salt installed!"
2422
+ else
2423
+ echoinfo "Salt configured"
2424
+ fi
2425
+ exit 0