mixlib-install 3.15.0 → 3.17.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 (30) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -14
  3. data/lib/mixlib/install/backend/base.rb +1 -1
  4. data/lib/mixlib/install/backend/package_router.rb +101 -12
  5. data/lib/mixlib/install/cli.rb +5 -1
  6. data/lib/mixlib/install/dist.rb +24 -4
  7. data/lib/mixlib/install/generator/base.rb +1 -14
  8. data/lib/mixlib/install/generator/bourne/scripts/check_product.sh +1 -1
  9. data/lib/mixlib/install/generator/bourne/scripts/fetch_metadata.sh.erb +49 -19
  10. data/lib/mixlib/install/generator/bourne/scripts/fetch_package.sh +47 -23
  11. data/lib/mixlib/install/generator/bourne/scripts/helpers.sh.erb +40 -38
  12. data/lib/mixlib/install/generator/bourne/scripts/install_package.sh +2 -2
  13. data/lib/mixlib/install/generator/bourne/scripts/platform_detection.sh +22 -22
  14. data/lib/mixlib/install/generator/bourne/scripts/proxy_env.sh +4 -4
  15. data/lib/mixlib/install/generator/bourne/scripts/script_cli_parameters.sh.erb +9 -3
  16. data/lib/mixlib/install/generator/bourne.rb +5 -20
  17. data/lib/mixlib/install/generator/powershell/scripts/get_project_metadata.ps1.erb +60 -36
  18. data/lib/mixlib/install/generator/powershell/scripts/helpers.ps1.erb +8 -4
  19. data/lib/mixlib/install/generator/powershell/scripts/install_project.ps1.erb +36 -16
  20. data/lib/mixlib/install/generator/powershell/scripts/platform_detection.ps1 +1 -0
  21. data/lib/mixlib/install/generator/powershell.rb +5 -9
  22. data/lib/mixlib/install/generator.rb +5 -4
  23. data/lib/mixlib/install/options.rb +40 -0
  24. data/lib/mixlib/install/product_matrix.rb +6 -1
  25. data/lib/mixlib/install/script_generator.rb +72 -22
  26. data/lib/mixlib/install/version.rb +1 -1
  27. data/lib/mixlib/install.rb +91 -16
  28. data/mixlib-install.gemspec +2 -0
  29. data/support/install_command.ps1 +3 -0
  30. metadata +17 -3
