New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use getops #561

Open
wants to merge 33 commits into
base: stretch-unstable
from

Conversation

Projects
None yet
3 participants
@maniackcrudelis
Copy link
Contributor

maniackcrudelis commented Oct 16, 2018

The problem

getopts is now available for all our official helpers

Solution

Migrate all our helpers to getopts

PR Status

  • ynh_use_logrotate: Fully tested (mainly because it was a specific case)
  • ynh_add_systemd_config: Legacy mode ?? | getopts mode ??
  • ynh_remove_systemd_config: Legacy mode ?? | getopts mode ??
  • ynh_backup: Legacy mode OK | getopts mode OK
  • ynh_restore_file: Legacy mode OK | getopts mode OK
  • ynh_store_file_checksum: Legacy mode OK | getopts mode OK
  • ynh_backup_if_checksum_is_different: Legacy mode OK | getopts mode OK
  • ynh_delete_file_checksum: Already done
  • ynh_secure_remove: Legacy mode OK | getopts mode OK
  • ynh_validate_ip: Legacy mode ?? | getopts mode ??
  • ynh_validate_ip4: Legacy mode ?? | getopts mode ??
  • ynh_validate_ip6: Legacy mode ?? | getopts mode ??
  • ynh_mysql_connect_as: Legacy mode OK | getopts mode OK
  • ynh_mysql_execute_as_root: Legacy mode OK | getopts mode OK
  • ynh_mysql_execute_file_as_root: Legacy mode ?? | getopts mode ??
  • ynh_mysql_dump_db: Legacy mode OK | getopts mode OK
  • ynh_mysql_user_exists: Legacy mode ?? | getopts mode OK
  • ynh_mysql_setup_db: Legacy mode OK | getopts mode OK
  • ynh_mysql_remove_db: Legacy mode OK | getopts mode OK
  • ynh_sanitize_dbid: Legacy mode OK | getopts mode OK
  • ynh_normalize_url_path: Legacy mode OK | getopts mode OK
  • ynh_find_port: Legacy mode ?? | getopts mode ??
  • ynh_webpath_available: Legacy mode OK | getopts mode OK
  • ynh_webpath_register: Legacy mode OK | getopts mode OK
  • ynh_install_nodejs: Legacy mode ?? | getopts mode ??
  • ynh_package_is_installed: Legacy mode ?? | getopts mode ??
  • ynh_package_version: Legacy mode ?? | getopts mode ??
  • ynh_die: Legacy mode ?? | getopts mode OK
  • ynh_print_info: Legacy mode ?? | getopts mode ??
  • ynh_print_warn: Legacy mode ?? | getopts mode ??
  • ynh_print_err: Legacy mode ?? | getopts mode ??
  • ynh_app_setting_get: Legacy mode OK | getopts mode OK
  • ynh_app_setting_set: Legacy mode OK | getopts mode OK
  • ynh_app_setting_delete: Legacy mode OK | getopts mode OK
  • ynh_string_random: Legacy mode ?? | getopts mode OK
  • ynh_replace_string: Legacy mode OK | getopts mode OK
  • ynh_replace_special_string: Legacy mode ?? | getopts mode ??
  • ynh_user_exists: Legacy mode ?? | getopts mode ??
  • ynh_user_get_info: Legacy mode ?? | getopts mode ??
  • ynh_system_user_exists: Legacy mode ?? | getopts mode OK
  • ynh_system_user_create: Legacy mode OK | getopts mode OK
  • ynh_system_user_delete: Legacy mode OK | getopts mode OK
  • ynh_setup_source: Legacy mode OK | getopts mode OK

How to test

Although it's not finished, I'm not going to go back unless there's an error to fix.
So don't hesitate to help by testing the helpers.

To test, replace the official helpers by this version. (/usr/share/yunohost/helpers.d/)

Validation

  • Principle agreement 0/2 :
  • Quick review 0/1 :
  • Simple test 0/1 :
  • Deep review 0/1 :

maniackcrudelis added some commits Oct 10, 2018

maniackcrudelis added some commits Oct 16, 2018

@alexAubin alexAubin added this to the 3.x milestone Oct 24, 2018

maniackcrudelis added some commits Dec 21, 2018

@maniackcrudelis

This comment has been minimized.

Copy link
Contributor

maniackcrudelis commented Dec 29, 2018

Work is done on this PR.
If some would like to test those helpers, it would be welcome 😀

@maniackcrudelis

This comment has been minimized.

Copy link
Contributor

maniackcrudelis commented Dec 31, 2018

I tried to test with a full replacement of the helpers.
Tried with wordpress directly, which isn't using getopts args.
So, getopts is used in Legacy mode , whith many weird errors...

Here my errors so far, for those who want to try as well.

@maniackcrudelis

This comment has been minimized.

Copy link
Contributor

maniackcrudelis commented Jan 4, 2019

Finally found the error with mysql, and that's bigger than I thought it would be...
An associative array isn't sorted like a indexed one is. Which means that we can't know in which order the array will be stored.

In ynh_mysql_setup_db, the array is set that way:

declare -Ar args_array=( [u]=db_user= [n]=db_name= [p]=db_password= )

Most of the time, for other helpers, the array will be set as:

[ u ] - [db_user=]
[ n ] - [db_name=]
[ p ] - [db_password=]

But, during my tests, the array is set that way

[ n ] - [db_name=]
[ p ] - [db_password=]
[ u ] - [db_user=]

That's not a problem when using getopts parameters, because we're using the key, n, p or u to access the array. But, when using the legacy mode, there's no way to know which argument is supposed to match which option, unless by using arguments in the same order than the array.
For this example, we assume that $1 is db_user, $2 db_name and $3 db_password. But when the array isn't sorted the same way than the line that create it. How can we know which option was the first one, and so on.

This issue will need to rethink a part of the legacy mode, and also to add a variable in the helper that call ynh_handle_getopts_args to fix that order in a strict way.

maniackcrudelis added some commits Jan 4, 2019

Fix getopts with blank argument's value
There's no reason in that loop where we're looking for values of an option to have a blank cell in the array of arguments. Unless for an option with a missing value.
In that case, it's better to ignore this condition and store a blank value in the variable.
Otherwise, in case of missing value for an option, with this condition, we enter in an infinite loop, because the shift will stay at 0.
@maniackcrudelis

This comment has been minimized.

Copy link
Contributor

maniackcrudelis commented Jan 4, 2019

I guess now the code is stable enough to really starting to test the helpers...

source getopts in filesystem
Many core backup script source /usr/share/yunohost/helpers.d/filesystem only. Not sure it's a wonderful idea...
@maniackcrudelis

This comment has been minimized.

Copy link
Contributor

maniackcrudelis commented Jan 5, 2019

I've tested most of the helpers with an app and package check, without any errors.
Some aren't tested yet, feel free to do it if you want. I do not expect any errors either.
For me this PR is finally ready to be reviewed.

@maniackcrudelis maniackcrudelis added helper and removed test needed labels Jan 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment