mixlib-install 3.15.0 → 3.16.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 (29) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -14
  3. data/lib/mixlib/install/backend/base.rb +15 -1
  4. data/lib/mixlib/install/backend/package_router.rb +60 -17
  5. data/lib/mixlib/install/dist.rb +24 -4
  6. data/lib/mixlib/install/generator/base.rb +1 -14
  7. data/lib/mixlib/install/generator/bourne/scripts/check_product.sh +1 -1
  8. data/lib/mixlib/install/generator/bourne/scripts/fetch_metadata.sh.erb +89 -19
  9. data/lib/mixlib/install/generator/bourne/scripts/fetch_package.sh +47 -23
  10. data/lib/mixlib/install/generator/bourne/scripts/helpers.sh.erb +30 -32
  11. data/lib/mixlib/install/generator/bourne/scripts/install_package.sh +2 -2
  12. data/lib/mixlib/install/generator/bourne/scripts/platform_detection.sh +22 -22
  13. data/lib/mixlib/install/generator/bourne/scripts/proxy_env.sh +4 -4
  14. data/lib/mixlib/install/generator/bourne/scripts/script_cli_parameters.sh.erb +5 -3
  15. data/lib/mixlib/install/generator/bourne.rb +5 -20
  16. data/lib/mixlib/install/generator/powershell/scripts/get_project_metadata.ps1.erb +52 -36
  17. data/lib/mixlib/install/generator/powershell/scripts/helpers.ps1.erb +8 -4
  18. data/lib/mixlib/install/generator/powershell/scripts/install_project.ps1.erb +33 -16
  19. data/lib/mixlib/install/generator/powershell/scripts/platform_detection.ps1 +1 -0
  20. data/lib/mixlib/install/generator/powershell.rb +5 -9
  21. data/lib/mixlib/install/generator.rb +5 -4
  22. data/lib/mixlib/install/options.rb +40 -0
  23. data/lib/mixlib/install/product_matrix.rb +1 -1
  24. data/lib/mixlib/install/script_generator.rb +80 -23
  25. data/lib/mixlib/install/util.rb +47 -0
  26. data/lib/mixlib/install/version.rb +1 -1
  27. data/lib/mixlib/install.rb +82 -11
  28. data/support/install_command.ps1 +3 -0
  29. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87576368d2d140a99f1e02a508c19bb3d55dbc637ca3b4d6b39f6bbfcd857ad6
4
- data.tar.gz: 4114e92d08cba4ea18093bfaa2e0f02b584dda06de878e56e11fd2c68aa58b9e
3
+ metadata.gz: 6d34030b7986d54d5391add8b932400aad83b2623f9a03a60667d54f82de8c50
4
+ data.tar.gz: e86a1612a3de84529fc03193e02d8e290609e389dd33bbeeef4d55fa929662fd
5
5
  SHA512:
6
- metadata.gz: 428a3a79f93b46f570ac709eaf7fcae54360dc893742360bf42b02ee0565c2992426d1588b4cd4baf6ae7d84898c284148a284824dece7d9890e75964fcea425
7
- data.tar.gz: 991621b4937be08512cc2bb556a3848485a2a2e0223dc05382987a400131e49d20536d06df04c84a9d3d18acd10d6f93a7e6d34bb83c3022999fcfe59b4d4756
6
+ metadata.gz: d978a599bd28442d1c2324d15e6e7898b312a30453c3e6cc778145f1afa2b3ff219ab632cc486b240c7052863777dfdb9d7d3049c699ade7a92319efc50eebcf
7
+ data.tar.gz: b68a1acc6f92a826a74ab867c2e6db32e31d96442d34c3154330d2a8c554a2e1d780f2d0148d7b18fdea185542711e490c16eca7aa9c3ac1df45eb701cba78b8
data/Gemfile CHANGED
@@ -3,20 +3,6 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem "chef-utils", "= 16.6.14" if RUBY_VERSION < "2.6.0"
6
- # OpenSSL version constraints to fix CRL checking issues in OpenSSL 3.6+
7
- # Ruby 2.6-2.7 bundled openssl needs update to 3.1.2+
8
- # Ruby 3.0-3.2 bundled openssl needs update to 3.1.2+
9
- # Ruby 3.3 bundled openssl needs update to 3.2.2+
10
- # Ruby 3.4 bundled openssl needs update to 3.3.1+
11
- if RUBY_VERSION < "2.7.0"
12
- gem "openssl", ">= 3.1.2", "< 3.2.0"
13
- elsif RUBY_VERSION < "3.3.0"
14
- gem "openssl", ">= 3.1.2"
15
- elsif RUBY_VERSION < "3.4.0"
16
- gem "openssl", ">= 3.2.2"
17
- elsif RUBY_VERSION < "4.0.0"
18
- gem "openssl", ">= 3.3.1"
19
- end
20
6
 
