This commit is contained in:
roydfalk 2024-10-13 15:53:50 +02:00
commit 09b657ae5c
8 changed files with 5614 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/.geany

1292
lib/plankton/plankton.d.ts vendored Normal file

File diff suppressed because it is too large Load diff

3972
lib/plankton/plankton.js Normal file

File diff suppressed because it is too large Load diff

157
source/main.ts Normal file
View file

@ -0,0 +1,157 @@
/**
*/
function get_stamp(): string
{
let date: Date = (new Date(Date.now()));
return lib_plankton.string.coin(
// "{{year}}{{month}}{{day}}T{{hour}}{{minute}}{{second}}",
"{{year}}-{{month}}-{{day}}",
{
"year": date.getFullYear().toFixed(0).padStart(4, "0"),
"month": (date.getMonth() + 1).toFixed(0).padStart(2, "0"),
"day": date.getDate().toFixed(0).padStart(2, "0"),
"hour": date.getHours().toFixed(0).padStart(2, "0"),
"minute": date.getMinutes().toFixed(0).padStart(2, "0"),
"second": date.getSeconds().toFixed(0).padStart(2, "0"),
}
);
}
/**
*/
async function main(): Promise<void>
{
const conf = lib_plankton.json.decode(await lib_plankton.file.read("conf.json"));
const stamp: string = get_stamp();
const target_directory = (conf.target.directory + "/" + stamp);
let commands: Array<string> = [];
const commands_add : (command: string) => void = (command) => {
commands.push(command);
};
const commands_apply : () => void = () => {
// TODO
process.stdout.write(commands.join("\n") + "\n");
};
commands_add(
lib_plankton.string.coin(
"mkdir --parents {{directory}}",
{
"directory": target_directory,
}
)
);
commands_add(
""
);
for await (const concern of conf.concerns) {
if (! concern.active) {
// do nothing
}
else {
commands_add(
lib_plankton.string.coin(
"# {{name}}",
{
"name": concern.name,
"kind": concern.kind,
}
)
);
commands_add(
lib_plankton.string.coin(
"echo '-- {{name}}' > /dev/stderr",
{
"name": concern.name,
"kind": concern.kind,
}
)
);
switch (concern.kind) {
case "postgresql_dump": {
const password_file_path: string = "${HOME}/.pgpass";
commands_add(
lib_plankton.string.coin(
"echo '{{host}}:{{port}}:{{schema}}:{{username}}:{{password}}' > {{path}} && chmod 0600 {{path}}",
{
"path": password_file_path,
"host": concern.parameters.credentials.host,
"port": concern.parameters.credentials.port.toFixed(0),
"username": concern.parameters.credentials.username,
"password": concern.parameters.credentials.password,
"schema": concern.parameters.credentials.schema,
}
)
);
commands_add(
lib_plankton.string.coin(
"pg_dump --host={{host}} --port={{port}} --username={{username}} {{schema}} > {{target_path}}",
{
"host": concern.parameters.credentials.host,
"port": concern.parameters.credentials.port.toFixed(0),
"username": concern.parameters.credentials.username,
"schema": concern.parameters.credentials.schema,
"target_path": lib_plankton.string.coin(
"{{directory}}/{{name}}.sql",
{
"directory": target_directory,
"name": concern.parameters.name,
}
),
}
)
);
commands_add(
lib_plankton.string.coin(
"rm {{path}}",
{
"path": password_file_path,
}
)
);
break;
}
case "files": {
commands_add(
lib_plankton.string.coin(
"tar --create --directory={{path}} . > {{target_path}}",
{
"path": concern.parameters.path,
"target_path": lib_plankton.string.coin(
"{{directory}}/{{name}}.tar",
{
"directory": target_directory,
"name": concern.parameters.name,
}
),
}
)
);
break;
}
default: {
throw (new Error("unhandled kind: " + concern.kind));
break;
}
}
commands_add(
""
);
}
}
commands_add(
lib_plankton.string.coin(
"echo '{{directory}}'",
{
"directory": target_directory,
}
)
);
commands_apply();
return Promise.resolve<void>(undefined);
}
main();

55
tools/build Executable file
View file

