manifestv2: automatically trigger ynh_abort_if_errors (set -eu) for scripts except remove

This commit is contained in:
Alexandre Aubin 2021-10-13 22:56:51 +02:00
parent 8da35ca4c8
commit fe6d9c2617
2 changed files with 14 additions and 7 deletions

View file

@ -61,6 +61,12 @@ ynh_abort_if_errors() {
trap ynh_exit_properly EXIT # Capturing exit signals on shell script trap ynh_exit_properly EXIT # Capturing exit signals on shell script
} }
# When running an app script with packaging format >= 2, auto-enable ynh_abort_if_errors except for remove script
if [[ ${YNH_APP_PACKAGING_FORMAT:-0} -ge 2 ]] && [[ ${YNH_APP_ACTION} != "remove" ]]
then
ynh_abort_if_errors
fi
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
# #
# usage: ynh_setup_source --dest_dir=dest_dir [--source_id=source_id] [--keep="file1 file2"] # usage: ynh_setup_source --dest_dir=dest_dir [--source_id=source_id] [--keep="file1 file2"]

View file

@ -1371,7 +1371,7 @@ def app_register_url(app, domain, path):
raise YunohostValidationError("app_already_installed_cant_change_url") raise YunohostValidationError("app_already_installed_cant_change_url")
# Check the url is available # Check the url is available
_assert_no_conflicting_apps(domain, path) _assert_no_conflicting_apps(domain, path, ignore_app=app)
app_setting(app, "domain", value=domain) app_setting(app, "domain", value=domain)
app_setting(app, "path", value=path) app_setting(app, "path", value=path)
@ -1930,7 +1930,9 @@ def _get_manifest_of_app(path):
raw_msg=True, raw_msg=True,
) )
if int(manifest.get("packaging_format", 0)) <= 1: manifest["packaging_format"] = float(str(manifest.get("packaging_format", "")).strip() or "0")
if manifest["packaging_format"] < 2:
manifest = _convert_v1_manifest_to_v2(manifest) manifest = _convert_v1_manifest_to_v2(manifest)
manifest["install"] = _set_default_ask_questions(manifest.get("install", {})) manifest["install"] = _set_default_ask_questions(manifest.get("install", {}))
@ -2284,8 +2286,7 @@ def _get_all_installed_apps_id():
def _check_manifest_requirements(manifest: Dict): def _check_manifest_requirements(manifest: Dict):
"""Check if required packages are met from the manifest""" """Check if required packages are met from the manifest"""
packaging_format = int(manifest.get("packaging_format", 0)) if manifest["packaging_format"] not in [1, 2]:
if packaging_format not in [2]:
raise YunohostValidationError("app_packaging_format_not_supported") raise YunohostValidationError("app_packaging_format_not_supported")
requirements = manifest.get("requirements", dict()) requirements = manifest.get("requirements", dict())
@ -2446,20 +2447,20 @@ def _make_environment_for_app_script(
"YNH_APP_INSTANCE_NAME": app, "YNH_APP_INSTANCE_NAME": app,
"YNH_APP_INSTANCE_NUMBER": str(app_instance_nb), "YNH_APP_INSTANCE_NUMBER": str(app_instance_nb),
"YNH_APP_MANIFEST_VERSION": manifest.get("version", "?"), "YNH_APP_MANIFEST_VERSION": manifest.get("version", "?"),
"YNH_APP_PACKAGING_FORMAT": str(manifest["packaging_format"]),
} }
if workdir: if workdir:
env_dict["YNH_APP_BASEDIR"] = workdir env_dict["YNH_APP_BASEDIR"] = workdir
if action: if action:
env_dict["YNH_ACTION"] = action env_dict["YNH_APP_ACTION"] = action
for arg_name, arg_value in args.items(): for arg_name, arg_value in args.items():
env_dict["YNH_%s%s" % (args_prefix, arg_name.upper())] = str(arg_value) env_dict["YNH_%s%s" % (args_prefix, arg_name.upper())] = str(arg_value)
# If packaging format v2, load all settings # If packaging format v2, load all settings
packaging_format = int(manifest.get("packaging_format", 0)) if manifest["packaging_format"] >= 2:
if packaging_format >= 2:
env_dict["app"] = app env_dict["app"] = app
for setting_name, setting_value in _get_app_settings(app): for setting_name, setting_value in _get_app_settings(app):