#!/usr/bin/env ruby # # Created on 2008-3-11. # Copyright (c) 2008. All rights reserved. begin require 'rubygems' rescue LoadError # no rubygems to load, so we fail silently end require 'optparse' # NOTE: the option -p/--path= is given as an example, and should probably be replaced in your application. OPTIONS = {} MANDATORY_OPTIONS = %w( path ) ARGV.each do |arg| ENV[$1] = $2 if arg =~ /^(\w+)=(.*)$/ end require File.dirname(__FILE__) + '/../lib/sprinkle/version' parser = OptionParser.new do |opts| opts.version = Sprinkle::Version opts.banner = < #{File.basename($0)} [options] Options are: BANNER opts.separator "" opts.on("-s", "--script=PATH", String, "path to a sprinkle script to run") { |v| OPTIONS[:path] = v } opts.on("--only [ROLE]", String, "only run sprinkle policies for given role") { |v| OPTIONS[:only_role] = v } opts.on("-t", "--test", "process but don't perform any actions","(this does not connect to any servers)") { |v| OPTIONS[:testing] = v } opts.on("-c", "--cloud", "show powder cloud, package hierarchy","and installation order") { |v| OPTIONS[:cloud] = v } opts.on("-f", "--force", "force installation of all packages","by skipping pre-verify checks.") { |v| OPTIONS[:force] = v } opts.on("-v", "--verbose", "verbose output") { |v| OPTIONS[:verbose] = v } opts.on("-h", "--help", "show this help message") { puts opts; exit } opts.parse!(ARGV) if MANDATORY_OPTIONS && MANDATORY_OPTIONS.find { |option| OPTIONS[option.to_sym].nil? } puts opts; exit end end def only_role(options) role=OPTIONS[:only_role] return if role.blank? Sprinkle::OPTIONS[:only_role] = role puts "Only running policies for :#{role}" end def force_mode(options) Sprinkle::OPTIONS[:force] = OPTIONS[:force] || false end def operation_mode(options) Sprinkle::OPTIONS[:testing] = OPTIONS[:testing] || false end def powder_cloud(options) Sprinkle::OPTIONS[:cloud] = OPTIONS[:cloud] || false end def verbosity(options) Sprinkle::OPTIONS[:verbose] = OPTIONS[:verbose] || false end def log_level(options) Object.logger.level = OPTIONS[:verbose] ? Logger::Severity::DEBUG : Logger::Severity::INFO end require File.dirname(__FILE__) + '/../lib/sprinkle' powder = OPTIONS[:path] raise "Sprinkle script is not readable: #{powder}" unless File.readable?(powder) force_mode(OPTIONS) operation_mode(OPTIONS) powder_cloud(OPTIONS) log_level(OPTIONS) verbosity(OPTIONS) only_role(OPTIONS) Sprinkle::Script.sprinkle File.read(powder), powder