@@ -62,10 +62,10 @@ unable_to_retrieve_package() {
62
62
  echo "Unable to retrieve a valid package!"
63
63
  report_bug
64
64
  echo "Metadata URL: $metadata_url"
65
- if test "x$download_url" != "x"; then
65
+ if [ -n "$download_url" ]; then
66
66
  echo "Download URL: $download_url"
67
67
  fi
68
- if test "x$stderr_results" != "x"; then
68
+ if [ -n "$stderr_results" ]; then
69
69
  echo "\nDEBUG OUTPUT FOLLOWS:\n$stderr_results"
70
70
  fi
71
71
  exit 1
@@ -94,10 +94,10 @@ http_404_error() {
94
94
  echo ""
95
95
  # deliberately do not call report_bug to suppress bug report noise.
96
96
  echo "Metadata URL: $metadata_url"
97
- if test "x$download_url" != "x"; then
97
+ if [ -n "$download_url" ]; then
98
98
  echo "Download URL: $download_url"
99
99
  fi
100
- if test "x$stderr_results" != "x"; then
100
+ if [ -n "$stderr_results" ]; then
101
101
  echo "\nDEBUG OUTPUT FOLLOWS:\n$stderr_results"
102
102
  fi
103
103
  exit 1
@@ -105,7 +105,7 @@ http_404_error() {
105
105
 
106
106
  capture_tmp_stderr() {
107
107
  # spool up /tmp/stderr from all the commands we called
108
- if test -f "$tmp_dir/stderr"; then
108
+ if [ -f "$tmp_dir/stderr" ]; then
109
109
  output=`cat $tmp_dir/stderr`
110
110
  stderr_results="${stderr_results}\nSTDERR from $1:\n\n$output\n"
111
111
  rm $tmp_dir/stderr
@@ -116,27 +116,26 @@ capture_tmp_stderr() {
116
116
  do_wget() {
117
117
  echo "trying wget..."
118
118
  # If filename is empty, use --content-disposition to get filename from server
119
- if test "x$2" = "x"; then
119
+ if [ -z "$2" ]; then
120
120
  wget --user-agent="User-Agent: <%= user_agent_string %>" --content-disposition "$1" 2>$tmp_dir/stderr
121
121
  else
122
122
  wget --user-agent="User-Agent: <%= user_agent_string %>" -O "$2" "$1" 2>$tmp_dir/stderr
123
123
  fi
124
124
  rc=$?
125
125
  # check for 404
126
- grep "ERROR 404" $tmp_dir/stderr 2>&1 >/dev/null
127
- if test $? -eq 0; then
126
+ if grep "ERROR 404" $tmp_dir/stderr 2>&1 >/dev/null; then
128
127
  echo "ERROR 404"
129
128
  http_404_error
130
129
  fi
131
130
 
132
131
  # check for bad return status (skip empty output check if using content-disposition)
133
- if test $rc -ne 0; then
132
+ if [ $rc -ne 0 ]; then
134
133
  capture_tmp_stderr "wget"
135
134
  return 1
136
135
  fi
137
-
136
+
138
137
  # Only check for empty output if we specified a filename
139
- if test "x$2" != "x" && test ! -s "$2"; then
138
+ if [ -n "$2" ] && [ ! -s "$2" ]; then
140
139
  capture_tmp_stderr "wget"
141
140
  return 1
142
141
  fi
@@ -148,29 +147,28 @@ do_wget() {
148
147
  do_curl() {
149
148
  echo "trying curl..."
150
149
  # If filename is empty, use -O and -J to get filename from Content-Disposition header
151
- if test "x$2" = "x"; then
152
- curl -A "User-Agent: <%= user_agent_string %>" --retry 5 -sL -D $tmp_dir/stderr -O -J "$1"
150
+ if [ -z "$2" ]; then
151
+ curl -A "User-Agent: <%= user_agent_string %>" --retry 5 -sL --fail -D $tmp_dir/stderr -O -J "$1"
153
152
  rc=$?
154
153
  else
155
- curl -A "User-Agent: <%= user_agent_string %>" --retry 5 -sL -D $tmp_dir/stderr "$1" > "$2"
154
+ curl -A "User-Agent: <%= user_agent_string %>" --retry 5 -sL --fail -D $tmp_dir/stderr "$1" > "$2"
156
155
  rc=$?
157
156
  fi
158
-
159
- # check for 404
160
- grep "404 Not Found" $tmp_dir/stderr 2>&1 >/dev/null
161
- if test $? -eq 0; then
157
+
158
+ # check for 404 (matches both HTTP/1.1 "404 Not Found" and HTTP/2 "404")
159
+ if grep "404" $tmp_dir/stderr 2>&1 >/dev/null; then
162
160
  echo "ERROR 404"
163
161
  http_404_error
164
162
  fi
165
163
 
166
164
  # check for bad return status
167
- if test $rc -ne 0; then
165
+ if [ $rc -ne 0 ]; then
168
166
  capture_tmp_stderr "curl"
169
167
  return 1
170
168
  fi
171
-
169
+
172
170
  # Only check for empty output if we specified a filename
173
- if test "x$2" != "x" && test ! -s "$2"; then
171
+ if [ -n "$2" ] && [ ! -s "$2" ]; then
174
172
  capture_tmp_stderr "curl"
175
173
  return 1
176
174
  fi
@@ -183,7 +181,7 @@ do_fetch() {
183
181
  echo "trying fetch..."
184
182
  fetch --user-agent="User-Agent: <%= user_agent_string %>" -o "$2" "$1" 2>$tmp_dir/stderr
185
183
  # check for bad return status
186
- test $? -ne 0 && return 1
184
+ [ $? -ne 0 ] && return 1
187
185
  return 0
188
186
  }
189
187
 
@@ -192,15 +190,18 @@ do_perl() {
192
190
  echo "trying perl..."
193
191
  perl -e 'use LWP::Simple; getprint($ARGV[0]);' "$1" > "$2" 2>$tmp_dir/stderr
194
192
  rc=$?
195
- # check for 404
196
- grep "404 Not Found" $tmp_dir/stderr 2>&1 >/dev/null
197
- if test $? -eq 0; then
198
- echo "ERROR 404"
199
- http_404_error
193
+ # check for HTTP error status codes (4xx/5xx)
194
+ if grep "^[45][0-9][0-9] " $tmp_dir/stderr 2>&1 >/dev/null; then
195
+ if grep "404 Not Found" $tmp_dir/stderr 2>&1 >/dev/null; then
196
+ echo "ERROR 404"
197
+ http_404_error
198
+ fi
199
+ capture_tmp_stderr "perl"
200
+ return 1
200
201
  fi
201
202
 
202
203
  # check for bad return status or empty output
203
- if test $rc -ne 0 || test ! -s "$2"; then
204
+ if [ $rc -ne 0 ] || [ ! -s "$2" ]; then
204
205
  capture_tmp_stderr "perl"
205
206
  return 1
206
207
  fi
@@ -214,14 +215,13 @@ do_python() {
214
215
  python -c "import sys,urllib2; sys.stdout.write(urllib2.urlopen(urllib2.Request(sys.argv[1], headers={ 'User-Agent': '<%= user_agent_string %>' })).read())" "$1" > "$2" 2>$tmp_dir/stderr
215
216
  rc=$?
216
217
  # check for 404
217
- grep "HTTP Error 404" $tmp_dir/stderr 2>&1 >/dev/null
218
- if test $? -eq 0; then
218
+ if grep "HTTP Error 404" $tmp_dir/stderr 2>&1 >/dev/null; then
219
219
  echo "ERROR 404"
220
220
  http_404_error
221
221
  fi
222
222
 
223
223
  # check for bad return status or empty output
224
- if test $rc -ne 0 || test ! -s "$2"; then
224
+ if [ $rc -ne 0 ] || [ ! -s "$2" ]; then
225
225
  capture_tmp_stderr "python"
226
226
  return 1
227
227
  fi
@@ -233,11 +233,13 @@ do_checksum() {
233
233
  if exists sha256sum; then
234
234
  echo "Comparing checksum with sha256sum..."
235
235
  checksum=`sha256sum $1 | awk '{ print $1 }'`
236
- return `test "x$checksum" = "x$2"`
236
+ [ "$checksum" = "$2" ]
237
+ return $?
237
238
  elif exists shasum; then
238
239
  echo "Comparing checksum with shasum..."
239
240
  checksum=`shasum -a 256 $1 | awk '{ print $1 }'`
240
- return `test "x$checksum" = "x$2"`
241
+ [ "$checksum" = "$2" ]
242
+ return $?
241
243
  else
242
244
  echo "WARNING: could not find a valid checksum program, pre-install shasum or sha256sum in your O/S image to get validation..."
243
245
  return 0
@@ -250,8 +252,8 @@ do_download() {
250
252
  echo " to file $2"
251
253
 
252
254
  url=`echo $1`
253
- if test "x$platform" = "xsolaris2"; then
254
- if test "x$platform_version" = "x5.9" -o "x$platform_version" = "x5.10"; then
255
+ if [ "$platform" = "solaris2" ]; then
256
+ if [ "$platform_version" = "5.9" ] || [ "$platform_version" = "5.10" ]; then
255
257
  # solaris 9 lacks openssl, solaris 10 lacks recent enough credentials - your base O/S is completely insecure, please upgrade
256
258
  url=`echo $url | sed -e 's/https/http/'`
257
259
  fi
@@ -289,7 +291,7 @@ install_file() {
289
291
  echo "Installing $project $version"
290
292
  case "$1" in
291
293
  "rpm")
292
- if test "x$platform" = "xnexus" || test "x$platform" = "xios_xr"; then
294
+ if [ "$platform" = "nexus" ] || [ "$platform" = "ios_xr" ]; then
293
295
  echo "installing with yum..."
294
296
  yum install -yv "$2"
295
297
  else
@@ -338,14 +340,14 @@ install_file() {
338
340
  exit 1
339
341
  ;;
340
342
  esac
341
- if test $? -ne 0; then
343
+ if [ $? -ne 0 ]; then
342
344
  echo "Installation failed"
343
345
  report_bug
344
346
  exit 1
345
347
  fi
346
348
  }
347
349
 
348
- if test "x$TMPDIR" = "x"; then
350
+ if [ -z "$TMPDIR" ]; then
349
351
  tmp="/tmp"
350
352
  else
351
353
  tmp=$TMPDIR
@@ -8,7 +8,7 @@
8
8
  # $version: The version requested. Used only for warning user if not set.
9
9
  ############
10
10
 
11
- if test "x$version" = "x" -a "x$CI" != "xtrue"; then
11
+ if [ -z "$version" ] && [ "$CI" != "true" ]; then
12
12
  echo
13
13
  echo "WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING"
14
14
  echo
@@ -24,7 +24,7 @@ fi
24
24
 
25
25
  install_file $filetype "$download_filename"
26
26
 
27
- if test "x$tmp_dir" != "x"; then
27
+ if [ -n "$tmp_dir" ]; then
28
28
  rm -r "$tmp_dir"
29
29
  fi
30
30
 
@@ -25,35 +25,35 @@
25
25
  machine=`uname -m`
26
26
  os=`uname -s`
27
27
 
28
- if test -f "/etc/lsb-release" && grep DISTRIB_ID /etc/lsb-release >/dev/null && ! grep wrlinux /etc/lsb-release >/dev/null; then
28
+ if [ -f "/etc/lsb-release" ] && grep DISTRIB_ID /etc/lsb-release >/dev/null && ! grep wrlinux /etc/lsb-release >/dev/null; then
29
29
  platform=`grep DISTRIB_ID /etc/lsb-release | cut -d "=" -f 2 | tr '[A-Z]' '[a-z]'`
30
30
  platform_version=`grep DISTRIB_RELEASE /etc/lsb-release | cut -d "=" -f 2`
31
31
 
32
- if test "$platform" = "\"cumulus linux\""; then
32
+ if [ "$platform" = '"cumulus linux"' ]; then
33
33
  platform="cumulus_linux"
34
- elif test "$platform" = "\"cumulus networks\""; then
34
+ elif [ "$platform" = '"cumulus networks"' ]; then
35
35
  platform="cumulus_networks"
36
36
  fi
37
37
 
38
- elif test -f "/etc/debian_version"; then
38
+ elif [ -f "/etc/debian_version" ]; then
39
39
  platform="debian"
40
40
  platform_version=`cat /etc/debian_version`
41
- elif test -f "/etc/Eos-release"; then
41
+ elif [ -f "/etc/Eos-release" ]; then
42
42
  # EOS may also contain /etc/redhat-release so this check must come first.
43
43
  platform=arista_eos
44
44
  platform_version=`awk '{print $4}' /etc/Eos-release`
45
45
  machine="i386"
46
- elif test -f "/etc/redhat-release"; then
46
+ elif [ -f "/etc/redhat-release" ]; then
47
47
  platform=`sed 's/^\(.\+\) release.*/\1/' /etc/redhat-release | tr '[A-Z]' '[a-z]'`
48
48
  platform_version=`sed 's/^.\+ release \([.0-9]\+\).*/\1/' /etc/redhat-release`
49
-
50
- if test "$platform" = "rocky linux"; then
49
+
50
+ if [ "$platform" = "rocky linux" ]; then
51
51
  source /etc/os-release
52
52
  os="${REDHAT_SUPPORT_PRODUCT}"
53
53
  platform_version="${ROCKY_SUPPORT_PRODUCT_VERSION}"
54
54
  platform=$ID
55
55
 
56
- elif test "$platform" = "xenserver"; then
56
+ elif [ "$platform" = "xenserver" ]; then
57
57
  # Current XenServer 6.2 is based on CentOS 5, platform is not reset to "el" server should handle response
58
58
  platform="xenserver"
59
59
  else
@@ -61,7 +61,7 @@ elif test -f "/etc/redhat-release"; then
61
61
  platform="el"
62
62
  fi
63
63
 
64
- elif test -f "/etc/system-release"; then
64
+ elif [ -f "/etc/system-release" ]; then
65
65
  platform=`sed 's/^\(.\+\) release.\+/\1/' /etc/system-release | tr '[A-Z]' '[a-z]'`
66
66
  platform_version=`sed 's/^.\+ release \([.0-9]\+\).*/\1/' /etc/system-release | tr '[A-Z]' '[a-z]'`
67
67
  case $platform in amazon*) # sh compat method of checking for a substring
@@ -88,11 +88,11 @@ elif test -f "/etc/system-release"; then
88
88
 
89
89
 
90
90
  # Apple macOS
91
- elif test -f "/usr/bin/sw_vers"; then
91
+ elif [ -f "/usr/bin/sw_vers" ]; then
92
92
  platform="mac_os_x"
93
93
  # Matching the tab-space with sed is error-prone
94
94
  platform_version=`sw_vers | awk '/^ProductVersion:/ { print $2 }' | cut -d. -f1,2`
95
- elif test -f "/etc/release"; then
95
+ elif [ -f "/etc/release" ]; then
96
96
  machine=`/usr/bin/uname -p`
97
97
  if grep SmartOS /etc/release >/dev/null; then
98
98
  platform="smartos"
@@ -101,7 +101,7 @@ elif test -f "/etc/release"; then
101
101
  platform="solaris2"
102
102
  platform_version=`/usr/bin/uname -r`
103
103
  fi
104
- elif test -f "/etc/SuSE-release"; then
104
+ elif [ -f "/etc/SuSE-release" ]; then
105
105
  if grep 'Enterprise' /etc/SuSE-release >/dev/null;
106
106
  then
107
107
  platform="sles"
@@ -110,16 +110,16 @@ elif test -f "/etc/SuSE-release"; then
110
110
  platform="opensuseleap"
111
111
  platform_version=`awk '/^VERSION =/ { print $3 }' /etc/SuSE-release`
112
112
  fi
113
- elif test "x$os" = "xFreeBSD"; then
113
+ elif [ "$os" = "FreeBSD" ]; then
114
114
  platform="freebsd"
115
115
  platform_version=`uname -r | sed 's/-.*//'`
116
- elif test "x$os" = "xAIX"; then
116
+ elif [ "$os" = "AIX" ]; then
117
117
  platform="aix"
118
118
  platform_version="`uname -v`.`uname -r`"
119
119
  machine="powerpc"
120
- elif test -f "/etc/os-release"; then
120
+ elif [ -f "/etc/os-release" ]; then
121
121
  . /etc/os-release
122
- if test "x$CISCO_RELEASE_INFO" != "x"; then
122
+ if [ -n "$CISCO_RELEASE_INFO" ]; then
123
123
  . $CISCO_RELEASE_INFO
124
124
  fi
125
125
 
@@ -127,14 +127,14 @@ elif test -f "/etc/os-release"; then
127
127
 
128
128
  # VERSION_ID is always the preferred variable to use, but not
129
129
  # every distro has it so fallback to VERSION
130
- if test "x$VERSION_ID" != "x"; then
130
+ if [ -n "$VERSION_ID" ]; then
131
131
  platform_version=$VERSION_ID
132
132
  else
133
133
  platform_version=$VERSION
134
134
  fi
135
135
  fi
136
136
 
137
- if test "x$platform" = "x"; then
137
+ if [ -z "$platform" ]; then
138
138
  echo "Unable to determine platform version!"
139
139
  report_bug
140
140
  exit 1
@@ -158,7 +158,7 @@ case $platform in
158
158
  platform_version=$major_version
159
159
  ;;
160
160
  "debian")
161
- if test "x$major_version" = "x5"; then
161
+ if [ "$major_version" = "5" ]; then
162
162
  # This is here for potential back-compat.
163
163
  # We do not have 5 in versions we publish for anymore but we
164
164
  # might have it for earlier versions.
@@ -194,13 +194,13 @@ case $machine in
194
194
  ;;
195
195
  esac
196
196
 
197
- if test "x$platform_version" = "x"; then
197
+ if [ -z "$platform_version" ]; then
198
198
  echo "Unable to determine platform version!"
199
199
  report_bug
200
200
  exit 1
201
201
  fi
202
202
 
203
- if test "x$platform" = "xsolaris2"; then
203
+ if [ "$platform" = "solaris2" ]; then
204
204
  # hack up the path on Solaris to find wget, pkgadd
205
205
  PATH=/usr/sfw/bin:/usr/sbin:$PATH
206
206
  export PATH
@@ -3,7 +3,7 @@
3
3
  # Otherwise, default proxy env vars will be loaded by the respective
4
4
  # download utility.
5
5
 
6
- if test "x$https_proxy" != "x"; then
6
+ if [ -n "$https_proxy" ]; then
7
7
  echo "setting https_proxy: $https_proxy"
8
8
  HTTPS_PROXY=$https_proxy
9
9
  https_proxy=$https_proxy
@@ -11,7 +11,7 @@ if test "x$https_proxy" != "x"; then
11
11
  export https_proxy
12
12
  fi
13
13
 
14
- if test "x$http_proxy" != "x"; then
14
+ if [ -n "$http_proxy" ]; then
15
15
  echo "setting http_proxy: $http_proxy"
16
16
  HTTP_PROXY=$http_proxy
17
17
  http_proxy=$http_proxy
@@ -19,7 +19,7 @@ if test "x$http_proxy" != "x"; then
19
19
  export http_proxy
20
20
  fi
21
21
 
22
- if test "x$ftp_proxy" != "x"; then
22
+ if [ -n "$ftp_proxy" ]; then
23
23
  echo "setting ftp_proxy: $ftp_proxy"
24
24
  FTP_PROXY=$ftp_proxy
25
25
  ftp_proxy=$ftp_proxy
@@ -27,7 +27,7 @@ if test "x$ftp_proxy" != "x"; then
27
27
  export ftp_proxy
28
28
  fi
29
29
 
30
- if test "x$no_proxy" != "x"; then
30
+ if [ -n "$no_proxy" ]; then
31
31
  echo "setting no_proxy: $no_proxy"
32
32
  NO_PROXY=$no_proxy
33
33
  no_proxy=$no_proxy
@@ -7,6 +7,8 @@
7
7
  # $version: Requested version to be installed.
8
8
  # $channel: Channel to install the product from
9
9
  # $project: Project to be installed
10
+ # $package_manager: (Optional) Package manager override (e.g. rpm, deb, tar, msi).
11
+ # If omitted, the server derives it from the platform (p) parameter.
10
12
  # $cmdline_filename: Name of the package downloaded on local disk.
11
13
  # $cmdline_dl_dir: Name of the directory downloaded package will be saved to on local disk.
12
14
  # $install_strategy: Method of package installations. default strategy is to always install upon exec. Set to "once" to skip if project is installed
@@ -18,12 +20,15 @@
18
20
  # Defaults
19
21
  channel="stable"
20
22
  project="<%= default_product %>"
23
+ package_manager=""
24
+ <%= "license_id=\"#{license_id}\"" if license_id && !license_id.to_s.empty? %>
21
25
 
22
- while getopts pnv:c:f:P:d:s:l:a:L: opt
26
+ while getopts pnv:b:c:f:P:d:s:l:a:L:i: opt
23
27
  do
24
28
  case "$opt" in
25
29
 
26
30
  v) version="$OPTARG";;
31
+ b) base_api_url="$OPTARG";;
27
32
  c) channel="$OPTARG";;
28
33
  p) channel="current";; # compat for prerelease option
29
34
  n) channel="current";; # compat for nightlies option
@@ -34,9 +39,10 @@ do
34
39
  l) download_url_override="$OPTARG";;
35
40
  a) checksum="$OPTARG";;
36
41
  L) license_id="$OPTARG";;
42
+ i) package_manager="$OPTARG";;
37
43
  \?) # unknown flag
