-
Notifications
You must be signed in to change notification settings - Fork 2
/
install
executable file
·60 lines (48 loc) · 1.41 KB
/
install
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
#!/usr/bin/env ruby
require 'fileutils'
def write_plist(plist_path, data)
File.write plist_path, data
end
def unload_plist(plist_path)
`/bin/launchctl unload #{plist_path}`
end
def load_plist(plist_path)
`/bin/launchctl load #{plist_path}`
end
def plist_content(plist_name, alpaca_path, log_path)
return <<~XML
<?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>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{alpaca_path}</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardOutPath</key>
<string>#{log_path}</string>
<key>StandardErrorPath</key>
<string>#{log_path}</string>
</dict>
</plist>
XML
end
def safe_append(file_path, data)
FileUtils.touch file_path
if IO.readlines(file_path).grep(/#{data}/).empty?
open file_path, 'a' do |file|
file.puts data
end
end
end
plist_name, plist_path, alpaca_path, log_path = ARGV
write_plist plist_path, plist_content(plist_name, alpaca_path, log_path)
unload_plist plist_path
load_plist plist_path
http_proxy="export {https,http}_proxy=localhost:3128"
safe_append File.join(Dir.home, ".zshrc"), http_proxy
safe_append File.join(Dir.home, ".bashrc"), http_proxy