21
7
  group :test do
22
8
  gem "contracts", "~> 0.16.0" # this entry can go away when ruby < 3 support is gone
@@ -84,9 +84,23 @@ module Mixlib
84
84
  def filter_artifacts(artifacts)
85
85
  return artifacts unless platform_filters_available?
86
86
 
87
+ # For chef-ice, normalize the platform for comparison since chef-ice uses
88
+ # normalized platform names (linux, macos, windows) in the API response
89
+ comparison_platform = if options.product_name == "chef-ice"
90
+ Util.normalize_platform_for_commercial(options.platform)
91
+ else
92
+ options.platform
93
+ end
94
+
87
95
  # First filter the artifacts based on the platform and architecture
88
96
  artifacts.select! do |a|
89
- a.platform == options.platform && a.architecture == options.architecture
97
+ a.platform == comparison_platform && a.architecture == options.architecture
98
+ end
99
+
100
+ # For chef-ice, platform_version is not used (it's empty in responses)
101
+ # so we should return the first match if available
102
+ if options.product_name == "chef-ice"
103
+ return artifacts.first if artifacts.any?
90
104
  end
91
105
 
92
106
  # Now we are going to filter based on platform_version.
@@ -137,23 +137,47 @@ EOF
137
137
  # Commercial/trial APIs use the packages endpoint which returns metadata for all platforms
138
138
  query = "v=#{version}"
139
139
  packages_hash = get("/#{options.channel}/#{omnibus_project}/packages?#{query}")
140
- # Response is a nested hash: platform -> platform_version -> architecture -> package_info
141
- # Flatten it to an array of package metadata objects
140
+ # Response structure differs between products:
141
+ # - For chef-ice: platform -> architecture -> package_manager -> package_info
142
+ # - For other products: platform -> platform_version -> architecture -> package_info
142
143
  results = []
143
- packages_hash.each do |platform, platform_versions|
144
- platform_versions.each do |platform_version, architectures|
145
- architectures.each do |arch, pkg_info|
146
- results << {
147
- "omnibus.version" => pkg_info["version"],
148
- "omnibus.platform" => platform,
149
- "omnibus.platform_version" => platform_version,
150
- "omnibus.architecture" => arch,
151
- "omnibus.project" => omnibus_project,
152
- "omnibus.license" => "Apache-2.0",
153
- "omnibus.sha256" => pkg_info["sha256"],
154
- "omnibus.sha1" => pkg_info.fetch("sha1", ""),
155
- "omnibus.md5" => pkg_info.fetch("md5", ""),
156
- }
144
+ if omnibus_project == "chef-ice"
145
+ # chef-ice structure: platform -> architecture -> package_manager -> package_info
146
+ packages_hash.each do |platform, architectures|
147
+ architectures.each do |arch, package_managers|
148
+ package_managers.each do |pm, pkg_info|
149
+ results << {
150
+ "omnibus.version" => pkg_info["version"],
151
+ "omnibus.platform" => platform,
152
+ "omnibus.platform_version" => "",
153
+ "omnibus.architecture" => arch,
154
+ "omnibus.project" => omnibus_project,
155
+ "omnibus.license" => "Apache-2.0",
156
+ "omnibus.sha256" => pkg_info["sha256"],
157
+ "omnibus.sha1" => pkg_info.fetch("sha1", ""),
158
+ "omnibus.md5" => pkg_info.fetch("md5", ""),
159
+ "omnibus.package_manager" => pm,
160
+ }
161
+ end
162
+ end
163
+ end
164
+ else
165
+ # Standard structure: platform -> platform_version -> architecture -> package_info
166
+ packages_hash.each do |platform, platform_versions|
167
+ platform_versions.each do |platform_version, architectures|
168
+ architectures.each do |arch, pkg_info|
169
+ results << {
170
+ "omnibus.version" => pkg_info["version"],
171
+ "omnibus.platform" => platform,
172
+ "omnibus.platform_version" => platform_version,
173
+ "omnibus.architecture" => arch,
174
+ "omnibus.project" => omnibus_project,
175
+ "omnibus.license" => "Apache-2.0",
176
+ "omnibus.sha256" => pkg_info["sha256"],
177
+ "omnibus.sha1" => pkg_info.fetch("sha1", ""),
178
+ "omnibus.md5" => pkg_info.fetch("md5", ""),
179
+ }
180
+ end
157
181
  end
