#!/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 the specified role") { |v| OPTIONS[:only_role] = v } opts.on("-t", "--test", "Process but don't perform any actions") { |v| OPTIONS[:testing] = v } opts.on("-v", "--verbose", "Verbose output") { |v| OPTIONS[:verbose] = v } opts.on("-c", "--cloud", "Show powder cloud, ie. package hierarchy and installation order") { |v| OPTIONS[:cloud] = v } opts.on("-f", "--force", "Force installation of all packages even if it is detected that it has been previously installed") { |v| OPTIONS[:force] = 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] 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) severity = ActiveSupport::BufferedLogger::Severity Object.logger.level = options[:verbose] ? severity::DEBUG : 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