-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpost_install.lua
More file actions
70 lines (59 loc) · 2.31 KB
/
post_install.lua
File metadata and controls
70 lines (59 loc) · 2.31 KB
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
--- Extension point, called after PreInstall, extracts carthage from .pkg
--- @param ctx table
--- @field ctx.rootPath string SDK installation directory
function PLUGIN:PostInstall(ctx)
local rootPath = ctx.rootPath
-- Check if we're on macOS (carthage is macOS only)
if OS_TYPE ~= "darwin" then
error("Carthage is only available for macOS")
end
-- Find the downloaded .pkg file
local find_cmd = string.format('ls "%s"/*.pkg 2>/dev/null | head -1', rootPath)
local handle = io.popen(find_cmd)
if not handle then
error("Failed to find .pkg file")
end
local pkg_path = handle:read("*l")
handle:close()
if not pkg_path or pkg_path == "" then
error("Could not find Carthage.pkg in " .. rootPath)
end
-- Clean extraction directory
local expand_dir = rootPath .. "/expanded"
os.execute(string.format('rm -rf "%s"', expand_dir))
-- Expand the .pkg file using pkgutil
local expand_cmd = string.format('pkgutil --expand "%s" "%s"', pkg_path, expand_dir)
local result = os.execute(expand_cmd)
if not result then
error("Failed to expand .pkg file")
end
-- Find the payload and extract it
-- The payload is typically in CarthageApp.pkg/Payload
local payload_dir = expand_dir .. "/CarthageApp.pkg"
local extract_cmd = string.format(
'cd "%s" && cat Payload | gunzip | cpio -id 2>/dev/null',
payload_dir
)
result = os.execute(extract_cmd)
if not result then
error("Failed to extract payload from .pkg")
end
-- Create bin directory and move carthage binary
local binDir = rootPath .. "/bin"
os.execute(string.format('mkdir -p "%s"', binDir))
local move_cmd = string.format(
'mv "%s/usr/local/bin/carthage" "%s/carthage"',
payload_dir, binDir
)
result = os.execute(move_cmd)
if not result then
error("Failed to move carthage binary to bin directory")
end
-- Make executable and remove quarantine
os.execute(string.format('chmod +x "%s/carthage"', binDir))
os.execute(string.format('xattr -d com.apple.quarantine "%s/carthage" 2>/dev/null || true', binDir))
-- Clean up
os.execute(string.format('rm -rf "%s"', expand_dir))
os.execute(string.format('rm -f "%s"', pkg_path))
print("Carthage installed successfully!")
end