summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-03-27 14:52:33 +0800
committerruki <[email protected]>2017-03-27 14:52:33 +0800
commit3bbd679fd2edbda30369d74a02949fd193a93211 (patch)
tree4ff12a24fe935be93c41525729f7f7ee47d09ed5
parentcbe9a6b04ec8fca881fc39d360e941bf795c86da (diff)
wrap sudo
-rw-r--r--xmake/actions/install/main.lua24
-rw-r--r--xmake/core/base/os.lua12
-rw-r--r--xmake/core/sandbox/modules/os.lua5
3 files changed, 31 insertions, 10 deletions
diff --git a/xmake/actions/install/main.lua b/xmake/actions/install/main.lua
index 2f7ca12a4..2999daa12 100644
--- a/xmake/actions/install/main.lua
+++ b/xmake/actions/install/main.lua
@@ -49,7 +49,6 @@ function main()
-- failed or not permission? request administrator permission and install it again
function (errors)
- -- TODO wrap xmake
-- init argv
local argv = {"xmake", "lua"}
for _, name in ipairs({"file", "project", "backtrace", "verbose", "quiet"}) do
@@ -66,17 +65,22 @@ function main()
-- show tips
cprint("${bright red}error: ${default red}installation failed, may permission denied!")
- cprint("${bright yellow}note: ${default yellow}try continue to install with administrator permission again?")
- cprint("please input: y (y/n)")
- -- TODO read
- -- get answer
- io.flush()
- if io._read() == 'y' then
+ -- continue to install with administrator permission?
+ if os.sudo() then
- -- TODO wrap sudo
- -- install target with administrator permission
- os.runv("sudo", argv)
+ -- show tips
+ cprint("${bright yellow}note: ${default yellow}try continue to install with administrator permission again?")
+ cprint("please input: y (y/n)")
+
+ -- TODO read
+ -- get answer
+ io.flush()
+ if io._read() == 'y' then
+
+ -- install target with administrator permission
+ os.runv(os.sudo(), argv)
+ end
end
end
}
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index cfbc00611..39be26ade 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -590,5 +590,17 @@ function os.isexec(filepath)
return os.isfile(filepath)
end
+-- get sudo program name for running program with administrator permission
+function os.sudo()
+
+ -- on windows?
+ if xmake._HOST == "windows" then
+ -- TODO
+ -- add sudo.bat
+ else
+ return "sudo"
+ end
+end
+
-- return module
return os
diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua
index 29cf115f4..15f75ae08 100644
--- a/xmake/core/sandbox/modules/os.lua
+++ b/xmake/core/sandbox/modules/os.lua
@@ -445,6 +445,11 @@ function sandbox_os.uuid(name)
return uuid
end
+-- get sudo program name for running program with administrator permission
+function sandbox_os.sudo()
+ return os.sudo()
+end
+
-- return module
return sandbox_os