Skip to content
Browse files

Updated Startup Item installation to use post_office binary

  • Loading branch information...
1 parent 2e52fc0 commit 60592ed6715882fca90339537e7375b03a19e876 @rvanlieshout rvanlieshout committed May 18, 2011
Showing with 80 additions and 49 deletions.
  1. +12 −2 README.md
  2. +1 −47 Rakefile
  3. +20 −0 bin/post_office
  4. +47 −0 lib/startup_item.rb
View
14 README.md
@@ -54,13 +54,23 @@ It's possible to start PostOffice as a daemon using post_officed:
-h, --help Show this message
--version Show version
+Mac OS X Startup Item
+---------------------
+
+PostOffice daemon can be started on Mac OS X system startup.
+
+ sudo post_office [options]
+
+ --install-osx-startup-item Installs Post Office as OS X Startup Item
+ --remove-osx-startup-item Removes Post Office as OS X Startup Item
+
+The Startup Item is stored in */Library/StartupItems/PostOffice*
+
Planned features
----------------
* Ability to use custom ports for SMTP and POP
* Growl notifications
-* Mac OS X Startup Item / launchctl service
* Store mail in tempfiles instead of in-memory array
-* Tests :)
Contributions are welcome! Feel free to fork and send a pull request through Github.
View
48 Rakefile
@@ -16,50 +16,4 @@ begin
end
rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install jeweler"
-end
-
-namespace :startup_item do
- desc "Installs Post Office Mac OS X Startup Item"
- task :install do
- target_path = File.join("/","Library","StartupItems")
-
- # We cannot install this twice
- if File.exists?(File.join(target_path,"PostOffice"))
- puts "PostOffice Startup Item is already installed."
- exit
- end
-
- # We need /usr/bin/post_officed for this startup item to function
- unless File.exists?(File.join("/","usr","bin","post_officed"))
- puts "Error: missing /usr/bin/post_officed. Have you gem install post_office?"
- exit
- end
-
- puts "Installing Post Office Mac OS X Startup Item..."
-
- # Make sure /Library/StartupItems exists
- FileUtils.mkdir_p(target_path)
-
- source = File.join(File.dirname(__FILE__), "startup_item", "PostOffice")
- destination = File.join(target_path, "PostOffice")
-
- FileUtils.cp_r(source, destination)
-
- puts "Successfully installed Startup Item!"
- end
-
- desc "Removes Post Office Mac OS X Startup Item"
- task :remove do
- target_path = File.join("/","Library","StartupItems")
-
- unless File.exists?(File.join(target_path,"PostOffice"))
- puts "PostOffice Startup Item not installed."
- exit
- end
-
- puts "removing Post Office Mac OS X Startup Item..."
- FileUtils.rm_rf(File.join(target_path, "PostOffice"))
- puts "Successfully removed Startup Item!"
- end
-end
-
+end
View
20 bin/post_office
@@ -24,6 +24,14 @@ optparse = OptionParser.new do |opts|
opts.on( '-l', '--logfile FILE', 'Write log to FILE. Outputs to STDOUT (or /var/log/post_office.log when daemonized) by default.' ) do |file|
options[:logfile] = file
end
+
+ options[:startup_item] = nil
+ opts.on('--install-osx-startup-item', 'Installs Post Office as OS X Startup Item') do
+ options[:startup_item] = :install
+ end
+ opts.on('--remove-osx-startup-item', 'Removes Post Office as OS X Startup Item') do
+ options[:startup_item] = :remove
+ end
opts.on( '-h', '--help', 'Display this screen' ) do
puts opts
@@ -34,6 +42,18 @@ end
optparse.parse!
#
+# OS X Startup Item
+#
+if options[:startup_item]
+ require 'startup_item.rb'
+ case options[:startup_item]
+ when :install then StartupItem.install
+ when :remove then StartupItem.remove
+ end
+ exit
+end
+
+#
# Create our logger
#
$log = Logger.new(options[:logfile] || STDOUT)
View
47 lib/startup_item.rb
@@ -0,0 +1,47 @@
+class StartupItem
+ def self.install
+ target_path = File.join("/","Library","StartupItems")
+
+ # We cannot install this twice
+ if File.exists?(File.join(target_path,"PostOffice"))
+ puts "PostOffice Startup Item is already installed."
+ exit
+ end
+
+ # We need /usr/bin/post_officed for this startup item to function
+ unless File.exists?(File.join("/","usr","bin","post_officed"))
+ puts "Error: missing /usr/bin/post_officed. Have you gem install post_office?"
+ exit
+ end
+
+ puts "Installing Post Office Mac OS X Startup Item..."
+
+ # Make sure /Library/StartupItems exists
+ FileUtils.mkdir_p(target_path)
+
+ source = File.join(File.dirname(__FILE__), "..", "startup_item", "PostOffice")
+ destination = File.join(target_path, "PostOffice")
+
+ FileUtils.cp_r(source, destination)
+
+ puts "Successfully installed Startup Item!"
+ end
+
+ def self.remove
+ target_path = File.join("/","Library","StartupItems")
+
+ unless File.exists?(File.join(target_path,"PostOffice"))
+ puts "PostOffice Startup Item not installed."
+ exit
+ end
+
+ puts "removing Post Office Mac OS X Startup Item..."
+ FileUtils.rm_rf(File.join(target_path, "PostOffice"))
+
+ unless File.exists?(File.join(target_path,"PostOffice"))
+ puts "Successfully removed Startup Item!"
+ else
+ puts "Unable to remove Startup Item: hae you used sudo?"
+ end
+ end
+end

0 comments on commit 60592ed

Please sign in to comment.
Something went wrong with that request. Please try again.