From da9f7695a74869f91feb3abb731ca02627a2f5b7 Mon Sep 17 00:00:00 2001 From: idk Date: Thu, 1 Jul 2021 16:55:29 -0400 Subject: [PATCH] Start working on an updater thing for the jpackage builds --- Makefile | 5 ++ build.sh | 4 +- i2pversion | 12 ++- java/net/i2p/router/WinLauncher.java | 26 ++----- .../router/WindowsUpdatePostProcessor.java | 75 +++++++++++++++++++ 5 files changed, 98 insertions(+), 24 deletions(-) create mode 100644 java/net/i2p/router/WindowsUpdatePostProcessor.java diff --git a/Makefile b/Makefile index bfbbffe..41d11bd 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ all: install.exe +jpackage: I2P all + prep: profile.tgz app-profile.tgz profile build/licenses build/I2P build/I2P/config cp src/nsis/*.nsi build cp src/nsis/*.nsh build @@ -11,6 +13,9 @@ install.exe: prep export RES_DIR="../i2p.i2p/installer/resources" export PKG_DIR="../i2p.i2p/pkg-temp" +I2P: + ./build.sh + build/I2P: build rm -rf build/I2P cp -rv I2P build/I2P ; true diff --git a/build.sh b/build.sh index f34ff8d..a8b9dc2 100755 --- a/build.sh +++ b/build.sh @@ -22,7 +22,7 @@ echo "cleaning" HERE="$PWD" cd "$HERE/../i2p.i2p/" git checkout "$VERSION" -ant distclean pkg || true +#ant distclean pkg || true cd "$HERE" RES_DIR="$HERE/../i2p.i2p/installer/resources" @@ -33,7 +33,7 @@ echo "compiling custom launcher" mkdir build cp "$I2P_JARS"/*.jar build cd java -"$JAVA_HOME"/bin/javac -d ../build -classpath "$HERE"/build/i2p.jar:"$HERE"/build/router.jar net/i2p/router/WinLauncher.java +"$JAVA_HOME"/bin/javac -d ../build -classpath "$HERE"/build/i2p.jar:"$HERE"/build/router.jar:"$HERE"/build/routerconsole.jar net/i2p/router/*.java #WinLauncher.java cd .. #echo "building launcher.jar" diff --git a/i2pversion b/i2pversion index 06b4540..cc33901 100644 --- a/i2pversion +++ b/i2pversion @@ -1,7 +1,13 @@ #! /usr/bin/env sh -I2P_VERSION=0.9.50 -export I2P_VERSION=0.9.50 +#I2P_VERSION=0.9.50 +#export I2P_VERSION=0.9.50 -VERSION=i2p-$I2P_VERSION +#VERSION=i2p-$I2P_VERSION +#export VERSION="$VERSION" + +I2P_VERSION=master +export I2P_VERSION=master + +VERSION=$I2P_VERSION export VERSION="$VERSION" diff --git a/java/net/i2p/router/WinLauncher.java b/java/net/i2p/router/WinLauncher.java index 73f2602..4112ce2 100644 --- a/java/net/i2p/router/WinLauncher.java +++ b/java/net/i2p/router/WinLauncher.java @@ -3,6 +3,7 @@ package net.i2p.router; import java.io.*; import java.util.*; import net.i2p.router.RouterLaunch; +import net.i2p.router.Router; import net.i2p.util.SystemVersion; /** @@ -14,12 +15,9 @@ import net.i2p.util.SystemVersion; * i2p.dir.config this points to the (read-write) config directory in local appdata * router.pid - the pid of the java process. */ -public class WinLauncher { - - private static final String LOCALAPPDATA = System.getenv("LOCALAPPDATA"); +public class WinLauncher extends WindowsUpdatePostProcessor { public static void main(String[] args) throws Exception { - File programs = selectProgramFile(); File home = selectHome(); @@ -35,15 +33,17 @@ public class WinLauncher { System.setProperty("router.pid", String.valueOf(ProcessHandle.current().pid())); System.out.println("\t"+System.getProperty("i2p.dir.base") +"\n\t"+System.getProperty("i2p.dir.config")+"\n\t"+ System.getProperty("router.pid")); - RouterLaunch.main(args); + i2pRouter = new Router(System.getProperties()); + + i2pRouter.runRouter(); } - private static File selectHome() throws Exception { + private static File selectHome() { //throws Exception { if (SystemVersion.isWindows()) { File home = new File(System.getProperty("user.home")); - File i2p; File appData = new File(home, "AppData"); File local = new File(appData, "Local"); + File i2p; i2p = new File(local, "I2P"); return i2p.getAbsoluteFile(); } else { @@ -53,16 +53,4 @@ public class WinLauncher { } } - private static File selectProgramFile() throws Exception { - if (SystemVersion.isWindows()) { - File jrehome = new File(System.getProperty("java.home")); - File programs = jrehome.getParentFile(); - return programs.getAbsoluteFile(); - } else { - File jrehome = new File(System.getProperty("java.home")); - File programs = new File(jrehome.getParentFile().getParentFile(), "i2p"); - return programs.getAbsoluteFile(); - } - } - } diff --git a/java/net/i2p/router/WindowsUpdatePostProcessor.java b/java/net/i2p/router/WindowsUpdatePostProcessor.java new file mode 100644 index 0000000..0e4c5f8 --- /dev/null +++ b/java/net/i2p/router/WindowsUpdatePostProcessor.java @@ -0,0 +1,75 @@ +package net.i2p.router; + +import java.io.*; +import java.util.*; + +import static net.i2p.update.UpdateType.*; +import net.i2p.update.UpdateType; +import net.i2p.util.SystemVersion; + +import java.lang.ProcessBuilder; +import java.lang.Process; +import java.lang.InterruptedException; + +public class WindowsUpdatePostProcessor { + protected static Router i2pRouter = null; + Process updateProcess = null; + public void updateDownloadedandVerified(UpdateType type, int fileType, String version, File file) throws IOException { + if (fileType == 6) { + if (runUpdate(file)) { + if (shutdownGracefullyAndRerun()) { + } + } else { + } + } + } + private boolean runUpdate(File file){ + ProcessBuilder pb = new ProcessBuilder("cmd", "/c", file.getAbsolutePath()); + try { + updateProcess = pb.start(); + } catch (IOException ex) { + // At this point a failure is harmless, but it's also not at all important to + // restart the router. Return false. + return false; + } + try { + updateProcess.waitFor(); + } catch (InterruptedException ex) { + // if the NSIS installer process got interrupted here, it's possible that the + // install was left in a broken state. I think we should direct the uses to + // re-run the installer if this happens. TODO: java dialog boxes. That should be + // easy. + return false; + } + return true; + } + private boolean shutdownGracefullyAndRerun() { + i2pRouter.shutdownGracefully(); + ProcessBuilder pb = new ProcessBuilder("cmd", "/c", selectProgramFile().getAbsolutePath()); + while (i2pRouter.gracefulShutdownInProgress()){ + } + if (i2pRouter.isFinalShutdownInProgress()){ + try { + Process restartProcess = pb.start(); + } catch (IOException ex) { + // + return false; + } + return true; + } + return false; + } + + protected static File selectProgramFile() { + if (SystemVersion.isWindows()) { + File jrehome = new File(System.getProperty("java.home")); + File programs = jrehome.getParentFile(); + return programs.getAbsoluteFile(); + } else { + File jrehome = new File(System.getProperty("java.home")); + File programs = new File(jrehome.getParentFile().getParentFile(), "i2p"); + return programs.getAbsoluteFile(); + } + } + +} \ No newline at end of file