38
44
  echo >&2 \
39
- "usage: $0 [-P project] [-c release_channel] [-v version] [-f filename | -d download_dir] [-s install_strategy] [-l download_url_override] [-a checksum] [-L license_id]"
45
+ "usage: $0 [-P project] [-b base_api_url] [-c release_channel] [-v version] [-f filename | -d download_dir] [-s install_strategy] [-l download_url_override] [-a checksum] [-L license_id] [-i package_manager]"
40
46
  exit 1;;
41
47
  esac
42
48
  done
@@ -44,6 +50,6 @@ done
44
50
  shift `expr $OPTIND - 1`
45
51
 
46
52
  # Use CHEF_LICENSE_KEY environment variable if license_id not provided via CLI
47
- if [ -z "$license_id" ] && [ -n "${CHEF_LICENSE_KEY:-}" ]; then
53
+ if [ -z "$license_id" ] && [ -n "$CHEF_LICENSE_KEY" ]; then
48
54
  license_id="$CHEF_LICENSE_KEY"
49
55
  fi
@@ -24,19 +24,7 @@ module Mixlib
24
24
  def self.install_sh(context)
25
25
  install_command = []
26
26
  install_command << get_script("helpers.sh", context)
27
- # If license_id is provided in context, pre-set it as a variable
28
- if context[:license_id] && !context[:license_id].to_s.empty?
29
- install_command << "# License ID provided via context"
30
- install_command << "license_id='#{context[:license_id]}'"
31
- end
32
- install_command << get_script("script_cli_parameters.sh")
33
- # Check for CHEF_LICENSE_KEY in execution environment if not already set
34
- install_command << <<~BASH.chomp
35
- # Use CHEF_LICENSE_KEY from execution environment if license_id not set
36
- if [ -z "${license_id:-}" ] && [ -n "${CHEF_LICENSE_KEY:-}" ]; then
37
- license_id="$CHEF_LICENSE_KEY"
38
- fi
39
- BASH
27
+ install_command << get_script("script_cli_parameters.sh", context)
40
28
  install_command << get_script("check_product.sh")
