irgat 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.
@@ -1,3 +1,16 @@
1
+ == 0.0.2 2008-11-3
2
+
3
+ * Backup Module:
4
+ * Fixed Purge and Move old Backups method
5
+ * Implemented new methods
6
+
7
+ * Irgat Base:
8
+ * Fixed bug in log Module (!@log error)
9
+ * Fixed commands_launched resume (!@command_log)
10
+
11
+ * Intituive
12
+ * Added some colors in cmd
13
+
1
14
  == 0.0.1 2008-10-24
2
15
 
3
16
  * 1 major enhancement:
@@ -6,6 +6,7 @@ Rakefile
6
6
  TODO
7
7
  bin/irgat
8
8
  bin/irgat_setup
9
+ bin/irgat_updater
9
10
  config/hoe.rb
10
11
  config/requirements.rb
11
12
  lib/irgat.rb
@@ -26,11 +27,8 @@ script/txt2html
26
27
  setup.rb
27
28
  setup/etc/backup.yml.example
28
29
  setup/etc/chroot.yml.example
29
- setup/etc/console.yml.default
30
30
  setup/etc/cron.yml.example
31
- setup/etc/dar.yml.example
32
31
  setup/etc/irgat.yml.example
33
- setup/etc/kwallet.yml.default
34
32
  setup/etc/kwallet.yml.example
35
33
  setup/etc/ssh.yml.example
36
34
  tasks/deployment.rake
@@ -1,4 +1,13 @@
1
+ New Install:
2
+ ------------
3
+
1
4
  Run irgat_setup to setup Irgat
2
5
 
3
- For more information on Irgat, see http://irgat.rubyforge.org
6
+ For more information on Irgat read the rdoc documentation or see http://irgat.rubyforge.org
7
+
8
+ Updater: (0.0.1 => 0.0.2)
9
+ -------------------------
10
+
11
+ If you have already installed run irgat_updater. These script checks your config files and show posible difference between older and new config files.
4
12
 
13
+ The program only marks these changes. You have to do it manually.
@@ -4,23 +4,24 @@ Interactive Ruby for Gnoxys Administration Tools
4
4
 
5
5
  == DESCRIPTION:
6
6
 
7
- FIX (describe your package)
7
+ IRGAT (Intuitive Ruby for Gnoxys Administration Tools) are some tools in Ruby for system administration (backups, ssh key management, etc...)
8
+
8
9
 
9
10
  == FEATURES/PROBLEMS:
10
11
 
11
- * FIX (list of features or problems)
12
+ None
12
13
 
13
14
  == SYNOPSIS:
14
15
 
15
- FIX (code sample of usage)
16
+ None
16
17
 
17
18
  == REQUIREMENTS:
18
19
 
19
- * FIX (list of requirements)
20
+ None
20
21
 
21
22
  == INSTALL:
22
23
 
23
- * FIX (sudo gem install, anything else)
24
+ None
24
25
 
25
26
  == LICENSE:
26
27
 
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
1
  require 'config/requirements'
2
2
  require 'config/hoe' # setup Hoe + all gem configuration
3
3
 
4
- Dir['tasks/**/*.rake'].each { |rake| load rake }
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/TODO CHANGED
@@ -11,6 +11,8 @@
11
11
 
12
12
  === Backup
13
13
 
14
+ ** URGENCY: HIGHT
15
+
14
16
  - Add a prevent control to predict how much space is going to need the backup and check if exist enought. If not, exit of application. Something like
15
17
  {
16
18
  get_older_size_backup=X
@@ -19,8 +21,26 @@
19
21
  end
20
22
  }
21
23
 
22
- - Add a option to distribute backups with ftp
24
+ ** URGENCY: LOW
25
+
26
+ - Add an option to distribute backups with ftp
27
+ - Add an option to do other sql backups
28
+
29
+ = Error Exits
30
+
31
+ 2 # Load error in Module
32
+ 3 # Process error in Module
33
+ 6 # Exit by fatal command
34
+ 7 # Not enough parameters
35
+
36
+
37
+ = Loggin
23
38
 