158
182
  end
159
183
  end
@@ -198,6 +222,16 @@ EOF
198
222
  res = http.request(create_http_request(full_path))
199
223
  res.value
200
224
  JSON.parse(res.body)
225
+ rescue Net::HTTPClientError, Net::HTTPServerError => e
226
+ # Provide helpful error messages for licensed API failures
227
+ if use_trial_api?
228
+ if options.channel != :stable || (options.product_version != :latest && options.product_version.to_sym != :latest)
229
+ raise "Trial API only supports stable channel and latest version. " \
230
+ "Current settings: channel=#{options.channel}, version=#{options.product_version}. " \
231
+ "Error: #{e.message}"
232
+ end
233
+ end
234
+ raise e
201
235
  end
202
236
 
203
237
  def create_http_request(full_path)
@@ -251,7 +285,16 @@ EOF
251
285
  pv_param = platform_version
252
286
  m_param = Util.normalize_architecture(artifact_map["omnibus.architecture"])
253
287
  v_param = artifact_map["omnibus.version"]
254
- download_url = "#{endpoint}/#{options.channel}/#{omnibus_project}/download?p=#{p_param}&pv=#{pv_param}&m=#{m_param}&v=#{v_param}&license_id=#{options.license_id}"
288
+
289
+ # For chef-ice, use normalized platform names and add package manager parameter
290
+ if omnibus_project == "chef-ice"
291
+ p_param = Util.normalize_platform_for_commercial(platform)
292
+ # Use package_manager from artifact_map if available, otherwise determine it
293
+ pm_param = artifact_map.fetch("omnibus.package_manager", Util.determine_package_manager(options.platform))
294
+ download_url = "#{endpoint}/#{options.channel}/#{omnibus_project}/download?v=#{v_param}&license_id=#{options.license_id}&m=#{m_param}&p=#{p_param}&pm=#{pm_param}"
295
+ else
296
+ download_url = "#{endpoint}/#{options.channel}/#{omnibus_project}/download?p=#{p_param}&pv=#{pv_param}&m=#{m_param}&v=#{v_param}&license_id=#{options.license_id}"
297
+ end
255
298
  else
256
299
  base_url = if use_compat_download_url_endpoint?(platform, platform_version)
257
300
  COMPAT_DOWNLOAD_URL_ENDPOINT
@@ -26,10 +26,30 @@ module Mixlib
26
26
  RESOURCES_URL = "https://www.chef.io/support".freeze
27
27
  # MacOS volume name
28
28
  MACOS_VOLUME = "chef_software".freeze
