From 1437610e5bf851ba48a6e82e4ad06b796d9223d2 Mon Sep 17 00:00:00 2001 From: knaccc Date: Wed, 16 Jan 2019 06:19:35 +0000 Subject: [PATCH] Now doesn't require any Ubuntu packages to be installed in order to build (java, ant, i2p). Produces a distribution with zero dependencies. --- LICENSE | 0 README.md | 41 +++++++++------------------------- bin/build-all.sh | 13 +++++++++++ bin/build-launcher.sh | 18 +++++++++++---- bin/build-original-i2p.sh | 27 ++++++++++++++++++++++ bin/convert-jars-to-modules.sh | 8 ++++--- bin/import-packages.sh | 14 ++++++++++++ resources/launch.sh | 5 +++++ src/module-info.java | 2 -- 9 files changed, 89 insertions(+), 39 deletions(-) mode change 100644 => 100755 LICENSE mode change 100644 => 100755 README.md create mode 100755 bin/build-all.sh create mode 100755 bin/build-original-i2p.sh create mode 100755 bin/import-packages.sh create mode 100755 resources/launch.sh diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 9f613dc..a8c2396 --- a/README.md +++ b/README.md @@ -2,45 +2,29 @@ This project will build a native launcher. The launcher will include the I2P router, a SAM listener and a minimal JVM. -## Prerequisites - -This project requires the JAR files and base configuration dir from an existing I2P installation. - -To install I2P on Ubuntu so that these files are available to you, type: +## Building the launcher -``` -sudo apt-add-repository ppa:i2p-maintainers/i2p -sudo apt-get update -sudo apt-get install i2p -``` +retrieve this project from git: -Then copy the following 6 JAR files from the I2P installation to the import/lib directory in your clone of this GitHub project: +`git clone https://github.com/knaccc/embedded-i2p-java-router-with-sam.git` -``` -mkdir -p import/lib -for i in i2p.jar mstreaming.jar router.jar sam.jar streaming.jar gnu-getopt.jar libintl.jar; do cp /usr/share/i2p/lib/$i import/lib/; done -mv import/lib/gnu-getopt.jar import/lib/gnugetopt.jar -``` +Note that the current version of this script uses jdk-11.0.2. If this version of Java becomes no longer available for +download, then update the references to jdk-11.0.2 in this folder structure to the later version. -You will need OpenJDK 11 installed: +Run the `bin/build-all.sh` script, which will in turn call the following scripts: -`sudo apt install openjdk-11-jdk-headless` +1. `bin/import-packages.sh` to retrieve the I2P Java sources, OpenJDK and the Ant build tool -## Building the launcher +2. `bin/build-original-i2p.sh` to build the i2p project retrieved from the I2P repository -`bin/build-launcher.sh` - -This will convert the imported JARs to modules, compile the Java source code in this project, and then use the jlink tool -to build a platform-specific launcher executable. +3. `build-launcher.sh` to convert the imported JARs to modules, compile the Java source code in this project, and then use +the jlink tool to build a zero-dependency platform-specific launcher. ## Running the launcher -The launcher will need access to the /usr/share/i2p base directory. It will create a .i2p directory for configuration -files in the current user's home directory if it does not already exist. - To run the router, type: -`target/router/bin/router` +`target/router/bin/launch.sh` If it launches successfully, you'll see the message: @@ -49,6 +33,3 @@ If it launches successfully, you'll see the message: ## Check that the I2P router is running and that it is listening for SAM connections `fuser 7656/tcp` - -## Todo -Need to determine the most minimal base configuration directory contents, and include it as part of this project. diff --git a/bin/build-all.sh b/bin/build-all.sh new file mode 100755 index 0000000..cd20a38 --- /dev/null +++ b/bin/build-all.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +basedir=$(dirname $(dirname $(readlink -fm $0))) + +# retrieve the I2P Java sources, OpenJDK and the Ant build tool +$basedir/bin/import-packages.sh + +# build the i2p project retrieved from the I2P repository +$basedir/bin/build-original-i2p.sh + +# convert the imported JARs to modules, compile the Java source code in this project, and then use the jlink tool +# to build a zero-dependency platform-specific launcher +$basedir/bin/build-launcher.sh diff --git a/bin/build-launcher.sh b/bin/build-launcher.sh index f38549a..b6ac698 100755 --- a/bin/build-launcher.sh +++ b/bin/build-launcher.sh @@ -2,20 +2,30 @@ basedir=$(dirname $(dirname $(readlink -fm $0))) +export JAVA_HOME=`realpath $basedir/import/jdk-11.0.2` + # convert the jar files from an existing I2P build into modules suitable for use with jlink $basedir/bin/convert-jars-to-modules.sh # compile the Main class that starts the I2P router and SAM listener echo "*** Compiling Main class" -javac --module-path import/lib -d target/classes $(find src -name '*.java') +$JAVA_HOME/bin/javac --module-path import/lib -d target/classes $(find src -name '*.java') # package as a modular jar echo "*** Packaging as a modular jar" -jar --create --file target/org.getmonero.i2p.embedded.jar --main-class org.getmonero.i2p.embedded.Main -C target/classes . +$JAVA_HOME/bin/jar --create --file target/org.getmonero.i2p.embedded.jar --main-class org.getmonero.i2p.embedded.Main -C target/classes . # create an OS specific launcher which will bundle together the code and a minimal JVM echo "*** Performing jlink" -jlink --module-path target/modules:target/org.getmonero.i2p.embedded.jar --add-modules org.getmonero.i2p.embedded --launcher router=org.getmonero.i2p.embedded --output target/router --strip-debug --compress 2 --no-header-files --no-man-pages +$JAVA_HOME/bin/jlink --module-path target/modules:target/org.getmonero.i2p.embedded.jar --add-modules org.getmonero.i2p.embedded --launcher router=org.getmonero.i2p.embedded --output target/router --strip-debug --compress 2 --no-header-files --no-man-pages + +cp $basedir/resources/launch.sh $basedir/target/router/bin/ + +cp -r $basedir/import/i2p.base $basedir/target/router/ +mkdir -p $basedir/target/router/i2p.config + +mkdir -p $basedir/dist/ +mv $basedir/target/router $basedir/dist/ echo "*** Done ***" -echo "To run, type: target/router/bin/router" \ No newline at end of file +echo "To run, type: dist/router/bin/launch.sh" \ No newline at end of file diff --git a/bin/build-original-i2p.sh b/bin/build-original-i2p.sh new file mode 100755 index 0000000..9fdbb4b --- /dev/null +++ b/bin/build-original-i2p.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +basedir=$(dirname $(dirname $(readlink -fm $0))) + +cd $basedir/import + +export JAVA_HOME=`realpath $basedir/import/jdk-11.0.2` + + +# build the jars we're going to modularize +cd $basedir/import/i2p.i2p +$basedir/import/apache-ant-1.10.5/bin/ant pkg +$basedir/import/apache-ant-1.10.5/bin/ant updaterWithJbigi +cd .. + + +# copy the jars that we're going to modularize +mkdir -p $basedir/import/lib +for i in i2p.jar mstreaming.jar router.jar sam.jar streaming.jar; do cp $basedir/import/i2p.i2p/build/$i $basedir/import/lib/; done + +# build a minimal i2p.base dir +mkdir -p $basedir/import/i2p.base +cp $basedir/import/i2p.i2p/build/jbigi.jar $basedir/import/i2p.base/ +for i in blocklist.txt hosts.txt certificates; do cp -r $basedir/import/i2p.i2p/installer/resources/$i $basedir/import/i2p.base/; done + +mkdir -p $basedir/import/i2p.base/geoip +for i in continents.txt countries.txt; do cp -r $basedir/import/i2p.i2p/installer/resources/$i $basedir/import/i2p.base/geoip/; done diff --git a/bin/convert-jars-to-modules.sh b/bin/convert-jars-to-modules.sh index c97ca70..539b08b 100755 --- a/bin/convert-jars-to-modules.sh +++ b/bin/convert-jars-to-modules.sh @@ -2,6 +2,8 @@ basedir=$(dirname $(dirname $(readlink -fm $0))) +export JAVA_HOME=`realpath $basedir/import/jdk-11.0.2` + jarPaths=`find $basedir/import/lib -name '*.jar'` mkdir -p $basedir/target/modules @@ -10,12 +12,12 @@ rm -f $basedir/target/modules/* for jarPath in $jarPaths; do moduleName=$(basename "${jarPath%.*}") echo "*** Determining dependencies for $moduleName" - jdeps --module-path $basedir/import/lib --add-modules=ALL-MODULE-PATH --generate-module-info $basedir/target/module-info $jarPath + $JAVA_HOME/bin/jdeps --module-path $basedir/import/lib --add-modules=ALL-MODULE-PATH --generate-module-info $basedir/target/module-info $jarPath done for jarPath in $jarPaths; do moduleName=$(basename "${jarPath%.*}") echo "*** Creating new modular jar for $moduleName" - javac --module-path $basedir/import/lib --patch-module $moduleName=$jarPath $basedir/target/module-info/$moduleName/module-info.java + $JAVA_HOME/bin/javac --module-path $basedir/import/lib --patch-module $moduleName=$jarPath $basedir/target/module-info/$moduleName/module-info.java cp $jarPath $basedir/target/modules/ - jar uf $basedir/target/modules/${moduleName}.jar -C $basedir/target/module-info/$moduleName module-info.class + $JAVA_HOME/bin/jar uf $basedir/target/modules/${moduleName}.jar -C $basedir/target/module-info/$moduleName module-info.class done diff --git a/bin/import-packages.sh b/bin/import-packages.sh new file mode 100755 index 0000000..d4216bc --- /dev/null +++ b/bin/import-packages.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +basedir=$(dirname $(dirname $(readlink -fm $0))) + +mkdir $basedir/import +cd $basedir/import + +git clone https://github.com/i2p/i2p.i2p.git + +wget https://download.java.net/java/GA/jdk11/7/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz +wget https://www-us.apache.org/dist//ant/binaries/apache-ant-1.10.5-bin.tar.gz + +tar zxvf openjdk-11.0.2_linux-x64_bin.tar.gz +tar zxvf apache-ant-1.10.5-bin.tar.gz \ No newline at end of file diff --git a/resources/launch.sh b/resources/launch.sh new file mode 100755 index 0000000..716493a --- /dev/null +++ b/resources/launch.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +basedir=$(dirname $(dirname $(readlink -fm $0))) + +$basedir/bin/java -cp $basedir/i2p.base/jbigi.jar -m org.getmonero.i2p.embedded --i2p.dir.base=$basedir/i2p.base --i2p.dir.config=$basedir/i2p.config \ No newline at end of file diff --git a/src/module-info.java b/src/module-info.java index d0f1de7..b325f19 100644 --- a/src/module-info.java +++ b/src/module-info.java @@ -4,7 +4,5 @@ module org.getmonero.i2p.embedded { requires streaming; requires router; requires sam; - requires libintl; - requires gnugetopt; requires jdk.crypto.ec; } \ No newline at end of file