diff options
Diffstat (limited to '')
-rw-r--r-- | install.bat | 122 |
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 | ||
7 | vars.PREFIX = [[C:\LuaRocks]] | 7 | vars.PREFIX = [[C:\LuaRocks]] |
8 | vars.VERSION = "2.1" | 8 | vars.VERSION = "2.1" |
9 | vars.SYSCONFDIR = [[C:\LuaRocks]] | 9 | vars.SYSCONFDIR = nil |
10 | vars.ROCKS_TREE = [[C:\LuaRocks]] | 10 | vars.ROCKS_TREE = nil |
11 | vars.SCRIPTS_DIR = nil | 11 | vars.SCRIPTS_DIR = nil |
12 | vars.LUA_INTERPRETER = nil | 12 | vars.LUA_INTERPRETER = nil |
13 | vars.LUA_PREFIX = nil | 13 | vars.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 |
89 | end | 89 | end |
90 | 90 | ||
91 | -- rename file (full path) to backup (name only), appending number if required | ||
92 | -- returns the new name (name only) | ||
93 | local 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 | ||
103 | end | ||
91 | 104 | ||
92 | -- interpolate string with values from 'vars' table | 105 | -- interpolate string with values from 'vars' table |
93 | local function S (tmpl) | 106 | local 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 |
426 | end | 437 | end |
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 |
430 | local config = {} | 445 | local config = {} |
431 | local with_arg = { -- options followed by an argument, others are flags | 446 | local with_arg = { -- options followed by an argument, others are flags |
@@ -466,7 +481,7 @@ end | |||
466 | for k,v in pairs(oarg) do if k < 1 then arg[k] = v end end -- copy 0 and negative indexes | 481 | for k,v in pairs(oarg) do if k < 1 then arg[k] = v end end -- copy 0 and negative indexes |
467 | oarg = nil | 482 | oarg = nil |
468 | 483 | ||
469 | 484 | -- build config option table with name and value elements | |
470 | local i = 1 | 485 | local i = 1 |
471 | while i <= #arg do | 486 | while 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") |
516 | end | 532 | end |
517 | 533 | ||
534 | vars.SYSCONFDIR = vars.SYSCONFDIR or vars.PREFIX | ||
535 | vars.ROCKS_TREE = vars.ROCKS_TREE or vars.PREFIX | ||
518 | vars.FULL_PREFIX = S"$PREFIX\\$VERSION" | 536 | vars.FULL_PREFIX = S"$PREFIX\\$VERSION" |
519 | vars.BINDIR = vars.FULL_PREFIX | 537 | vars.BINDIR = vars.FULL_PREFIX |
520 | vars.LIBDIR = vars.FULL_PREFIX | 538 | vars.LIBDIR = vars.FULL_PREFIX |
@@ -644,8 +662,13 @@ else | |||
644 | end | 662 | end |
645 | 663 | ||
646 | 664 | ||
665 | -- *********************************************************** | ||
666 | -- Configure LuaRocks | ||
667 | -- *********************************************************** | ||
668 | |||
647 | print() | 669 | print() |
648 | print("Configuring LuaRocks...") | 670 | print("Configuring LuaRocks...") |
671 | |||
649 | -- Create a site-config file | 672 | -- Create a site-config file |
650 | if exists(S[[$LUADIR\luarocks\site_config.lua]]) then | 673 | if 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" | |||
689 | if not exists(vars.SYSCONFDIR) then | 712 | if not exists(vars.SYSCONFDIR) then |
690 | mkdir(vars.SYSCONFDIR) | 713 | mkdir(vars.SYSCONFDIR) |
691 | end | 714 | end |
692 | if not exists(vars.CONFIG_FILE) then | 715 | if 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("***************") | ||
720 | end | ||
721 | local f = io.open(vars.CONFIG_FILE, "w") | ||
722 | f:write([=[ | ||
695 | rocks_servers = { | 723 | rocks_servers = { |
696 | [[http://luarocks.org/repositories/rocks]] | 724 | [[http://luarocks.org/repositories/rocks]] |
697 | } | 725 | } |
698 | rocks_trees = { | 726 | rocks_trees = { |
699 | ]=]) | 727 | ]=]) |
700 | if FORCE_CONFIG then | 728 | if FORCE_CONFIG then |
701 | f:write(" home..[[/luarocks]],\n") | 729 | f:write(" home..[[/luarocks]],\n") |
702 | end | 730 | end |
703 | f:write(S" [[$ROCKS_TREE]]\n") | 731 | f:write(S" [[$ROCKS_TREE]]\n") |
704 | f:write("}\n") | 732 | f:write("}\n") |
705 | if vars.SCRIPTS_DIR then | 733 | if vars.SCRIPTS_DIR then |
706 | f:write(S"scripts_dir=[[$SCRIPTS_DIR]]\n") | 734 | f:write(S"scripts_dir=[[$SCRIPTS_DIR]]\n") |
707 | end | 735 | end |
708 | f:write("variables = {\n") | 736 | f:write("variables = {\n") |
709 | if USE_MINGW and vars.LUA_RUNTIME == "MSVCRT" then | 737 | if 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") | ||
719 | else | 739 | else |
720 | print(S"LuaRocks config file already exists: $CONFIG_FILE") | 740 | f:write(" MSVCRT = '"..vars.LUA_RUNTIME.."',\n") |
721 | end | 741 | end |
742 | f:write(S" LUALIB = '$LUA_LIBNAME'\n") | ||
743 | f:write("}\n") | ||
744 | f:write("verbose = false -- set to 'true' to enable verbose output\n") | ||
745 | f:close() | ||
746 | |||
747 | print(S"Created LuaRocks config file: $CONFIG_FILE") | ||
748 | |||
722 | 749 | ||
723 | print() | 750 | print() |
724 | print("Creating rocktrees...") | 751 | print("Creating rocktrees...") |
725 | if not exists(vars.ROCKS_TREE) then | 752 | if 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"]]) |
728 | else | 755 | else |
729 | print(S[[Rocktree exists: "$ROCKS_TREE"]]) | 756 | print(S[[System rocktree exists : "$ROCKS_TREE"]]) |
730 | end | 757 | end |
731 | local APPDATA = os.getenv("APPDATA") | 758 | |
732 | if not exists(APPDATA.."\\luarocks") then | 759 | vars.LOCAL_TREE = os.getenv("APPDATA")..[[\LuaRocks]] |
733 | mkdir(APPDATA.."\\luarocks") | 760 | if 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"]]) | ||
735 | else | 763 | else |
736 | print([[Rocktree exists: "]]..APPDATA..[[\luarocks"]]) | 764 | print(S[[Local user rocktree exists : "$LOCAL_TREE"]]) |
737 | end | 765 | end |
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 | ||
760 | print(S[[ | 788 | print(S[[ |
789 | |||
761 | *** LuaRocks is installed! *** | 790 | *** LuaRocks is installed! *** |
762 | 791 | ||
763 | You may want to add the following elements to your paths; | 792 | You may want to add the following elements to your paths; |
764 | PATH : $LUA_BINDIR;$FULL_PREFIX | 793 | Lua interpreter; |
765 | LUA_PATH : $ROCKS_TREE\share\lua\$LUA_VERSION\?.lua;$ROCKS_TREE\share\lua\$LUA_VERSION\?\init.lua | 794 | PATH : $LUA_BINDIR |
766 | LUA_CPATH: $ROCKS_TREE\lib\lua\$LUA_VERSION\?.dll | 795 | PATHEXT : .LUA |
796 | LuaRocks; | ||
797 | PATH : $FULL_PREFIX | ||
798 | LUA_PATH : $FULL_PREFIX\lua\?.lua;$FULL_PREFIX\lua\?\init.lua | ||
799 | Local 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 | ||
803 | System 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 | ]]) |
769 | os.exit(0) | 809 | os.exit(0) |