41
29
  install_command << get_script("platform_detection.sh")
42
30
  install_command << get_script("proxy_env.sh")
@@ -61,7 +49,7 @@ module Mixlib
61
49
  install_command << get_script("check_product.sh")
62
50
  install_command << get_script("platform_detection.sh")
63
51
  install_command << get_script("proxy_env.sh")
64
- install_command << get_script("fetch_metadata.sh")
52
+ install_command << get_script("fetch_metadata.sh", license_id: options.license_id, base_url: options.base_url)
65
53
  install_command << get_script("fetch_package.sh")
66
54
  install_command << get_script("install_package.sh")
67
55
 
@@ -73,16 +61,13 @@ module Mixlib
73
61
  project=#{options.product_name}
74
62
  version=#{options.product_version}
75
63
  channel=#{options.channel}
64
+ #{"license_id=#{options.license_id}" if options.license_id && !options.license_id.to_s.empty?}
65
+ #{"base_api_url=#{options.base_url}" if options.base_url && !options.base_url.to_s.empty?}
76
66
  EOS
77
- # Add license_id if provided, otherwise use CHEF_LICENSE_KEY env var
78
- license_id_value = options.license_id || ENV["CHEF_LICENSE_KEY"]
79
- if license_id_value && !license_id_value.to_s.empty?
80
- vars += "license_id=#{license_id_value}\n"
81
- end
82
67
  # Check for CHEF_LICENSE_KEY in execution environment if not already set
