forked from ttscoff/Slogger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.rb
executable file
·83 lines (74 loc) · 2.19 KB
/
install.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/ruby
curloc = File.expand_path(File.dirname(__FILE__))
unless File.exists?(curloc+'/slogger_config')
puts
puts "Please run `#{curloc}/slogger` once to generate the configuration file."
puts
puts "The file will show up in your slogger folder, and you can edit usernames"
puts "and options in it. Once you're done, run this installer again."
exit
end
puts
puts "Installing Slogger logging scheduler"
puts "This script will install the following files:"
puts "~/Library/LaunchAgents/com.brettterpstra.slogger.plist"
puts
puts "Is '#{curloc}' the location of your Slogger folder?"
print "(Y/n)"
ans = gets.chomp
if ans.downcase == "n"
puts "Please enter the path to the 'slogger' folder on your drive"
print "> "
dir = gets.chomp
else
dir = curloc
end
if File.exists?(dir+"/slogger")
flags = ""
puts "By default, Slogger runs once a day at 11:50PM."
puts "If your computer is not always on, you can have"
puts "Slogger fetch data back to the time of the last"
puts "successful run."
puts
puts "Is your Mac routinely offline at 11:50PM?"
print "(Y/n)"
ans = gets.chomp
flags += " -s" if ans.downcase == "y"
print "Setting up launchd... "
xml=<<LAUNCHCTLPLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.brettterpstra.Slogger</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/ruby</string>
<string>#{dir}/slogger#{flags}</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>23</integer>
<key>Minute</key>
<integer>50</integer>
</dict>
</dict>
</plist>
LAUNCHCTLPLIST
target_dir = File.expand_path("~/Library/LaunchAgents")
target_file = File.expand_path(target_dir+"/com.brettterpstra.slogger.plist")
Dir.mkdir(target_dir) unless File.exists?(target_dir)
open(target_file,'w') { |f|
f.puts xml
} unless File.exists?(target_file)
%x{launchctl load "#{target_file}"}
puts "done!"
puts
puts "----------------------"
puts "Installation complete."
else
puts "Slogger doesn't appear to exist in the directory specified."
puts "Please check your file location and try again."
end