Skip to content

Instantly share code, notes, and snippets.

@tduffield
Last active September 22, 2016 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tduffield/bd96305fec75a9ea8a39a174a200285f to your computer and use it in GitHub Desktop.
Save tduffield/bd96305fec75a9ea8a39a174a200285f to your computer and use it in GitHub Desktop.
ChefDK Download Script - Download Chef Software Packages
#!/usr/bin/env ruby
require 'mixlib/install'
require 'mixlib/cli'
require 'mixlib/shellout'
class Download
include Mixlib::CLI
option :target,
short: '-t TARGET',
long: '--target TARGET',
description: 'Where to download the file',
required: true
option :product,
short: '-p PRODUCT',
long: '--product PRODUCT',
description: 'The product to download',
required: true
option :channel,
short: '-c CHANNEL',
long: '--channel CHANNEL',
description: 'The channel from which to download the specified product',
default: 'stable'
option :version,
short: '-v VERSION',
long: '--version VERSION',
description: 'The version of the product to download',
default: :latest
option :platform,
short: '-P PLATFORM',
long: '--platform PLATFORM',
description: 'The platform which the product will be installed',
default: 'ubuntu'
option :platform_version,
short: '-V PLATFORM_VERSION',
long: '--platform-version PLATFORM_VERSION',
description: 'The version of the platform on which the product will be installed',
default: '14.04'
option :architecture,
short: '-a ARCHITECTURE',
long: '--arch ARCHITECTURE',
description: 'The architecture of the platform',
default: 'x86_64'
end
cli = Download.new
cli.parse_options
options = {
channel: cli.config[:channel].to_sym,
product_name: cli.config[:product],
product_version: cli.config[:version],
platform: cli.config[:platform],
platform_version: cli.config[:platform_version],
architecture: cli.config[:architecture]
}
artifact = Mixlib::Install.new(options).artifact_info
command = "wget --content-disposition #{artifact.url} -O #{cli.config[:target]}"
cmd = Mixlib::ShellOut.new(command)
cmd.live_stream ||= $stdout.tty? ? $stdout : nil
cmd.run_command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment