]> gitweb.michael.orlitzky.com - dead/janitor.git/blob - bin/janitize.rb
Initial commit.
[dead/janitor.git] / bin / janitize.rb
1 # Actually run the thing.
2
3 require 'src/janitor'
4 require 'optparse'
5
6 # Set up the default options
7 options = { :apache_vhost_directory => '/etc/apache2/vhosts.d',
8 :maximum_file_age => 7 }
9
10 # And parse any that were given on the command line.
11 OptionParser.new do |opts|
12 opts.banner = "Usage: #{$0} [options]"
13
14 opts.on('-a', '--apache_vhosts_directory VHOSTS_DIR',
15 'Apache vhost conf file directory') do |vhost_dir|
16 options[:apache_vhost_directory] = vhost_dir
17 end
18
19 opts.on('-m', '--maximum_file_age MAX_DAYS_OLD', Integer,
20 'Maximum file age (in days)') do |max_age|
21 options[:maximum_file_age] = max_age
22 end
23
24 opts.on_tail("-h", "--help", "Show this message") do
25 puts opts
26 exit
27 end
28
29 end.parse!
30
31
32 # Print an informational header every time the program is run.
33 puts "Command line: #{$0 + ' ' + ARGV.join(' ')}"
34
35 current_time = Time.now()
36 if current_time.respond_to?(:iso8601)
37 # Somehow this method is missing on some machines.
38 puts "Time: #{current_time.iso8601}"
39 else
40 # Fall back to whatever this looks like.
41 puts "Time: #{current_time}"
42 end
43
44 puts "Apache vhost directory: #{options[:apache_vhost_directory]}"
45 puts "Max File Age: #{options[:maximum_file_age]}"
46
47 j = Janitor.new()
48 j.apache_vhosts_directory = options[:apache_vhost_directory]
49
50 temp_dirs = j.get_temporary_directories()
51
52 puts "Temporary directories: #{temp_dirs.join(', ')}\n\n"
53
54 temp_dirs.each do |dir|
55 j.clean_directory(dir, options[:maximum_file_age])
56 end