Add new config panel values -> updat error

I tried to add two config values e.g.:

diff --git a/config_panel.toml b/config_panel.toml
index 9a8148e..62b32eb 100644
--- a/config_panel.toml
+++ b/config_panel.toml
@@ -40,3 +40,19 @@ services = ["__APP__"]
         choices = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
         default = "WARNING"
         bind = "log_level:/home/yunohost.app/__APP__/settings.py"
+
+        [main.config.fritz_username]
+        ask = "FRITZ USERNAME"
+        type = "string"
+        help = "Connection user name for your FritzBox"
+        default = ""
+        optional = true
+        bind = "admin_email:/home/yunohost.app/__APP__/settings.py"
+
+        [main.config.fritz_password]
+        ask = "FRITZ PASSWORD"
+        type = "string"
+        help = "Connection user password for your FritzBox"
+        default = ""
+        optional = true
+        bind = "admin_email:/home/yunohost.app/__APP__/settings.py"
diff --git a/manifest.toml b/manifest.toml
index c64bb92..429fda3 100644
--- a/manifest.toml
+++ b/manifest.toml
@@ -75,6 +75,20 @@ ram.runtime = "50M" # **estimate** minimum ram requirement. e.g. 50M, 400M, 1G,
     choices = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
     default = "WARNING"
 
+    [main.config.fritz_username] # __FRITZ_USERNAME__
+    ask.en = "FRITZ USERNAME"
+    type = "string"
+    help = "Connection user name for your FritzBox"
+    default = ""
+    optional = true
+
+    [main.config.fritz_password] # __FRITZ_PASSWORD__
+    ask.en = "FRITZ PASSWORD"
+    type = "string"
+    help = "Connection user password for your FritzBox"
+    default = ""
+    optional = true
+

On app upgrade i get this:

+ yunohost app upgrade django-fritzconnection -u https://github.com/YunoHost-Apps/django-fritzconnection_ynh/tree/dev --force --no-safety-backup
Info: Now upgrading django-fritzconnection...
Warning: Skipping the creation of a backup prior to the upgrade.
Info: Updating system_user...
Info: Updating install_dir...
Info: Updating data_dir...
Info: Updating permissions...
Info: Updating ports...
Info: Updating apt...
Info: Updating database...
Info: [+...................] > Stopping systemd service 'django-fritzconnection'...
Info: [#+..................] > Configuring systemd service 'django-fritzconnection'...
Info: [##++++++++++++......] > Create and setup Python virtualenv...
Info: [##############+.....] > Create project configuration files...
Warning: File /home/yunohost.app/django-fritzconnection/settings.py has been manually modified since the installation or last upgrade. So it has been duplicated in /var/cache/yunohost/appconfbackup//home/yunohost.app/django-fritzconnection/settings.py.backup.20231130.175540
Warning: Variable $fritz_password wasn't initialized when trying to replace __FRITZ_PASSWORD__ in /home/yunohost.app/django-fritzconnection/settings.py
Error: Could not upgrade django-fritzconnection: An error occurred inside the app upgrade script
Info: The operation 'Upgrade the 'django-fritzconnection' app' could not be completed. Please share the full log of this operation using the command 'yunohost log share 20231130-165524-app_upgrade-django-fritzconnection' to get help
Warning: Here's an extract of the logs before the crash. It might help debugging the error:
Info: DEBUG - + [[ -v default_from_email ]]
Info: DEBUG - + match_string=__DEFAULT_FROM_EMAIL__
Info: DEBUG - + match_string=__DEFAULT_FROM_EMAIL__
Info: DEBUG - + replace_string=django-fritzconnection@testyunohost.fritz.box
Info: DEBUG - + replace_string=django-fritzconnection@testyunohost.fritz.box
Info: DEBUG - + replace_string='django-fritzconnection\@testyunohost.fritz.box'
Info: DEBUG - + sed --in-place 's@__DEFAULT_FROM_EMAIL__@django-fritzconnection\@testyunohost.fritz.box@g' /home/yunohost.app/django-fritzconnection/settings.py
Info: DEBUG - + for one_var in "${uniques_vars[@]}"
Info: DEBUG - + [[ -v domain ]]
Info: DEBUG - + match_string=__DOMAIN__
Info: DEBUG - + match_string=__DOMAIN__
Info: DEBUG - + replace_string=testyunohost.fritz.box
Info: DEBUG - + replace_string=testyunohost.fritz.box
Info: DEBUG - + replace_string=testyunohost.fritz.box
Info: DEBUG - + sed --in-place s@__DOMAIN__@testyunohost.fritz.box@g /home/yunohost.app/django-fritzconnection/settings.py
Info: DEBUG - + for one_var in "${uniques_vars[@]}"
Info: DEBUG - + [[ -v fritz_password ]]
Info: DEBUG - + ynh_die '--message=Variable $fritz_password wasn'\''t initialized when trying to replace __FRITZ_PASSWORD__ in /home/yunohost.app/django-fritzconnection/settings.py'
Info: WARNING - Variable $fritz_password wasn't initialized when trying to replace __FRITZ_PASSWORD__ in /home/yunohost.app/django-fritzconnection/settings.py
Info: DEBUG - + ynh_exit_properly

How introduce new configs?!?

Nobody any idea?

gotta add a snippet like this here : https://github.com/YunoHost-Apps/django-fritzconnection_ynh/blob/dev/scripts/upgrade#L18

Beware that you need to test if [[ -z "${foobar:-}" ]] instead of just if [[ -z "$foobar" ]] because set -eu will trigger a crash if the variable doesnt exist even though you’re kind of trying to check if it exists

1 Like

I’ve done this: Poetry -> pip-tools + CLI + update to v0.3.0 by jedie · Pull Request #23 · YunoHost-Apps/django-fritzconnection_ynh · GitHub

if [ -z "${fritz_username:-}" ]; then
    fritz_username=""
	ynh_app_setting_set --app=$app --key=fritz_username --value="$fritz_username"
fi
if [ -z "${fritz_password:-}" ]; then
    fritz_password=""
	ynh_app_setting_set --app=$app --key=fritz_password --value="$fritz_password"
fi

Seems to work.

I come to the conclusion, that everything around config settings are still a little to complicated.

Why not, just one single point to define these stuff?
Everything just in manifest.toml and remove config_panel.toml completely and remove all needed ynh_add_config in scripts.

Add the bind option into manifest.toml and a boolean flag, that says that this option should be exposed on config panel, too.
Or maybe a “type” with these choices:

  • expose only on install
  • expose only in config panel
  • expose on install and config panel

Yes, there are various discussions around this, but design has to be careful, and even when you know how to design it it doesnt magically get implemented. Cf also the whole discussion about Packaging v3. But for now the focus is Bookworm.

2 Likes