restart_notifier 0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .DS_Store
2
+ pkg/*
3
+ *.gem
4
+ .bundle
5
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in report_restart.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # Overview
2
+
3
+ Notify each time a computer (server) restarts to the receiver email.
4
+ It's useful to quickly report if a machine ever gets restarted because of crash or power cut-off.
5
+ It's intended to be used only on Mac OS X.
6
+
7
+ ## Getting Started
8
+
9
+ Install as a gem.
10
+
11
+ gem install restart_notifier
12
+
13
+ Setup restart_notifier.
14
+
15
+ cd /path/to/destination/directory
16
+ setup_restart_notifier -s sender@mail.com -p password -r receiver1@mail.com,receiver2@mail.com
17
+
18
+ To remove restart_notifier completely, perform the following command.
19
+
20
+ cd /path/to/destination/directory
21
+ remove_restart_notifier
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "fileutils"
4
+
5
+ FileUtils.rm(File.expand_path("~/Library/LaunchAgents/com.restart.notifier.plist"))
6
+ FileUtils.rm_r("restart_notifier") if File.directory?("restart_notifier")
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "optparse"
4
+ require "fileutils"
5
+
6
+ options = {}
7
+
8
+ OptionParser.new do |opts|
9
+ opts.banner = "Usage: setup_restart_notifier [options]"
10
+ opts.on("-s", "--sender [sender]", "Sender email address (must be Gmail).") do |sender|
11
+ options[:sender] = sender if sender
12
+ end
13
+ opts.on("-p", "--password [password]", "Password for sender email account.") do |password|
14
+ options[:password] = password if password
15
+ end
16
+ opts.on("-r", "--receivers [receivers]", "Receiver email addresses. Split with comma for multiple addresses.") do |receivers|
17
+ options[:receivers] = receivers if receivers
18
+ end
19
+ end.parse!
20
+
21
+ restart_notifier_rb = <<-RESTART_NOTIFIER_RB
22
+ require 'gmail'
23
+
24
+ gmail = Gmail.connect('#{options[:sender]}', '#{options[:password]}')
25
+
26
+ receivers = '#{options[:receivers]}'
27
+
28
+ for receiver in receivers.split(",")
29
+ gmail.deliver do
30
+ to receiver.strip
31
+ subject 'Just Restarted!'
32
+ text_part do
33
+ body Time.now.to_s
34
+ end
35
+ end
36
+ end
37
+
38
+ gmail.logout
39
+ RESTART_NOTIFIER_RB
40
+
41
+ FileUtils.mkdir "restart_notifier" unless File.directory?("restart_notifier")
42
+
43
+ restart_notifier_rb_file = File.new("restart_notifier/restart_notifier.rb", "w")
44
+ restart_notifier_rb_file << restart_notifier_rb
45
+ restart_notifier_rb_file_path = restart_notifier_rb_file.path
46
+ restart_notifier_rb_file.close
47
+
48
+ restart_notifier_sh = <<-RESTART_NOTIFIER_SH
49
+ # ! /bin/sh
50
+ source ~/.bash_profile;
51
+ ruby #{File.expand_path(restart_notifier_rb_file_path)};
52
+ RESTART_NOTIFIER_SH
53
+
54
+ restart_notifier_sh_file = File.new("restart_notifier/restart_notifier.sh", "w")
55
+ restart_notifier_sh_file << restart_notifier_sh
56
+ restart_notifier_sh_file_path = restart_notifier_sh_file.path
57
+ restart_notifier_sh_file.close
58
+ # Give execute permission.
59
+ FileUtils.chmod 0744, restart_notifier_sh_file_path
60
+
61
+ restart_notifier_plist = <<-RESTART_NOTIFIER_PLIST
62
+ <?xml version="1.0" encoding="UTF-8"?>
63
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
64
+ <plist version="1.0">
65
+ <dict>
66
+ <key>Label</key>
67
+ <string>com.restart.notifier</string>
68
+ <key>ProgramArguments</key>
69
+ <array>
70
+ <string>#{File.expand_path(restart_notifier_sh_file_path)}</string>
71
+ </array>
72
+ <key>RunAtLoad</key>
73
+ <true/>
74
+ <key>KeepAlive</key>
75
+ <false/>
76
+ </dict>
77
+ </plist>
78
+ RESTART_NOTIFIER_PLIST
79
+
80
+ restart_notifier_plist_file = File.new("restart_notifier/com.restart.notifier.plist", "w")
81
+ restart_notifier_plist_file << restart_notifier_plist
82
+ restart_notifier_plist_file_path = restart_notifier_plist_file.path
83
+ restart_notifier_plist_file.close
84
+
85
+ FileUtils.cp restart_notifier_plist_file_path, File.expand_path("~/Library/LaunchAgents/")
86
+
87
+ puts "Successfully setup restart_notifier."
88
+ puts "There is a new directory created: #{File.expand_path("restart_notifier/")}"
@@ -0,0 +1,3 @@
1
+ module RestartNotifier
2
+ # Your code goes here...
3
+ end
@@ -0,0 +1,3 @@
1
+ module RestartNotifier
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "restart_notifier/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "restart_notifier"
7
+ s.version = RestartNotifier::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Steve Randy Tantra"]
10
+ s.email = ["steve.randy@gmail.com"]
11
+ s.homepage = "http://steverandytantra.com"
12
+ s.summary = %q{Restart notifier for Mac OS X.}
13
+ s.description = %q{Notify each time a computer (server) restarts to the receiver emails. It's useful to quickly report if a machine ever gets restarted because of crash or power cut-off. It's intended to be used only on Mac OS X.}
14
+
15
+ s.rubyforge_project = "restart_notifier"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency("gmail", "0.4.0")
23
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: restart_notifier
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ version: "0.1"
9
+ platform: ruby
10
+ authors:
11
+ - Steve Randy Tantra
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2011-01-16 00:00:00 +07:00
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: gmail
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - "="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 4
30
+ - 0
31
+ version: 0.4.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: Notify each time a computer (server) restarts to the receiver emails. It's useful to quickly report if a machine ever gets restarted because of crash or power cut-off. It's intended to be used only on Mac OS X.
35
+ email:
36
+ - steve.randy@gmail.com
37
+ executables:
38
+ - remove_restart_notifier
39
+ - setup_restart_notifier
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .gitignore
46
+ - Gemfile
47
+ - README.md
48
+ - Rakefile
49
+ - bin/remove_restart_notifier
50
+ - bin/setup_restart_notifier
51
+ - lib/restart_notifier.rb
52
+ - lib/restart_notifier/version.rb
53
+ - restart_notifier.gemspec
54
+ has_rdoc: true
55
+ homepage: http://steverandytantra.com
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirements: []
80
+
81
+ rubyforge_project: restart_notifier
82
+ rubygems_version: 1.3.7
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Restart notifier for Mac OS X.
86
+ test_files: []
87
+