add ability to not overwrite some resources like config files

This commit is contained in:
Zlatin Balevsky
2021-03-19 02:46:56 +00:00
parent 446b87d71c
commit 52dbe4c90a
3 changed files with 9 additions and 4 deletions

View File

@ -25,7 +25,7 @@ The I2P router expects to find some resources in specific places. The legacy I2
* All router certificates * All router certificates
* GeoIP database * GeoIP database
* Custom Launcher * 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. 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 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. 1. The compiled custom main class gets added to the .jar as well.

View File

@ -1,4 +1,5 @@
#!/bin/bash #!/bin/bash
set -e
if [ -z "${JAVA_HOME}" ]; then if [ -z "${JAVA_HOME}" ]; then
echo "JAVA_HOME needs to point to Java 14+" echo "JAVA_HOME needs to point to Java 14+"
@ -19,9 +20,11 @@ HERE=$PWD
echo "preparing resources.csv" echo "preparing resources.csv"
mkdir build mkdir build
cd $RES_DIR 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 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" echo "copying certificates"
cp -R $RES_DIR/certificates build/ cp -R $RES_DIR/certificates build/

View File

@ -61,6 +61,7 @@ public class PackageLauncher {
String []split = description.split(","); String []split = description.split(",");
String url = split[0]; String url = split[0];
String target = split[1]; String target = split[1];
boolean overwrite = Boolean.parseBoolean(split[2]);
var resource = PackageLauncher.class.getClassLoader().getResourceAsStream(url); var resource = PackageLauncher.class.getClassLoader().getResourceAsStream(url);
@ -75,7 +76,8 @@ public class PackageLauncher {
else if (!targetDir.isDirectory()) else if (!targetDir.isDirectory())
throw new Exception(targetDir + " exists but not a directory. Please get it out of the way"); 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);
} }
} }