29
- # Windows install directory name
30
- WINDOWS_INSTALL_DIR = "opscode".freeze
31
- # Linux install directory name
32
- LINUX_INSTALL_DIR = "/opt"
29
+ # Omnibus Windows install directory name
30
+ OMNIBUS_WINDOWS_INSTALL_DIR = "opscode".freeze
31
+ # Omnibus Linux install directory name
32
+ OMNIBUS_LINUX_INSTALL_DIR = "/opt".freeze
33
+ # Habitat Windows install directory name
34
+ HABITAT_WINDOWS_INSTALL_DIR = "hab\\pkgs".freeze
35
+ # Habitat Linux install directory name
36
+ HABITAT_LINUX_INSTALL_DIR = "/hab/pkgs".freeze
37
+
38
+ # Check if a license_id is for trial API
39
+ # @param license_id [String] the license ID to check
40
+ # @return [Boolean] true if license_id indicates trial API usage
41
+ def self.trial_license?(license_id)
42
+ !license_id.nil? && !license_id.to_s.empty? &&
43
+ license_id.start_with?("free-", "trial-")
44
+ end
45
+
46
+ # Check if a license_id is for commercial API
47
+ # @param license_id [String] the license ID to check
48
+ # @return [Boolean] true if license_id indicates commercial API usage
49
+ def self.commercial_license?(license_id)
50
+ !license_id.nil? && !license_id.to_s.empty? &&
51
+ !trial_license?(license_id)
52
+ end
33
53
  end
34
54
  end
35
55
  end
@@ -19,7 +19,6 @@ require "erb" unless defined?(Erb)
19
19
  require "ostruct" unless defined?(OpenStruct)
20
20
  require_relative "../util"
21
21
  require_relative "../dist"
22
- require "net/http" unless defined?(Net::HTTP)
23
22
 
24
23
  module Mixlib
25
24
  class Install
@@ -50,13 +49,12 @@ module Mixlib
50
49
  if File.exist? "#{script_path}.erb"
51
50
  # Default values to use incase they are not set in the context
52
51
  context[:project_name] ||= Mixlib::Install::Dist::PROJECT_NAME.freeze
53
- context[:base_url] ||= Mixlib::Install::Dist::OMNITRUCK_ENDPOINT.freeze
54
52
  context[:default_product] ||= Mixlib::Install::Dist::DEFAULT_PRODUCT.freeze
55
53
  context[:bug_url] ||= Mixlib::Install::Dist::BUG_URL.freeze
56
54
  context[:support_url] ||= Mixlib::Install::Dist::SUPPORT_URL.freeze
57
55
  context[:resources_url] ||= Mixlib::Install::Dist::RESOURCES_URL.freeze
58
56
  context[:macos_dir] ||= Mixlib::Install::Dist::MACOS_VOLUME.freeze
59
- context[:windows_dir] ||= Mixlib::Install::Dist::WINDOWS_INSTALL_DIR.freeze
57
+ context[:windows_dir] ||= context[:default_product].casecmp("chef-ice") == 0 ? Mixlib::Install::Dist::HABITAT_WINDOWS_INSTALL_DIR.freeze : Mixlib::Install::Dist::OMNIBUS_WINDOWS_INSTALL_DIR.freeze
60
58
  context[:user_agent_string] = Util.user_agent_string(context[:user_agent_headers])
61
59
 
62
60
  context_object = OpenStruct.new(context).instance_eval { binding }
@@ -69,17 +67,6 @@ module Mixlib
69
67
  def get_script(name, context = {})
70
68
  self.class.get_script(name, context)
71
69
  end
72
-
73
- def install_sh_from_upstream
74
- uri = URI.parse(options.options[:new_omnibus_download_url])
75
- response = Net::HTTP.get_response(uri)
76
-
77
- if response.code == "200"
78
- response.body
79
- else
80
- raise StandardError, "unable to fetch the install.sh"
81
- end
82
- end
83
70
  end
84
71
  end
85
72
  end
@@ -8,7 +8,7 @@ else
8
8
  fi
9
9
 
10
10
  for path in $install_paths; do
11
- if [ -d "$path" ] 2>/dev/null && [ "x$install_strategy" = "xonce" ]; then
11
+ if [ -d "$path" ] && [ "$install_strategy" = "once" ]; then
12
12
  echo "$project installation detected at $path"
