Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions hooks/post_install.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,46 @@ function PLUGIN:PostInstall(ctx)
-- So we need to reorganize: move rootPath/* to rootPath/cmdline-tools/VERSION/

local temp_path = root_path .. "-temp"
local target_path = file.join_path(root_path, "cmdline-tools", version)
local parent_path = file.join_path(root_path, "cmdline-tools")
local target_path = file.join_path(parent_path, version)

-- Move current rootPath to temp location
os.execute("mv " .. root_path .. " " .. temp_path)
-- Cross-platform file operations (works on Unix and Windows)
local win = RUNTIME.osType == "windows"
local cmd = require("cmd")

-- Recreate rootPath with proper structure
os.execute("mkdir -p " .. target_path)
-- Move current rootPath to temp location
if win then
local systemroot = os.getenv("SystemRoot") or "C:\\Windows"
cmd.exec('move "' .. root_path .. '" "' .. temp_path .. '"', {cwd = systemroot})
else
cmd.exec('mv "' .. root_path .. '" "' .. temp_path .. '"')
end

-- Move contents from temp to target
os.execute("mv " .. temp_path .. "/* " .. target_path .. "/")
-- Recreate parent_path with proper structure
if win then
local systemroot = os.getenv("SystemRoot") or "C:\\Windows"
cmd.exec('mkdir "' .. parent_path .. '"', {cwd = systemroot})
else
cmd.exec('mkdir -p "' .. parent_path .. '"')
end

-- Clean up temp
os.execute("rm -rf " .. temp_path)
-- Move temp to target
if win then
local systemroot = os.getenv("SystemRoot") or "C:\\Windows"
cmd.exec('move "' .. temp_path .. '" "' .. target_path .. '"', {cwd = systemroot})
else
cmd.exec('mv "' .. temp_path .. '" "' .. target_path .. '"')
end

-- Verify installation
local sdkmanager_path = file.join_path(target_path, "bin", "sdkmanager")
local ext = win and ".bat" or ""
local sdkmanager_path = file.join_path(target_path, "bin", "sdkmanager" .. ext)
if not file.exists(sdkmanager_path) then
error("Installation verification failed: sdkmanager not found at " .. sdkmanager_path)
end

-- Make sure binaries are executable (for Unix systems)
os.execute("chmod +x " .. file.join_path(target_path, "bin", "*") .. " 2>/dev/null || true")
if not win then
cmd.exec("chmod +x " .. file.join_path(target_path, "bin", "*") .. " 2>/dev/null || true")
end
end