lib/shutter/command_line.rb in shutter-0.0.3 vs lib/shutter/command_line.rb in shutter-0.0.4

- old
+ new

@@ -3,24 +3,25 @@ require 'shutter/os' module Shutter class CommandLine def initialize( path = "/etc/shutter.d") - # Currently only available to RedHat variants - @os = Shutter::OS.new - unless @os.redhat? - puts "Shutter is currently only compatible with RedHat and its variants." - puts "Help make it compatible with others (github.com/rlyon/shutter)" - exit + # Currently only available to RedHat variants uless testing + unless ENV['SHUTTER_MODE'] == "testing" + @os = Shutter::OS.new + unless @os.redhat? + puts "Shutter is currently only compatible with RedHat and its variants." + puts "Help make it compatible with others (github.com/rlyon/shutter)" + exit + end end @config_path = path - @iptables = Shutter::IPTables::Base.new(@config_path) - end def execute + @iptables = Shutter::IPTables::Base.new(@config_path) options = {} optparse = OptionParser.new do |opts| opts.banner = "Usage: shutter [options]" options[:command] = :save opts.on( '--init', 'Create the initial configuration files' ) do @@ -57,10 +58,11 @@ puts "* Running command: #{options[:command].to_s}" if @debug send(options[:command]) end def init + create_config_dir Shutter::CONFIG_FILES.each do |name| file = "#{@config_path}/#{name}" unless File.exists?(file) # puts "Creating: #{file}" File.open(file, 'w') do |f| @@ -69,10 +71,11 @@ end end end def reinit + create_config_dir Shutter::CONFIG_FILES.each do |name| file = "#{@config_path}/#{name}" File.open(file, 'w') do |f| f.write(Shutter.const_get(name.upcase.gsub(/\./, "_"))) end @@ -96,9 +99,21 @@ def persist pfile = ENV['SHUTTER_PERSIST_FILE'] ? ENV['SHUTTER_PERSIST_FILE'] : @iptables.persist_file(@os) File.open(pfile, "w") do |f| f.write(@ipt) + end + end + + private + def create_config_dir + # Check to see if the path to the config files exist + unless File.directory?(@config_path) + begin + Dir.mkdir(@config_path) + rescue Errno::ENOENT + raise "Could not create the configuration directory. Check to see if the parent directory exists." + end end end end end \ No newline at end of file