83
68
  vars += <<EOS
84
69
  # Use CHEF_LICENSE_KEY from execution environment if license_id not set
85
- if [ -z "${license_id:-}" ] && [ -n "${CHEF_LICENSE_KEY:-}" ]; then
70
+ if [ -z "$license_id" ] && [ -n "$CHEF_LICENSE_KEY" ]; then
86
71
  license_id="$CHEF_LICENSE_KEY"
87
72
  fi
88
73
  EOS
@@ -1,3 +1,4 @@
1
+ ################ get_project_metadata.ps1
1
2
  function Get-ProjectMetadata {
2
3
  <#
3
4
  .SYNOPSIS
@@ -5,22 +6,21 @@ function Get-ProjectMetadata {
5
6
  .DESCRIPTION
6
7
  Get metadata for project
7
8
  .EXAMPLE
8
- iex (new-object net.webclient).downloadstring('<%= base_url %>/install.ps1'); Get-ProjectMetadata -project chef -channel stable
9
+ iex (new-object net.webclient).downloadstring('<%= base_url || "https://chefdownload-commercial.chef.io" %>/install.ps1<%= base_url && base_url.include?("chefdownload") ? "?license_id=$env:CHEF_LICENSE_KEY" : "" %>'); Get-ProjectMetadata -project chef -channel stable
9
10
 
10
11
  Gets the download url and SHA256 checksum for the latest stable release of Chef.
11
12
  .EXAMPLE
12
- iex (irm '<%= base_url %>/install.ps1'); Get-ProjectMetadata -project chefdk -channel stable -version 0.8.0
13
-
14
- Gets the download url and SHA256 checksum for ChefDK 0.8.0.
13
+ iex (irm '<%= base_url || "https://chefdownload-commercial.chef.io" %>/install.ps1<%= base_url && base_url.include?("chefdownload") ? "?license_id=$env:CHEF_LICENSE_KEY" : "" %>'); Get-ProjectMetadata -project chef-workstation -channel stable
15
14
  #>
16
15
  [cmdletbinding()]
17
16
  param (
18
17
  # Base url to retrieve metadata from.
19
- [uri]$base_server_uri = '<%= base_url %>',
18
+ [uri]
19
+ $base_server_uri,
20
20
  [string]
21
21
  # Project to install
22
22
  [string]
23
- $project = 'chef',
23
+ $project = '<%= default_product %>',
24
24
  # Version of the application to install
25
25
  # This parameter is optional, if not supplied it will provide the latest version,
26
26
  # and if an iteration number is not specified, it will grab the latest available iteration.
@@ -42,7 +42,10 @@ function Get-ProjectMetadata {
42
42
  $architecture = 'auto',
43
43
  # License ID for commercial API access
44
44
  [string]
45
- $license_id
45
+ $license_id <%= "= '#{license_id}'" if license_id && !license_id.to_s.empty? %>,
46
+ # Package manager override (e.g. msi, zip). If omitted, the server derives it from platform.
47
+ [string]
48
+ $package_manager
46
49
  )
47
50
 
48
51
  # The following legacy switches are just aliases for the current channel
@@ -51,47 +54,68 @@ function Get-ProjectMetadata {
51
54
 
52
55
  # PowerShell is only on Windows ATM
53
56
  $platform = 'windows'
54
- Write-Verbose "Platform: $platform"
57
+ Write-Host "Platform: $platform"
55
58
 
56
59
  $platform_version = Get-PlatformVersion
57
- Write-Verbose "Platform Version: $platform_version"
60
+ Write-Host "Platform Version: $platform_version"
58
61
 
59
62
  if ($architecture -eq 'auto') {
60
63
  $architecture = Get-PlatformArchitecture
61
64
  }
62
65
 
63
- Write-Verbose "Architecture: $architecture"
64
- Write-Verbose "Project: $project"
66
+ Write-Host "Architecture: $architecture"
67
+ Write-Host "Project: $project"
65
68
 
66
- # Use commercial API if license_id is provided, otherwise use omnitruck
67
- if ($license_id) {
68
- # Check if license_id starts with 'free-' or 'trial-' for trial API
69
- if ($license_id -match '^(free-|trial-)') {
70
- $base_server_uri = 'https://chefdownload-trial.chef.io'
71
- Write-Verbose "Using Trial API with license ID"
72
- } else {
73
- $base_server_uri = 'https://chefdownload-commercial.chef.io'
74
- Write-Verbose "Using Commercial API with license ID"
69
+ <% if base_url && !base_url.to_s.empty? %>
70
+ # Set base_server_uri from option if not already set via parameter
71
+ if ([string]::IsNullOrEmpty($base_server_uri)) {
72
+ $base_server_uri = "<%= base_url %>"
73
+ }
74
+ <% end %>
75
+
76
+ if ([string]::IsNullOrEmpty($base_server_uri)) {
77
+ if (-not [string]::IsNullOrEmpty($license_id)) {
78
+ # Check if license_id starts with 'free-' or 'trial-' for trial API
79
+ if ($license_id -match '^(free-|trial-)') {
80
+ # Trial API endpoint
81
+ $base_server_uri = "<%= Mixlib::Install::Dist::TRIAL_API_ENDPOINT %>"
82
+ }
83
+ else {
84
+ # Commercial API endpoint
85
+ $base_server_uri = "<%= Mixlib::Install::Dist::COMMERCIAL_API_ENDPOINT %>"
86
+ }
87
+ }
88
+ else {
89
+ # Omnitruck endpoint
90
+ $base_server_uri = "<%= Mixlib::Install::Dist::OMNITRUCK_ENDPOINT %>"
75
91
  }
76
92
  }
77
93
 
78
- $metadata_base_url = "/$($channel)/$($project)/metadata"
79
- $metadata_array = ("?v=$($version)",
80
- "p=$platform",
81
- "pv=$platform_version",
82
- "m=$architecture")
83
-
84
- # Add license_id to query parameters if provided
85
- if ($license_id) {
86
- $metadata_array += "license_id=$license_id"
94
+ # Only include pm param when the caller explicitly passed -package_manager;
95
+ # the server derives it from the platform (p) parameter otherwise.
96
+
97
+ if (-not [string]::IsNullOrEmpty($package_manager)) {
98
+ $pm_param = "&pm=$package_manager"
99
+ }
100
+ else {
101
+ $pm_param = ""
102
+ }
103
+
104
+ # License param (appended only when a license_id is present)
105
+ $license_param = ""
106
+ if (-not [string]::IsNullOrEmpty($license_id)) {
107
+ $license_param = "&license_id=$license_id"
108
+ }
109
+ else {
110
+ $license_param = ""
87
111
  }
88
-
89
- $metadata_base_url += [string]::join('&', $metadata_array)
90
- $metadata_url = new-uri $base_server_uri $metadata_base_url
91
112
 
92
- Write-Verbose "Downloading $project details from $metadata_url"
113
+ # Build the metadata URL.
114
+ $metadata_url = "$base_server_uri$channel/$project/metadata?v=$version&p=$platform&pv=$platform_version&m=$architecture$license_param$pm_param"
115
+
116
+ Write-Host "Downloading $project details from $metadata_url"
93
117
  $response = (Get-WebContent $metadata_url).trim()
94
-
118
+
95
119
  # Commercial and trial APIs return JSON, omnitruck returns text format
96
120
  if ($license_id) {
97
121
  # Parse JSON response from commercial/trial API
@@ -114,9 +138,9 @@ function Get-ProjectMetadata {
114
138
  foreach { $hash = @{} } {$key, $value = $_ -split '\s+'; $hash.Add($key, $value)} {$hash}
115
139
  }
116
140
 
117
- Write-Verbose "Project details: "
141
+ Write-Host "Project details: "
118
142
  foreach ($key in $package_metadata.keys) {
119
- Write-Verbose "`t$key = $($package_metadata[$key])"
143
+ Write-Host "`t$key = $($package_metadata[$key])"
120
144
  }
121
145
  $package_metadata
122
146
  }