13
13
  echo "install_strategy set to 'once'"
14
14
  echo "Nothing to install"
@@ -3,7 +3,15 @@
3
3
  # This section calls omnitruck to get the information about the build to be
4
4
  # installed.
5
5
  #
6
+ # EXAMPLE
7
+ # curl -L '<%= base_url || "https://chefdownload-commercial.chef.io" %>/install.sh<%= base_url && base_url.include?("chefdownload") ? "?license_id=$CHEF_LICENSE_KEY" : "" %>' | sudo bash -s -- -P chef -c stable
8
+ #
9
+ # Gets the download url and SHA256 checksum for the latest stable release of Chef Workstation.
10
+ # EXAMPLE
11
+ # curl -L '<%= base_url || "https://chefdownload-commercial.chef.io" %>/install.sh<%= base_url && base_url.include?("chefdownload") ? "?license_id=$CHEF_LICENSE_KEY" : "" %>' | sudo bash -s -- -P chef-workstation -c stable
12
+ #
6
13
  # Inputs:
14
+ # $base_api_url:
7
15
  # $channel:
8
16
  # $project:
9
17
  # $version:
@@ -17,38 +25,100 @@
17
25
  # $sha256:
18
26
  ############
19
27
 
20
- if test "x$download_url_override" = "x"; then
28
+ # Determine package manager based on platform for commercial API
29
+ determine_package_manager() {
30
+ case "$platform" in
31
+ el|centos|rhel|fedora|amazon|rocky|opensuse*|sles|scientific)
32
+ echo "rpm"
33
+ ;;
34
+ debian|ubuntu|linuxmint|raspbian)
35
+ echo "deb"
36
+ ;;
37
+ mac_os_x|macos|solaris*|smartos|freebsd|aix|omnios)
38
+ echo "tar"
39
+ ;;
40
+ *)
41
+ echo "tar"
42
+ ;;
43
+ esac
44
+ }
45
+
46
+ # Normalize platform name for commercial API
47
+ normalize_platform_name() {
48
+ case "$platform" in
49
+ el|centos|rhel|fedora|rocky|scientific)
50
+ echo "linux"
51
+ ;;
52
+ mac_os_x|macos)
53
+ echo "macos"
54
+ ;;
55
+ debian|ubuntu|linuxmint|raspbian)
56
+ echo "linux"
57
+ ;;
58
+ freebsd|aix|solaris*|smartos|omnios)
59
+ echo "unix"
60
+ ;;
61
+ *)
62
+ # For anything else, use linux as default
63
+ echo "linux"
64
+ ;;
65
+ esac
66
+ }
67
+
68
+ if [ -z "$download_url_override" ]; then
21
69
  echo "Getting information for $project $channel $version for $platform..."
22
70
 
23
71
  metadata_filename="$tmp_dir/metadata.txt"
72
+ <% if base_url && !base_url.to_s.empty? %>
73
+ # Set base_api_url from option if not already set via CLI parameter
74
+ if [ -z "$base_api_url" ]; then
75
+ base_api_url="<%= base_url %>"
76
+ fi
77
+ <% end %>
24
78
 
25
79
  # Use commercial API if license_id is provided, otherwise use omnitruck
