source: launchers/common/src/main/scala/net/i2p/launchers/DeployProfile.scala @ a3a8ee1

Last change on this file since a3a8ee1 was a3a8ee1, checked in by meeh <meeh@…>, 3 years ago

Major update for the OSX Launcher code. Now it will bundle
installer resources with the fat jar (we add an exclusion list later)
which the base directory will be built(or updated if lacking files) upon
startup of the I2P router. This is done by the OSXDeployment class which
is an extension for the DeployProfile? class written for Mac OS X.

Since the app bundle itself should be R/O, we use ~/Library/I2P as base path,
and continue using ~/Library/Application? Support/i2p as config path. The BB
code will have other paths.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1package net.i2p.launchers
2
3import java.io.{File, InputStream}
4
5
6object DeployProfile {
7
8  /**
9    * This joins two paths in a cross platform way. Meaning it takes care of either we use
10    * \\ or / as directory separator. It returns the resulting path in a string.
11    *
12    * @since 0.9.35
13    * @param parent The parent path
14    * @param child The child path to append
15    * @return String
16    */
17  def pathJoin(parent:String,child:String): String = new File(new File(parent), child).getPath
18}
19
20/**
21  *
22  * The purpose of this class is to copy files from the i2p "default config" directory
23  * and to a "current config" directory relative to the browser bundle - but this class is
24  * also used by the OSX launcher since it shares common properties like that the bundle has
25  * to be read only.
26  *
27  * @author Meeh
28  * @version 0.0.1
29  * @since 0.9.35
30  */
31class DeployProfile(val confDir: String, val baseDir: String) {
32  import java.nio.file.{Files, Paths}
33
34  /**
35    * This function copies resources from the fatjar to the config directory of i2p.
36    *
37    * @since 0.9.35
38    * @param fStr
39    * @return Unit
40    */
41  def copyFileResToDisk(fStr: String) = Files.copy(
42    getClass.getResource("/".concat(fStr)).getContent.asInstanceOf[InputStream],
43    Paths.get(DeployProfile.pathJoin(confDir, fStr)).normalize()
44  )
45
46
47  /**
48    * This function copies resources from the fatjar to the config directory of i2p.
49    *
50    * @since 0.9.35
51    * @param path
52    * @param is
53    * @return Unit
54    */
55  def copyBaseFileResToDisk(path: String, is: InputStream) = Files.copy(
56    is,
57    Paths.get(DeployProfile.pathJoin(baseDir, path)).normalize()
58  )
59
60  /**
61    * Filter function for finding missing required files.
62    *
63    * @since 0.9.35
64    * @param l1
65    * @param l2
66    * @return
67    */
68  def missingFiles(l1: List[String], l2: List[String]) = l1.filter { x => !l2.contains(x) }
69
70
71  val warFiles = List("routerconsole.war")
72
73  val staticFiles = List(
74    "blocklist.txt",
75    "clients.config",
76    "continents.txt",
77    "countries.txt",
78    "hosts.txt",
79    "geoip.txt",
80    "i2ptunnel.config",
81    "logger.config",
82    "router.config",
83    "webapps.config"
84  )
85
86  /**
87    *
88    * This function will check the existence of static files,
89    * and if any of them are lacking, it will be copied from the
90    * fat jar's resources.
91    *
92    * @since 0.9.35
93    * @return Unit (Null)
94    */
95  def verifyExistenceOfConfig() = {
96    val fDir = new File(confDir)
97    if (fDir.exists()) {
98      // We still check if files are in place
99      val currentDirContentList = fDir.list.toList
100      val missing = missingFiles(staticFiles, currentDirContentList)
101      if (!missing.isEmpty) {
102        missing.map(copyFileResToDisk)
103      }
104    } else {
105      // New deployment!
106      deployDefaultConfig()
107    }
108  }
109
110  /**
111    *
112    * This function does the default deployment of files,
113    * map is the same as a loop. we're looping over the file list.
114    *
115    * @since 0.9.35
116    * @return Unit
117    */
118  def deployDefaultConfig(): Unit = staticFiles.map(copyFileResToDisk)
119
120}
Note: See TracBrowser for help on using the repository browser.