Sha256: 917a1486d89cd5d30c4b3a4c0f912bccd242d03a21a3b7304409a5b74f96137c

Contents?: true

Size: 1.96 KB

Versions: 8

Compression:

Stored size: 1.96 KB

Contents

require 'user_config'
require 'drbqs/config/ssh_host'
require 'drbqs/config/process_list'

module DRbQS

  ACL_DEFAULT_PATH = 'acl.txt'
  ACL_SAMPLE_PATH = 'acl.txt.sample'
  HOST_FILE_DIRECTORY = 'host'
  HOST_FILE_SAMPLE_PATH = 'host.yaml.sample'
  SHELL_FILE_DIRECTORY = 'shell'
  SHELL_BASHRC = 'bashrc'

  class Config
    class Directory < UserConfig
    end

    DRBQS_CONFIG_DIRECTORY = '.drbqs'

    @@home_directory = nil

    def self.set_home_directory(path)
      @@home_directory = File.expand_path(path)
    end

    def self.get_home_directory
      @@home_directory || ENV['HOME']
    end

    ACL_SAMPLE =<<SAMPLE
deny all
allow localhost
allow 127.0.0.1
SAMPLE

    HOST_YAML_SAMPLE =<<SAMPLE
--- 
:dest: user@example.com
:dir:
:shell: bash --noprofile --init-file ~/.drbqs/shell/bashrc
:rvm:
:rvm_init: ~/.rvm/scripts/rvm
:output: 
SAMPLE

    BASHRC_SAMPLE = <<SAMPLE
HISTFILE=$HOME/.drbqs/shell/bash_history
HISTSIZE=10000
HISTFILESIZE=20000
SAMPLE

    attr_reader :directory, :list, :ssh_host

    def initialize
      home = self.class.get_home_directory
      @directory = DRbQS::Config::Directory.new(DRBQS_CONFIG_DIRECTORY, :home => home)
      @list = DRbQS::ProcessList.new(File.join(home, DRBQS_CONFIG_DIRECTORY))
      @ssh_host = DRbQS::Config::SSHHost.new(@directory.file_path(HOST_FILE_DIRECTORY))
    end

    def directory_path
      @directory.directory
    end

    def save_sample
      @directory.open(ACL_SAMPLE_PATH, 'w') do |f|
        f.print ACL_SAMPLE
      end
      @directory.open(File.join(HOST_FILE_DIRECTORY, HOST_FILE_SAMPLE_PATH), 'w') do |f|
        f.print HOST_YAML_SAMPLE
      end
      @directory.open(File.join(SHELL_FILE_DIRECTORY, SHELL_BASHRC), 'w') do |f|
        f.print BASHRC_SAMPLE
      end
    end

    # Return path of ACL file if '.drbqs/acl.txt' exists.
    def get_acl_file
      @directory.exist?(ACL_DEFAULT_PATH)
    end

    def get_shell_file_directory
      @directory.file_path(SHELL_FILE_DIRECTORY)
    end

  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
drbqs-0.1.1 lib/drbqs/config/config.rb
drbqs-0.1.0 lib/drbqs/config/config.rb
drbqs-0.0.19 lib/drbqs/config/config.rb
drbqs-0.0.18 lib/drbqs/config/config.rb
drbqs-0.0.17 lib/drbqs/config/config.rb
drbqs-0.0.16 lib/drbqs/config/config.rb
drbqs-0.0.15 lib/drbqs/config/config.rb
drbqs-0.0.14 lib/drbqs/config/config.rb