diff options
| author | ruki <[email protected]> | 2017-09-21 00:28:19 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-09-20 20:49:57 +0800 |
| commit | 9b3dc3d2a9250be9bfde08fbd3afadd0eb406894 (patch) | |
| tree | b7d1e4c19674892aa14e6dc1867aa13eae835386 /xmake/modules/package/manager | |
| parent | 33d847860f7f963fc47286634460dc435941c1e9 (diff) | |
add root perm to apt/yum
Diffstat (limited to 'xmake/modules/package/manager')
| -rw-r--r-- | xmake/modules/package/manager/apt/install.lua | 36 | ||||
| -rw-r--r-- | xmake/modules/package/manager/pacman/install.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/package/manager/yum/install.lua | 33 |
3 files changed, 61 insertions, 10 deletions
diff --git a/xmake/modules/package/manager/apt/install.lua b/xmake/modules/package/manager/apt/install.lua index 6c36bcfb3..57bc88e94 100644 --- a/xmake/modules/package/manager/apt/install.lua +++ b/xmake/modules/package/manager/apt/install.lua @@ -25,6 +25,7 @@ -- imports import("core.base.option") import("lib.detect.find_tool") +import("privilege.sudo") -- install package -- @@ -46,13 +47,36 @@ function main(name, opt) -- init argv local argv = {"install", "-y", opt.apt or name} - if opt.verbose or option.get("verbose") then - table.insert(argv, "--verbose") - end - -- TOOD sudo - -- install package - os.vrunv(apt.program, argv) + -- install package directly if the current user is root + if os.isroot() then + os.vrunv(apt.program, argv) + -- install with administrator permission? + elseif sudo.has() then + + -- get confirm + local confirm = option.get("yes") + if confirm == nil then + + -- show tips + cprint("${bright yellow}note: ${default yellow}try to install %s with administrator permission?", name) + cprint("please input: y (y/n)") + + -- get answer + io.flush() + local answer = io.read() + if answer == 'y' or answer == '' then + confirm = true + end + end + + -- install it if be confirmed + if confirm then + sudo.vrunv(apt.program, argv) + end + else + return false + end -- ok return true diff --git a/xmake/modules/package/manager/pacman/install.lua b/xmake/modules/package/manager/pacman/install.lua index 7e449654a..95116ba45 100644 --- a/xmake/modules/package/manager/pacman/install.lua +++ b/xmake/modules/package/manager/pacman/install.lua @@ -46,7 +46,7 @@ function main(name, opt) end -- init argv - local argv = {"-S", "--noconfirm", "--needed", opt.pacman or name} + local argv = {"-Sy", "--noconfirm", "--needed", opt.pacman or name} if opt.verbose or option.get("verbose") then table.insert(argv, "--verbose") end diff --git a/xmake/modules/package/manager/yum/install.lua b/xmake/modules/package/manager/yum/install.lua index dcbffbc02..581f557e0 100644 --- a/xmake/modules/package/manager/yum/install.lua +++ b/xmake/modules/package/manager/yum/install.lua @@ -25,6 +25,7 @@ -- imports import("core.base.option") import("lib.detect.find_tool") +import("privilege.sudo") -- install package -- @@ -50,9 +51,35 @@ function main(name, opt) table.insert(argv, "--verbose") end - -- TODO sudo - -- install package - os.vrunv(yum.program, argv) + -- install package directly if the current user is root + if os.isroot() then + os.vrunv(yum.program, argv) + -- install with administrator permission? + elseif sudo.has() then + + -- get confirm + local confirm = option.get("yes") + if confirm == nil then + + -- show tips + cprint("${bright yellow}note: ${default yellow}try to install %s with administrator permission?", name) + cprint("please input: y (y/n)") + + -- get answer + io.flush() + local answer = io.read() + if answer == 'y' or answer == '' then + confirm = true + end + end + + -- install it if be confirmed + if confirm then + sudo.vrunv(yum.program, argv) + end + else + return false + end -- ok return true |
