From 33e0ec7be10734235c165c9777d90e28ecc0878c Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Wed, 25 Dec 2013 00:05:23 +0100 Subject: updated default system tree location to 'program files', so it is protected with admin rights. Implemented a /SELFCONTAINED installation option that makes a single directory installation --- install.bat | 66 ++++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 16 deletions(-) diff --git a/install.bat b/install.bat index f6d6f842..ed2a49ff 100644 --- a/install.bat +++ b/install.bat @@ -5,10 +5,10 @@ rem=rem --[[ local vars = {} -vars.PREFIX = os.getenv("PROGRAMFILES")..[[\LuaRocks]] +vars.PREFIX = nil vars.VERSION = "2.1" -vars.SYSCONFDIR = (os.getenv("PROGRAMDATA") or (os.getenv("ALLUSERSPROFILE")..[[\Application Data]])) .. [[\LuaRocks]] -- ALLUSERS for WinXP compat -vars.ROCKS_TREE = vars.SYSCONFDIR +vars.SYSCONFDIR = nil +vars.ROCKS_TREE = nil vars.SCRIPTS_DIR = nil vars.LUA_INTERPRETER = nil vars.LUA_PREFIX = nil @@ -26,9 +26,10 @@ local FORCE = false local FORCE_CONFIG = false local INSTALL_LUA = false local USE_MINGW = false -local REGISTRY = false +local REGISTRY = true local NOADMIN = false local PROMPT = true +local SELFCONTAINED = false --- -- Some helpers @@ -120,10 +121,19 @@ Installs LuaRocks. Configuring the destinations: /TREE [dir] Root of the local tree of installed rocks. - Default is %PROGRAMDATA%\LuaRocks + Default is %PROGRAMFILES%\LuaRocks\systree /SCRIPTS [dir] Where to install commandline scripts installed by rocks. Default is {TREE}/bin. - +/CONFIG [dir] Location where the config file should be installed. + Default is %PROGRAMFILES%\LuaRocks +/SELFCONTAINED Creates a self contained installation in a single + directory given by /P. + Sets the /TREE and /CONFIG options to the same + location as /P. And does not load registry info + with option /NOREG. The only option NOT self + contained is the user rock tree, so don't use that + if you create a self contained installation. + Configuring the Lua interpreter: /LV [version] Lua version to use; either 5.1 or 5.2. Default is 5.1 @@ -149,14 +159,12 @@ Compiler configuration: /MW Use mingw as build system instead of MSVC Other options: -/CONFIG [dir] Location where the config file should be installed. - Default is %PROGRAMDATA%\LuaRocks /FORCECONFIG Use a single config location. Do not use the LUAROCKS_CONFIG variable or the user's home directory. Useful to avoid conflicts when LuaRocks is embedded within an application. /F Remove installation directory if it already exists. -/R Load registry information to register '.rockspec' +/NOREG Do not load registry info to register '.rockspec' extension with LuaRocks commands (right-click). /NOADMIN The installer requires admin priviledges. If not available it will elevate a new process. Use this @@ -165,10 +173,6 @@ Other options: user. /Q Do not prompt for confirmation of settings -Example: -To create a self contained install use (assuming Lua is in your PATH): -INSTALL /P c:\LuaRocks /TREE c:\LuaRocks /CONFIG c:\LuaRocks - ]]) end @@ -207,8 +211,10 @@ local function parse_options(args) FORCE_CONFIG = true elseif name == "/F" then FORCE = true - elseif name == "/R" then - REGISTRY = true + elseif name == "/SELFCONTAINED" then + SELFCONTAINED = true + elseif name == "/NOREG" then + REGISTRY = false elseif name == "/NOADMIN" then NOADMIN = true elseif name == "/Q" then @@ -221,6 +227,14 @@ end -- check for combination/required flags local function check_flags() + if SELFCONTAINED then + if not vars.PREFIX then + die("Option /P is required when using /SELFCONTAINED") + end + if vars.SYSCONFDIR or vars.ROCKS_TREE or vars.SCRIPTS_DIR then + die("Cannot combine /TREE, /SCRIPTS or /CONFIG with /SELFCONTAINED") + end + end if INSTALL_LUA then if vars.LUA_INCDIR or vars.LUA_BINDIR or vars.LUA_LIBDIR or vars.LUA_PREFIX then die("Cannot combine option /L with any of /LUA /BIN /LIB /INC") @@ -536,6 +550,7 @@ else print("Admin priviledges available for installing") end +vars.PREFIX = vars.PREFIX or os.getenv("PROGRAMFILES")..[[\LuaRocks]] vars.FULL_PREFIX = S"$PREFIX\\$VERSION" vars.BINDIR = vars.FULL_PREFIX vars.LIBDIR = vars.FULL_PREFIX @@ -561,15 +576,34 @@ else vars.UNAME_M = get_architecture() -- can only do when installation was found end +local datapath +if vars.UNAME_M == "x86" then + datapath = os.getenv("PROGRAMFILES") .. [[\LuaRocks]] +else + -- our target interpreter is 64bit, so the tree (with binaries) should go into 64bit program files + datapath = os.getenv("ProgramW6432") .. [[\LuaRocks]] +end +vars.SYSCONFDIR = vars.SYSCONDFIR or datapath +vars.ROCKS_TREE = vars.ROCKS_TREE or datapath..[[\systree]] +if SELFCONTAINED then + vars.SYSCONFDIR = vars.PREFIX + vars.ROCKS_TREE = vars.PREFIX..[[\systree]] + REGISTRY = false +end + print(S[[ Will configure LuaRocks with the following paths: LuaRocks : $FULL_PREFIX +Config file : $SYSCONFDIR\config.lua +Rocktree : $ROCKS_TREE + Lua interpreter: $LUA_BINDIR\$LUA_INTERPRETER binaries : $LUA_BINDIR libraries : $LUA_LIBDIR includes : $LUA_INCDIR -Binaries will be linked against: $LUA_LIBNAME with runtime $LUA_RUNTIME + +Binaries will be linked against: $LUA_LIBNAME with runtime $LUA_RUNTIME.dll System architecture detected as: $UNAME_M ]]) -- cgit v1.2.3-55-g6feb From e4760c86b1a0a90e13017a1f3057216d87595ccf Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Wed, 25 Dec 2013 00:30:20 +0100 Subject: specify error exitcodes, specifically 'permission denied'. --- src/luarocks/build.lua | 2 +- src/luarocks/cfg.lua | 17 ++++++++++++++++- src/luarocks/command_line.lua | 11 ++++++----- src/luarocks/install.lua | 2 +- src/luarocks/make.lua | 2 +- src/luarocks/remove.lua | 2 +- 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index 5555d94a..cee65781 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua @@ -364,7 +364,7 @@ function run(...) return pack.pack_binary_rock(name, version, do_build, name, version, deps.get_deps_mode(flags)) else local ok, err = fs.check_command_permissions(flags) - if not ok then return nil, err end + if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end ok, err = do_build(name, version, deps.get_deps_mode(flags)) if not ok then return nil, err end local name, version = ok, err diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 2904146b..87777b86 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -35,6 +35,21 @@ major_version = program_version:match("([^.]%.[^.])") local persist = require("luarocks.persist") +_M.errorcodes = setmetatable({ + OK = 0, + UNSPECIFIED = 1, + PERMISSIONDENIED = 2, +},{ + __index = function(t, key) + local val = rawget(t, key) + if not val then + error("'"..tostring(key).."' is not a valid errorcode", 2) + end + return val + end +}) + + local popen_ok, popen_result = pcall(io.popen, "") if popen_ok then if popen_result then @@ -43,7 +58,7 @@ if popen_ok then else io.stderr:write("Your version of Lua does not support io.popen,\n") io.stderr:write("which is required by LuaRocks. Please check your Lua installation.\n") - os.exit(1) + os.exit(_M.errorcodes.UNSPECIFIED) end -- System detection: diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index b98084e0..e79b1442 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua @@ -12,7 +12,8 @@ local program = util.this_program("luarocks") --- Display an error message and exit. -- @param message string: The error message. -local function die(message) +-- @param exitcode number: the exitcode to use +local function die(message, exitcode) assert(type(message) == "string") local ok, err = pcall(util.run_scheduled_functions) @@ -20,7 +21,7 @@ local function die(message) util.printerr("\nLuaRocks "..cfg.program_version.." internal bug (please report at luarocks-developers@lists.sourceforge.net):\n"..err) end util.printerr("\nError: "..message) - os.exit(1) + os.exit(exitcode or cfg.errorcodes.UNSPECIFIED) end local function replace_tree(flags, args, tree) @@ -83,7 +84,7 @@ function run_command(...) util.printout(program.." "..cfg.program_version) util.printout(program_description) util.printout() - os.exit(0) + os.exit(cfg.errorcodes.OK) elseif flags["help"] or #nonflags == 0 then command = "help" args = nonflags @@ -184,13 +185,13 @@ function run_command(...) -- I'm not changing this now to avoid messing with the run() -- interface, which I know some people use (even though -- I never published it as a public API...) - local xp, ok, err = xpcall(function() return commands[command].run(unpack(args)) end, function(err) + local xp, ok, err, exitcode = xpcall(function() return commands[command].run(unpack(args)) end, function(err) die(debug.traceback("LuaRocks "..cfg.program_version .." bug (please report at luarocks-developers@lists.sourceforge.net).\n" ..err, 2)) end) if xp and (not ok) then - die(err) + die(err, exitcode) end else die("Unknown command: "..command) diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua index c181d612..041d8ca2 100644 --- a/src/luarocks/install.lua +++ b/src/luarocks/install.lua @@ -129,7 +129,7 @@ function run(...) end local ok, err = fs.check_command_permissions(flags) - if not ok then return nil, err end + if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end if name:match("%.rockspec$") or name:match("%.src%.rock$") then util.printout("Using "..name.."... switching to 'build' mode") diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua index eef49d0c..aff4f93c 100644 --- a/src/luarocks/make.lua +++ b/src/luarocks/make.lua @@ -73,7 +73,7 @@ function run(...) return pack.pack_binary_rock(rspec.name, rspec.version, build.build_rockspec, rockspec, false, true, deps.get_deps_mode(flags)) else local ok, err = fs.check_command_permissions(flags) - if not ok then return nil, err end + if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end ok, err = build.build_rockspec(rockspec, false, true, deps.get_deps_mode(flags)) if not ok then return nil, err end local name, version = ok, err diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua index 5a6e4dc5..9ab6d11f 100644 --- a/src/luarocks/remove.lua +++ b/src/luarocks/remove.lua @@ -144,7 +144,7 @@ function run(...) local deps_mode = flags["deps-mode"] or cfg.deps_mode local ok, err = fs.check_command_permissions(flags) - if not ok then return nil, err end + if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end local rock_type = name:match("%.(rock)$") or name:match("%.(rockspec)$") local filename = name -- cgit v1.2.3-55-g6feb From 57c4c60f352c0bbecdb28b0f5c27831b48f653a2 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Thu, 26 Dec 2013 09:31:09 +0100 Subject: updated comments for exitcodes batch wrapper script (luarocks.bat) updated to auto-elevate if permission was denied --- install.bat | 54 +++++++++++++++++++++++++++++++++++++++++++++++- src/luarocks/build.lua | 4 ++-- src/luarocks/install.lua | 4 ++-- src/luarocks/make.lua | 4 ++-- src/luarocks/remove.lua | 4 ++-- 5 files changed, 61 insertions(+), 9 deletions(-) diff --git a/install.bat b/install.bat index ed2a49ff..03ec7c94 100644 --- a/install.bat +++ b/install.bat @@ -519,6 +519,14 @@ end print(S"LuaRocks $VERSION.x installer.\n") +print([[ + +======================== +== Checking system... == +======================== + +]]) + parse_options(config) check_flags() @@ -593,6 +601,10 @@ end print(S[[ +========================== +== System check results == +========================== + Will configure LuaRocks with the following paths: LuaRocks : $FULL_PREFIX Config file : $SYSCONFDIR\config.lua @@ -613,6 +625,14 @@ if PROMPT then io.read() end +print([[ + +============================ +== Installing LuaRocks... == +============================ + +]]) + -- *********************************************************** -- Install LuaRocks files -- *********************************************************** @@ -680,6 +700,35 @@ IF NOT "%LUA_PATH_5_2%"=="" ( ) SET "PATH=$BINDIR;%PATH%" "$LUA_INTERPRETER" "$BINDIR\]]..c..[[.lua" %* +IF NOT "%ERRORLEVEL%"=="2" GOTO EXITLR + +REM Permission denied error, try and auto elevate... +REM already an admin? (checking to prevent loops) +NET SESSION >NUL 2>&1 +IF "%ERRORLEVEL%"=="0" GOTO EXITLR + +REM Do we have PowerShell available? +PowerShell /? >NUL 2>&1 +IF NOT "%ERRORLEVEL%"=="0" GOTO EXITLR + +:GETTEMPNAME +SET TMPFILE=%TEMP%\LuaRocks-Elevator-%RANDOM%.bat +IF EXIST "%TMPFILE%" GOTO :GETTEMPNAME + +ECHO @ECHO OFF > "%TMPFILE%" +ECHO CHDIR /D %CD% >> "%TMPFILE%" +ECHO ECHO %0 %* >> "%TMPFILE%" +ECHO ECHO. >> "%TMPFILE%" +ECHO CALL %0 %* >> "%TMPFILE%" +ECHO ECHO. >> "%TMPFILE%" +ECHO ECHO Press any key to close this window... >> "%TMPFILE%" +ECHO PAUSE ^> NUL >> "%TMPFILE%" +ECHO DEL "%TMPFILE%" >> "%TMPFILE%" + +ECHO Now trying to run again elevated... +PowerShell -Command (New-Object -com 'Shell.Application').ShellExecute('%TMPFILE%', '', '', 'runas') + +:EXITLR ENDLOCAL ]]) f:close() @@ -833,7 +882,10 @@ exec( S[[del "$FULL_PREFIX\pe-parser.lua" >NUL]] ) print(S[[ -*** LuaRocks is installed! *** +============================ +== LuaRocks is installed! == +============================ + You may want to add the following elements to your paths; Lua interpreter; diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index cee65781..ec269023 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua @@ -351,8 +351,8 @@ end -- if returned a result, installs the matching rock. -- @param version string: When passing a package name, a version number may -- also be given. --- @return boolean or (nil, string): True if build was successful; nil and an --- error message otherwise. +-- @return boolean or (nil, string, exitcode): True if build was successful; nil and an +-- error message otherwise. exitcode is optionally returned. function run(...) local flags, name, version = util.parse_flags(...) if type(name) ~= "string" then diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua index 041d8ca2..b28e6282 100644 --- a/src/luarocks/install.lua +++ b/src/luarocks/install.lua @@ -120,8 +120,8 @@ end -- if returned a result, installs the matching rock. -- @param version string: When passing a package name, a version number -- may also be given. --- @return boolean or (nil, string): True if installation was --- successful, nil and an error message otherwise. +-- @return boolean or (nil, string, exitcode): True if installation was +-- successful, nil and an error message otherwise. exitcode is optionally returned. function run(...) local flags, name, version = util.parse_flags(...) if type(name) ~= "string" then diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua index aff4f93c..3999e39f 100644 --- a/src/luarocks/make.lua +++ b/src/luarocks/make.lua @@ -40,8 +40,8 @@ To install rocks, you'll normally want to use the "install" and --- Driver function for "make" command. -- @param name string: A local rockspec. --- @return boolean or (nil, string): True if build was successful; nil and an --- error message otherwise. +-- @return boolean or (nil, string, exitcode): True if build was successful; nil and an +-- error message otherwise. exitcode is optionally returned. function run(...) local flags, rockspec = util.parse_flags(...) assert(type(rockspec) == "string" or not rockspec) diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua index 9ab6d11f..f2f6997b 100644 --- a/src/luarocks/remove.lua +++ b/src/luarocks/remove.lua @@ -132,8 +132,8 @@ end -- a specific version; otherwise, try to remove all versions. -- @param version string: When passing a package name, a version number -- may also be given. --- @return boolean or (nil, string): True if removal was --- successful, nil and an error message otherwise. +-- @return boolean or (nil, string, exitcode): True if removal was +-- successful, nil and an error message otherwise. exitcode is optionally returned. function run(...) local flags, name, version = util.parse_flags(...) -- cgit v1.2.3-55-g6feb