rbfs 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rbfs'
3
+ require 'rbfs/command'
4
+
5
+ config = Rbfs::Command.config
6
+ hosts = Rbfs::Hosts.new(config[:hosts])
7
+ hosts.each do |host|
8
+ puts "#{host} (#{host.ip})" if config[:verbose]
9
+ host.sync(config)
10
+ end
@@ -1,4 +1,5 @@
1
1
  require "rbfs/version"
2
+ require "rbfs/hosts"
2
3
 
3
4
  module Rbfs
4
5
  # Your code goes here...
@@ -0,0 +1,30 @@
1
+ require 'optparse'
2
+
3
+ module Rbfs
4
+ class Args
5
+ def parse
6
+ options = {}
7
+
8
+ OptionParser.new do |opts|
9
+ opts.banner = "Usage: rbfs [options]"
10
+ opts.on("-c", "--config FILE", "Configuration file") do |v|
11
+ options[:config] = v
12
+ end
13
+ opts.on("-h", "--hosts FILE", "Hosts file") do |v|
14
+ options[:hosts] = v
15
+ end
16
+ opts.on("-r", "--root ROOT", "Root path to sync") do |v|
17
+ options[:root] = v
18
+ end
19
+ opts.on("-v", "--[no-]verbose", "Print extra debugging info") do |v|
20
+ options[:verbose] = v
21
+ end
22
+ opts.on("-d", "--dry", "Test config settings") do |v|
23
+ options[:dry] = v
24
+ end
25
+ end.parse!
26
+
27
+ options
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,12 @@
1
+ require 'rbfs/args'
2
+ require 'rbfs/config'
3
+
4
+ module Rbfs
5
+ class Command
6
+ def self.config
7
+ args = Rbfs::Args.new.parse
8
+ options = Rbfs::Config.new(args[:config]).parse
9
+ options.merge(args)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ require 'yaml'
2
+
3
+ module Rbfs
4
+ class Config
5
+ def initialize(file_name = "/etc/rbfs.yml")
6
+ @file_name = file_name
7
+ end
8
+
9
+ def parse
10
+ YAML.load(File.read(@file_name))
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ require 'rbfs/rsync'
2
+
3
+ module Rbfs
4
+ class Host
5
+ include Rsync
6
+
7
+ def initialize(raw)
8
+ @raw = raw
9
+ end
10
+
11
+ def ip
12
+ @raw.split.first
13
+ end
14
+
15
+ def to_s
16
+ name
17
+ end
18
+
19
+ def name
20
+ @raw.split[1]
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ require "rbfs/host"
2
+
3
+ module Rbfs
4
+ class Hosts
5
+ def initialize(file_name)
6
+ @file_name = file_name
7
+ end
8
+
9
+ def each(&block)
10
+ lines = File.read(@file_name).split("\n")
11
+ lines.reject! {|line| line.strip.start_with? "#"}
12
+ lines.each do |line|
13
+ yield(Host.new(line))
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ module Rbfs
2
+ module Rsync
3
+ def sync(config)
4
+ command = "rsync -ave ssh --delete #{config[:root]} #{ip}:#{config[:root]}"
5
+ command += " -n" if config[:dry]
6
+ result = `#{command}`
7
+ puts result if config[:verbose]
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module Rbfs
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbfs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-17 00:00:00.000000000Z
12
+ date: 2013-07-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &17341520 !ruby/object:Gem::Requirement
16
+ requirement: &17891980 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.3'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *17341520
24
+ version_requirements: *17891980
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &17340520 !ruby/object:Gem::Requirement
27
+ requirement: &17891020 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,11 +32,12 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *17340520
35
+ version_requirements: *17891020
36
36
  description: Ruby File Sync
37
37
  email:
38
38
  - jbussdieker@gmail.com
39
- executables: []
39
+ executables:
40
+ - rbfs
40
41
  extensions: []
41
42
  extra_rdoc_files: []
42
43
  files:
@@ -44,7 +45,14 @@ files:
44
45
  - Gemfile
45
46
  - README.md
46
47
  - Rakefile
48
+ - bin/rbfs
47
49
  - lib/rbfs.rb
50
+ - lib/rbfs/args.rb
51
+ - lib/rbfs/command.rb
52
+ - lib/rbfs/config.rb
53
+ - lib/rbfs/host.rb
54
+ - lib/rbfs/hosts.rb
55
+ - lib/rbfs/rsync.rb
48
56
  - lib/rbfs/version.rb
49
57
  - rbfs.gemspec
50
58
  homepage: ''