-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.rb
67 lines (63 loc) · 2.05 KB
/
utils.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
# helps to set proxy if settings passed in query params
def check_for_proxy(params)
hostname = params[:hostname]
port = params[:port]
if hostname && port
if `networksetup -getwebproxy 'Wi-Fi' | grep '^Enabled:' | cut -d' ' -f2 | tr -d $'\n'` == "No"
`networksetup -setwebproxy 'Wi-Fi' #{hostname} #{port}`
end
if `networksetup -getsecurewebproxy 'Wi-Fi' | grep '^Enabled:' | cut -d' ' -f2 | tr -d $'\n'` == "No"
`networksetup -setsecurewebproxy 'Wi-Fi' #{hostname} #{port}`
end
end
end
# helps to disable proxy
def disable_proxy
if `networksetup -getsecurewebproxy 'Wi-Fi' | grep '^Enabled:' | cut -d' ' -f2 | tr -d $'\n'` == "Yes"
`networksetup -setsecurewebproxystate 'Wi-Fi' off`
end
if `networksetup -getwebproxy 'Wi-Fi' | grep '^Enabled:' | cut -d' ' -f2 | tr -d $'\n'` == "Yes"
` networksetup -setwebproxystate 'Wi-Fi' off`
end
end
# helps to open particular browser
def open(browser, url="")
case browser
when 'chrome'
`open -a '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome' #{url}`
when 'firefox'
`open -a 'Firefox' #{url}`
when 'safari'
`open -a 'Safari' #{url}`
end
end
# helps to do cleaning of browser
def cleanup(browser)
case browser
when 'chrome'
`rm -rf "#{Dir.home}/Library/Caches/Google/Chrome/Default/"`
`rm -rf "#{Dir.home}/Library/Application Support/Google/Chrome/"`
when 'firefox'
`rm -rf "#{Dir.home}/Library/Application Support/Firefox"`
`rm -Rf "#{Dir.home}/Library/Caches/Firefox"`
puts "Deletion done"
when 'safari'
`rm -Rf "#{Dir.home}/Library/Caches/Metadata/Safari"`
`rm -Rf "#{Dir.home}/Library/Caches/com.apple.Safari"`
`rm -Rf "#{Dir.home}/Library/Cookies/Cookies.binarycookies"`
end
end
# helps to close a specific browser
def close(browser)
disable_proxy # disabling proxy is part of closing process
kill_all_arg = ""
case browser
when 'chrome'
kill_all_arg = 'Google Chrome'
when 'firefox'
kill_all_arg = 'firefox'
when 'safari'
kill_all_arg = 'Safari'
end
`killall -SIGTERM #{kill_all_arg}`
end