summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-07-09 21:22:16 +0200
committerDavid Härdeman <david@hardeman.nu>2020-07-09 21:22:16 +0200
commit984f586e3ef70b9db759ce48da4f06f0a6680c6f (patch)
tree3fe76aa0140255aab9bb08f21615ea7ada150796
parentdd6321c0acf7b0570811200a205cc4104bee49c7 (diff)
Move example config files to external files and generate at build time
-rw-r--r--debian/control3
-rw-r--r--examples/README.TXT1
-rw-r--r--examples/eula.txt1
-rw-r--r--examples/example.mcserver1
-rw-r--r--examples/meson.build29
-rw-r--r--examples/minecproxy.conf1
-rw-r--r--examples/minecproxy.service1
-rw-r--r--examples/minecserver@.service1
-rw-r--r--examples/server.properties1
-rw-r--r--man/meson.build2
-rw-r--r--meson.build1
-rw-r--r--minecctl/misc-commands.c50
12 files changed, 69 insertions, 23 deletions
diff --git a/debian/control b/debian/control
index c3739b6..3027ff8 100644
--- a/debian/control
+++ b/debian/control
@@ -10,7 +10,8 @@ Build-Depends: debhelper-compat (= 12),
liburing-dev,
meson,
pkg-config,
- xsltproc
+ xsltproc,
+ xxd
Standards-Version: 4.5.0
Rules-Requires-Root: no
Homepage: <insert the upstream URL, if relevant>
diff --git a/examples/README.TXT b/examples/README.TXT
new file mode 100644
index 0000000..4de7a1c
--- /dev/null
+++ b/examples/README.TXT
@@ -0,0 +1 @@
+This is an example README.TXT
diff --git a/examples/eula.txt b/examples/eula.txt
new file mode 100644
index 0000000..aaf5a5a
--- /dev/null
+++ b/examples/eula.txt
@@ -0,0 +1 @@
+This is an example eula
diff --git a/examples/example.mcserver b/examples/example.mcserver
new file mode 100644
index 0000000..ed919dc
--- /dev/null
+++ b/examples/example.mcserver
@@ -0,0 +1 @@
+This is an example mcserver
diff --git a/examples/meson.build b/examples/meson.build
new file mode 100644
index 0000000..e50f459
--- /dev/null
+++ b/examples/meson.build
@@ -0,0 +1,29 @@
+# SPDX-License-Identifier: GPL-2
+
+example_files = [
+ 'eula.txt',
+ 'example.mcserver',
+ 'minecproxy.conf',
+ 'minecproxy.service',
+ 'minecserver@.service',
+ 'README.TXT',
+ 'server.properties',
+]
+
+xxd = find_program('xxd')
+
+xxd_cmd = [xxd, '-i', '@INPUT@', '@OUTPUT@']
+
+foreach example_file: example_files
+ example_output = example_file + '.h'
+
+ file = custom_target(
+ example_output,
+ input: example_file,
+ output: example_output,
+ command: xxd_cmd,
+ build_by_default: true,
+ )
+endforeach
+
+
diff --git a/examples/minecproxy.conf b/examples/minecproxy.conf
new file mode 100644
index 0000000..b17d8ef
--- /dev/null
+++ b/examples/minecproxy.conf
@@ -0,0 +1 @@
+This is the minecproxy conf example
diff --git a/examples/minecproxy.service b/examples/minecproxy.service
new file mode 100644
index 0000000..e14ed81
--- /dev/null
+++ b/examples/minecproxy.service
@@ -0,0 +1 @@
+This is an example service
diff --git a/examples/minecserver@.service b/examples/minecserver@.service
new file mode 100644
index 0000000..e14ed81
--- /dev/null
+++ b/examples/minecserver@.service
@@ -0,0 +1 @@
+This is an example service
diff --git a/examples/server.properties b/examples/server.properties
new file mode 100644
index 0000000..f992c40
--- /dev/null
+++ b/examples/server.properties
@@ -0,0 +1 @@
+This is an example server.properties file
diff --git a/man/meson.build b/man/meson.build
index 88f34ef..508a531 100644
--- a/man/meson.build
+++ b/man/meson.build
@@ -1,4 +1,4 @@
-# SPDX-License-Identifier: LGPL-2.1+
+# SPDX-License-Identifier: GPL-2
man_pages = [
{
diff --git a/meson.build b/meson.build
index 7f30575..a88b523 100644
--- a/meson.build
+++ b/meson.build
@@ -62,6 +62,7 @@ dep_config_h = declare_dependency(
)
subdir('shared')
+subdir('examples')
subdir('minecproxy')
subdir('minecctl')
subdir('man')
diff --git a/minecctl/misc-commands.c b/minecctl/misc-commands.c
index 054279b..5a6fe3a 100644
--- a/minecctl/misc-commands.c
+++ b/minecctl/misc-commands.c
@@ -17,6 +17,14 @@
#include "shared/systemd.h"
#include "misc.h"
+#include "examples/eula.txt.h"
+#include "examples/example.mcserver.h"
+#include "examples/minecproxy.conf.h"
+#include "examples/minecproxy.service.h"
+#include "examples/minecserver@.service.h"
+#include "examples/README.TXT.h"
+#include "examples/server.properties.h"
+
static bool create_link(int dfd, const char *source, const char *target)
{
if (symlinkat(target, dfd, source) < 0) {
@@ -27,10 +35,10 @@ static bool create_link(int dfd, const char *source, const char *target)
return true;
}
-static bool write_cfg_file(int dfd, const char *name, const char *content)
+static bool write_cfg_file(int dfd, const char *name, unsigned char *content,
+ size_t len)
{
int fd;
- ssize_t len = strlen(content);
ssize_t done = 0, r;
bool rv = true;
@@ -57,14 +65,6 @@ static bool write_cfg_file(int dfd, const char *name, const char *content)
return rv;
}
-static const char txt_server_readme[] = "This is the server readme\n";
-static const char txt_server_eula[] = "This is the server eula\n";
-static const char txt_server_properties[] = "This is the server properties\n";
-static const char txt_server_conf[] = "This is the server conf\n";
-static const char txt_minecproxy_conf[] = "This is the minecproxy conf\n";
-static const char txt_minecproxy_service[] = "This is the minecproxy service\n";
-static const char txt_minecserver_service[] = "This is the minecserver service\n";
-
static bool find_user_service(int xfd, const char *service)
{
int dfd;
@@ -118,7 +118,7 @@ static bool find_user_service(int xfd, const char *service)
}
static bool create_user_service(int xfd, const char *service,
- const char *content)
+ unsigned char *content, size_t len)
{
int sfd, ufd = -1;
bool rv = false;
@@ -134,7 +134,7 @@ static bool create_user_service(int xfd, const char *service,
if (ufd < 0)
goto out;
- if (!write_cfg_file(ufd, service, content))
+ if (!write_cfg_file(ufd, service, content, len))
goto out;
info("Created user service file $XDG_CONFIG_HOME/systemd/user/%s",
@@ -162,17 +162,21 @@ static bool create_config_tree(int xfd)
if (sfd < 0)
goto out;
- if (!write_cfg_file(sfd, "README.TXT", txt_server_readme))
+ if (!write_cfg_file(sfd, "README.TXT", ___examples_README_TXT,
+ ___examples_README_TXT_len))
goto out;
- efd = open_subdir(sfd, "example-server", true);
+ efd = open_subdir(sfd, "example", true);
if (efd < 0)
goto out;
- if (!write_cfg_file(efd, "eula.txt", txt_server_eula))
+ if (!write_cfg_file(efd, "eula.txt", ___examples_eula_txt,
+ ___examples_eula_txt_len))
goto out;
- if (!write_cfg_file(efd, "server.properties", txt_server_properties))
+ if (!write_cfg_file(efd, "server.properties",
+ ___examples_server_properties,
+ ___examples_server_properties_len))
goto out;
if (!create_link(efd, "server.jar", "../server.jar"))
@@ -182,10 +186,13 @@ static bool create_config_tree(int xfd)
if (cfd < 0)
goto out;
- if (!write_cfg_file(cfd, "example-server.mcserver", txt_server_conf))
+ if (!write_cfg_file(cfd, "example.mcserver",
+ ___examples_example_mcserver,
+ ___examples_example_mcserver_len))
goto out;
- if (!write_cfg_file(cfd, "minecproxy.conf", txt_minecproxy_conf))
+ if (!write_cfg_file(cfd, "minecproxy.conf", ___examples_minecproxy_conf,
+ ___examples_minecproxy_conf_len))
goto out;
info("Created configuration in $XDG_CONFIG_HOME/minecproxy");
@@ -228,11 +235,13 @@ bool do_init(struct cfg *cfg)
}
if (!create_user_service(xfd, "minecserver@.service",
- txt_minecserver_service))
+ ___examples_minecserver__service,
+ ___examples_minecserver__service_len))
goto out;
if (!create_user_service(xfd, "minecproxy.service",
- txt_minecproxy_service))
+ ___examples_minecproxy_service,
+ ___examples_minecproxy_service_len))
goto out;
rv = true;
@@ -424,4 +433,3 @@ bool do_status(struct cfg *cfg)
return true;
}
-