24
- - Check mount folder
39
+ # option by cmd line: -w || --without_output
40
+ -d <debug level> || --debug_level <debug_level>
25
41
 
26
- - Include by default to exclude backup folder from backup
42
+ = Colors
43
+ green = 2
44
+ red = 9
45
+ dark red = 160
46
+ orange = 220
data/bin/irgat CHANGED
@@ -1,14 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- #= Usage
4
- #
5
- # irgat -v || --version # display version information and exit
6
- # irgat -h || --help # display help and exit
7
- # irgat < arg > # process an irgat petition
8
- # ---------------------
9
- # irgat works like a modular tool. For example, the syntaxis for a backup is:
10
- # $: irgat backup launch
11
- #
12
3
  #= Help
13
4
  #
14
5
  # Irgat is an utility to manage administration script and all the tools needed for it.
@@ -28,18 +19,10 @@
28
19
  #
29
20
  # For more info, view the API of irgat and read the documentation
30
21
  #
31
- #= License
32
- #
33
- # IRGAT (Intuitive Ruby for Gnoxys Administration Tools)
34
- # 2007 - 2008 Gnoxys. info@gnoxys.net
35
- # This program is released under the terms of the GPL v3 license as you cand find in http://www.gnu.org/licenses/gpl.html
36
- #
37
- #
38
22
 
39
23
 
40
24
  # IRGAT constants
41
25
  IRGAT_ROOT = File.dirname(__FILE__) + '/..'
42
- puts IRGAT_ROOT
43
26
  # Default paths, if you want to change, change hear
44
27
  IRGAT_CONFIG = '/etc/irgat' unless defined?(IRGAT_CONFIG)
45
28
  IRGAT_LANG = IRGAT_ROOT + '/lang' unless defined?(IRGAT_LANG)
@@ -66,22 +49,25 @@ rescue LoadError => msj
66
49
  end
67
50
 
68
51
  # check launch
69
- case $*[0]
70
- when nil
71
- # no command line params. Show usage and exit
72
- puts "\n * ERROR: missing options"
73
- RDoc::usage(1,'usage')
74
- when '--version','-v'
75
- # display version. license and exit
76
- puts "\nVERSION: " + Irgat::VERSION
77
- RDoc::usage('license')
78
- when '--help','-h'
79
- # help, and exit
80
- RDoc::usage('help')
81
- else
82
- args = $*
83
- # process irgat request
84
- Irgat.process(args)
52
+ args = $*
53
+
54
+ case args[0]
55
+ when nil
56
+ # no command line params. Show usage and exit
57
+ puts "\n * ERROR: missing options"
58
+ Irgat.help(["help","usage"])
59
+ exit 1
60
+ when '--version','-v','version'
61
+ # display version. license and exit
62
+ puts "\nVERSION\n=======\n #{ ::Irgat::Version }"
63
+ Irgat.help(["help","license"])
64
+ exit 0
65
+ when '--help','-h','help'
66
+ # help, and exit
67
+ Irgat.help(args)
68
+ else
69
+ # process irgat request
70
+ Irgat.process(args)
85
71
  end
86
72
 
87
73
 
@@ -13,19 +13,28 @@ Read more info in <irgat_path>/README
13
13
  =end
14
14
 
15
15
  def stop_install(msj)
16
- puts 'Irgat installation was stopped with this message:'
16
+ puts "#{ colorize("Irgat updater was stopped with this message:","red") }"
17
17
  puts '"'+msj+'"'
18
18
  puts ''
19
19
  puts 'Bye!'
20
20
  exit 1
21
21
  end
22
22
 
23
+ def colorize(msj, color)
24
+ case color
25
+ when "red"
26
+ color_num = 1
27
+ when "green"
28
+ color_num = 2
29
+ end
30
+ "\x1b[#{ 38 };5;#{ color_num }m#{ msj }\x1b[0m"
31
+ end
23
32
 
24
33
 