26
- if test "x$license_id" != "x"; then
27
- # Check if license_id starts with 'free-' or 'trial-' for trial API
28
- case "$license_id" in
29
- free-*|trial-*)
30
- # Trial API endpoint
31
- base_api_url="https://chefdownload-trial.chef.io"
32
- ;;
33
- *)
34
- # Commercial API endpoint
35
- base_api_url="https://chefdownload-commercial.chef.io"
36
- ;;
37
- esac
38
- metadata_url="$base_api_url/$channel/$project/metadata?v=$version&p=$platform&pv=$platform_version&m=$machine&license_id=$license_id"
80
+ if [ -z "$base_api_url" ]; then
81
+ if [ -n "$license_id" ]; then
82
+ # Check if license_id starts with 'free-' or 'trial-' for trial API
83
+ case "$license_id" in
84
+ free-*|trial-*)
85
+ # Trial API endpoint
86
+ base_api_url="<%= Mixlib::Install::Dist::TRIAL_API_ENDPOINT %>"
87
+ ;;
88
+ *)
89
+ # Commercial API endpoint
90
+ base_api_url="<%= Mixlib::Install::Dist::COMMERCIAL_API_ENDPOINT %>"
91
+ ;;
92
+ esac
93
+ else
94
+ # Omnitruck endpoint
95
+ base_api_url="<%= Mixlib::Install::Dist::OMNITRUCK_ENDPOINT %>"
96
+ fi
97
+ fi
98
+
99
+ # For chef-ice product, add platform (p), machine (m), and package_manager (pm) parameters
100
+ if [ -n "$license_id" ]; then
101
+ if [ "$project" = "chef-ice" ]; then
102
+ package_manager=$(determine_package_manager)
103
+ platform_param=$(normalize_platform_name)
104
+ metadata_url="$base_api_url/$channel/$project/metadata?license_id=$license_id&v=$version&m=$machine&p=$platform_param&pm=$package_manager"
105
+ else
106
+ # For other products, use standard parameters
107
+ metadata_url="$base_api_url/$channel/$project/metadata?license_id=$license_id&v=$version&p=$platform&pv=$platform_version&m=$machine"
108
+ fi
39
109
  else
40
- # Omnitruck endpoint
41
- metadata_url="<%= base_url %>/$channel/$project/metadata?v=$version&p=$platform&pv=$platform_version&m=$machine"
110
+ # Omnitruck URL parameters without license_id
111
+ metadata_url="$base_api_url/$channel/$project/metadata?v=$version&p=$platform&pv=$platform_version&m=$machine"
42
112
  fi
43
113
 
44
- do_download "$metadata_url" "$metadata_filename"
114
+ do_download "$metadata_url" "$metadata_filename"
45
115
 
46
116
  cat "$metadata_filename"
47
117
 
48
118
  echo ""
49
119
 
50
120
  # Commercial and trial APIs return JSON, omnitruck returns text format
51
- if test "x$license_id" != "x"; then
121
+ if [ -n "$license_id" ]; then
52
122
  # Parse JSON response from commercial/trial API
53
123
  # Check if response looks like JSON
54
124
  if grep -q '^{' "$metadata_filename" 2>/dev/null; then
@@ -57,7 +127,7 @@ if test "x$download_url_override" = "x"; then
57
127
  download_url=`sed -n 's/.*"url":"\([^"]*\)".*/\1/p' "$metadata_filename"`
58
128
  sha256=`sed -n 's/.*"sha256":"\([^"]*\)".*/\1/p' "$metadata_filename"`
59
129
 
60
- if test "x$download_url" != "x" && test "x$sha256" != "x"; then
130
+ if [ -n "$download_url" ] && [ -n "$sha256" ]; then
61
131
  echo "downloaded metadata file looks valid..."
62
132
  else
63
133
  echo "downloaded metadata file is corrupted or an uncaught error was encountered in downloading the file..."
@@ -17,16 +17,36 @@
17
17
 
18
18
  # For licensed APIs (commercial/trial), the URL is an endpoint, not a direct file URL
19
19
  # The actual filename will come from the Content-Disposition header
20
- if test "x$license_id" != "x"; then
21
- # Use content-disposition to get the filename
20
+ # Also check if download_url_override is used with a URL that doesn't have a filename
21
+ # (e.g., ends with /download or /download?params instead of /package-1.2.3.rpm)
22
+
23
+ # Function to check if URL path contains a valid package filename
24
+ has_package_filename() {
25
+ url_path=`echo "$1" | sed -e 's/?.*//' -e 's/^.*\///'`
26
+ # Check if the path segment has a package extension
27
+ case "$url_path" in
28
+ *.rpm|*.deb|*.pkg|*.msi|*.dmg|*.bff|*.p5p|*.solaris|*.sh)
29
+ return 0 # has valid filename
30
+ ;;
31
+ *)
32
+ return 1 # no valid filename
33
+ ;;
34
+ esac
35
+ }
36
+
37
+ # Determine if we need to use content-disposition based on license_id or URL structure
38
+ if [ -n "$license_id" ] || ! has_package_filename "$download_url"; then
39
+ # Use content-disposition to get the filename if:
40
+ # 1. license_id is set (commercial/trial API)
41
+ # 2. URL doesn't contain a package filename (e.g., ends with /download or /download?params)
22
42
  use_content_disposition="true"
