From 6ed739fab738b13b79568b6c37ecef6319220c9b Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Mon, 20 May 2019 17:03:46 +0200 Subject: [PATCH] Normalization from example_ynh --- README.md | 7 ++++--- check_process | 12 +----------- conf/nginx.conf | 2 +- manifest.json | 2 +- scripts/backup | 16 ++++++++-------- scripts/install | 39 ++++++++++++++++++--------------------- scripts/remove | 18 ++++++++++++------ scripts/restore | 35 ++++++++++++++++++----------------- scripts/upgrade | 37 ++++++++++++++++++------------------- 9 files changed, 81 insertions(+), 87 deletions(-) diff --git a/README.md b/README.md index 5843833..d6b25d1 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,9 @@ Shell In A Box implements a web server that can export arbitrary command line to #### Supported architectures -* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/shellinabox%20%28Official%29.svg)](https://ci-apps.yunohost.org/ci/apps/shellinabox/) -* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/shellinabox%20%28Official%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/shellinabox/) -* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/shellinabox%20%28Official%29.svg)](https://ci-stretch.nohost.me/ci/apps/shellinabox/) +* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/shellinabox%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/shellinabox/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/shellinabox%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/shellinabox/) +* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/shellinabox%20%28Apps%29.svg)](https://ci-stretch.nohost.me/ci/apps/shellinabox/) ## Limitations @@ -41,6 +41,7 @@ Shell In A Box implements a web server that can export arbitrary command line to * Report a bug: https://github.com/YunoHost-Apps/shellinabox_ynh/issues * Shell In A Box website: https://github.com/shellinabox/shellinabox + * Shell In A Box repository: https://github.com/shellinabox/shellinabox * YunoHost website: https://yunohost.org/ --- diff --git a/check_process b/check_process index bc68332..6651ea4 100644 --- a/check_process +++ b/check_process @@ -17,17 +17,7 @@ port_already_use=0 change_url=0 ;;; Levels - Level 1=auto - Level 2=auto - Level 3=auto - Level 4=na -# Level 5: https://github.com/YunoHost-Apps/shellinabox_ynh/issues/3 - Level 5=1 - Level 6=auto - Level 7=auto - Level 8=0 - Level 9=0 - Level 10=0 + Level 5=auto ;;; Options Email= Notification=none diff --git a/conf/nginx.conf b/conf/nginx.conf index 99cde99..a86f6cb 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -14,7 +14,7 @@ location __PATH__/ { access_log off; # Allow shellinabox to use 'eval' without blocking the execution. But keep a warning. - add_header Content-Security-Policy-Report-Only "script-src https: 'unsafe-eval'"; + more_set_headers Content-Security-Policy-Report-Only "script-src https: 'unsafe-eval'"; more_clear_input_headers 'Accept-Encoding'; diff --git a/manifest.json b/manifest.json index a26262d..52a89e6 100644 --- a/manifest.json +++ b/manifest.json @@ -14,7 +14,7 @@ "email": "kload@kload.fr" }, "requirements": { - "yunohost": ">= 3.2.0" + "yunohost": ">= 3.5.0" }, "multi_instance": false, "services": [ diff --git a/scripts/backup b/scripts/backup index 24a3678..a58fb6d 100644 --- a/scripts/backup +++ b/scripts/backup @@ -18,31 +18,31 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_print_info "Loading installation settings..." +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) +domain=$(ynh_app_setting_get --app=$app --key=domain) #================================================= # STANDARD BACKUP STEPS #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_print_info "Backing up the main app directory..." +ynh_script_progression --message="Backing up the main app directory..." -ynh_backup "/etc/shellinabox" -ynh_backup "/etc/default/shellinabox" +ynh_backup --src_path="/etc/shellinabox" +ynh_backup --src_path="/etc/default/shellinabox" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_print_info "Backing up nginx web server configuration..." +ynh_script_progression --message="Backing up nginx web server configuration..." -ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # END OF SCRIPT #================================================= -ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." +ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last diff --git a/scripts/install b/scripts/install index c018ed9..26ce1c5 100644 --- a/scripts/install +++ b/scripts/install @@ -27,37 +27,34 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -ynh_print_info "Validating installation parameters..." - -# Normalize the url path syntax -path_url=$(ynh_normalize_url_path $path_url) +ynh_script_progression --message="Validating installation parameters..." # Register (book) web path -ynh_webpath_register $app $domain $path_url +ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_print_info "Storing installation settings..." +ynh_script_progression --message="Storing installation settings..." -ynh_app_setting_set $app domain $domain -ynh_app_setting_set $app path $path_url +ynh_app_setting_set --app=$app --key=domain --value=$domain +ynh_app_setting_set --app=$app --key=path --value=$path_url #================================================= # STANDARD MODIFICATIONS #================================================= # FIND AND OPEN A PORT #================================================= -ynh_print_info "Looking for a free port..." +ynh_script_progression --message="Configuring firewall..." --weight=2 # Find a free port -port=$(ynh_find_port 4200) -ynh_app_setting_set $app port $port +port=$(ynh_find_port --port=4200) +ynh_app_setting_set --app=$app --key=port --value=$port #================================================= # INSTALL SHELLINABOX #================================================= -ynh_print_info "Installing shellinabox..." +ynh_script_progression --message="Installing shellinabox..." --weight=7 ynh_package_update ynh_package_install shellinabox @@ -65,7 +62,7 @@ ynh_package_install shellinabox #================================================= # NGINX CONFIGURATION #================================================= -ynh_print_info "Configuring nginx web server..." +ynh_script_progression --message="Configuring nginx web server..." --weight=2 # Create a dedicated nginx config ynh_add_nginx_config @@ -75,23 +72,23 @@ ynh_add_nginx_config #================================================= # CONFIGURE SHELLINABOX #================================================= -ynh_print_info "Configuring shellinabox..." +ynh_script_progression --message="Configuring shellinabox..." --weight=2 cp ../conf/shellinabox /etc/default/shellinabox -ynh_replace_string "__PORT__" "$port" "/etc/default/shellinabox" +ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="/etc/default/shellinabox" # Allow the service to log in syslog -ynh_replace_string " -- -q --background" " -- --background" "/etc/init.d/shellinabox" +ynh_replace_string --match_string=" -- -q --background" --replace_string=" -- --background" --target_file="/etc/init.d/shellinabox" systemctl daemon-reload -systemctl restart shellinabox +ynh_systemd_action --service_name=shellinabox --action=restart #================================================= # STORE THE CHECKSUM OF THE CONFIG FILE #================================================= # Calculate and store the config file checksum into the app settings -ynh_store_file_checksum "/etc/default/shellinabox" +ynh_store_file_checksum --file="/etc/default/shellinabox" #================================================= # GENERIC FINALIZATION @@ -104,12 +101,12 @@ yunohost service add $app #================================================= # RELOAD NGINX #================================================= -ynh_print_info "Reloading nginx web server..." +ynh_script_progression --message="Reloading nginx web server..." -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_print_info "Installation of $app completed" +ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove index cc64979..56374d6 100644 --- a/scripts/remove +++ b/scripts/remove @@ -11,12 +11,12 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_print_info "Loading installation settings..." +ynh_script_progression --message="Loading installation settings..." --weight=2 app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -port=$(ynh_app_setting_get $app port) +domain=$(ynh_app_setting_get --app=$app --key=domain) +port=$(ynh_app_setting_get --app=$app --key=port) #================================================= # STANDARD REMOVE @@ -27,21 +27,27 @@ port=$(ynh_app_setting_get $app port) # Remove a service from the admin panel, added by `yunohost service add` if yunohost service status $app >/dev/null 2>&1 then - ynh_print_info "Removing $app service" + ynh_script_progression --message="Removing $app service..." yunohost service remove $app fi #================================================= # REMOVE SHELLINABOX #================================================= -ynh_print_info "Removing shellinabox" +ynh_script_progression --message="Removing shellinabox..." --weight=20 ynh_package_autopurge shellinabox #================================================= # REMOVE NGINX CONFIGURATION #================================================= -ynh_print_info "Removing nginx web server configuration" +ynh_script_progression --message="Removing nginx web server configuration..." # Remove the dedicated nginx config ynh_remove_nginx_config + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore index a8a979e..2924c9a 100644 --- a/scripts/restore +++ b/scripts/restore @@ -18,21 +18,21 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_print_info "Loading settings..." +ynh_script_progression --message="Loading settings..." app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -port=$(ynh_app_setting_get $app port) +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +port=$(ynh_app_setting_get --app=$app --key=port) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_print_info "Validating restoration parameters..." +ynh_script_progression --message="Validating restoration parameters..." -ynh_webpath_available $domain $path_url \ - || ynh_die "Path not available: ${domain}${path_url}" +ynh_webpath_available --domain=$domain --path_url=$path_url \ + || ynh_die --message="Path not available: ${domain}${path_url}" #================================================= # STANDARD RESTORATION STEPS @@ -40,12 +40,12 @@ ynh_webpath_available $domain $path_url \ # RESTORE THE NGINX CONFIGURATION #================================================= -ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # INSTALL SHELLINABOX #================================================= -ynh_print_info "Installing shellinabox..." +ynh_script_progression --message="Installing shellinabox..." --weight=7 ynh_package_update ynh_package_install shellinabox @@ -53,16 +53,17 @@ ynh_package_install shellinabox #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_print_info "Restoring the app main directory..." +ynh_script_progression --message="Restoring the app main directory..." --weight=3 -ynh_restore_file "/etc/shellinabox" -ynh_restore_file "/etc/default/shellinabox" +ynh_restore_file --origin_path="/etc/shellinabox" +ynh_restore_file --origin_path="/etc/default/shellinabox" # Allow the service to log in syslog -ynh_replace_string " -- -q --background" " -- --background" "/etc/init.d/shellinabox" +ynh_replace_string --match_string=" -- -q --background" --replace_string=" -- --background" --target_file="/etc/init.d/shellinabox" + systemctl daemon-reload -systemctl restart shellinabox +ynh_systemd_action --service_name=shellinabox --action=restart #================================================= # ADVERTISE SERVICE IN ADMIN PANEL @@ -75,12 +76,12 @@ yunohost service add $app #================================================= # RELOAD NGINX #================================================= -ynh_print_info "Reloading nginx web server and php-fpm..." +ynh_script_progression --message="Reloading nginx web server..." -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_print_info "Restoration completed for $app" +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index 0cef4c3..71f210a 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -11,29 +11,29 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_print_info "Loading installation settings..." +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -port=$(ynh_app_setting_get $app port) +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +port=$(ynh_app_setting_get --app=$app --key=port) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_print_info "Ensuring downward compatibility..." +ynh_script_progression --message="Ensuring downward compatibility..." --weight=2 # If port doesn't exist, create it if [ -z "$port" ]; then port=4200 - ynh_app_setting_set $app port $port + ynh_app_setting_set --app=$app --key=port --value=$port fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_print_info "Backing up the app before upgrading (may take a while)..." +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=5 # Backup the current version of the app ynh_backup_before_upgrade @@ -49,14 +49,14 @@ ynh_abort_if_errors #================================================= # Normalize the URL path syntax -path_url=$(ynh_normalize_url_path $path_url) +path_url=$(ynh_normalize_url_path --path_url=$path_url) #================================================= # STANDARD UPGRADE STEPS #================================================= # NGINX CONFIGURATION #================================================= -ynh_print_info "Upgrading nginx web server configuration..." +ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=2 # Create a dedicated nginx config ynh_add_nginx_config @@ -64,36 +64,35 @@ ynh_add_nginx_config #================================================= # CONFIGURE SHELLINABOX #================================================= -ynh_print_info "Upgrading shellinabox configuration..." +ynh_script_progression --message="Upgrading shellinabox configuration..." --weight=4 # Verify the checksum and backup the file if it's different -ynh_backup_if_checksum_is_different "/etc/default/shellinabox" +ynh_backup_if_checksum_is_different --file="/etc/default/shellinabox" cp ../conf/shellinabox /etc/default/shellinabox -ynh_replace_string "__PORT__" "$port" "/etc/default/shellinabox" +ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="/etc/default/shellinabox" -# Allow the service to log in syslog -ynh_replace_string " -- -q --background" " -- --background" "/etc/init.d/shellinabox" +ynh_replace_string --match_string=" -- -q --background" --replace_string=" -- --background" --target_file="/etc/init.d/shellinabox" systemctl daemon-reload -systemctl restart shellinabox +ynh_systemd_action --service_name=shellinabox --action=restart #================================================= # STORE THE CHECKSUM OF THE CONFIG FILE #================================================= # Calculate and store the config file checksum into the app settings -ynh_store_file_checksum "/etc/default/shellinabox" +ynh_store_file_checksum --file="/etc/default/shellinabox" #================================================= # RELOAD NGINX #================================================= -ynh_print_info "Reloading nginx web server..." +ynh_script_progression --message="Reloading nginx web server..." -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_print_info "Upgrade of $app completed" +ynh_script_progression --message="Upgrade of $app completed" --last