25
34
  puts ''
26
35
  puts 'Welcome to IRGAT setup'
27
36
  puts '------------------------'
28
- puts ''
37
+
29
38
 
30
39
  if Process.euid != 0
31
40
  stop_install('You must run this program as root.')
@@ -77,7 +86,7 @@ end
77
86
  puts 'Copy Irgat config sample files to destination'
78
87
  puts ''
79
88
 
80
- %x[ cp -rf #{ File.dirname(__FILE__) }/../setup/etc/* #{irgat_config_folder} ]
89
+ %x[ cp -rf #{ File.dirname(__FILE__) }/../setup/etc/*.yml.example #{irgat_config_folder} ]
81
90
 
82
91
  if $? != 0
83
92
  stop_install("Exec: cp -r #{ File.dirname(__FILE__) }/../setup/etc/* #{irgat_config_folder} return error")
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/ruby
2
+
3
+ =begin
4
+
5
+ Irgat updater program
6
+ ---------------------
7
+
8
+ Author: Gnoxys. info@gnoxys.net
9
+ License: GPL v3.
10
+
11
+ Read more info in <irgat_path>/README
12
+
13
+ =end
14
+
15
+ require 'yaml'
16
+
17
+ def stop_update(msj)
18
+ puts "#{ colorize("Irgat updater was stopped with this message:","red") }"
19
+ puts '"'+msj+'"'
20
+ puts ''
21
+ puts 'Bye!'
22
+ exit 1
23
+ end
24
+
25
+ def colorize(msj, color)
26
+ case color
27
+ when "red"
28
+ color_num = 1
29
+ when "green"
30
+ color_num = 2
31
+ when "orange"
32
+ color_num = 220
33
+ end
34
+ "\x1b[#{ 38 };5;#{ color_num }m#{ msj }\x1b[0m"
35
+ end
36
+
37
+
38
+
39
+ puts ''
40
+ puts 'Welcome to IRGAT updater'
41
+ puts '------------------------'
42
+
43
+ if Process.euid != 0
44
+ stop_update('You must run this program as root.')
45
+ end
46
+
47
+ puts ''
48
+ puts 'Irgat Updater checks yours config files and compare it with the newer examples in the new install release.
49
+ Changes are show in screen, but you must edit it manually.'
50
+ puts 'You can repeat these command whatever times you need'
51
+ puts ''
52
+ puts '* Start with the update'
53
+ puts " Do it? [Y/n]"
54
+
55
+ answer = $stdin.gets
56
+
57
+ stop_update('Halted by user') if answer.strip == 'n'
58
+
59
+ Dir.chdir("/etc/irgat")
60
+ # Takes all the entries but not examples
61
+ (Dir["*"] - Dir["*example*"]).each { |config_file|
62
+ puts "\n* Check #{ config_file }? [Y/n]"
63
+ answer = $stdin.gets
64
+
65
+ if answer.strip != 'n'
66
+ # load yml
67
+ system_yml = YAML.load_file(config_file)
68
+ # load release yml
69
+ release_yml = YAML.load_file("#{ File.dirname(__FILE__) }/../setup/etc/#{ config_file.split('.').first }.yml.example")
70
+ release_yml.each_pair { |release_option, release_value|
71
+ # Exist in config file
72
+ if !system_yml.has_key?(release_option)
73
+ puts "[ #{ colorize("ERROR","red") } ] Not found => #{ release_option }"
74
+ else
75
+ # check value
76
+ if release_value != system_yml[release_option]
77
+ puts "[ #{ colorize("WARNING","orange") } ] Different Value => #{ release_option }"
78
+ else
79
+ puts "[ #{ colorize("OK","green") } ] Same Value => #{ release_option } "
80
+ end
81
+ end
82
+ }
83
+ end
84
+
85
+
86
+ }
@@ -1,5 +1,6 @@
1
1
  require 'irgat/version'
2
2
 
3
+
3
4
  AUTHOR = 'Gnoxys' # can also be an array of Authors
4
5
  EMAIL = "info@gnoxys.net"
5
6
  DESCRIPTION = "Intuitive Ruby for Gnoxys Administration Tools"
@@ -9,7 +10,6 @@ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
10
  DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
11
  EXTRA_DEPENDENCIES = [
11
12
  ['net-ssh', '>= 2.0.4'],
12
- ['rdoc', '>= 2.2.1'],
13
13
  ['termios', '>= 0.9.4'],
14
14
  ['tmail', '>= 1.2.3.1']
15
15
  ] # An array of rubygem dependencies [name, version]
@@ -40,7 +40,7 @@ end
40
40
  REV = nil
41
41
  # UNCOMMENT IF REQUIRED:
42
42
  # REV = YAML.load(`svn info`)['Revision']
43
- VERS = Irgat::VERSION::STRING + (REV ? ".#{REV}" : "")
43
+ VERS = "#{::Irgat::Version}" + (REV ? ".#{REV}" : "")
44
44
  RDOC_OPTS = ['--quiet', '--title', 'irgat documentation',
45
45
  "--opname", "index.html",
46
46
  "--line-numbers",
@@ -1,12 +1,33 @@
1
1
  $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
- #= License
5
- #
6
- # IRGAT (Intuitive Ruby for Gnoxys Administration Tools)
7
- # 2007 - 2008 Gnoxys. info@gnoxys.net
8
- # This program is released under the terms of the GPL v3 license
9
- # as you cand find in http://www.gnu.org/licenses/gpl.html
4
+ # IRGAT constants
5
+ IRGAT_ROOT = File.dirname(__FILE__) + '/..' unless defined?(IRGAT_ROOT)
6
+ # Default paths, if you want to change, change hear
7
+ IRGAT_CONFIG = '/etc/irgat' unless defined?(IRGAT_CONFIG)
8
+ IRGAT_LANG = IRGAT_ROOT + '/lang' unless defined?(IRGAT_LANG)
9
+ IRGAT_LIB = IRGAT_ROOT + '/lib' unless defined?(IRGAT_LIB)
10
+
11
+ begin
12
+ # requiere other modules, if not loaded yet
13
+ require 'yaml'
14
+ require 'erb'
15
+ # RDoc, built inside help
16
+ require 'rdoc/usage'
17
+ require 'rdoc/code_objects'
18
+ require 'rdoc/markup/simple_markup'
19
+ require 'rdoc/markup/simple_markup/to_flow'
20
+ require 'rdoc/ri/ri_formatter'
21
+ require 'rdoc/ri/ri_options'
22
+ require 'net/smtp'
23
+ require 'tmail'
24
+ # irgat Base
25
+ require 'irgat'
26
+ rescue LoadError => msj
27
+ puts "Irgat needed the follow gem:"+(msj.to_s.split('--'))[1]+", but not found."
28
+ puts "[ ERROR ] in file "+msj.backtrace.to_s
29
+ end
30
+
10
31
 
11
32
  # start with Irgat module. Build namespace IRGAT
12
33
  module Irgat
@@ -17,11 +38,16 @@ module Irgat
17
38
  irgat = Irgat.new
18
39
  irgat.process(args)
19
40
  end
41
+
42
+ def help(args = {})
43
+ irgat = Irgat.new
44
+ irgat.help(args)
45
+ end
20
46
  end
21
47
 
22
48
  class Irgat
23
49
  #accesor to configs
24
- attr_reader :config
50
+ attr :config
25
51
  attr_reader :config_module
26
52
  #accesor to init time
27
53
  attr_reader :init_time
@@ -29,56 +55,92 @@ module Irgat
29
55
  attr :programs
30
56
  #accesor to folders
31
57
  attr :folders
58
+ #accesor log
59
+ attr :log_process
60
+ #accesor to command launched
61
+ attr :commands_launched
62
+ #accesor to action
63
+ attr :action
64
+
65
+
66
+ # Class top variable debug level :: can override config debug level
67
+ @@debug_level = nil
68
+
69
+ # version, FIXME ?
70
+ require 'irgat/version'
32
71
 
33
72
  # add utils
34
73
  require 'irgat/utils'
74
+ include ::Irgat::Help
35
75
  include ::Irgat::Log
36
76
  include ::Irgat::Mail
37
77
  include ::Irgat::Execs
38
78
  include ::Irgat::Dependencies
39
79
 
40
80
  # simple initialize of a Irgat object... loading general config
41
- def initialize(options = {})
81
+ def initialize(values = {})
42
82
  @init_time = Time.now
43
83
  @config = self.load_config
84
+ # modify debug by cmd line class
85
+ if @@debug_level.to_i >= 1
86
+ @config[:debug_level] = @@debug_level.to_i
87
+ end
88
+ end
89
+
90
+ def help(args)
91
+ @log_to_stdout = true
92
+ # help
93
+ args.shift
94
+ pattern = args.to_s
95
+ show_help(pattern, exit_irgat = true)
44
96
  end
45
97
 
46
98
  def process(args = [])
47
99
  irgat_module = args.shift
48
100
  # get subsytem if active FIXME
49
101
  if !self.config[:enable_subsystem].include?(irgat_module)
50
- exit_with_error('Module not enable in irgat config')
102
+ exit_with_error('Module not enable in irgat config',
103
+ { :exit_level => 2 })
51
104
  end
52
105
 
53
106
  # action ?
54
107
  ( args.first ? action = args.shift : action = "default" )
55
108
 
56
- # no action : is parameter
57
- if action.include?("-")
58
- args.push(action)
59
- action = "default"
60
- end
61
-
62
- # debug to stdout?
63
- if args.include?("-d")
64
- @log_to_stdout = true
109
+ # irgat options
110
+ module_args = Array.new
111
+ while arg = args.shift
112
+ case arg
113
+ when "-w","--without_output"
114
+ # modify stdout
115
+ $stdout = File.new("/dev/null","w")
116
+ when "-d","--debug_level"
117
+ # take new debug level
118
+ @@debug_level = args.shift
119
+ else
120
+ module_args << arg
121
+ end
65
122
  end
66
123
 
67
124
  # init the module
68
125
  begin
69
126
  require 'modules/' + irgat_module
70
- irgat_process = Object.module_eval("#{ irgat_module.capitalize }").new
127
+ irgat_process = Object.module_eval("#{ irgat_module.capitalize }").new({:action => action })
71
128
  rescue LoadError => msj
72
- exit_with_error("Unable to start the #{ irgat_module } module. Error was: #{ msj.backtrace.to_s } ")
129
+ exit_with_error("Unable to start the #{ irgat_module } module. Error was: #{ msj.backtrace.to_s } ", { :exit_level => 2 })
73
130
  end
74
131
 
75
132
  # scape possible private methods throught a bug in send method
76
133
  # http://joshstaiger.org/archives/2006/12/the_ruby_send_h.html
77
134
  if irgat_process.public_methods.include?(action)
78
- irgat_process.send(action, args)
135
+ module_return = irgat_process.send(action, module_args)
79
136
  else
80
- exit_with_error("Unable to exec action. Not avaible public method '#{ action }' in '#{ irgat_module }' Module. }", { :no_finish_process => true })
137
+ exit_with_error("Unable to exec action. Not avaible public method '#{ action }' in '#{ irgat_module }' Module.", { :exit_level => 2 })
81
138
  end
139
+
140
+ # report
141
+ output_log(irgat_process,
142
+ { :main_msj => (module_return || "[IRGAT] [#{ irgat_module.upcase }] [OK] #{ action } process in #{ @config[:server_name] }")})
143
+ exit 0
82
144
  end
83
145
 
84
146
  # method to load the config options for a module and return a hash symbol
@@ -89,6 +151,7 @@ module Irgat
89
151
  config_yml.each{|k, v| config_to_symbols[k.to_sym] = v}
90
152
  config_to_symbols
91
153
  end
154
+
92
155
  end
93
156
  end
94
157