diff --git a/Makefile b/Makefile index 0854b02..7f62030 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,9 @@ PROFILE_VERSION=$(MAJOR).$(MINOR).$(BUILD) all: version prep install.exe +fmt: + find . -name '*.java' -exec clang-format -i {} \; + tag: git tag $(PROFILE_VERSION) diff --git a/java/net/i2p/router/CopyConfigDir.java b/java/net/i2p/router/CopyConfigDir.java index 66333e6..c7a6c5c 100644 --- a/java/net/i2p/router/CopyConfigDir.java +++ b/java/net/i2p/router/CopyConfigDir.java @@ -66,18 +66,21 @@ public class CopyConfigDir extends WindowsServiceUtil { if (0 == cnr) return false; if (1 == cnr) { - logger.info("using jpackaged configs in a jpackaged install, creating jpackaged file"); + logger.info( + "using jpackaged configs in a jpackaged install, creating jpackaged file"); File jpackagedConfigsInUse = new File(appImageHome(), "jpackaged"); - if (!jpackagedConfigsInUse.exists()){ - try{ + if (!jpackagedConfigsInUse.exists()) { + try { jpackagedConfigsInUse.createNewFile(); - }catch(IOException e){ - logger.warning("Error creating jpackaged file, delete config files manually when uninstalling"); + } catch (IOException e) { + logger.warning( + "Error creating jpackaged file, delete config files manually when uninstalling"); } } } if (-1 == cnr) { - logger.info("not overwriting existing config file, not creating jpackaged file"); + logger.info( + "not overwriting existing config file, not creating jpackaged file"); } } } diff --git a/java/net/i2p/router/WinLauncher.java b/java/net/i2p/router/WinLauncher.java index 4587d50..6ce22f2 100644 --- a/java/net/i2p/router/WinLauncher.java +++ b/java/net/i2p/router/WinLauncher.java @@ -172,7 +172,8 @@ public class WinLauncher extends CopyConfigDir { i2pRouter = new Router(routerconf, System.getProperties()); String newsURL = i2pRouter.getConfigSetting("router.newsURL"); if (newsURL != null) { - if (newsURL.contains("http://dn3tvalnjz432qkqsvpfdqrwpqkw3ye4n4i2uyfr4jexvo3sp5ka.b32.i2p/news/win/beta/news.su3")) { + if (newsURL.contains( + "http://dn3tvalnjz432qkqsvpfdqrwpqkw3ye4n4i2uyfr4jexvo3sp5ka.b32.i2p/news/win/beta/news.su3")) { logger.info( "checked router.newsURL config, containes win/beta in a service install, invalid update type"); if (i2pRouter.saveConfig("router.newsURL", ServiceUpdaterString())) { @@ -183,7 +184,8 @@ public class WinLauncher extends CopyConfigDir { } String backupNewsURL = i2pRouter.getConfigSetting("router.backupNewsURL"); if (backupNewsURL != null) { - if (backupNewsURL.contains("http://tc73n4kivdroccekirco7rhgxdg5f3cjvbaapabupeyzrqwv5guq.b32.i2p/win/beta/news.su3")) { + if (backupNewsURL.contains( + "http://tc73n4kivdroccekirco7rhgxdg5f3cjvbaapabupeyzrqwv5guq.b32.i2p/win/beta/news.su3")) { logger.info( "checked router.backupNewsURL config, containes win/beta in a service install, invalid update type"); if (i2pRouter.saveConfig("router.backupNewsURL", @@ -195,7 +197,8 @@ public class WinLauncher extends CopyConfigDir { } String updateURL = i2pRouter.getConfigSetting("router.updateURL"); if (updateURL != null) { - if (updateURL.contains("http://ekm3fu6fr5pxudhwjmdiea5dovc3jdi66hjgop4c7z7dfaw7spca.b32.i2p/i2pwinupdate.su3")) { + if (updateURL.contains( + "http://ekm3fu6fr5pxudhwjmdiea5dovc3jdi66hjgop4c7z7dfaw7spca.b32.i2p/i2pwinupdate.su3")) { logger.info( "checked router.updateURL config, containes easy-intall update in a service install, invalid update type"); if (i2pRouter.saveConfig("router.updateURL", diff --git a/java/net/i2p/router/WinUpdateProcess.java b/java/net/i2p/router/WinUpdateProcess.java index 433284c..6952ff3 100644 --- a/java/net/i2p/router/WinUpdateProcess.java +++ b/java/net/i2p/router/WinUpdateProcess.java @@ -62,13 +62,22 @@ class WinUpdateProcess implements Runnable { env.put("RESTART_I2P", "true"); try { - pb.directory(workingDir) - .redirectErrorStream(true) - .redirectOutput(logFile) - .start(); + Process p = pb.directory(workingDir) + .redirectErrorStream(true) + .redirectOutput(logFile) + .start(); + exitCode = p.waitFor(); + if (exitCode != 0) + _log.error("Update failed with exit code " + exitCode + " see " + + logFile.getAbsolutePath() + " for more details"); } catch (IOException ex) { _log.error( - "Unable to run update-program in background. Update will fail."); + "Unable to run update program in background. Update will fail.", + ex); + } catch (InterruptedException ex) { + _log.error( + "Unable to run update program in background. Update will fail.", + ex); } } else { // If we cant write to the log file and we're on Windows, use the elevator diff --git a/java/net/i2p/router/WindowsUpdatePostProcessor.java b/java/net/i2p/router/WindowsUpdatePostProcessor.java index 41fa99a..11bfea7 100644 --- a/java/net/i2p/router/WindowsUpdatePostProcessor.java +++ b/java/net/i2p/router/WindowsUpdatePostProcessor.java @@ -39,6 +39,20 @@ public class WindowsUpdatePostProcessor implements UpdatePostProcessor { String version, File file) throws IOException { _log.info("Got an update to post-process"); + if (fileType != SU3File.TYPE_ZIP) { + this.positionedFile = moveUpdateInstaller(file); + this.version = version; + + if (!hook.compareAndSet(false, true)) { + _log.info("shutdown hook was already set"); + return; + } + + _log.info("adding shutdown hook"); + + ctx.addFinalShutdownTask( + new ZipUpdateProcess(ctx, this::getVersion, this::getFile)); + } if (SystemVersion.isWindows()) { if (type != UpdateType.ROUTER_SIGNED_SU3 && diff --git a/java/net/i2p/router/ZipUpdateProcess.java b/java/net/i2p/router/ZipUpdateProcess.java new file mode 100644 index 0000000..35c62fe --- /dev/null +++ b/java/net/i2p/router/ZipUpdateProcess.java @@ -0,0 +1,82 @@ +package net.i2p.router; + +import java.io.*; +import java.util.Map; +import java.util.function.*; +import net.i2p.I2PAppContext; +import net.i2p.router.*; +import net.i2p.util.Log; + +public class ZipUpdateProcess implements Runnable { + private final RouterContext ctx; + private final Supplier versionSupplier; + private final Supplier fileSupplier; + private final Log _log; + + ZipUpdateProcess(RouterContext ctx, Supplier versionSupplier, + Supplier fileSupplier) { + this.ctx = ctx; + this.versionSupplier = versionSupplier; + this.fileSupplier = fileSupplier; + this._log = ctx.logManager().getLog(ZipUpdateProcess.class); + } + + private File workDir() throws IOException { + if (ctx != null) { + File workDir = + new File(ctx.getConfigDir().getAbsolutePath(), "i2p_update_win"); + if (workDir.exists()) { + if (workDir.isFile()) + throw new IOException(workDir + + " exists but is a file, get it out of the way"); + return workDir; + } else { + workDir.mkdirs(); + } + return workDir; + } + return null; + } + + private void unzipUpdateInstaller() throws IOException { + String version = versionSupplier.get(); + File file = fileSupplier.get(); + if (file == null) + return; + + File workingDir = workDir(); + File logFile = new File(workingDir, "log-" + version + ".txt"); + + // check if we can write to the log file. If we can, use the + // ProcessBuilder to run the installer. + // ProcessBuilder pb = new ProcessBuilder( + // file.getAbsolutePath(), "/S", "/D=" + workingDir.getAbsolutePath()); + // Map env = pb.environment(); + // env.put("OLD_I2P_VERSION", version); + // env.remove("RESTART_I2P"); + + int exitCode = ctx.router().scheduledGracefulExitCode(); + // if (exitCode == Router.EXIT_HARD_RESTART || + // exitCode == Router.EXIT_GRACEFUL_RESTART) + // env.put("RESTART_I2P", "true"); + + /*try { + pb.directory(workingDir) + .redirectErrorStream(true) + .redirectOutput(logFile) + .start(); + } catch (IOException ex) { + _log.error( + "Unable to run update-program in background. Update will fail.", ex); + }*/ + } + + @Override + public void run() { + try { + unzipUpdateInstaller(); + } catch (IOException ioe) { + _log.error("Error running updater, update may fail." + ioe); + } + } +} diff --git a/launcher.sh b/launcher.sh index 7447d4a..b6de2be 100755 --- a/launcher.sh +++ b/launcher.sh @@ -76,10 +76,12 @@ cd java net/i2p/router/CopyConfigDir.java \ net/i2p/router/Elevator.java \ net/i2p/router/Shell32X.java \ + net/i2p/router/WindowsServiceUtil.java \ net/i2p/router/WinLauncher.java \ net/i2p/router/WindowsUpdatePostProcessor.java \ net/i2p/router/WinUpdateProcess.java \ - net/i2p/router/WindowsServiceUtil.java + net/i2p/router/WindowsServiceUtil.java \ + net/i2p/router/ZipUpdateProcess.java cd ..