From 7929740b847a07ff16656d95cee1f6ebfa8635e3 Mon Sep 17 00:00:00 2001 From: Chris Vogel Date: Mon, 17 Jun 2024 20:17:18 +0200 Subject: [PATCH] pimp my config_panel --- config_panel.toml | 39 ++++++++++++++++++++++++++++----------- scripts/_common.sh | 12 ++++++++++++ scripts/config | 30 ++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 11 deletions(-) create mode 100644 scripts/config diff --git a/config_panel.toml b/config_panel.toml index a6e682e..fcd2243 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -1,16 +1,33 @@ version = "1.0" -[notifications] - name = "notifications" - help.en = "The flohmarkt yunohost integration uses urlwatch to check for changes in the user database." - help.de = "Die flohmarkt yunohost Integration verwendet urlwatch um Änderungen an der Benutzerdatenbank zu überwachen." - [notifications.email] - name = "notify via email" - [notifications.email.admin_mail] +[main] + name.en = "configuration" + name.de = "Konfiguration" + [main.notifications] + name.en = "email notifications" + name.de = "E-Mail Benachrichtigungen" + [main.notifications.admin_mail] type = "email" - ask.en = "email address of this flohmarkts admin" - help.en = "you'll get notified about events like changes in the user database of flohmarkt" - ask.de = "E-Mail Adresse des Administrators dieses flohmarkts" - help.de = "an diese Adresse werden Informationen zu z.B. Änderungen an der Benutzerdatenbank geschickt" + ask.en = "recipient of notifications" + help.en = "this email gets notified about events like changes in the user database of flohmarkt" + ask.de = "Empfänger von Benachrichtigungen" + help.de = "an diese E-Mail Adresse werden Informationen zu z.B. Änderungen an der Benutzerdatenbank geschickt" bind = "email>to:__INSTALL_DIR__/urlwatch/config.yaml" + [main.flohmarkt] + name.en = "flohmarkt settings" + name.de = "flohmarkt Konfiguration" + [main.flohmarkt.flohmarkt_initial_setup_url] + type = "text" + readonly = true + ask.en = "initial setup" + ask.de = "Initiales Setup" + help.en = "open this url to finish your flohmarkt setup" + help.de = "öffne die URL um flohmarkt fertig zu konfigurieren" +#[flohmarkt_setup] +# name = "setup" +# [flohmarkt_setup.flohmarkt_initial_setup_url] +# name = "initial setup url" +# type = "string" +# ask = "open this url to initially setup flohmarkt" +# help = "you can't change this value" diff --git a/scripts/_common.sh b/scripts/_common.sh index ea94469..75d9e77 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -776,6 +776,18 @@ flohmarkt_ynh_urlwatch_cron() { --cache /var/www/${app}/urlwatch/cache.file } +flohmarkt_initialized() { + flohmarkt_ynh_local_curl -n -m GET -u admin -p "$password_couchdb_admin" \ + -l '"initialized":true' \ + "http://127.0.0.1:5984/${app}/instance_settings" +} + +flohmarkt_ynh_get_initialization_key() { + flohmarkt_ynh_local_curl -n -m GET -u admin -p "$password_couchdb_admin" \ + "http://127.0.0.1:5984/${app}/instance_settings" \ + | jq -r .initialization_key +} + # move files and directories to their new places flohmarkt_ynh_upgrade_path_ynh5() { # flohmarkt and couchdb are already stopped in upgrade script diff --git a/scripts/config b/scripts/config new file mode 100644 index 0000000..71aa970 --- /dev/null +++ b/scripts/config @@ -0,0 +1,30 @@ +#!/bin/bash + +source /etc/yunohost/apps/$app/scripts/_common.sh +source /usr/share/yunohost/helpers + +ynh_abort_if_errors + +# my code starts here: + +get__flohmarkt_initial_setup_url(){ + local init_key="$(flohmarkt_ynh_get_initialization_key)" + # TODO: wenn leer, dann etwas anderes zurückgeben + if ! [[ -v init_key ]] || + [[ "${init_key}" == 'null' ]] || + [[ -z "${init_key}" ]] + then + if flohmarkt_initialized; then + echo '✅ done already' + else + echo "error: couldn't find the initialization key" + fi + else + echo -n "" + echo "https://${domain}/setup/${init_key}" + fi +} + +# https://yunohost.org/en/packaging_config_panels#custom-getter-setter +# we're supposed to put this here, to fill variables with values from settings +ynh_app_config_run $1