Browse Source

Added --install flag.

pull/271/head
EinMByte 9 years ago
parent
commit
3ef89718a1
  1. 15
      client/Daemon.cpp
  2. 4
      client/HTTPServer.cpp
  3. 12
      client/i2p.cpp
  4. 45
      core/util/util.cpp
  5. 17
      core/util/util.h

15
client/Daemon.cpp

@ -56,7 +56,19 @@ namespace i2p @@ -56,7 +56,19 @@ namespace i2p
LogPrint("\n\n\n\ni2pd starting\n");
LogPrint("Version ", VERSION);
LogPrint("data directory: ", i2p::util::filesystem::GetDataDir().string());
i2p::util::filesystem::ReadConfigFile(i2p::util::config::mapArgs, i2p::util::config::mapMultiArgs);
i2p::util::filesystem::ReadConfigFile(
i2p::util::config::mapArgs, i2p::util::config::mapMultiArgs
);
if(i2p::util::config::HasArg("-install")) {
try {
i2p::util::filesystem::InstallFiles();
LogPrint("Succesfully installed all files.");
} catch(const std::runtime_error& e) {
LogPrint(eLogError, "Failed to install: ", e.what());
return false;
}
}
isDaemon = i2p::util::config::GetArg("-daemon", 0);
isLogging = i2p::util::config::GetArg("-log", 1);
@ -104,7 +116,6 @@ namespace i2p @@ -104,7 +116,6 @@ namespace i2p
else
StartLog (""); // write to stdout
}
d.httpServer = new i2p::util::HTTPServer(
i2p::util::config::GetArg("-httpaddress", "127.0.0.1"),
i2p::util::config::GetArg("-httpport", 7070)

4
client/HTTPServer.cpp

@ -107,7 +107,9 @@ void HTTPConnection::Send404Reply() @@ -107,7 +107,9 @@ void HTTPConnection::Send404Reply()
"<head><title>Error: 404 - webui not installed</title></head><body>"
"<p>It looks like your webui installation is broken.</p>"
"<p>Run the following command to (re)install it:</p>"
"<pre>./i2pd --install /path/to/webui</pre>"
"<pre>./i2pd --install=/path/to/webui</pre>"
"<p>Or from a directory containing a folder named webui:</p>"
"<pre>./i2pd --install</pre>"
"<p>The webui folder should come with the binaries.</p>"
"</body></html>"
);

12
client/i2p.cpp

@ -3,13 +3,13 @@ @@ -3,13 +3,13 @@
#include "Daemon.h"
#include "Reseed.h"
int main( int argc, char* argv[] )
int main(int argc, char* argv[])
{
Daemon.init(argc, argv);
if (Daemon.start())
{
while (Daemon.running)
{
if(!Daemon.init(argc, argv))
return EXIT_FAILURE;
if(Daemon.start()) {
while (Daemon.running) {
//TODO Meeh: Find something better to do here.
std::this_thread::sleep_for (std::chrono::seconds(1));
}

45
core/util/util.cpp

@ -125,6 +125,11 @@ namespace config { @@ -125,6 +125,11 @@ namespace config {
return nDefault;
}
bool HasArg(const std::string& strArg)
{
return mapArgs.count(strArg);
}
}
namespace filesystem
@ -258,6 +263,46 @@ namespace filesystem @@ -258,6 +263,46 @@ namespace filesystem
{
return GetDataDir () / "certificates";
}
void InstallFiles()
{
namespace bfs = boost::filesystem;
boost::system::error_code e;
const bfs::path source = bfs::canonical(
config::GetArg("-install", "webui"), e
);
const bfs::path destination = GetWebuiDataDir();
if(e || !bfs::is_directory(source))
throw std::runtime_error("Given directory is invalid or does not exist");
// TODO: check that destination is not in source
try {
CopyDir(source, destination);
} catch(...) {
throw std::runtime_error("Could not copy webui folder to i2pd folder.");
}
}
void CopyDir(const boost::filesystem::path& src, const boost::filesystem::path& dest)
{
namespace bfs = boost::filesystem;
bfs::create_directory(dest);
for(bfs::directory_iterator file(src); file != bfs::directory_iterator(); ++file) {
const bfs::path current(file->path());
if(bfs::is_directory(current))
CopyDir(current, dest / current.filename());
else
bfs::copy_file(
current, dest / current.filename(),
bfs::copy_option::overwrite_if_exists
);
}
}
}
namespace http

17
core/util/util.h

@ -41,6 +41,11 @@ namespace util @@ -41,6 +41,11 @@ namespace util
* @param nDefault the default value to be returned
*/
const char* GetCharArg(const std::string& strArg, const std::string& nDefault);
/**
* @return true if the argument is set, false otherwise
*/
bool HasArg(const std::string& strArg);
}
namespace filesystem
@ -95,6 +100,18 @@ namespace util @@ -95,6 +100,18 @@ namespace util
* @return the path of the certificates directory
*/
boost::filesystem::path GetCertificatesDir();
/**
* Installs the webui files.
* @throw std::runtime_error when installation fails
*/
void InstallFiles();
/**
* Copies all files and directories in src to dest.
* @warning overrides existing files
*/
void CopyDir(const boost::filesystem::path& src, const boost::filesystem::path& dest);
}
namespace http

Loading…
Cancel
Save