irgat 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +45 -0
  3. data/PostInstall.txt +4 -0
  4. data/README.rdoc +29 -0
  5. data/Rakefile +4 -0
  6. data/TODO +26 -0
  7. data/bin/irgat +87 -0
  8. data/bin/irgat_setup +135 -0
  9. data/config/hoe.rb +80 -0
  10. data/config/requirements.rb +15 -0
  11. data/lib/irgat.rb +94 -0
  12. data/lib/irgat/console.rb +85 -0
  13. data/lib/irgat/dependencies.rb +75 -0
  14. data/lib/irgat/execs.rb +73 -0
  15. data/lib/irgat/log.rb +116 -0
  16. data/lib/irgat/mail.rb +88 -0
  17. data/lib/irgat/utils.rb +17 -0
  18. data/lib/irgat/version.rb +10 -0
  19. data/lib/modules/backup.rb +348 -0
  20. data/lib/modules/console.rb +48 -0
  21. data/lib/modules/kwallet.rb +133 -0
  22. data/script/console +10 -0
  23. data/script/destroy +14 -0
  24. data/script/generate +14 -0
  25. data/script/txt2html +82 -0
  26. data/setup.rb +1585 -0
  27. data/setup/etc/backup.yml.example +103 -0
  28. data/setup/etc/chroot.yml.example +42 -0
  29. data/setup/etc/console.yml.default +11 -0
  30. data/setup/etc/cron.yml.example +56 -0
  31. data/setup/etc/dar.yml.example +16 -0
  32. data/setup/etc/irgat.yml.example +37 -0
  33. data/setup/etc/kwallet.yml.default +18 -0
  34. data/setup/etc/kwallet.yml.example +18 -0
  35. data/setup/etc/ssh.yml.example +17 -0
  36. data/tasks/deployment.rake +34 -0
  37. data/tasks/environment.rake +7 -0
  38. data/tasks/website.rake +17 -0
  39. data/test/test_helper.rb +2 -0
  40. data/test/test_irgat.rb +11 -0
  41. data/website/index.html +83 -0
  42. data/website/index.txt +83 -0
  43. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  44. data/website/stylesheets/screen.css +138 -0
  45. data/website/template.html.erb +48 -0
  46. metadata +157 -0
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-10-24
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
@@ -0,0 +1,45 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ TODO
7
+ bin/irgat
8
+ bin/irgat_setup
9
+ config/hoe.rb
10
+ config/requirements.rb
11
+ lib/irgat.rb
12
+ lib/irgat/console.rb
13
+ lib/irgat/dependencies.rb
14
+ lib/irgat/execs.rb
15
+ lib/irgat/log.rb
16
+ lib/irgat/mail.rb
17
+ lib/irgat/utils.rb
18
+ lib/irgat/version.rb
19
+ lib/modules/backup.rb
20
+ lib/modules/console.rb
21
+ lib/modules/kwallet.rb
22
+ script/console
23
+ script/destroy
24
+ script/generate
25
+ script/txt2html
26
+ setup.rb
27
+ setup/etc/backup.yml.example
28
+ setup/etc/chroot.yml.example
29
+ setup/etc/console.yml.default
30
+ setup/etc/cron.yml.example
31
+ setup/etc/dar.yml.example
32
+ setup/etc/irgat.yml.example
33
+ setup/etc/kwallet.yml.default
34
+ setup/etc/kwallet.yml.example
35
+ setup/etc/ssh.yml.example
36
+ tasks/deployment.rake
37
+ tasks/environment.rake
38
+ tasks/website.rake
39
+ test/test_helper.rb
40
+ test/test_irgat.rb
41
+ website/index.html
42
+ website/index.txt
43
+ website/javascripts/rounded_corners_lite.inc.js
44
+ website/stylesheets/screen.css
45
+ website/template.html.erb
@@ -0,0 +1,4 @@
1
+ Run irgat_setup to setup Irgat
2
+
3
+ For more information on Irgat, see http://irgat.rubyforge.org
4
+
@@ -0,0 +1,29 @@
1
+ = irgat
2
+
3
+ Interactive Ruby for Gnoxys Administration Tools
4
+
5
+ == DESCRIPTION:
6
+
7
+ FIX (describe your package)
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ * FIX (sudo gem install, anything else)
24
+
25
+ == LICENSE:
26
+
27
+ Copyright (c) 2007 - 2008 Gnoxys, info@gnoxys.net
28
+
29
+ This program is released under the terms of the GPL v3 license as you cand find in http://www.gnu.org/licenses/gpl.html
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/TODO ADDED
@@ -0,0 +1,26 @@
1
+ # TODO file
2
+
3
+ === General
4
+
5
+ - When the folders tree is checked, we build a hash symbol array with the form
6
+ folders[:<name_dir>]=<absolute path>, that's great, the problem is when two directoris are called eqal, but inside of differents parents folders (for example, /current/archive, /old/archive.
7
+
8
+ In this case, the last folder will be reported as folders[:archive]='/old/archive', and for the first entry, won't be any hash entry
9
+
10
+ [ TODO ] => Think about it ;)
11
+
12
+ === Backup
13
+
14
+ - 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
+ {
16
+ get_older_size_backup=X
17
+ if df -h(working_folder) < get_older_size_backup
18
+ exit
19
+ end
20
+ }
21
+
22
+ - Add a option to distribute backups with ftp
23
+
24
+ - Check mount folder
25
+
26
+ - Include by default to exclude backup folder from backup
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env ruby
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
+ #= Help
13
+ #
14
+ # Irgat is an utility to manage administration script and all the tools needed for it.
15
+ #
16
+ # Irgat use two modes (at this moment)
17
+ #
18
+ # 1. Mode Cron
19
+ #
20
+ # Perform operations in function of irgat config files.
21
+ # <mas informacion de cron>
22
+ #
23
+ # 2. Mode CMD [command]
24
+ #
25
+ # In this mode, irgat show you an irb console with the default modules loaded. You can perform all the normal operations and check the works of your irgat's subsytems, make test and launch debug commands.
26
+ #
27
+ # Also, the command line is builded with the intention of a helpper tool, so you can get easy a lot of help of methods, requirements, external programs needed or all the stuff needed for your administration script.
28
+ #
29
+ # For more info, view the API of irgat and read the documentation
30
+ #
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
+
39
+
40
+ # IRGAT constants
41
+ IRGAT_ROOT = File.dirname(__FILE__) + '/..'
42
+ puts IRGAT_ROOT
43
+ # Default paths, if you want to change, change hear
44
+ IRGAT_CONFIG = '/etc/irgat' unless defined?(IRGAT_CONFIG)
45
+ IRGAT_LANG = IRGAT_ROOT + '/lang' unless defined?(IRGAT_LANG)
46
+ IRGAT_LIB = IRGAT_ROOT + '/lib' unless defined?(IRGAT_LIB)
47
+
48
+ begin
49
+ # requiere other modules, if not loaded yet
50
+ require 'yaml'
51
+ require 'erb'
52
+ # RDoc, built inside help
53
+ require 'rdoc/usage'
54
+ require 'rdoc/code_objects'
55
+ require 'rdoc/markup/simple_markup'
56
+ require 'rdoc/markup/simple_markup/to_flow'
57
+ require 'rdoc/ri/ri_formatter'
58
+ require 'rdoc/ri/ri_options'
59
+ require 'net/smtp'
60
+ require 'tmail'
61
+ # irgat Base
62
+ require 'irgat'
63
+ rescue LoadError => msj
64
+ puts "Irgat needed the follow gem:"+(msj.to_s.split('--'))[1]+", but not found."
65
+ puts "[ ERROR ] in file "+msj.backtrace.to_s
66
+ end
67
+
68
+ # 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)
85
+ end
86
+
87
+
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/ruby
2
+
3
+ =begin
4
+
5
+ Irgat setup 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
+ def stop_install(msj)
16
+ puts 'Irgat installation was stopped with this message:'
17
+ puts '"'+msj+'"'
18
+ puts ''
19
+ puts 'Bye!'
20
+ exit 1
21
+ end
22
+
23
+
24
+
25
+ puts ''
26
+ puts 'Welcome to IRGAT setup'
27
+ puts '------------------------'
28
+ puts ''
29
+
30
+ if Process.euid != 0
31
+ stop_install('You must run this program as root.')
32
+ end
33
+
34
+
35
+ puts ''
36
+ puts '* Irgat is going to check the programs needed'
37
+ puts " Do it? [Y/n]"
38
+
39
+ answer = $stdin.gets
40
+
41
+ stop_install('Halted by user') if answer.strip == 'n'
42
+
43
+ #programs_needed = [ 'dar', 'dar_manager', 'mutt', 'ssh', 'irb' ]
44
+ programs_needed = [ 'ssh', 'irb' ]
45
+
46
+ for program in programs_needed
47
+ program_path = %x[ which #{program}]
48
+ if program_path == ''
49
+ puts "Irgat cannot found the following #program:#{program}"
50
+ stop_install('Program not found')
51
+ end
52
+ end
53
+
54
+ puts '-> Programs ok'
55
+
56
+ #test folder irgat
57
+
58
+ irgat_config_folder = '/etc/irgat'
59
+
60
+ if ! test(?d, irgat_config_folder)
61
+ puts "Folder #{ irgat_config_folder } doesn't exits. Create it? [Y/n]"
62
+ answer_create = $stdin.gets
63
+ stop_install('Halted by user') if answer_create.strip == 'n'
64
+ %x[ mkdir -p #{ irgat_config_folder} ]
65
+ if $?!=0
66
+ stop_install("Exec: mkdir -p #{ irgat_config_folder } return error")
67
+ end
68
+ else
69
+ if Dir.entries(irgat_config_folder).length > 2
70
+ puts 'Target folder is not empty, continue anyway? [Y/n]'
71
+ answer_empty = $stdin.gets
72
+ stop_install('Halted by user') if answer_empty.strip == 'n'
73
+ end
74
+ end
75
+
76
+
77
+ puts 'Copy Irgat config sample files to destination'
78
+ puts ''
79
+
80
+ %x[ cp -rf #{ File.dirname(__FILE__) }/../setup/etc/* #{irgat_config_folder} ]
81
+
82
+ if $? != 0
83
+ stop_install("Exec: cp -r #{ File.dirname(__FILE__) }/../setup/etc/* #{irgat_config_folder} return error")
84
+ end
85
+
86
+ =begin
87
+ puts 'Irgat comes with an init.d script that launches the macros init_system and stop_system (see irgat/macros.rb for more information)'
88
+ puts 'Do you want to copy to /etc/init.d/irgat? [Y/n]'
89
+ answer = $stdin.gets
90
+ if answer.strip != 'n'
91
+ %x[ cp bin/irgat_init /etc/init.d/irgat ]
92
+ %x[ chmod 755 /etc/init.d/irgat]
93
+ if $? != 0
94
+ puts '* I can\t copy the file'
95
+ else
96
+ puts 'ok'
97
+ puts ''
98
+ puts 'Do i also add to the default init? [Y/n]'
99
+ answer = $stdin.gets
100
+ if answer.strip != 'n'
101
+ puts 'Linux Distributions have different ways to make this. So, choose'
102
+ puts ' 1. Debian way (update-rc.d)'
103
+ puts ' 2. RedHat way (chkconfig)'
104
+ puts ''
105
+ puts ' 0. Make nothing'
106
+ puts ''
107
+ puts ' Choose option [1,2,0]'
108
+ answer_option = $stdin.gets
109
+ case answer_option.strip.to_s
110
+ when "1"
111
+ %x[ update-rc.d irgat defaults 99]
112
+ if $? != 0
113
+ puts '* Error, I can\'t add irgat to default run-leves. do it yourself'
114
+ end
115
+ when "2"
116
+ %x[ chkconfig --add irgat]
117
+ if $? != 0
118
+ puts '* Error, I can\'t add irgat to default run-leves. do it yourself'
119
+ end
120
+ else
121
+ puts ' Do nothing'
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
127
+ =end
128
+
129
+ puts ''
130
+ puts '* Ok. All done! Edit your config in /etc/irgat to set the variables for irgat and modules'
131
+ puts ''
132
+ puts 'Irgat setup finished!!! Happy Admin ;-)'
133
+ puts 'Bye!'
134
+
135
+ # finish install
@@ -0,0 +1,80 @@
1
+ require 'irgat/version'
2
+
3
+ AUTHOR = 'Gnoxys' # can also be an array of Authors
4
+ EMAIL = "info@gnoxys.net"
5
+ DESCRIPTION = "Intuitive Ruby for Gnoxys Administration Tools"
6
+ GEM_NAME = 'irgat' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'irgat' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+ EXTRA_DEPENDENCIES = [
11
+ ['net-ssh', '>= 2.0.4'],
12
+ ['rdoc', '>= 2.2.1'],
13
+ ['termios', '>= 0.9.4'],
14
+ ['tmail', '>= 1.2.3.1']
15
+ ] # An array of rubygem dependencies [name, version]
16
+ EXTRA_DEV_DEPENDENCIES = [
17
+ # ['rspec', '>= 1.1.5']
18
+ ] # An array of rubygem dependencies [name, version]
19
+
20
+ @config_file = "~/.rubyforge/user-config.yml"
21
+ @config = nil
22
+ RUBYFORGE_USERNAME = "unknown"
23
+ def rubyforge_username
24
+ unless @config
25
+ begin
26
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
27
+ rescue
28
+ puts <<-EOS
29
+ ERROR: No rubyforge config file found: #{@config_file}
30
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
31
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
32
+ EOS
33
+ exit
34
+ end
35
+ end
36
+ RUBYFORGE_USERNAME.replace @config["username"]
37
+ end
38
+
39
+
40
+ REV = nil
41
+ # UNCOMMENT IF REQUIRED:
42
+ # REV = YAML.load(`svn info`)['Revision']
43
+ VERS = Irgat::VERSION::STRING + (REV ? ".#{REV}" : "")
44
+ RDOC_OPTS = ['--quiet', '--title', 'irgat documentation',
45
+ "--opname", "index.html",
46
+ "--line-numbers",
47
+ "--main", "README",
48
+ "--inline-source"]
49
+
50
+ class Hoe
51
+ def extra_deps
52
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
53
+ @extra_deps
54
+ end
55
+ end
56
+
57
+ # Generate all the Rake tasks
58
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
59
+ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
60
+ p.developer(AUTHOR, EMAIL)
61
+ p.description = DESCRIPTION
62
+ p.summary = DESCRIPTION
63
+ p.url = HOMEPATH
64
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
65
+ p.test_globs = ["test/**/test_*.rb"]
66
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
67
+
68
+ # == Optional
69
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
70
+ p.extra_deps = EXTRA_DEPENDENCIES
71
+ p.extra_dev_deps = EXTRA_DEV_DEPENDENCIES
72
+
73
+ p.spec_extras = {} # A hash of extra values to set in the gemspec.
74
+ end
75
+
76
+ CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
77
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
78
+ $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
79
+ $hoe.rsync_args = '-av --delete --ignore-errors'
80
+ $hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
@@ -0,0 +1,94 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
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
10
+
11
+ # start with Irgat module. Build namespace IRGAT
12
+ module Irgat
13
+
14
+ # Singelton pass to Irgat::Irgat.process
15
+ class << self
16
+ def process(args = {})
17
+ irgat = Irgat.new
18
+ irgat.process(args)
19
+ end
20
+ end
21
+
22
+ class Irgat
23
+ #accesor to configs
24
+ attr_reader :config
25
+ attr_reader :config_module
26
+ #accesor to init time
27
+ attr_reader :init_time
28
+ #accesor to programs
29
+ attr :programs
30
+ #accesor to folders
31
+ attr :folders
32
+
33
+ # add utils
34
+ require 'irgat/utils'
35
+ include ::Irgat::Log
36
+ include ::Irgat::Mail
37
+ include ::Irgat::Execs
38
+ include ::Irgat::Dependencies
39
+
40
+ # simple initialize of a Irgat object... loading general config
41
+ def initialize(options = {})
42
+ @init_time = Time.now
43
+ @config = self.load_config
44
+ end
45
+
46
+ def process(args = [])
47
+ irgat_module = args.shift
48
+ # get subsytem if active FIXME
49
+ if !self.config[:enable_subsystem].include?(irgat_module)
50
+ exit_with_error('Module not enable in irgat config')
51
+ end
52
+
53
+ # action ?
54
+ ( args.first ? action = args.shift : action = "default" )
55
+
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
65
+ end
66
+
67
+ # init the module
68
+ begin
69
+ require 'modules/' + irgat_module
70
+ irgat_process = Object.module_eval("#{ irgat_module.capitalize }").new
71
+ rescue LoadError => msj
72
+ exit_with_error("Unable to start the #{ irgat_module } module. Error was: #{ msj.backtrace.to_s } ")
73
+ end
74
+
75
+ # scape possible private methods throught a bug in send method
76
+ # http://joshstaiger.org/archives/2006/12/the_ruby_send_h.html
77
+ if irgat_process.public_methods.include?(action)
78
+ irgat_process.send(action, args)
79
+ else
80
+ exit_with_error("Unable to exec action. Not avaible public method '#{ action }' in '#{ irgat_module }' Module. }", { :no_finish_process => true })
81
+ end
82
+ end
83
+
84
+ # method to load the config options for a module and return a hash symbol
85
+ def load_config(config_file = nil)
86
+ config_yml = YAML.load_file(config_file || IRGAT_CONFIG + '/' + self.class.to_s.downcase.split('::')[1] + '.yml')
87
+ # parse to symbols the config options
88
+ config_to_symbols = Hash.new
89
+ config_yml.each{|k, v| config_to_symbols[k.to_sym] = v}
90
+ config_to_symbols
91
+ end
92
+ end
93
+ end
94
+