From 71102354aa9bfdfc691a14d4cbaeea5a9a1c0f70 Mon Sep 17 00:00:00 2001 From: oiseauroch <5622590+oiseauroch@users.noreply.github.com> Date: Sun, 20 Nov 2022 18:31:01 +0000 Subject: [PATCH] add config panel (#21) * add config panel --- README.md | 2 +- README_fr.md | 2 +- config_panel.toml | 14 +++++++++++++ manifest.json | 2 +- scripts/config | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 config_panel.toml create mode 100644 scripts/config diff --git a/README.md b/README.md index c66cc8a..ae90989 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in The news reader that doesn't know you -**Shipped version:** 1.6.0~ynh1 +**Shipped version:** 1.6.0~ynh2 **Demo:** https://petrolette.space diff --git a/README_fr.md b/README_fr.md index 44a1d9b..a1dedbc 100644 --- a/README_fr.md +++ b/README_fr.md @@ -17,7 +17,7 @@ Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour La page d'actu qui ne sait rien de toi -**Version incluse :** 1.6.0~ynh1 +**Version incluse :** 1.6.0~ynh2 **Démo :** https://petrolette.space diff --git a/config_panel.toml b/config_panel.toml new file mode 100644 index 0000000..5d52a78 --- /dev/null +++ b/config_panel.toml @@ -0,0 +1,14 @@ +version = "1.0" + +[main] + +services = ["__APP__"] + + [main.customization] + + [main.customization.instanceType] + ask = "Mono user instance" + type = "boolean" + help = "if this instance is mono user, the feed list will be the same for all users" + bind = "instance_type()" + diff --git a/manifest.json b/manifest.json index 8a963f9..2763ee7 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "The news reader that doesn't know you", "fr": "La page d'actu qui ne sait rien de toi" }, - "version": "1.6.0~ynh1", + "version": "1.6.0~ynh2", "url": "https://framagit.org/yphil/petrolette", "upstream": { "license": "AGPL-3.0-only", diff --git a/scripts/config b/scripts/config new file mode 100644 index 0000000..a504e39 --- /dev/null +++ b/scripts/config @@ -0,0 +1,50 @@ +#!/bin/bash +# In simple cases, you don't need a config script. + +# With a simple config_panel.toml, you can write in the app settings, in the +# upstream config file or replace complete files (logo ...) and restart services. + +# The config scripts allows you to go further, to handle specific cases +# (validation of several interdependent fields, specific getter/setter for a value, +# display dynamic informations or choices, pre-loading of config type .cube... ). + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source /usr/share/yunohost/helpers + +ynh_abort_if_errors + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +final_path=$(ynh_app_setting_get $app final_path) + + +get__instance_type() { + if [ -f "$final_path/petrolette.config.json" ] + then + echo 1 + else + echo 0 + fi +} + +set__instance_type() { + if [ "$instanceType" -eq 1 ] + then + echo '{ "instanceType" : "monoUser" }' > "$final_path/petrolette.config.json" + ynh_app_setting_set --app=$app --key=mono_user --value=1 + else + rm "$final_path/petrolette.config.json" + ynh_app_setting_set --app=$app --key=mono_user --value=0 + fi +} +#================================================= +# GENERIC FINALIZATION +#================================================= +ynh_app_config_run $1