mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 11:04:00 +01:00
Added --install flag.
This commit is contained in:
parent
c741382fc9
commit
3ef89718a1
|
@ -56,7 +56,19 @@ namespace i2p
|
||||||
LogPrint("\n\n\n\ni2pd starting\n");
|
LogPrint("\n\n\n\ni2pd starting\n");
|
||||||
LogPrint("Version ", VERSION);
|
LogPrint("Version ", VERSION);
|
||||||
LogPrint("data directory: ", i2p::util::filesystem::GetDataDir().string());
|
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);
|
isDaemon = i2p::util::config::GetArg("-daemon", 0);
|
||||||
isLogging = i2p::util::config::GetArg("-log", 1);
|
isLogging = i2p::util::config::GetArg("-log", 1);
|
||||||
|
@ -104,7 +116,6 @@ namespace i2p
|
||||||
else
|
else
|
||||||
StartLog (""); // write to stdout
|
StartLog (""); // write to stdout
|
||||||
}
|
}
|
||||||
|
|
||||||
d.httpServer = new i2p::util::HTTPServer(
|
d.httpServer = new i2p::util::HTTPServer(
|
||||||
i2p::util::config::GetArg("-httpaddress", "127.0.0.1"),
|
i2p::util::config::GetArg("-httpaddress", "127.0.0.1"),
|
||||||
i2p::util::config::GetArg("-httpport", 7070)
|
i2p::util::config::GetArg("-httpport", 7070)
|
||||||
|
|
|
@ -107,7 +107,9 @@ void HTTPConnection::Send404Reply()
|
||||||
"<head><title>Error: 404 - webui not installed</title></head><body>"
|
"<head><title>Error: 404 - webui not installed</title></head><body>"
|
||||||
"<p>It looks like your webui installation is broken.</p>"
|
"<p>It looks like your webui installation is broken.</p>"
|
||||||
"<p>Run the following command to (re)install it:</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>"
|
"<p>The webui folder should come with the binaries.</p>"
|
||||||
"</body></html>"
|
"</body></html>"
|
||||||
);
|
);
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
#include "Daemon.h"
|
#include "Daemon.h"
|
||||||
#include "Reseed.h"
|
#include "Reseed.h"
|
||||||
|
|
||||||
int main( int argc, char* argv[] )
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
Daemon.init(argc, argv);
|
if(!Daemon.init(argc, argv))
|
||||||
if (Daemon.start())
|
return EXIT_FAILURE;
|
||||||
{
|
|
||||||
while (Daemon.running)
|
if(Daemon.start()) {
|
||||||
{
|
while (Daemon.running) {
|
||||||
//TODO Meeh: Find something better to do here.
|
//TODO Meeh: Find something better to do here.
|
||||||
std::this_thread::sleep_for (std::chrono::seconds(1));
|
std::this_thread::sleep_for (std::chrono::seconds(1));
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,6 +125,11 @@ namespace config {
|
||||||
return nDefault;
|
return nDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool HasArg(const std::string& strArg)
|
||||||
|
{
|
||||||
|
return mapArgs.count(strArg);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace filesystem
|
namespace filesystem
|
||||||
|
@ -258,6 +263,46 @@ namespace filesystem
|
||||||
{
|
{
|
||||||
return GetDataDir () / "certificates";
|
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
|
namespace http
|
||||||
|
|
|
@ -41,6 +41,11 @@ namespace util
|
||||||
* @param nDefault the default value to be returned
|
* @param nDefault the default value to be returned
|
||||||
*/
|
*/
|
||||||
const char* GetCharArg(const std::string& strArg, const std::string& nDefault);
|
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
|
namespace filesystem
|
||||||
|
@ -95,6 +100,18 @@ namespace util
|
||||||
* @return the path of the certificates directory
|
* @return the path of the certificates directory
|
||||||
*/
|
*/
|
||||||
boost::filesystem::path GetCertificatesDir();
|
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
|
namespace http
|
||||||
|
|
Loading…
Reference in a new issue