23
43
  # We don't know the filename yet - it will come from Content-Disposition
24
44
  # Just set the download directory
25
- if test "x$cmdline_filename" != "x"; then
45
+ if [ -n "$cmdline_filename" ]; then
26
46
  download_filename="$cmdline_filename"
27
47
  download_dir=`dirname $download_filename`
28
48
  use_content_disposition="false" # User specified exact filename
29
- elif test "x$cmdline_dl_dir" != "x"; then
49
+ elif [ -n "$cmdline_dl_dir" ]; then
30
50
  download_dir="$cmdline_dl_dir"
31
51
  download_filename="" # Will be determined after download
32
52
  else
@@ -41,9 +61,9 @@ else
41
61
  filetype=`echo $filename | sed -e 's/^.*\.//'`
42
62
 
43
63
  # use either $tmp_dir, the provided directory (-d) or the provided filename (-f)
44
- if test "x$cmdline_filename" != "x"; then
64
+ if [ -n "$cmdline_filename" ]; then
45
65
  download_filename="$cmdline_filename"
46
- elif test "x$cmdline_dl_dir" != "x"; then
66
+ elif [ -n "$cmdline_dl_dir" ]; then
47
67
  download_filename="$cmdline_dl_dir/$filename"
48
68
  else
49
69
  download_filename="$tmp_dir/$filename"
@@ -64,19 +84,19 @@ cached_file_available="false"
64
84
  verify_checksum="true"
65
85
 
66
86
  # Skip caching checks when using content-disposition since we don't know the real filename yet
67
- if test "x$use_content_disposition" = "xtrue"; then
87
+ if [ "$use_content_disposition" = "true" ]; then
68
88
  cached_file_available="false"
69
89
  verify_checksum="true"
70
- elif test "x$download_filename" != "x" && test -f "$download_filename"; then
90
+ elif [ -n "$download_filename" ] && [ -f "$download_filename" ]; then
71
91
  echo "$download_filename exists"
72
92
  cached_file_available="true"
73
93
  fi
74
94
 
75
- if test "x$download_url_override" != "x" && test "x$use_content_disposition" = "xfalse"; then
95
+ if [ -n "$download_url_override" ] && [ "$use_content_disposition" = "false" ]; then
76
96
  echo "Download URL override specified"
77
- if test "x$cached_file_available" = "xtrue"; then
97
+ if [ "$cached_file_available" = "true" ]; then
78
98
  echo "Verifying local file"
79
- if test "x$sha256" = "x"; then
99
+ if [ -z "$sha256" ]; then
80
100
  echo "Checksum not specified, ignoring existing file"
81
101
  cached_file_available="false" # download new file
82
102
  verify_checksum="false" # no checksum to compare after download
@@ -92,7 +112,7 @@ if test "x$download_url_override" != "x" && test "x$use_content_disposition" = "
92
112
  else
93
113
  echo "$download_filename not found"
94
114
  cached_file_available="false" # download new file
95
- if test "x$sha256" = "x"; then
115
+ if [ -z "$sha256" ]; then
96
116
  verify_checksum="false" # no checksum to compare after download
97
117
  else
98
118
  verify_checksum="true" # checksum new downloaded file
@@ -100,8 +120,8 @@ if test "x$download_url_override" != "x" && test "x$use_content_disposition" = "
100
120
  fi
101
121
  fi
102
122
 
