Sha256: a1b064b3a2dd4e859d3aadd6bb1e1b0ee6db44acf681ae1f775fe4ca34ee010b

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

#!/usr/bin/env ruby

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'cli_helper'
require 'pathname'

CONFIG = File.join(File.dirname(__FILE__), '..', 'config/config.json')
DATASETS = File.join(File.dirname(__FILE__), '..', 'config/fixtures/datasets.json')
PACKAGES = File.join(File.dirname(__FILE__), '..', 'config/fixtures/packages.json')
config = {}

config[:url] = ARGV[0] if ARGV[0]
unless config[:url]
  puts 'url is empty.'
  exit 1
end

print 'version:[~6.5] '
config[:version] = STDIN.gets.chomp.to_s
if config[:version].size == 0
  config[:version] = '~6.5'
end

print 'Username (login): '
config[:username] = STDIN.gets.chomp.to_s
if config[:username].size == 0
  puts 'Username is empty.'
  exit 1
end

print 'Password: '
config[:password] = STDIN.gets.chomp.to_s
if config[:password].size == 0
  puts 'Password is empty.'
  exit 1
end

config[:format] = 'json'

Pathname.new(File.dirname(CONFIG)).mkpath unless File.exist?(File.dirname(CONFIG))
File.open(CONFIG, 'w') do |file|
  file.write MultiJson.encode(config)
end

begin
  client.format = 'mash'
  datacenters = client.datacenters.find
  if client.datacenters.find.first[1] == config[:url]
    puts 'Successful configuration.'

    client.format = 'json'
    Pathname.new(File.dirname(DATASETS)).mkpath unless File.exist?(File.dirname(DATASETS))
    File.open(DATASETS, 'w') do |file|
      file.write client.datasets.find
    end

    Pathname.new(File.dirname(PACKAGES)).mkpath unless File.exist?(File.dirname(PACKAGES))
    File.open(PACKAGES, 'w') do |file|
      file.write client.packages.find
    end
  else
    puts 'Failed Configuration.'
  end
rescue => e
  puts e.inspect
  puts 'Failed Setup.'
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
smartdc-0.4.0 bin/sdc-setup