mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2026-01-10 23:18:59 -05:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2308b02504 | ||
|
|
81d9a6cc02 | ||
|
|
0232f0a95f | ||
|
|
309d4d01f1 |
@@ -10,7 +10,8 @@ VOLUME /data
|
||||
WORKDIR /data
|
||||
|
||||
# running as a named unprivileged user
|
||||
RUN addgroup -S user && adduser -S user -G user
|
||||
RUN addgroup -S -g 1001 user && adduser -S -u 1001 user -G user
|
||||
RUN chown user:user /data
|
||||
USER user
|
||||
|
||||
COPY ./start.sh /usr/local/bin/
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
# Download if necessary a file
|
||||
if [ ! -z "$DOWNLOAD" ]
|
||||
then
|
||||
# Check if /data is writable
|
||||
if [ ! -w /data ]
|
||||
then
|
||||
echo "'/data' directory is not writable by '$(id -n -u):$(id -n -g)' ($(id -u):$(id -g)). ZIM file(s) can not be written."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Dwonload ZIM file
|
||||
ZIM=`basename $DOWNLOAD`
|
||||
wget $DOWNLOAD -O "$ZIM"
|
||||
|
||||
|
||||
@@ -39,8 +39,6 @@ be provided as a semicolon (``;``) separated list.
|
||||
|
||||
``ZIM_FILE_PATH``: ZIM file path (multiple arguments are allowed).
|
||||
|
||||
``DIRECTORY_PATH``: Directory path containing ZIM files (multiple arguments are allowed).
|
||||
|
||||
Options
|
||||
-------
|
||||
|
||||
|
||||
@@ -8,10 +8,6 @@ kiwix-serve \- Kiwix HTTP Server
|
||||
.B kiwix-serve --library [OPTIONS] LIBRARY_FILE_PATH
|
||||
.br
|
||||
.B kiwix-serve [OPTIONS] ZIM_FILE_PATH ...
|
||||
.br
|
||||
.B kiwix-serve [OPTIONS] DIRECTORY_PATH ...
|
||||
.br
|
||||
.B kiwix-serve [OPTIONS] ZIM_FILE_PATH DIRECTORY_PATH ...
|
||||
|
||||
.SH DESCRIPTION
|
||||
The \fBkiwix-serve\fR command is used to run a stand-alone HTTP server for serving ZIM contents over the network.
|
||||
@@ -25,10 +21,6 @@ Path of an XML library file listing ZIM files to serve. To be used only with the
|
||||
\fBZIM_FILE_PATH ...\fR
|
||||
ZIM file path(s). Multiple arguments are allowed.
|
||||
|
||||
.TP
|
||||
\fBDIRECTORY_PATH ...\fR
|
||||
Path(s) of directories containing ZIM files. Multiple arguments are allowed.
|
||||
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
\fB--library\fR
|
||||
@@ -131,11 +123,6 @@ Serve multiple ZIM files:
|
||||
.B kiwix-serve zim1.zim zim2.zim zim3.zim
|
||||
.fi
|
||||
|
||||
Serve ZIM files within a directory or directories:
|
||||
.sp
|
||||
.nf
|
||||
.B kiwix-serve zimDir1 zimDir2
|
||||
|
||||
Serve ZIM files from a library:
|
||||
.sp
|
||||
.nf
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include <kiwix/server.h>
|
||||
#include <kiwix/name_mapper.h>
|
||||
#include <kiwix/tools.h>
|
||||
#include <filesystem>
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <windows.h>
|
||||
@@ -45,22 +44,19 @@
|
||||
#define LITERAL_AS_STR(A) #A
|
||||
#define AS_STR(A) LITERAL_AS_STR(A)
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
static const char USAGE[] =
|
||||
R"(Deliver ZIM file(s) articles via HTTP
|
||||
|
||||
Usage:
|
||||
kiwix-serve [options] ZIMPATH ...
|
||||
kiwix-serve [options] DIRECTORYPATH ...
|
||||
kiwix-serve [options] ZIMPATH DIRECTORYPATH ...
|
||||
kiwix-serve [options] (-l | --library) LIBRARYPATH
|
||||
kiwix-serve -h | --help
|
||||
kiwix-serve -V | --version
|
||||
|
||||
Mandatory arguments:
|
||||
LIBRARYPATH XML library file path listing ZIM file to serve. To be used only with the --library argument."
|
||||
ZIMPATH ZIM file/directory path(s)
|
||||
ZIMPATH ZIM file path(s)
|
||||
|
||||
Options:
|
||||
-h --help Print this help
|
||||
@@ -187,26 +183,6 @@ bool reloadLibrary(kiwix::Manager& mgr, const std::vector<std::string>& paths)
|
||||
}
|
||||
}
|
||||
|
||||
void addPathsInManager(kiwix::Manager& manager, const std::vector<std::string>& zimPaths,
|
||||
bool skipInvalid, bool isVerboseFlag)
|
||||
{
|
||||
for (auto it = zimPaths.begin(); it != zimPaths.end(); it++) {
|
||||
if (fs::is_directory(*it)) {
|
||||
manager.addBooksFromDirectory(*it, isVerboseFlag);
|
||||
} else {
|
||||
if (!manager.addBookFromPath(*it, *it, "", false)) {
|
||||
if (skipInvalid) {
|
||||
std::cerr << "Skipping invalid '" << *it << "' ...continuing" << std::endl;
|
||||
} else {
|
||||
std::cerr << "Unable to add the ZIM file '" << *it
|
||||
<< "' to the internal library." << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// docopt::value::isLong() is counting repeated values.
|
||||
// It doesn't check if the string can be parsed as long.
|
||||
// (Contrarly to `asLong` which will try to convert string to long)
|
||||
@@ -238,7 +214,7 @@ int main(int argc, char** argv)
|
||||
std::string rootLocation = "/";
|
||||
auto library = kiwix::Library::create();
|
||||
unsigned int nb_threads = DEFAULT_THREADS;
|
||||
std::vector<std::string> zimPaths;
|
||||
std::vector<std::string> zimPathes;
|
||||
std::string libraryPath;
|
||||
std::string rootPath;
|
||||
std::string address;
|
||||
@@ -294,7 +270,7 @@ int main(int argc, char** argv)
|
||||
STRING("--customIndex", customIndexPath)
|
||||
INT("--ipConnectionLimit", ipConnectionLimit, "IP connection limit must be an integer")
|
||||
INT("--searchLimit", searchLimit, "Search limit must be an integer")
|
||||
STRING_LIST("ZIMPATH", zimPaths, "ZIMPATH must be a string list")
|
||||
STRING_LIST("ZIMPATH", zimPathes, "ZIMPATH must be a string list")
|
||||
}
|
||||
|
||||
if (!errorString.empty()) {
|
||||
@@ -328,7 +304,18 @@ int main(int argc, char** argv)
|
||||
<< "' is empty (or has only remote books)." << std::endl;
|
||||
}
|
||||
} else {
|
||||
addPathsInManager(manager, zimPaths, skipInvalid, isVerboseFlag);
|
||||
std::vector<std::string>::iterator it;
|
||||
for (it = zimPathes.begin(); it != zimPathes.end(); it++) {
|
||||
if (!manager.addBookFromPath(*it, *it, "", false)) {
|
||||
if (skipInvalid) {
|
||||
std::cerr << "Skipping invalid '" << *it << "' ...continuing" << std::endl;
|
||||
} else {
|
||||
std::cerr << "Unable to add the ZIM file '" << *it
|
||||
<< "' to the internal library." << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
auto libraryFileTimestamp = newestFileTimestamp(libraryPaths);
|
||||
auto curLibraryFileTimestamp = libraryFileTimestamp;
|
||||
|
||||
Reference in New Issue
Block a user