@ -0,0 +1,55 @@
#!/usr/bin/env python3
import sys as _sys
import os as _os
import argparse as _argparse
def main():
## args
argument_parser = _argparse.ArgumentParser()
argument_parser.add_argument(
"-c",
"--conf-path",
type = str,
default = None,
metavar = "<conf-path>",
help = "conf path",
)
argument_parser.add_argument(
"-o",
"--output-directory",
type = str,
default = "/tmp/mimir",
metavar = "<output-directory>",
help = "output directory",
)
args = argument_parser.parse_args()
## exec
targets = []
targets.append("main")
if True:
_os.system(
"make dir_build=%s --file=tools/makefile %s"
% (
args.output_directory,
" ".join(targets),
)
)
if True:
if (args.conf_path is None):
pass
else:
_os.system(
"cp %s %s/conf.json"
% (
args.conf_path,
args.output_directory,
)
)
_sys.stdout.write("%s\n" % args.output_directory)
main()

59
tools/deploy Executable file
View file

@ -0,0 +1,59 @@
#!/usr/bin/env python3
import sys as _sys
import os as _os
import argparse as _argparse
def main():
## args
argument_parser = _argparse.ArgumentParser()
argument_parser.add_argument(
type = str,
dest = "target_system",
metavar = "<target-system>",
help = "either 'localhost' or SSH handle of the target system",
)
argument_parser.add_argument(
"-t",
"--target-directory",
type = str,
dest = "target_directory",
default = "/opt/mimir",
metavar = "<target-directory>",
help = "directory on the target system, where the files shall be put; default: /opt/mimir",
)
argument_parser.add_argument(
"-b",
"--build-directory",
type = str,
dest = "build_directory",
default = "build",
metavar = "<build-directory>",
help = "directory to where the build was put",
)
args = argument_parser.parse_args()
## exec
if (not _os.path.exists(args.build_directory)):
_sys.stderr.write("-- build directory not found; probably you need to run /tools/build\n")
_sys.exit(1)
else:
_os.system(
" ".join([
"rsync",
"--recursive",
"--update",
"--verbose",
"--exclude='conf.json'",
("%s/" % args.build_directory),
(
("%s" % args.target_directory)
if (args.target_system == "localhost") else
("%s:%s" % (args.target_system, args.target_directory, ))
),
])
)
main()

58
tools/makefile Normal file
View file

@ -0,0 +1,58 @@
# Espe | Ein schlichtes Werkzeug zur Mitglieder-Verwaltung | Backend
# Copyright (C) 2024 Christian Fraß
#
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program. If not, see
# <https://www.gnu.org/licenses/>.
## consts
dir_lib := lib
dir_source := source
dir_temp := /tmp/mimir-temp
dir_build := build
dir_tools := tools
cmd_log := echo "--"
cmd_cat := cat
cmd_chmod := chmod
cmd_mkdir := mkdir -p
cmd_cp := cp
cmd_tsc := tsc
## rules
.PHONY: default
default: main
.PHONY: main
main: ${dir_build}/mimir
${dir_temp}/head.js:
@ ${cmd_log} "head …"
@ ${cmd_mkdir} $(dir $@)
@ echo "#!/usr/bin/env node\n" > $@
${dir_temp}/mimir-raw.js: \
${dir_lib}/plankton/plankton.d.ts \
${dir_source}/main.ts
@ ${cmd_log} "compile …"
@ ${cmd_mkdir} $(dir $@)
@ ${cmd_tsc} --lib es2020 --strict $^ --outFile $@
${dir_build}/mimir: \
${dir_temp}/head.js \
${dir_lib}/plankton/plankton.js \
${dir_temp}/mimir-raw.js
@ ${cmd_log} "link …"
@ ${cmd_mkdir} $(dir $@)
@ ${cmd_cat} $^ > $@
@ ${cmd_chmod} +x $@

20
tools/update-plankton Executable file
View file

@ -0,0 +1,20 @@
#!/usr/bin/env sh
## consts
dir=lib/plankton
modules=""
modules="${modules} base"
modules="${modules} file"
modules="${modules} call"
modules="${modules} json"
modules="${modules} string"
## exec
mkdir -p ${dir}
cd ${dir}
ptk bundle node ${modules}
cd - > /dev/null