Last active
September 22, 2016 15:47
-
-
Save tduffield/bd96305fec75a9ea8a39a174a200285f to your computer and use it in GitHub Desktop.
ChefDK Download Script - Download Chef Software Packages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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