aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--install.bat122
1 files changed, 81 insertions, 41 deletions
diff --git a/install.bat b/install.bat
index 11558f7f..8373f856 100644
--- a/install.bat
+++ b/install.bat
@@ -6,8 +6,8 @@ local vars = {}
6 6
7vars.PREFIX = [[C:\LuaRocks]] 7vars.PREFIX = [[C:\LuaRocks]]
8vars.VERSION = "2.1" 8vars.VERSION = "2.1"
9vars.SYSCONFDIR = [[C:\LuaRocks]] 9vars.SYSCONFDIR = nil
10vars.ROCKS_TREE = [[C:\LuaRocks]] 10vars.ROCKS_TREE = nil
11vars.SCRIPTS_DIR = nil 11vars.SCRIPTS_DIR = nil
12vars.LUA_INTERPRETER = nil 12vars.LUA_INTERPRETER = nil
13vars.LUA_PREFIX = nil 13vars.LUA_PREFIX = nil
@@ -88,6 +88,19 @@ local function permission()
88 return exec("net session >nul 2>&1") -- fails if not admin 88 return exec("net session >nul 2>&1") -- fails if not admin
89end 89end
90 90
91-- rename file (full path) to backup (name only), appending number if required
92-- returns the new name (name only)
93local function backup(filename, backupname)
94 local path = filename:match("(.+)%\\.-$").."\\"
95 local nname = backupname
96 local i = 0
97 while exists(path..nname) do
98 i = i + 1
99 nname = backupname..tostring(i)
100 end
101 exec([[REN "]]..filename..[[" "]]..nname..[[" > NUL]])
102 return nname
103end
91 104
92-- interpolate string with values from 'vars' table 105-- interpolate string with values from 'vars' table
93local function S (tmpl) 106local function S (tmpl)
@@ -163,8 +176,6 @@ local function parse_options(args)
163 os.exit(0) 176 os.exit(0)
164 elseif name == "/P" then 177 elseif name == "/P" then
165 vars.PREFIX = option.value 178 vars.PREFIX = option.value
166 vars.SYSCONFDIR = option.value
167 vars.ROCKS_TREE = option.value
168 P_SET = true 179 P_SET = true
169 elseif name == "/CONFIG" then 180 elseif name == "/CONFIG" then
170 vars.SYSCONFDIR = option.value 181 vars.SYSCONFDIR = option.value
@@ -425,7 +436,11 @@ local function look_for_lua_install ()
425 return false 436 return false
426end 437end
427 438
428--- 439
440-- ***********************************************************
441-- Installer script start
442-- ***********************************************************
443
429-- Poor man's command-line parsing 444-- Poor man's command-line parsing
430local config = {} 445local config = {}
431local with_arg = { -- options followed by an argument, others are flags 446local with_arg = { -- options followed by an argument, others are flags
@@ -466,7 +481,7 @@ end
466for k,v in pairs(oarg) do if k < 1 then arg[k] = v end end -- copy 0 and negative indexes 481for k,v in pairs(oarg) do if k < 1 then arg[k] = v end end -- copy 0 and negative indexes
467oarg = nil 482oarg = nil
468 483
469 484-- build config option table with name and value elements
470local i = 1 485local i = 1
471while i <= #arg do 486while i <= #arg do
472 local opt = arg[i] 487 local opt = arg[i]
@@ -499,10 +514,11 @@ if not permission() then
499 local runner = os.getenv("TEMP").."\\".."LuaRocks_Installer.bat" 514 local runner = os.getenv("TEMP").."\\".."LuaRocks_Installer.bat"
500 local f = io.open(runner, "w") 515 local f = io.open(runner, "w")
501 f:write("@echo off\n") 516 f:write("@echo off\n")
502 f:write("CHDIR /D "..arg[0]:match("(.+)%\\.-$").."\n") -- return to current die, elevation changes current path 517 f:write("CHDIR /D "..arg[0]:match("(.+)%\\.-$").."\n") -- return to current dir, elevation changes current path
503 f:write('"'..arg[-1]..'" "'..table.concat(arg, '" "', 0)..'"\n') 518 f:write('"'..arg[-1]..'" "'..table.concat(arg, '" "', 0)..'"\n')
504 f:write("ECHO Press any key to close this window...\n") 519 f:write("ECHO Press any key to close this window...\n")
505 f:write("PAUSE > NUL\n") 520 f:write("PAUSE > NUL\n")
521 f:write('DEL "'..runner..'"') -- temp batch file deletes itself
506 f:close() 522 f:close()
507 -- run the created temp batch file in elevated mode 523 -- run the created temp batch file in elevated mode
508 exec("PowerShell -Command (New-Object -com 'Shell.Application').ShellExecute('"..runner.."', '', '', 'runas')\n") 524 exec("PowerShell -Command (New-Object -com 'Shell.Application').ShellExecute('"..runner.."', '', '', 'runas')\n")
@@ -515,6 +531,8 @@ else
515 print("Admin priviledges available for installing") 531 print("Admin priviledges available for installing")
516end 532end
517 533
534vars.SYSCONFDIR = vars.SYSCONFDIR or vars.PREFIX
535vars.ROCKS_TREE = vars.ROCKS_TREE or vars.PREFIX
518vars.FULL_PREFIX = S"$PREFIX\\$VERSION" 536vars.FULL_PREFIX = S"$PREFIX\\$VERSION"
519vars.BINDIR = vars.FULL_PREFIX 537vars.BINDIR = vars.FULL_PREFIX
520vars.LIBDIR = vars.FULL_PREFIX 538vars.LIBDIR = vars.FULL_PREFIX
@@ -644,8 +662,13 @@ else
644end 662end
645 663
646 664
665-- ***********************************************************
666-- Configure LuaRocks
667-- ***********************************************************
668
647print() 669print()
648print("Configuring LuaRocks...") 670print("Configuring LuaRocks...")
671
649-- Create a site-config file 672-- Create a site-config file
650if exists(S[[$LUADIR\luarocks\site_config.lua]]) then 673if exists(S[[$LUADIR\luarocks\site_config.lua]]) then
651 exec(S[[RENAME "$LUADIR\luarocks\site_config.lua" site_config.lua.bak]]) 674 exec(S[[RENAME "$LUADIR\luarocks\site_config.lua" site_config.lua.bak]])
@@ -689,51 +712,56 @@ vars.CONFIG_FILE = vars.SYSCONFDIR.."\\config.lua"
689if not exists(vars.SYSCONFDIR) then 712if not exists(vars.SYSCONFDIR) then
690 mkdir(vars.SYSCONFDIR) 713 mkdir(vars.SYSCONFDIR)
691end 714end
692if not exists(vars.CONFIG_FILE) then 715if exists(vars.CONFIG_FILE) then
693 local f = io.open(vars.CONFIG_FILE, "w") 716 local nname = backup(vars.CONFIG_FILE, "config.bak")
694 f:write([=[ 717 print("***************")
718 print(S"*** WARNING *** LuaRocks config file already exists: '$CONFIG_FILE'. The old file has been renamed to '"..nname.."'")
719 print("***************")
720end
721local f = io.open(vars.CONFIG_FILE, "w")
722f:write([=[
695rocks_servers = { 723rocks_servers = {
696 [[http://luarocks.org/repositories/rocks]] 724 [[http://luarocks.org/repositories/rocks]]
697} 725}
698rocks_trees = { 726rocks_trees = {
699]=]) 727]=])
700 if FORCE_CONFIG then 728if FORCE_CONFIG then
701 f:write(" home..[[/luarocks]],\n") 729 f:write(" home..[[/luarocks]],\n")
702 end 730end
703 f:write(S" [[$ROCKS_TREE]]\n") 731f:write(S" [[$ROCKS_TREE]]\n")
704 f:write("}\n") 732f:write("}\n")
705 if vars.SCRIPTS_DIR then 733if vars.SCRIPTS_DIR then
706 f:write(S"scripts_dir=[[$SCRIPTS_DIR]]\n") 734 f:write(S"scripts_dir=[[$SCRIPTS_DIR]]\n")
707 end 735end
708 f:write("variables = {\n") 736f:write("variables = {\n")
709 if USE_MINGW and vars.LUA_RUNTIME == "MSVCRT" then 737if USE_MINGW and vars.LUA_RUNTIME == "MSVCRT" then
710 f:write(" MSVCRT = 'm', -- make MinGW use MSVCRT.DLL as runtime\n") 738 f:write(" MSVCRT = 'm', -- make MinGW use MSVCRT.DLL as runtime\n")
711 else
712 f:write(" MSVCRT = '"..vars.LUA_RUNTIME.."',\n")
713 end
714 f:write(S" LUALIB = '$LUA_LIBNAME'\n")
715 f:write("}\n")
716 f:write("verbose = false -- set to 'true' to enable verbose output\n")
717 f:close()
718 print(S"Created LuaRocks config file: $CONFIG_FILE")
719else 739else
720 print(S"LuaRocks config file already exists: $CONFIG_FILE") 740 f:write(" MSVCRT = '"..vars.LUA_RUNTIME.."',\n")
721end 741end
742f:write(S" LUALIB = '$LUA_LIBNAME'\n")
743f:write("}\n")
744f:write("verbose = false -- set to 'true' to enable verbose output\n")
745f:close()
746
747print(S"Created LuaRocks config file: $CONFIG_FILE")
748
722 749
723print() 750print()
724print("Creating rocktrees...") 751print("Creating rocktrees...")
725if not exists(vars.ROCKS_TREE) then 752if not exists(vars.ROCKS_TREE) then
726 mkdir(vars.ROCKS_TREE) 753 mkdir(vars.ROCKS_TREE)
727 print(S[[Created rocktree: "$ROCKS_TREE"]]) 754 print(S[[Created system rocktree : "$ROCKS_TREE"]])
728else 755else
729 print(S[[Rocktree exists: "$ROCKS_TREE"]]) 756 print(S[[System rocktree exists : "$ROCKS_TREE"]])
730end 757end
731local APPDATA = os.getenv("APPDATA") 758
732if not exists(APPDATA.."\\luarocks") then 759vars.LOCAL_TREE = os.getenv("APPDATA")..[[\LuaRocks]]
733 mkdir(APPDATA.."\\luarocks") 760if not exists(vars.LOCAL_TREE) then
734 print([[Created rocktree: "]]..APPDATA..[[\luarocks"]]) 761 mkdir(vars.LOCAL_TREE)
762 print(S[[Created local user rocktree: "$LOCAL_TREE"]])
735else 763else
736 print([[Rocktree exists: "]]..APPDATA..[[\luarocks"]]) 764 print(S[[Local user rocktree exists : "$LOCAL_TREE"]])
737end 765end
738 766
739-- Load registry information 767-- Load registry information
@@ -758,12 +786,24 @@ exec( S[[del "$FULL_PREFIX\pe-parser.lua" > nul]] )
758-- *********************************************************** 786-- ***********************************************************
759 787
760print(S[[ 788print(S[[
789
761*** LuaRocks is installed! *** 790*** LuaRocks is installed! ***
762 791
763 You may want to add the following elements to your paths; 792You may want to add the following elements to your paths;
764PATH : $LUA_BINDIR;$FULL_PREFIX 793Lua interpreter;
765LUA_PATH : $ROCKS_TREE\share\lua\$LUA_VERSION\?.lua;$ROCKS_TREE\share\lua\$LUA_VERSION\?\init.lua 794 PATH : $LUA_BINDIR
766LUA_CPATH: $ROCKS_TREE\lib\lua\$LUA_VERSION\?.dll 795 PATHEXT : .LUA
796LuaRocks;
797 PATH : $FULL_PREFIX
798 LUA_PATH : $FULL_PREFIX\lua\?.lua;$FULL_PREFIX\lua\?\init.lua
799Local user rocktree (Note: %APPDATA% is user dependent);
800 PATH : %APPDATA%\LuaRock\bin
801 LUA_PATH : %APPDATA%\LuaRocks\share\lua\$LUA_VERSION\?.lua;%APPDATA%\LuaRocks\share\lua\$LUA_VERSION\?\init.lua
802 LUA_CPATH: %APPDATA%\LuaRocks\lib\lua\$LUA_VERSION\?.dll
803System rocktree
804 PATH : $ROCKS_TREE\bin
805 LUA_PATH : $ROCKS_TREE\share\lua\$LUA_VERSION\?.lua;$ROCKS_TREE\share\lua\$LUA_VERSION\?\init.lua
806 LUA_CPATH: $ROCKS_TREE\lib\lua\$LUA_VERSION\?.dll
767 807
768]]) 808]])
769os.exit(0) 809os.exit(0)