diff options
| author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2015-07-18 23:56:16 +0200 |
|---|---|---|
| committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2015-07-18 23:56:16 +0200 |
| commit | 8c182d5dec64de03a8226f562b4caec49982f025 (patch) | |
| tree | 10c3fd5563eec92f01d30d07104c7ee3f62ce803 | |
| parent | c9d57bd30f07dca8ac104fdadc6486a127e8509c (diff) | |
| download | luarocks-8c182d5dec64de03a8226f562b4caec49982f025.tar.gz luarocks-8c182d5dec64de03a8226f562b4caec49982f025.tar.bz2 luarocks-8c182d5dec64de03a8226f562b4caec49982f025.zip | |
Windows installer: backup configuration files before removing installation directory
| -rw-r--r-- | install.bat | 73 |
1 files changed, 38 insertions, 35 deletions
diff --git a/install.bat b/install.bat index b9bfcb9b..398a64eb 100644 --- a/install.bat +++ b/install.bat | |||
| @@ -8,6 +8,7 @@ local vars = {} | |||
| 8 | vars.PREFIX = nil | 8 | vars.PREFIX = nil |
| 9 | vars.VERSION = "2.2" | 9 | vars.VERSION = "2.2" |
| 10 | vars.SYSCONFDIR = nil | 10 | vars.SYSCONFDIR = nil |
| 11 | vars.CONFBACKUPDIR = nil | ||
| 11 | vars.SYSCONFFILENAME = nil | 12 | vars.SYSCONFFILENAME = nil |
| 12 | vars.CONFIG_FILE = nil | 13 | vars.CONFIG_FILE = nil |
| 13 | vars.TREE_ROOT = nil | 14 | vars.TREE_ROOT = nil |
| @@ -79,7 +80,7 @@ end | |||
| 79 | 80 | ||
| 80 | local function exec(cmd) | 81 | local function exec(cmd) |
| 81 | --print(cmd) | 82 | --print(cmd) |
| 82 | local status = os.execute(cmd) | 83 | local status = os.execute("type NUL && "..cmd) |
| 83 | return (status == 0 or status == true) -- compat 5.1/5.2 | 84 | return (status == 0 or status == true) -- compat 5.1/5.2 |
| 84 | end | 85 | end |
| 85 | 86 | ||
| @@ -479,6 +480,29 @@ local function look_for_lua_install () | |||
| 479 | return false | 480 | return false |
| 480 | end | 481 | end |
| 481 | 482 | ||
| 483 | -- backup config[x.x].lua[.bak] and site_config[_x_x].lua | ||
| 484 | local function backup_config_files() | ||
| 485 | local temppath | ||
| 486 | while not temppath do | ||
| 487 | temppath = os.getenv("temp").."\\LR-config-backup-"..tostring(math.random(10000)) | ||
| 488 | if exists(temppath) then temppath = nil end | ||
| 489 | end | ||
| 490 | print("'"..temppath.."'") | ||
| 491 | vars.CONFBACKUPDIR = temppath | ||
| 492 | mkdir(vars.CONFBACKUPDIR) | ||
| 493 | exec(S[[COPY "$PREFIX\config*.*" "$CONFBACKUPDIR" >NUL]]) | ||
| 494 | exec(S[[COPY "$FULL_PREFIX\lua\luarocks\site_config*.*" "$CONFBACKUPDIR" >NUL]]) | ||
| 495 | end | ||
| 496 | |||
| 497 | -- restore previously backed up config files | ||
| 498 | local function restore_config_files() | ||
| 499 | if not vars.CONFBACKUPDIR then return end -- there is no backup to restore | ||
| 500 | exec(S[[COPY "$CONFBACKUPDIR\config*.*" "$PREFIX" >NUL]]) | ||
| 501 | exec(S[[COPY "$CONFBACKUPDIR\site_config*.*" "$FULL_PREFIX\lua\luarocks" >NUL]]) | ||
| 502 | -- cleanup | ||
| 503 | exec(S[[RD /S /Q "$CONFBACKUPDIR"]]) | ||
| 504 | vars.CONFBACKUPDIR = nil | ||
| 505 | end | ||
| 482 | 506 | ||
| 483 | -- *********************************************************** | 507 | -- *********************************************************** |
| 484 | -- Installer script start | 508 | -- Installer script start |
| @@ -664,14 +688,16 @@ print([[ | |||
| 664 | -- *********************************************************** | 688 | -- *********************************************************** |
| 665 | -- Install LuaRocks files | 689 | -- Install LuaRocks files |
| 666 | -- *********************************************************** | 690 | -- *********************************************************** |
| 667 | if FORCE then | ||
| 668 | print(S"Removing $FULL_PREFIX...") | ||
| 669 | exec(S[[RD /S /Q "$FULL_PREFIX"]]) | ||
| 670 | print() | ||
| 671 | end | ||
| 672 | 691 | ||
| 673 | if exists(vars.FULL_PREFIX) then | 692 | if exists(vars.FULL_PREFIX) then |
| 674 | die(S"$FULL_PREFIX exists. Use /F to force removal and reinstallation.") | 693 | if not FORCE then |
| 694 | die(S"$FULL_PREFIX exists. Use /F to force removal and reinstallation.") | ||
| 695 | else | ||
| 696 | backup_config_files() | ||
| 697 | print(S"Removing $FULL_PREFIX...") | ||
| 698 | exec(S[[RD /S /Q "$FULL_PREFIX"]]) | ||
| 699 | print() | ||
| 700 | end | ||
| 675 | end | 701 | end |
| 676 | 702 | ||
| 677 | print(S"Installing LuaRocks in $FULL_PREFIX...") | 703 | print(S"Installing LuaRocks in $FULL_PREFIX...") |
| @@ -776,37 +802,21 @@ exit /b %EXITCODE% | |||
| 776 | print(S"Created LuaRocks command: $BINDIR\\"..c..".bat") | 802 | print(S"Created LuaRocks command: $BINDIR\\"..c..".bat") |
| 777 | end | 803 | end |
| 778 | 804 | ||
| 779 | -- part below was commented out as its purpose was unclear | ||
| 780 | -- see https://github.com/keplerproject/luarocks/pull/197#issuecomment-30176548 | ||
| 781 | |||
| 782 | -- configure 'scripts' directory | ||
| 783 | -- if vars.TREE_BIN then | ||
| 784 | -- mkdir(vars.TREE_BIN) | ||
| 785 | -- if not USE_MINGW then | ||
| 786 | -- -- definitly not for MinGW because of conflicting runtimes | ||
| 787 | -- -- but is it ok to do it for others??? | ||
| 788 | -- exec(S[[COPY lua5.1\bin\*.dll "$TREE_BIN" >NUL]]) | ||
| 789 | -- end | ||
| 790 | -- else | ||
| 791 | -- if not USE_MINGW then | ||
| 792 | -- mkdir(S[[$TREE_ROOT\bin]]) | ||
| 793 | -- -- definitly not for MinGW because of conflicting runtimes | ||
| 794 | -- -- but is it ok to do it for others??? | ||
| 795 | -- exec(S[[COPY lua5.1\bin\*.dll "$TREE_ROOT"\bin >NUL]]) | ||
| 796 | -- end | ||
| 797 | -- end | ||
| 798 | |||
| 799 | -- *********************************************************** | 805 | -- *********************************************************** |
| 800 | -- Configure LuaRocks | 806 | -- Configure LuaRocks |
| 801 | -- *********************************************************** | 807 | -- *********************************************************** |
| 802 | 808 | ||
| 809 | restore_config_files() | ||
| 803 | print() | 810 | print() |
| 804 | print("Configuring LuaRocks...") | 811 | print("Configuring LuaRocks...") |
| 805 | 812 | ||
| 806 | -- Create a site-config file | 813 | -- Create a site-config file |
| 807 | local site_config = S("site_config_$LUA_VERSION"):gsub("%.","_") | 814 | local site_config = S("site_config_$LUA_VERSION"):gsub("%.","_") |
| 808 | if exists(S([[$LUADIR\luarocks\]]..site_config..[[.lua]])) then | 815 | if exists(S([[$LUADIR\luarocks\]]..site_config..[[.lua]])) then |
| 809 | exec(S([[RENAME "$LUADIR\luarocks\]]..site_config..[[.lua" site_config.lua.bak]])) | 816 | local nname = backup(S([[$LUADIR\luarocks\]]..site_config..[[.lua]]), site_config..".lua.bak") |
| 817 | print("***************") | ||
| 818 | print("*** WARNING *** LuaRocks site_config file already exists: '"..site_config..".lua'. The old file has been renamed to '"..nname.."'") | ||
| 819 | print("***************") | ||
| 810 | end | 820 | end |
| 811 | local f = io.open(vars.LUADIR.."\\luarocks\\"..site_config..".lua", "w") | 821 | local f = io.open(vars.LUADIR.."\\luarocks\\"..site_config..".lua", "w") |
| 812 | f:write(S[=[ | 822 | f:write(S[=[ |
| @@ -832,13 +842,6 @@ site_config.LUAROCKS_MD5CHECKER=[[md5sum]] | |||
| 832 | if FORCE_CONFIG then | 842 | if FORCE_CONFIG then |
| 833 | f:write("site_config.LUAROCKS_FORCE_CONFIG=true\n") | 843 | f:write("site_config.LUAROCKS_FORCE_CONFIG=true\n") |
| 834 | end | 844 | end |
| 835 | if exists(vars.LUADIR.."\\luarocks\\"..site_config..".lua.bak") then | ||
| 836 | for line in io.lines(vars.LUADIR.."\\luarocks\\"..site_config..".lua.bak", "r") do | ||
| 837 | f:write(line) | ||
| 838 | f:write("\n") | ||
| 839 | end | ||
| 840 | exec(S([[DEL /F /Q "$LUADIR\luarocks\]]..site_config..[[.lua.bak"]])) | ||
| 841 | end | ||
| 842 | f:write("return site_config\n") | 845 | f:write("return site_config\n") |
| 843 | f:close() | 846 | f:close() |
| 844 | print(S([[Created LuaRocks site-config file: $LUADIR\luarocks\]]..site_config..[[.lua]])) | 847 | print(S([[Created LuaRocks site-config file: $LUADIR\luarocks\]]..site_config..[[.lua]])) |
