cleanfb 0.2.3 → 0.2.4

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cleanfb/version.rb +1 -1
  3. data/lib/cleanfb.rb +51 -78
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec907caef2443978ba0882ead174458517237fcc
4
- data.tar.gz: 29ccd78095c8009ec7b4d82edf4c05d388a95399
3
+ metadata.gz: 55951c522be14dc9d71fc1da2d68d8e14f425292
4
+ data.tar.gz: eaf665346feb36f002f5d86e01cd55e74b0350b1
5
5
  SHA512:
6
- metadata.gz: cf2d771e100d8dce08740da5d6702a33d3dc07bdae9e4409659b9fee226c94d44465c76e88983d63da258e0cbdc8dac56d288a82f749a3bf059c3bbb9d34b4cf
7
- data.tar.gz: 02211cfdffc069a753590cc53ce6b4a7376612010767675bd386fc21c50ddd71d2364b579958f0c70145d0ac7063025139bd4a41503c8a36a838ad1e50546623
6
+ metadata.gz: 7b5d5f71254d371151fdc15ace8cbf7deb87eff7bd065a9c2d7ed1c3951359f7fa4b50b17976d925d6dfb79730d3caa6c9568719ad5c13d0782e6cef79f0f57e
7
+ data.tar.gz: 382cfc26318ef552b7138ac52cbdd26d027b2f3028d4fe6c90178922ce0db51257a4f382776df3c536a0399abb1fe7a3d6e9e1b665a11382f6851c8f15d2145e
@@ -1,3 +1,3 @@
1
1
  module Cleanfb
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
data/lib/cleanfb.rb CHANGED
@@ -8,18 +8,25 @@ module Cleanfb
8
8
 
9
9
  @force = false
10
10
  @hostname = ""
11
+ @restore = ""
11
12
 
12
13
  def parse_input
13
14
  OptionParser.new do |opts|
14
- opts.banner = ""
15
- opts.on("-f", "--force", "Ignore all prompts") { |f| @force = f }
16
- opts.on("-nNAME", "--name=NAME", "Hostname") { |n| @hostname = n }
17
- opts.on_tail("-h", "--help", "Display help information") { puts opts; exit }
15
+ opts.banner = "Usage: cleanfb [options]..."
16
+ opts.on("-f", "--force", "ignore all prompts") { |f| @force = f }
17
+ opts.on("-nNAME", "--name=NAME", "hostname to clean") { |n| @hostname = n }
18
+ opts.on("-rRESTORE", "--restore=FILE", "file to restore") { |r| @restore = r }
19
+ opts.on_tail("-h", "--help", "display this message") { puts opts; exit }
18
20
  end.parse!
19
21
  end
20
22
 
21
23
  def remove
22
-
24
+
25
+ if hostname == ""
26
+ puts "Hostname required. See cleanfb --help for usage."
27
+ return
28
+ end
29
+
23
30
  unless @force
24
31
  print "Remove #{@hostname}? (y|n): "
25
32
  ans = STDIN.gets.chomp
@@ -35,42 +42,14 @@ module Cleanfb
35
42
  cmd.each_line { |line| (multi_match = true) if (!line.include? test) }
36
43
 
37
44
  if multi_match
38
- print "Matched multiple hosts. Remove all? y|n: "
45
+ print "Matched multiple hosts. Remove all? (y|n): "
39
46
  ans = STDIN.gets.chomp
40
47
 
41
48
  return "Ending run" unless (@force || ans =~/^y/)
42
49
  end
43
50
  end
44
51
 
45
- unless(cmd.nil? || cmd.empty?)
46
- cmd.each_line do |line|
47
- path = "/opt/puppetlabs/puppet/cache/bucket"
48
- sum = line.split(" ")[0]
49
-
50
- start = (sum.scan /\w/).join("/")
51
-
52
- file = line.split(" ")[3].split("/").last
53
- name = file.split("_")[0]
54
- date = line.split(" ")[1]
55
- time = line.split(" ")[2]
56
-
57
- save_dir = "/root/saved_configs/"
58
-
59
- Dir.mkdir(File.join(Dir.home("root"), "saved_configs"), 0700) unless (Dir.exist? save_dir)
60
- Dir.mkdir(File.join("#{save_dir}", "#{name}"), 0700) unless (Dir.exist? "#{save_dir}/#{name}/")
61
-
62
- path += "/" + start[0..15] + sum + "/"
63
-
64
- if File.exist? "#{path}/contents"
65
- puts "Storing " + path
66
- puts "at /root/saved_configs/#{name}/#{date}_#{time}_#{file}"
67
- cmd = `mv -f #{path}contents /root/saved_configs/#{name}/#{date}_#{time}_#{file}`
68
- cmd = `rm -rf #{path}`
69
- else
70
- puts "No file #{@hostname} found."
71
- end
72
- end
73
- end
52
+ (backup cmd) unless (cmd.nil? || cmd.empty?)
74
53
 