103
- if test "x$cached_file_available" != "xtrue"; then
104
- if test "x$use_content_disposition" = "xtrue"; then
123
+ if [ "$cached_file_available" != "true" ]; then
124
+ if [ "$use_content_disposition" = "true" ]; then
105
125
  # For licensed APIs, download to a temporary file and extract filename from response headers
106
126
  # The download_dir was already set during initialization above
107
127
 
@@ -112,33 +132,33 @@ if test "x$cached_file_available" != "xtrue"; then
112
132
  do_download "$download_url" "$temp_download"
113
133
 
114
134
  # Extract filename from response headers (try multiple methods for compatibility)
115
- if test -f "$tmp_dir/stderr"; then
135
+ if [ -f "$tmp_dir/stderr" ]; then
116
136
  # Method 1: Try to extract filename from content-disposition header
117
137
  # Format: content-disposition: attachment; filename="chef-18.8.54-1.el9.x86_64.rpm"
118
138
  actual_filename=`grep -i 'content-disposition' $tmp_dir/stderr | sed -n 's/.*filename="\([^"]*\)".*/\1/p' | head -1`
119
139
 
120
140
  # Method 2: If content-disposition failed, try to extract from location redirect header
121
141
  # Format: location: https://packages.chef.io/files/stable/chef/18.8.54/el/9/chef-18.8.54-1.el9.x86_64.rpm?licenseId=...
122
- if test "x$actual_filename" = "x"; then
142
+ if [ -z "$actual_filename" ]; then
123
143
  actual_filename=`grep -i '^location:' $tmp_dir/stderr | head -1 | sed 's/.*\///' | sed 's/?.*//'`
124
144
  fi
125
145
 
126
146
  # Method 3: Try extracting from any URL-like pattern in stderr
127
- if test "x$actual_filename" = "x"; then
147
+ if [ -z "$actual_filename" ]; then
128
148
  actual_filename=`grep -i '\.rpm\|\.deb\|\.pkg\|\.msi\|\.dmg' $tmp_dir/stderr | sed -n 's/.*\/\([^/?]*\.\(rpm\|deb\|pkg\|msi\|dmg\)\).*/\1/p' | head -1`
129
149
  fi
130
150
  fi
131
151
 
132
152
  # If we still couldn't extract from headers, construct filename from metadata
133
- if test "x$actual_filename" = "x"; then
153
+ if [ -z "$actual_filename" ]; then
134
154
  echo "Warning: Could not extract filename from response headers, using fallback"
135
155
  # Construct a reasonable filename from available metadata
136
156
  # This is a fallback and may not match the exact package name
137
- if test "x$platform" = "xel" || test "x$platform" = "xfedora" || test "x$platform" = "xamazon"; then
157
+ if [ "$platform" = "el" ] || [ "$platform" = "fedora" ] || [ "$platform" = "amazon" ]; then
138
158
  actual_filename="chef-${version}-1.${platform}${platform_version}.${machine}.rpm"
139
- elif test "x$platform" = "xdebian" || test "x$platform" = "xubuntu"; then
159
+ elif [ "$platform" = "debian" ] || [ "$platform" = "ubuntu" ]; then
140
160
  actual_filename="chef_${version}-1_${machine}.deb"
141
- elif test "x$platform" = "xmac_os_x"; then
161
+ elif [ "$platform" = "mac_os_x" ]; then
142
162
  actual_filename="chef-${version}.dmg"
143
163
  else
144
164
  actual_filename="chef-${version}.pkg"
@@ -160,8 +180,12 @@ if test "x$cached_file_available" != "xtrue"; then
160
180
  fi
161
181
  fi
162
182
 
163
- if test "x$verify_checksum" = "xtrue"; then
164
- do_checksum "$download_filename" "$sha256" || checksum_mismatch
183
+ if [ "$verify_checksum" = "true" ]; then
184
+ if [ -z "$sha256" ]; then
185
+ echo "Skipping checksum verification - no checksum provided"
186
+ else
187
+ do_checksum "$download_filename" "$sha256" || checksum_mismatch
188
+ fi
165
189
  fi
166
190
 
167
191
  ############