forked from Homebrew/homebrew-cask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstaged.rb
52 lines (44 loc) · 1.47 KB
/
staged.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
module Hbc::Staged
def info_plist_file(index = 0)
index = 0 if index == :first
index = 1 if index == :second
index = -1 if index == :last
Hbc.appdir.join(@cask.artifacts[:app].to_a.at(index).first, 'Contents', 'Info.plist')
end
def plist_exec(cmd)
@command.run!('/usr/libexec/PlistBuddy', :args => ['-c', cmd, info_plist_file])
end
def plist_set(key, value)
begin
plist_exec("Set #{key} #{value}")
rescue StandardError => e
raise Hbc::CaskError.new("#{@cask.token}: 'plist_set' failed with: #{e}")
end
end
def bundle_identifier
begin
plist_exec('Print CFBundleIdentifier').stdout.chomp
rescue StandardError => e
raise Hbc::CaskError.new("#{@cask.token}: 'bundle_identifier' failed with: #{e}")
end
end
def set_permissions(paths, permissions_str)
full_paths = remove_nonexistent(paths)
return if full_paths.empty?
@command.run!('/bin/chmod', args: ['-R', '--', permissions_str] + full_paths,
sudo: true)
end
def set_ownership(paths, user: current_user, group: 'staff')
full_paths = remove_nonexistent(paths)
return if full_paths.empty?
@command.run!('/usr/sbin/chown', args: ['-R', '--', "#{user}:#{group}"] + full_paths,
sudo: true)
end
def current_user
Hbc::Utils.current_user
end
private
def remove_nonexistent(paths)
Array(paths).map { |p| Pathname(p).expand_path }.select(&:exist?)
end
end