From 4389f277d6cf2180640575f40042d7487d81352b Mon Sep 17 00:00:00 2001 From: kytv Date: Fri, 28 Dec 2012 20:59:17 +0000 Subject: [PATCH] * windows installer fixes / improvements - move deprecated installer-only classes (Exec, Delete, and Copy) from i2p.jar into installer/ - replace installer/resources/fixpaths.cmd with an improved method in java - combine the installer-only utility classes into a single jar and call the classes from within izpack --- build.xml | 39 +-- core/java/src/net/i2p/util/Delete.java | 12 - installer/install.xml | 246 ++++++++++++------ installer/java/build.xml | 72 +++++ .../java/src/net/i2p/installer}/Copy.java | 6 +- .../java/src/net/i2p/installer/Delete.java | 15 ++ .../java/src/net/i2p/installer}/Exec.java | 4 +- .../src/net/i2p/installer/FixWinPaths.java | 89 +++++++ installer/resources/fixpaths.cmd | 39 --- installer/resources/postinstall.sh | 2 +- installer/resources/wrapper.config | 1 - 11 files changed, 350 insertions(+), 175 deletions(-) delete mode 100644 core/java/src/net/i2p/util/Delete.java create mode 100644 installer/java/build.xml rename {core/java/src/net/i2p/util => installer/java/src/net/i2p/installer}/Copy.java (58%) create mode 100644 installer/java/src/net/i2p/installer/Delete.java rename {core/java/src/net/i2p/util => installer/java/src/net/i2p/installer}/Exec.java (86%) create mode 100644 installer/java/src/net/i2p/installer/FixWinPaths.java delete mode 100644 installer/resources/fixpaths.cmd diff --git a/build.xml b/build.xml index a2f41cb93..16f6c9fa5 100644 --- a/build.xml +++ b/build.xml @@ -620,6 +620,7 @@ + @@ -802,7 +803,6 @@ - @@ -1154,40 +1154,11 @@ basedir="${basedir}/installer/lib/izpack/patches" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + - - + + @@ -112,15 +112,12 @@ - - - - - - + + + + @@ -138,88 +135,170 @@ - - - SYSTEM_sun_arch_data_model - 64 - - + + + SYSTEM_sun_arch_data_model + 64 + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + - - + + + + + + + + + + + + @@ -231,10 +310,6 @@ removed when uninstalling. --> - - - - @@ -253,3 +328,6 @@ + diff --git a/installer/java/build.xml b/installer/java/build.xml new file mode 100644 index 000000000..458299bae --- /dev/null +++ b/installer/java/build.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/java/src/net/i2p/util/Copy.java b/installer/java/src/net/i2p/installer/Copy.java similarity index 58% rename from core/java/src/net/i2p/util/Copy.java rename to installer/java/src/net/i2p/installer/Copy.java index efc8e80b3..49fa2c6d6 100644 --- a/core/java/src/net/i2p/util/Copy.java +++ b/installer/java/src/net/i2p/installer/Copy.java @@ -1,9 +1,11 @@ -package net.i2p.util; +package net.i2p.installer; + +import net.i2p.util.FileUtil; /** * Usage: Copy from to * - * @deprecated only for use by installer, to be removed from i2p.jar, use FileUtil.copy() + * only for use by installer */ public class Copy { public static void main(String args[]) { diff --git a/installer/java/src/net/i2p/installer/Delete.java b/installer/java/src/net/i2p/installer/Delete.java new file mode 100644 index 000000000..afc9f78a9 --- /dev/null +++ b/installer/java/src/net/i2p/installer/Delete.java @@ -0,0 +1,15 @@ +package net.i2p.installer; + +import net.i2p.util.FileUtil; + +/** + * Usage: Delete name + * + * only for use by installer + */ +public class Delete { + public static void main(String args[]) { + for(int file=0; file < args.length; file++) + FileUtil.rmdir(args[file], false); + } +} diff --git a/core/java/src/net/i2p/util/Exec.java b/installer/java/src/net/i2p/installer/Exec.java similarity index 86% rename from core/java/src/net/i2p/util/Exec.java rename to installer/java/src/net/i2p/installer/Exec.java index d805ed96f..83d9accce 100644 --- a/core/java/src/net/i2p/util/Exec.java +++ b/installer/java/src/net/i2p/installer/Exec.java @@ -1,11 +1,11 @@ -package net.i2p.util; +package net.i2p.installer; import java.io.File; /** * Usage: Exec dir command [args ...] * - * @deprecated only for use by installer, to be removed from i2p.jar, use ShellCommand + * only for use by installer */ public class Exec { public static void main(String args[]) { diff --git a/installer/java/src/net/i2p/installer/FixWinPaths.java b/installer/java/src/net/i2p/installer/FixWinPaths.java new file mode 100644 index 000000000..503f688fc --- /dev/null +++ b/installer/java/src/net/i2p/installer/FixWinPaths.java @@ -0,0 +1,89 @@ +package net.i2p.installer; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.PrintStream; + + +/** + * Usage: FixWinPaths WrapperConfigFile + * + * only for use by installer + */ +public class FixWinPaths{ + public static void main(String args[]) { + if(args.length != 1) { + System.err.println("Usage: FixWinPaths [wrapper.conf]\r\n"); + System.exit(1); + } + + // This is only intended for Windows systems + if(!System.getProperty("os.name").startsWith("Win")) { + return; + } + replace(args[0]); + + } + private static void replace(String file) { + // Shouldn't be true + if (!file.contains("wrapper.conf")) + return; + String wConf = file; + String wConfTemp = wConf + ".tmp"; + + BufferedReader br = null; + BufferedWriter bw = null; + try { + br = new BufferedReader(new FileReader(wConf)); + bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(wConfTemp), "UTF-8")); + String line; + while ((line = br.readLine()) != null) { + if (line.startsWith("wrapper.logfile=")) + line = "wrapper.logfile=%appdata%\\i2p\\wrapper.log"; + else if (line.startsWith("#wrapper.java.pidfile=")) + line = "#wrapper.java.pidfile=%appdata%\\i2p\\routerjvm.pid"; + else if (line.startsWith("#wrapper.pidfile=")) + line = "#wrapper.pidfile=%appdata%\\i2p\\i2p.pid"; + if (line.contains("\\i2p/")) + line = line.replace("\\i2p/", "\\i2p\\"); + if (line.contains("lib/")) + line = line.replace("lib/", "lib\\"); + if (line.contains("\\/")) + line = line.replace("\\/", "\\"); + if (line.contains("logs/log-router")) + line = line.replace("logs/log-router", "logs\\log-router"); + bw.write(line); + bw.newLine(); + } + } catch (IOException e) { + return; + } finally { + try { + if(br != null) + br.close(); + } catch (IOException e) { + // + } + try { + if(bw != null) + bw.close(); + } catch (IOException e) { + // + } + } + // Once everything is complete, delete the original wrapper.conf + File oldFile = new File(wConf); + oldFile.delete(); + + // ...and rename temp file's name to wrapper.conf + File newFile = new File(wConfTemp); + newFile.renameTo(oldFile); + + } +} diff --git a/installer/resources/fixpaths.cmd b/installer/resources/fixpaths.cmd deleted file mode 100644 index d8bc5850a..000000000 --- a/installer/resources/fixpaths.cmd +++ /dev/null @@ -1,39 +0,0 @@ -@echo off -:: fixpaths.cmd -:: -:: This is a simple (and/or stupid) script whose sole purpose is to set the -:: correct path for wrapper.logfile, by explicitly setting it to use the -:: environment variable %temp%. -:: -:: On every *NIX-like system, $SYSTEM_java_io_tmpdir/wrapper.log points to a system-level -:: temp directory (/tmp on Linux, /var/tmp on BSD, etc.), but in Windows the value of %temp% -:: depends on whose account a process is running under. If the same user that installs I2P -:: is the only one that will run I2P, this isn't a problem. -:: -:: The problem comes from trying to run the process as a service, or trying to run under an -:: account other than the one that did the installation. For example if the user "Administrator" -:: installed I2P on Windows 7, the value for wrapper.logfile will be set to the hardcoded value of -:: C:\Users\Administrator\AppData\Local\Temp\wrapper.log (if it's left at the default value of -:: $SYSTEM_java_io_tmpdir/wrapper.log. -:: -:: If user Alice tries to run I2P, the wrapper will try to write its logfile to -:: C:\Users\Administrator\AppData\Local\Temp\wrapper.log. Unfortunately Alice -:: doesn't have the rights to access Administrator's temp directory. The same -:: will happen with the "limited access account" that the I2P service runs -:: under. -:: -:: Since Windows doesn't have sed and it has a retarded find, we resort to this -:: lameness. -:: -cd /d %~dp0 -findstr /V /R "^wrapper.logfile=" wrapper.config > wrapper.tmp1 -findstr /V /R "^wrapper.java.pidfile=" wrapper.tmp1 > wrapper.tmp2 -findstr /V /R "^wrapper.pidfile=" wrapper.tmp2 > wrapper.new -del /F /Q wrapper.tmp* -echo #PORTABLE installation: >> wrapper.new -echo # The remaining lines should be commented out (or removed) >> wrapper.new -echo # for PORTABLE I2P installations: >> wrapper.new -echo wrapper.logfile=%%temp%%\wrapper.log >> wrapper.new -echo wrapper.java.pidfile=%%temp%%\routerjvm.pid >> wrapper.new -echo wrapper.pidfile=%%temp%%\i2p.pid >> wrapper.new -move /Y wrapper.new wrapper.config diff --git a/installer/resources/postinstall.sh b/installer/resources/postinstall.sh index 4003d2d57..fdfa2f164 100644 --- a/installer/resources/postinstall.sh +++ b/installer/resources/postinstall.sh @@ -117,7 +117,7 @@ rm -f ./lib/*.dll rm -f ./*.bat rm -f ./*.cmd rm -f ./*.exe -rm -rf ./installer +rm -rf ./utility.jar if [ ! `echo $HOST_OS |grep osx` ]; then rm -rf ./Start\ I2P\ Router.app diff --git a/installer/resources/wrapper.config b/installer/resources/wrapper.config index cfc59182f..379b0609d 100644 --- a/installer/resources/wrapper.config +++ b/installer/resources/wrapper.config @@ -142,7 +142,6 @@ wrapper.console.loglevel=INFO # Log file to use for wrapper output logging. # You may wish to change this. # NOTE: On Linux/Mac this is overridden in the i2prouter script; changes here will have no effect. -# Windows users may wish to change this to %APPDATA%\I2P\wrapper.log # System temp directory: wrapper.logfile=$SYSTEM_java_io_tmpdir/wrapper.log # PORTABLE installation: