mixlib-install 0.7.1 → 0.8.0.alpha.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/CONTRIBUTING.md +14 -0
  4. data/Gemfile +1 -0
  5. data/README.md +30 -21
  6. data/Rakefile +5 -1
  7. data/acceptance/.gitignore +2 -0
  8. data/acceptance/Gemfile +10 -0
  9. data/acceptance/Gemfile.lock +57 -0
  10. data/acceptance/current/.acceptance/acceptance-cookbook/.chef/config.rb +1 -0
  11. data/acceptance/current/.acceptance/acceptance-cookbook/metadata.rb +1 -0
  12. data/acceptance/current/.acceptance/acceptance-cookbook/recipes/destroy.rb +3 -0
  13. data/acceptance/current/.acceptance/acceptance-cookbook/recipes/provision.rb +1 -0
  14. data/acceptance/current/.acceptance/acceptance-cookbook/recipes/verify.rb +3 -0
  15. data/acceptance/current/.kitchen.yml +45 -0
  16. data/lib/mixlib/install.rb +50 -173
  17. data/lib/mixlib/install/artifact_info.rb +76 -0
  18. data/lib/mixlib/install/backend.rb +36 -0
  19. data/lib/mixlib/install/backend/artifactory.rb +90 -0
  20. data/lib/mixlib/install/backend/omnitruck.rb +76 -0
  21. data/lib/mixlib/install/generator.rb +28 -0
  22. data/lib/mixlib/install/generator/bourne.rb +62 -0
  23. data/lib/mixlib/install/generator/bourne/scripts/fetch_metadata.sh +47 -0
  24. data/lib/mixlib/install/generator/bourne/scripts/fetch_package.sh +53 -0
  25. data/lib/mixlib/install/generator/bourne/scripts/helpers.sh +335 -0
  26. data/lib/mixlib/install/generator/bourne/scripts/install_package.sh +33 -0
  27. data/lib/mixlib/install/generator/bourne/scripts/platform_detection.sh +157 -0
  28. data/lib/mixlib/install/options.rb +98 -0
  29. data/lib/mixlib/install/script_generator.rb +217 -0
  30. data/lib/mixlib/install/version.rb +1 -1
  31. data/mixlib-install.gemspec +5 -3
  32. data/support/install_command.ps1 +4 -4
  33. metadata +71 -5