75
54
  else
76
55
  puts "No file #{@hostname} found."
@@ -78,58 +57,52 @@ module Cleanfb
78
57
 
79
58
  return
80
59
  end
81
-
82
- def store host
83
-
84
- cmd = `puppet filebucket list -l|grep -i #{host}`
85
- unless(cmd.nil? || cmd.empty?)
86
- cmd.each_line do |line|
87
- path = "/opt/puppetlabs/puppet/cache/bucket"
88
- sum = line.split(" ")[0]
89
- start = (sum.scan /\w/).join("/")
90
-
91
- name = file.split("_")[0]
92
- date = line.split(" ")[1]
93
- time = line.split(" ")[2]
94
- file = line.split(" ")[3].split("/").last
95
-
96
- save_dir = "/root/saved_configs/"
97
-
98
- Dir.mkdir(File.join(Dir.home("root"), "saved_configs"), 0700) unless (Dir.exist? save_dir)
99
- Dir.mkdir(File.join("#{save_dir}", "#{name}"), 0700) unless (Dir.exist? "#{save_dir}/#{name}/")
60
+
61
+ def backup cmd
62
+
63
+ cmd.each_line do |line|
64
+ path = "/opt/puppetlabs/puppet/cache/bucket"
65
+ sum = line.split(" ")[0]
66
+
67
+ start = (sum.scan /\w/).join("/")
68
+
69
+ file = line.split(" ")[3].split("/").last
70
+ name = file.split("_")[0]
71
+ date = line.split(" ")[1]
72
+ time = line.split(" ")[2]
73
+
74
+ save_dir = "/root/saved_configs/"
75
+
76
+ Dir.mkdir(File.join(Dir.home("root"), "saved_configs"), 0700) unless (Dir.exist? save_dir)
77
+ Dir.mkdir(File.join("#{save_dir}", "#{name}"), 0700) unless (Dir.exist? "#{save_dir}/#{name}/")
78
+
79
+ path += "/" + start[0..15] + sum + "/"
100
80
 
101
- path += "/" + start[0..15] + sum + "/"
102
-
103
- if File.exist? "#{path}/contents"
104
- puts "Storing " + path
105
- puts "at /root/saved_configs/#{name}/#{date}_#{time}_#{file}"
106
- cmd = `mv -f #{path}contents /root/saved_configs/#{name}/#{date}_#{time}_#{file}`
107
- cmd = `rm -rf #{path}`
108
- else
109
- puts "No file #{host} found."
110
- end
81
+ if File.exist? "#{path}/contents"
82
+ puts "Storing " + path
83
+ puts "at /root/saved_configs/#{name}/#{date}_#{time}_#{file}"
84
+ cmd = `mv -f #{path}contents /root/saved_configs/#{name}/#{date}_#{time}_#{file}`
85
+ cmd = `rm -rf #{path}`
86
+ else
87
+ puts "No file #{@hostname} found."
111
88
  end
112
- else
113
- puts "No file #{host} found."
114
89
  end
115
-
116
- return
117
90
  end
118
91
 
119
92
  def restore
120
93
 
121
- #host = arg.scan(/_\w+\.\w+\.?\w+?_/).join("").gsub!("_", "")
122
- #store(host)
123
- #file = arg
94
+ host = @restore.scan(/_\w+\.\w+\.?\w+?_/).join("").gsub!("_", "")
95
+ backup host
96
+ file = host
124
97
 
125
- #if File.exist? file
126
- # puts "puppet filebucket -l backup #{file}"
127
- # cmd = `puppet filebucket -l backup #{file}`
128
- #else
129
- # puts "No file #{arg} found."
130
- #end
98
+ if File.exist? file
99
+ puts "puppet filebucket -l backup #{file}"
100
+ cmd = `puppet filebucket -l backup #{file}`
101
+ else
102
+ puts "No file #{@restore} found."
103
+ end
131
104
 
132
- #return
105
+ return
133
106
  end
134
107
 
135
108
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cleanfb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - lhoffl