aboutsummaryrefslogtreecommitdiff
path: root/install.bat
diff options
context:
space:
mode:
Diffstat (limited to 'install.bat')
-rw-r--r--install.bat41
1 files changed, 41 insertions, 0 deletions
diff --git a/install.bat b/install.bat
index a4257be6..26255502 100644
--- a/install.bat
+++ b/install.bat
@@ -27,6 +27,7 @@ local FORCE_CONFIG = false
27local INSTALL_LUA = false 27local INSTALL_LUA = false
28local USE_MINGW = false 28local USE_MINGW = false
29local REGISTRY = false 29local REGISTRY = false
30local NOADMIN = false
30 31
31--- 32---
32-- Some helpers 33-- Some helpers
@@ -82,6 +83,12 @@ local function mkdir (dir)
82 return exec([[.\bin\bin\mkdir -p "]]..dir..[[" >NUL]]) 83 return exec([[.\bin\bin\mkdir -p "]]..dir..[[" >NUL]])
83end 84end
84 85
86-- does the current user have admin priviledges ( = elevated)
87local function permission()
88 return exec("net session >nul 2>&1") -- fails if not admin
89end
90
91
85-- interpolate string with values from 'vars' table 92-- interpolate string with values from 'vars' table
86local function S (tmpl) 93local function S (tmpl)
87 return (tmpl:gsub('%$([%a_][%w_]*)', vars)) 94 return (tmpl:gsub('%$([%a_][%w_]*)', vars))
@@ -136,6 +143,11 @@ Other options:
136/F Remove installation directory if it already exists. 143/F Remove installation directory if it already exists.
137/R Load registry information to register '.rockspec' 144/R Load registry information to register '.rockspec'
138 extension with LuaRocks commands (right-click). 145 extension with LuaRocks commands (right-click).
146/NOADMIN The installer requires admin priviledges. If not
147 available it will elevate a new process. Use this
148 switch to prevent elevation, but make sure the
149 destination paths are all accessible for the current
150 user.
139 151
140]]) 152]])
141end 153end
@@ -180,6 +192,8 @@ local function parse_options(args)
180 FORCE = true 192 FORCE = true
181 elseif name == "/R" then 193 elseif name == "/R" then
182 REGISTRY = true 194 REGISTRY = true
195 elseif name == "/NOADMIN" then
196 NOADMIN = true
183 else 197 else
184 die("Unrecognized option: " .. name) 198 die("Unrecognized option: " .. name)
185 end 199 end
@@ -427,6 +441,7 @@ local with_arg = { -- options followed by an argument, others are flags
427} 441}
428-- reconstruct argument values with spaces and double quotes 442-- reconstruct argument values with spaces and double quotes
429-- this will be damaged by the batch construction at the start of this file 443-- this will be damaged by the batch construction at the start of this file
444local oarg = arg -- retain old table
430if #arg > 0 then 445if #arg > 0 then
431 farg = table.concat(arg, " ") .. " " 446 farg = table.concat(arg, " ") .. " "
432 arg = {} 447 arg = {}
@@ -448,6 +463,9 @@ if #arg > 0 then
448 while farg:sub(1,1) == " " do farg = farg:sub(2,-1) end -- remove prefix spaces 463 while farg:sub(1,1) == " " do farg = farg:sub(2,-1) end -- remove prefix spaces
449 end 464 end
450end 465end
466for k,v in pairs(oarg) do if k < 1 then arg[k] = v end end -- copy 0 and negative indexes
467oarg = nil
468
451 469
452local i = 1 470local i = 1
453while i <= #arg do 471while i <= #arg do
@@ -470,6 +488,29 @@ print(S"LuaRocks $VERSION.x installer.\n")
470parse_options(config) 488parse_options(config)
471check_flags() 489check_flags()
472 490
491if not permission() then
492 if not NOADMIN then
493 -- must elevate the process with admin priviledges
494 print("Need admin priviledges, now elevating a new process to continue installing...")
495 local runner = os.getenv("TEMP").."\\".."LuaRocks_Installer.bat"
496 local f = io.open(runner, "w")
497 f:write("@echo off\n")
498 f:write("CHDIR /D "..arg[0]:match("(.+)%\\.-$").."\n") -- return to current die, elevation changes current path
499 f:write('"'..arg[-1]..'" "'..table.concat(arg, '" "', 0)..'"\n')
500 f:write("ECHO Press any key to close this window...\n")
501 f:write("PAUSE > NUL\n")
502 f:close()
503 -- run the created temp batch file in elevated mode
504 exec("PowerShell -Command (New-Object -com 'Shell.Application').ShellExecute('"..runner.."', '', '', 'runas')\n")
505 print("Now exiting unpriviledged installer")
506 os.exit() -- exit here, the newly created elevated process will do the installing
507 else
508 print("Attempting to install without admin priviledges...")
509 end
510else
511 print("Admin priviledges available for installing")
512end
513
473vars.FULL_PREFIX = S"$PREFIX\\$VERSION" 514vars.FULL_PREFIX = S"$PREFIX\\$VERSION"
474vars.BINDIR = vars.FULL_PREFIX 515vars.BINDIR = vars.FULL_PREFIX
475vars.LIBDIR = vars.FULL_PREFIX 516vars.LIBDIR = vars.FULL_PREFIX