From 52dbe4c90a0a27229bc391318dcd06254b6936e6 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Fri, 19 Mar 2021 02:46:56 +0000 Subject: [PATCH] add ability to not overwrite some resources like config files --- README.md | 2 +- build.sh | 7 +++++-- java/net/i2p/router/PackageLauncher.java | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ad46b28..27b1262 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ The I2P router expects to find some resources in specific places. The legacy I2 * All router certificates * GeoIP database * Custom Launcher -1. Enumerate these resources and generate a file called `resources.csv`. The format is CSV file where the first entry is the path that the classloader will use to locate the file, and the second entry is the path under the preferences directory where the resource should be copied. Add this file in the .jar built in step 1. +1. Enumerate these resources and generate a file called `resources.csv`. The format is CSV file where the first entry is the path that the classloader will use to locate the file, the second entry is the path under the preferences directory where the resource should be copied, and the third entry indicates whether to overwrite any existing files (true|false). Add this file in the .jar built in step 1. 1. Use a custom main class `net.i2p.router.PackageLauncher` which reads the above list and copies each resource to the appropriate path under the current user's preferences directory, which is OS-dependent. 1. The custom main class will also set any system properties necessary for I2P to work, then invoke the "real" main class `net.i2p.router.RouterLaunch`. 1. The compiled custom main class gets added to the .jar as well. diff --git a/build.sh b/build.sh index d271ed0..eeb154e 100644 --- a/build.sh +++ b/build.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e if [ -z "${JAVA_HOME}" ]; then echo "JAVA_HOME needs to point to Java 14+" @@ -19,9 +20,11 @@ HERE=$PWD echo "preparing resources.csv" mkdir build cd $RES_DIR -find certificates -name *.crt -exec echo '{},{}' >> $HERE/build/resources.csv \; +find certificates -name *.crt -exec echo '{},{},true' >> $HERE/build/resources.csv \; +# TODO add others cd $HERE -echo "geoip/GeoLite2-Country.mmdb,geoip/GeoLite2-Country.mmdb" >> build/resources.csv +echo "geoip/GeoLite2-Country.mmdb,geoip/GeoLite2-Country.mmdb,true" >> build/resources.csv +# TODO: decide on blocklist.txt echo "copying certificates" cp -R $RES_DIR/certificates build/ diff --git a/java/net/i2p/router/PackageLauncher.java b/java/net/i2p/router/PackageLauncher.java index a9e82e5..c5b56c4 100644 --- a/java/net/i2p/router/PackageLauncher.java +++ b/java/net/i2p/router/PackageLauncher.java @@ -61,6 +61,7 @@ public class PackageLauncher { String []split = description.split(","); String url = split[0]; String target = split[1]; + boolean overwrite = Boolean.parseBoolean(split[2]); var resource = PackageLauncher.class.getClassLoader().getResourceAsStream(url); @@ -75,7 +76,8 @@ public class PackageLauncher { else if (!targetDir.isDirectory()) throw new Exception(targetDir + " exists but not a directory. Please get it out of the way"); - Files.copy(resource, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + if (!targetFile.exists() || overwrite) + Files.copy(resource, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING); } }