setup wizard
This commit is contained in:
@ -0,0 +1,71 @@
|
||||
package com.muwire.tracker
|
||||
|
||||
class SetupWizard {
|
||||
|
||||
private final File home
|
||||
|
||||
SetupWizard(File home) {
|
||||
this.home = home
|
||||
}
|
||||
|
||||
Properties performSetup() {
|
||||
println "**** Welcome to mwtrackerd setup wizard *****"
|
||||
println "This wizard ask you some questions and configure the settings for the MuWire tracker daemon."
|
||||
println "The settings will be saved in ${home.getAbsolutePath()} where you can edit them manually if you wish."
|
||||
println "You can re-run this wizard by launching mwtrackerd with the \"setup\" argument."
|
||||
println "*****************"
|
||||
|
||||
Scanner scanner = new Scanner(System.in)
|
||||
|
||||
Properties rv = new Properties()
|
||||
|
||||
// nickname
|
||||
while(true) {
|
||||
println "Please select a nickname for your tracker"
|
||||
String nick = scanner.nextLine()
|
||||
if (nick.trim().length() == 0) {
|
||||
println "nickname cannot be empty"
|
||||
continue
|
||||
}
|
||||
rv['nickname'] = nick
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
// i2cp host and port
|
||||
println "Enter the address of an I2P or I2Pd router to connect to. (default is 127.0.0.1)"
|
||||
String i2cpHost = scanner.nextLine()
|
||||
if (i2cpHost.trim().length() == 0)
|
||||
i2cpHost = "127.0.0.1"
|
||||
rv['i2cp.tcp.host'] = i2cpHost
|
||||
|
||||
println "Enter the port of the I2CP interface of the I2P[d] router (default is 7654)"
|
||||
String i2cpPort = scanner.nextLine()
|
||||
if (i2cpPort.trim().length() == 0)
|
||||
i2cpPort = "7654"
|
||||
rv['i2cp.tcp.port'] = i2cpPort
|
||||
|
||||
// json-rpc interface
|
||||
println "Enter the address to which to bind the JSON-RPC interface of the tracker."
|
||||
println "Default is 127.0.0.1. If you want to allow JSON-RPC connections from other hosts you can enter 0.0.0.0"
|
||||
String jsonRpcIface = scanner.nextLine()
|
||||
if (jsonRpcIface.trim().length() == 0)
|
||||
jsonRpcIface = "127.0.0.1"
|
||||
rv['jsonrpc.iface'] = jsonRpcIface
|
||||
|
||||
println "Enter the port on which the JSON-RPC interface should listen. (default is 12345)"
|
||||
String jsonRpcPort = scanner.nextLine()
|
||||
if (jsonRpcPort.trim().length() == 0)
|
||||
jsonRpcPort = "12345"
|
||||
rv['jsonrpc.port'] = jsonRpcPort
|
||||
|
||||
// that's all
|
||||
println "*****************"
|
||||
println "That's all the setup that's required to get the tracker up and running."
|
||||
println "The tracker has many other settings which can be changed in the config files."
|
||||
println "Refer to the documentation for their description."
|
||||
println "*****************"
|
||||
|
||||
rv
|
||||
}
|
||||
}
|
@ -1,7 +1,57 @@
|
||||
package com.muwire.tracker
|
||||
|
||||
import com.muwire.core.MuWireSettings
|
||||
|
||||
class Tracker {
|
||||
|
||||
private static final String VERSION = "0.6.12"
|
||||
|
||||
public static void main(String [] args) {
|
||||
println "hello from tracker"
|
||||
println "Launching MuWire Tracker version $VERSION"
|
||||
|
||||
File home = new File(System.getProperty("user.home"))
|
||||
home = new File(home, ".mwtrackerd")
|
||||
home.mkdir()
|
||||
|
||||
File mwProps = new File(home, "MuWire.properties")
|
||||
File i2pProps = new File(home, "i2p.properties")
|
||||
File trackerProps = new File(home, "tracker.properties")
|
||||
|
||||
boolean launchSetup = false
|
||||
|
||||
if (args.length > 0 && args[0] == "setup") {
|
||||
println "Setup requested, entering setup wizard"
|
||||
launchSetup = true
|
||||
} else if (!(mwProps.exists() && i2pProps.exists() && trackerProps.exists())) {
|
||||
println "Config files not found, entering setup wizard"
|
||||
launchSetup = true
|
||||
}
|
||||
|
||||
if (launchSetup) {
|
||||
SetupWizard wizard = new SetupWizard(home)
|
||||
Properties props = wizard.performSetup()
|
||||
|
||||
// nickname goes to mw.props
|
||||
MuWireSettings mwSettings = new MuWireSettings()
|
||||
mwSettings.nickname = props['nickname']
|
||||
|
||||
mwProps.withPrintWriter("UTF-8", {
|
||||
mwSettings.write(it)
|
||||
})
|
||||
|
||||
// i2cp host & port go in i2p.properties
|
||||
def i2cpProps = new Properties()
|
||||
i2cpProps['i2cp.tcp.port'] = props['i2cp.tcp.port']
|
||||
i2cpProps['i2cp.tcp.host'] = props['i2cp.tcp.host']
|
||||
|
||||
i2pProps.withPrintWriter { i2cpProps.store(it, "") }
|
||||
|
||||
// json rcp props go in tracker.properties
|
||||
def jsonProps = new Properties()
|
||||
jsonProps['jsonrpc.iface'] = props['jsonrpc.iface']
|
||||
jsonProps['jsonrpc.port'] = props['jsonrpc.port']
|
||||
|
||||
trackerProps.withPrintWriter { jsonProps.store(it, "") }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user