@@ -0,0 +1,335 @@
1
+ #!/bin/sh
2
+ # WARNING: REQUIRES /bin/sh
3
+ #
4
+ # - must run on /bin/sh on solaris 9
5
+ # - must run on /bin/sh on AIX 6.x
6
+ #
7
+ # Copyright:: Copyright (c) 2010-2015 Chef Software, Inc.
8
+ # License:: Apache License, Version 2.0
9
+ #
10
+ # Licensed under the Apache License, Version 2.0 (the "License");
11
+ # you may not use this file except in compliance with the License.
12
+ # You may obtain a copy of the License at
13
+ #
14
+ # http://www.apache.org/licenses/LICENSE-2.0
15
+ #
16
+ # Unless required by applicable law or agreed to in writing, software
17
+ # distributed under the License is distributed on an "AS IS" BASIS,
18
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ # See the License for the specific language governing permissions and
20
+ # limitations under the License.
21
+ #
22
+
23
+ # helpers.sh
24
+ ############
25
+ # This section has some helper functions to make life easier.
26
+ #
27
+ # Outputs:
28
+ # $tmp_dir: secure-ish temp directory that can be used during installation.
29
+ ############
30
+
31
+ # Check whether a command exists - returns 0 if it does, 1 if it does not
32
+ exists() {
33
+ if command -v $1 >/dev/null 2>&1
34
+ then
35
+ return 0
36
+ else
37
+ return 1
38
+ fi
39
+ }
40
+
41
+ # Output the instructions to report bug about this script
42
+ report_bug() {
43
+ echo "Version: $version"
44
+ echo ""
45
+ echo "Please file a Bug Report at https://github.com/chef/omnitruck/issues/new"
46
+ echo "Alternatively, feel free to open a Support Ticket at https://www.chef.io/support/tickets"
47
+ echo "More Chef support resources can be found at https://www.chef.io/support"
48
+ echo ""
49
+ echo "Please include as many details about the problem as possible i.e., how to reproduce"
50
+ echo "the problem (if possible), type of the Operating System and its version, etc.,"
51
+ echo "and any other relevant details that might help us with troubleshooting."
52
+ echo ""
53
+ }
54
+
55
+ checksum_mismatch() {
56
+ echo "Package checksum mismatch!"
57
+ report_bug
58
+ exit 1
59
+ }
60
+
61
+ unable_to_retrieve_package() {
62
+ echo "Unable to retrieve a valid package!"
63
+ report_bug
64
+ echo "Metadata URL: $metadata_url"
65
+ if test "x$download_url" != "x"; then
66
+ echo "Download URL: $download_url"
67
+ fi
68
+ if test "x$stderr_results" != "x"; then
69
+ echo "\nDEBUG OUTPUT FOLLOWS:\n$stderr_results"
70
+ fi
71
+ exit 1
72
+ }
73
+
74
+ http_404_error() {
75
+ echo "Omnitruck artifact does not exist for version $version on platform $platform"
76
+ echo ""
77
+ echo "Either this means:"
78
+ echo " - We do not support $platform"
79
+ echo " - We do not have an artifact for $version"
80
+ echo ""
81
+ echo "This is often the latter case due to running a prerelease or RC version of chef"
82
+ echo "or a gem version which was only pushed to rubygems and not omnitruck."
83
+ echo ""
84
+ echo "You may be able to set your knife[:bootstrap_version] to the most recent stable"
85
+ echo "release of Chef to fix this problem (or the most recent stable major version number)."
86
+ echo ""
87
+ echo "In order to test the version parameter, adventurous users may take the Metadata URL"
88
+ echo "below and modify the '&v=<number>' parameter until you successfully get a URL that"
89
+ echo "does not 404 (e.g. via curl or wget). You should be able to use '&v=11' or '&v=12'"
90
+ echo "succesfully."
91
+ echo ""
92
+ echo "If you cannot fix this problem by setting the bootstrap_version, it probably means"
93
+ echo "that $platform is not supported."
94
+ echo ""
95
+ # deliberately do not call report_bug to suppress bug report noise.
96
+ echo "Metadata URL: $metadata_url"
97
+ if test "x$download_url" != "x"; then
98
+ echo "Download URL: $download_url"
99
+ fi
100
+ if test "x$stderr_results" != "x"; then
101
+ echo "\nDEBUG OUTPUT FOLLOWS:\n$stderr_results"
102
+ fi
103
+ exit 1
104
+ }
105
+
106
+ capture_tmp_stderr() {
107
+ # spool up /tmp/stderr from all the commands we called
108
+ if test -f "$tmp_dir/stderr"; then
109
+ output=`cat $tmp_dir/stderr`
110
+ stderr_results="${stderr_results}\nSTDERR from $1:\n\n$output\n"
111
+ rm $tmp_dir/stderr
112
+ fi
113
+ }
114
+
115
+ # do_wget URL FILENAME
116
+ do_wget() {
117
+ echo "trying wget..."
118
+ wget -O "$2" "$1" 2>$tmp_dir/stderr
119
+ rc=$?
120
+ # check for 404
121
+ grep "ERROR 404" $tmp_dir/stderr 2>&1 >/dev/null
122
+ if test $? -eq 0; then
123
+ echo "ERROR 404"
124
+ http_404_error
125
+ fi
126
+
127
+ # check for bad return status or empty output
128
+ if test $rc -ne 0 || test ! -s "$2"; then
129
+ capture_tmp_stderr "wget"
130
+ return 1
131
+ fi
132
+
133
+ return 0
134
+ }
135
+
136
+ # do_curl URL FILENAME
137
+ do_curl() {
138
+ echo "trying curl..."
139
+ curl -sL -D $tmp_dir/stderr "$1" > "$2"
140
+ rc=$?
141
+ # check for 404
142
+ grep "404 Not Found" $tmp_dir/stderr 2>&1 >/dev/null
143
+ if test $? -eq 0; then
144
+ echo "ERROR 404"
145
+ http_404_error
146
+ fi
147
+
148
+ # check for bad return status or empty output
149
+ if test $rc -ne 0 || test ! -s "$2"; then
150
+ capture_tmp_stderr "curl"
151
+ return 1
152
+ fi
153
+
154
+ return 0
155
+ }
156
+
157
+ # do_fetch URL FILENAME
158
+ do_fetch() {
159
+ echo "trying fetch..."
160
+ fetch -o "$2" "$1" 2>$tmp_dir/stderr
161
+ # check for bad return status
162
+ test $? -ne 0 && return 1
163
+ return 0
164
+ }
165
+
166
+ # do_curl URL FILENAME
167
+ do_perl() {
168
+ echo "trying perl..."
169
+ perl -e 'use LWP::Simple; getprint($ARGV[0]);' "$1" > "$2" 2>$tmp_dir/stderr
170
+ rc=$?
171
+ # check for 404
172
+ grep "404 Not Found" $tmp_dir/stderr 2>&1 >/dev/null
173
+ if test $? -eq 0; then
174
+ echo "ERROR 404"
175
+ http_404_error
176
+ fi
177
+
178
+ # check for bad return status or empty output
179
+ if test $rc -ne 0 || test ! -s "$2"; then
180
+ capture_tmp_stderr "perl"
181
+ return 1
182
+ fi
183
+
184
+ return 0
185
+ }
186
+
187
+ # do_curl URL FILENAME
188
+ do_python() {
189
+ echo "trying python..."
190
+ python -c "import sys,urllib2 ; sys.stdout.write(urllib2.urlopen(sys.argv[1]).read())" "$1" > "$2" 2>$tmp_dir/stderr
191
+ rc=$?
192
+ # check for 404
193
+ grep "HTTP Error 404" $tmp_dir/stderr 2>&1 >/dev/null
194
+ if test $? -eq 0; then
195
+ echo "ERROR 404"
196
+ http_404_error
197
+ fi
198
+
199
+ # check for bad return status or empty output
200
+ if test $rc -ne 0 || test ! -s "$2"; then
201
+ capture_tmp_stderr "python"
202
+ return 1
203
+ fi
204
+ return 0
205
+ }
206
+
207
+ # returns 0 if checksums match
208
+ do_checksum() {
209
+ if exists sha256sum; then
210
+ echo "Comparing checksum with sha256sum..."
211
+ checksum=`sha256sum $1 | awk '{ print $1 }'`
212
+ return `test "x$checksum" = "x$2"`
213
+ elif exists shasum; then
214
+ echo "Comparing checksum with shasum..."
215
+ checksum=`shasum -a 256 $1 | awk '{ print $1 }'`
216
+ return `test "x$checksum" = "x$2"`
217
+ elif exists md5sum; then
218
+ echo "Comparing checksum with md5sum..."
219
+ checksum=`md5sum $1 | awk '{ print $1 }'`
220
+ return `test "x$checksum" = "x$3"`
221
+ elif exists md5; then
222
+ echo "Comparing checksum with md5..."
223
+ # this is for md5 utility on MacOSX (OSX 10.6-10.10) and $4 is the correct field
224
+ checksum=`md5 $1 | awk '{ print $4 }'`
225
+ return `test "x$checksum" = "x$3"`
226
+ else
227
+ echo "WARNING: could not find a valid checksum program, pre-install shasum, md5sum or md5 in your O/S image to get valdation..."
228
+ return 0
229
+ fi
230
+ }
231
+
232
+ # do_download URL FILENAME
233
+ do_download() {
234
+ echo "downloading $1"
235
+ echo " to file $2"
236
+
237
+ url=`echo $1`
238
+ if test "x$platform" = "xsolaris2"; then
239
+ if test "x$platform_version" = "x5.9" -o "x$platform_version" = "x5.10"; then
240
+ # solaris 9 lacks openssl, solaris 10 lacks recent enough credentials - your base O/S is completely insecure, please upgrade
241
+ url=`echo $url | sed -e 's/https/http/'`
242
+ fi
243
+ fi
244
+
245
+ # we try all of these until we get success.
246
+ # perl, in particular may be present but LWP::Simple may not be installed
247
+
248
+ if exists wget; then
249
+ do_wget $url $2 && return 0
250
+ fi
251
+
252
+ if exists curl; then
253
+ do_curl $url $2 && return 0
254
+ fi
255
+
256
+ if exists fetch; then
257
+ do_fetch $url $2 && return 0
258
+ fi
259
+
260
+ if exists perl; then
261
+ do_perl $url $2 && return 0
262
+ fi
263
+
264
+ if exists python; then
265
+ do_python $url $2 && return 0
266
+ fi
267
+
268
+ unable_to_retrieve_package
269
+ }
270
+
271
+ # install_file TYPE FILENAME
272
+ # TYPE is "rpm", "deb", "solaris", "sh", etc.
273
+ install_file() {
274
+ echo "Installing $project $version"
275
+ case "$1" in
276
+ "rpm")
277
+ echo "installing with rpm..."
278
+ rpm -Uvh --oldpackage --replacepkgs "$2"
279
+ ;;
280
+ "deb")
281
+ echo "installing with dpkg..."
282
+ dpkg -i "$2"
283
+ ;;
284
+ "bff")
285
+ echo "installing with installp..."
286
+ installp -aXYgd "$2" all
287
+ ;;
288
+ "solaris")
289
+ echo "installing with pkgadd..."
290
+ echo "conflict=nocheck" > $tmp_dir/nocheck
291
+ echo "action=nocheck" >> $tmp_dir/nocheck
292
+ echo "mail=" >> $tmp_dir/nocheck
293
+ pkgrm -a $tmp_dir/nocheck -n $project >/dev/null 2>&1 || true
294
+ pkgadd -n -d "$2" -a $tmp_dir/nocheck $project
295
+ ;;
296
+ "pkg")
297
+ echo "installing with installer..."
298
+ cd / && /usr/sbin/installer -pkg "$2" -target /
299
+ ;;
300
+ "dmg")
301
+ echo "installing dmg file..."
302
+ hdiutil detach "/Volumes/chef_software" >/dev/null 2>&1 || true
303
+ hdiutil attach "$2" -mountpoint "/Volumes/chef_software"
304
+ cd / && /usr/sbin/installer -pkg `find "/Volumes/chef_software" -name \*.pkg` -target /
305
+ hdiutil detach "/Volumes/chef_software"
306
+ ;;
307
+ "sh" )
308
+ echo "installing with sh..."
309
+ sh "$2"
310
+ ;;
311
+ *)
312
+ echo "Unknown filetype: $1"
313
+ report_bug
314
+ exit 1
315
+ ;;
316
+ esac
317
+ if test $? -ne 0; then
318
+ echo "Installation failed"
319
+ report_bug
320
+ exit 1
321
+ fi
322
+ }
323
+
324
+ if test "x$TMPDIR" = "x"; then
325
+ tmp="/tmp"
326
+ else
327
+ tmp=$TMPDIR
328
+ fi
329
+ # secure-ish temp dir creation without having mktemp available (DDoS-able but not expliotable)
330
+ tmp_dir="$tmp/install.sh.$$"
331
+ (umask 077 && mkdir $tmp_dir) || exit 1
332
+
333
+ ############
334
+ # end of helpers.sh
335
+ ############
@@ -0,0 +1,33 @@
1
+ # install_package.sh
2
+ ############
3
+ # Installs a package and removed the temp directory.
4
+ #
5
+ # Inputs:
6
+ # $download_filename: Name of the file to be installed.
7
+ # $filetype: Type of the file to be installed.
8
+ # $version: The version requested. Used only for warning user if not set.
9
+ ############
10
+
11
+ if test "x$version" = "x"; then
12
+ echo
13
+ echo "WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING"
14
+ echo
15
+ echo "You are installing an omnibus package without a version pin. If you are installing"
16
+ echo "on production servers via an automated process this is DANGEROUS and you will"
17
+ echo "be upgraded without warning on new releases, even to new major releases."
18
+ echo "Letting the version float is only appropriate in desktop, test, development or"
19
+ echo "CI/CD environments."
20
+ echo
21
+ echo "WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING"
22
+ echo
23
+ fi
24
+
25
+ install_file $filetype "$download_filename"
26
+
27
+ if test "x$tmp_dir" != "x"; then
28
+ rm -r "$tmp_dir"
29
+ fi
30
+
31
+ ############
32
+ # end of install_package.sh
33
+ ############
@@ -0,0 +1,157 @@
1
+ # platform_detection.sh
2
+ ############
3
+ # This section makes platform detection compatible with omnitruck on the system
4
+ # it runs.
5
+ #
6
+ # Outputs:
7
+ # $platform: Name of the platform.
8
+ # $platform_version: Version of the platform.
9
+ # $machine: System's architecture.
10
+ ############
11
+
12
+ #
13
+ # Platform and Platform Version detection
14
+ #
15
+ # NOTE: This should now match ohai platform and platform_version matching.
16
+ # do not invented new platform and platform_version schemas, just make this behave
17
+ # like what ohai returns as platform and platform_version for the server.
18
+ #
19
+ # ALSO NOTE: Do not mangle platform or platform_version here. It is less error
20
+ # prone and more future-proof to do that in the server, and then all omnitruck clients
21
+ # will 'inherit' the changes (install.sh is not the only client of the omnitruck
22
+ # endpoint out there).
23
+ #
24
+
25
+ machine=`uname -m`
26
+ os=`uname -s`
27
+
28
+ if test -f "/etc/lsb-release" && grep -q DISTRIB_ID /etc/lsb-release; then
29
+ platform=`grep DISTRIB_ID /etc/lsb-release | cut -d "=" -f 2 | tr '[A-Z]' '[a-z]'`
30
+ platform_version=`grep DISTRIB_RELEASE /etc/lsb-release | cut -d "=" -f 2`
31
+ elif test -f "/etc/debian_version"; then
32
+ platform="debian"
33
+ platform_version=`cat /etc/debian_version`
34
+ elif test -f "/etc/redhat-release"; then
35
+ platform=`sed 's/^\(.\+\) release.*/\1/' /etc/redhat-release | tr '[A-Z]' '[a-z]'`
36
+ platform_version=`sed 's/^.\+ release \([.0-9]\+\).*/\1/' /etc/redhat-release`
37
+
38
+ # If /etc/redhat-release exists, we act like RHEL by default
39
+ if test "$platform" = "fedora"; then
40
+ # FIXME: stop remapping fedora to el
41
+ # FIXME: remove client side platform_version mangling and hard coded yolo
42
+ # Change platform version for use below.
43
+ platform_version="6.0"
44
+ fi
45
+
46
+ if test "$platform" = "xenserver"; then
47
+ # Current XenServer 6.2 is based on CentOS 5, platform is not reset to "el" server should hanlde response
48
+ platform="xenserver"
49
+ else
50
+ # FIXME: use "redhat"
51
+ platform="el"
52
+ fi
53
+
54
+ elif test -f "/etc/system-release"; then
55
+ platform=`sed 's/^\(.\+\) release.\+/\1/' /etc/system-release | tr '[A-Z]' '[a-z]'`
56
+ platform_version=`sed 's/^.\+ release \([.0-9]\+\).*/\1/' /etc/system-release | tr '[A-Z]' '[a-z]'`
57
+ # amazon is built off of fedora, so act like RHEL
58
+ if test "$platform" = "amazon linux ami"; then
59
+ # FIXME: remove client side platform_version mangling and hard coded yolo, and remapping to deprecated "el"
60
+ platform="el"
61
+ platform_version="6.0"
62
+ fi
63
+ # Apple OS X
64
+ elif test -f "/usr/bin/sw_vers"; then
65
+ platform="mac_os_x"
66
+ # Matching the tab-space with sed is error-prone
67
+ platform_version=`sw_vers | awk '/^ProductVersion:/ { print $2 }' | cut -d. -f1,2`
68
+
69
+ # x86_64 Apple hardware often runs 32-bit kernels (see OHAI-63)
70
+ x86_64=`sysctl -n hw.optional.x86_64`
71
+ if test $x86_64 -eq 1; then
72
+ machine="x86_64"
73
+ fi
74
+ elif test -f "/etc/release"; then
75
+ machine=`/usr/bin/uname -p`
76
+ if grep -q SmartOS /etc/release; then
77
+ platform="smartos"
78
+ platform_version=`grep ^Image /etc/product | awk '{ print $3 }'`
79
+ else
80
+ platform="solaris2"
81
+ platform_version=`/usr/bin/uname -r`
82
+ fi
83
+ elif test -f "/etc/SuSE-release"; then
84
+ if grep -q 'Enterprise' /etc/SuSE-release;
85
+ then
86
+ platform="sles"
87
+ platform_version=`awk '/^VERSION/ {V = $3}; /^PATCHLEVEL/ {P = $3}; END {print V "." P}' /etc/SuSE-release`
88
+ else
89
+ platform="suse"
90
+ platform_version=`awk '/^VERSION =/ { print $3 }' /etc/SuSE-release`
91
+ fi
92
+ elif test "x$os" = "xFreeBSD"; then
93
+ platform="freebsd"
94
+ platform_version=`uname -r | sed 's/-.*//'`
95
+ elif test "x$os" = "xAIX"; then
96
+ platform="aix"
97
+ platform_version="`uname -v`.`uname -r`"
98
+ machine="powerpc"
99
+ fi
100
+
101
+ if test "x$platform" = "x"; then
102
+ echo "Unable to determine platform version!"
103
+ report_bug
104
+ exit 1
105
+ fi
106
+
107
+ #
108
+ # NOTE: platform manging in the install.sh is DEPRECATED
109
+ #
110
+ # - install.sh should be true to ohai and should not remap
111
+ # platform or platform versions.
112
+ #
113
+ # - remapping platform and mangling platform version numbers is
114
+ # now the complete responsibility of the server-side endpoints
115
+ #
116
+
117
+ major_version=`echo $platform_version | cut -d. -f1`
118
+ case $platform in
119
+ # FIXME: should remove this case statement completely
120
+ "el")
121
+ # FIXME: "el" is deprecated, should use "redhat"
122
+ platform_version=$major_version
123
+ ;;
124
+ "debian")
125
+ # FIXME: remove client-side yolo here
126
+ case $major_version in
127
+ "5") platform_version="6";; # FIXME: need to port this "reverse-yolo" into platform.rb
128
+ "6") platform_version="6";;
129
+ "7") platform_version="6";;
130
+ esac
131
+ ;;
132
+ "freebsd")
133
+ platform_version=$major_version
134
+ ;;
135
+ "sles")
136
+ platform_version=$major_version
137
+ ;;
138
+ "suse")
139
+ platform_version=$major_version
140
+ ;;
141
+ esac
142
+
143
+ if test "x$platform_version" = "x"; then
144
+ echo "Unable to determine platform version!"
145
+ report_bug
146
+ exit 1
147
+ fi
148
+
149
+ if test "x$platform" = "xsolaris2"; then
150
+ # hack up the path on Solaris to find wget, pkgadd
151
+ PATH=/usr/sfw/bin:/usr/sbin:$PATH
152
+ export PATH
153
+ fi
154
+
155
+ ############
156
+ # end of platform_detection.sh
157
+ ############