From 803e8ff4a60314a7e223a9f9ed9224dc578bb3ed Mon Sep 17 00:00:00 2001 From: Yalh Date: Sat, 19 Jan 2019 03:32:55 +0100 Subject: [PATCH 1/8] Apply example_Ynh to solve CI error: https://travis-ci.org/YunoHost-Apps/my_webapp_ynh/builds/481615933?utm_source=github_status&utm_medium=notification --- README.md | 7 ++++-- conf/nginx.conf | 12 +++++++--- manifest.json | 18 +++++++------- scripts/backup | 19 +++++++++------ scripts/install | 63 ++++++++++++++++++++++++++++++++++++++++--------- scripts/remove | 9 ++++--- scripts/restore | 19 +++++++++------ scripts/upgrade | 21 ++++++++++++++--- 8 files changed, 123 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index a37e805..4f7d99f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ -Custom Webapp -------------- +# Custom Webapp + +[![Integration level](https://dash.yunohost.org/integration/my_webapp.svg)](https://ci-apps.yunohost.org/jenkins/job/my_webapp%20%28Community%29/lastBuild/consoleFull) +[![Install my_webapp with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=my_webapp) + Empty application with SFTP access to the Web directory. diff --git a/conf/nginx.conf b/conf/nginx.conf index 2d343ab..c69065d 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,6 +1,10 @@ -location __PATH__ { - alias __FINALPATH__/www/; - +#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; +location __PATH__/ { + + # Path to source + alias __FINALPATH__/www/ ; + + # Force usage of https if ($scheme = http) { rewrite ^ https://$server_name$request_uri? permanent; } @@ -29,12 +33,14 @@ location __PATH__ { location ~ [^/]\.php(/|$) { fastcgi_split_path_info ^(.+?\.php)(/.*)$; fastcgi_pass unix:/var/run/php5-fpm-__NAME__.sock; + fastcgi_index index.php; include fastcgi_params; fastcgi_param REMOTE_USER $remote_user; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $request_filename; } +### End of PHP configuration part # Include SSOWAT user panel. include conf.d/yunohost_panel.conf.inc; diff --git a/manifest.json b/manifest.json index 1152e2a..4da5d54 100644 --- a/manifest.json +++ b/manifest.json @@ -42,15 +42,6 @@ "example": "/site", "default": "/site" }, - { - "name": "password", - "type": "password", - "ask": { - "en": "Set the password for the SFTP access. ≥ 5 character", - "fr": "Définissez le mot de passe pour l'accès SFTP. ≥ cinq charactères" - }, - "example": "myreallystrengthpassword" - }, { "name": "is_public", "type": "boolean", @@ -60,6 +51,15 @@ }, "default": true }, + { + "name": "password", + "type": "password", + "ask": { + "en": "Set the password for the SFTP access. ≥ 5 character", + "fr": "Définissez le mot de passe pour l'accès SFTP. ≥ cinq charactères" + }, + "example": "myreallystrengthpassword" + }, { "name": "with_mysql", "type": "boolean", diff --git a/scripts/backup b/scripts/backup index 13b9193..be17d69 100644 --- a/scripts/backup +++ b/scripts/backup @@ -2,19 +2,24 @@ #================================================= # GENERIC START -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Exit on command errors and treat access to unset variables as an error -set -eu - #================================================= # IMPORT GENERIC HELPERS #================================================= +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +ynh_clean_setup () { + ### Remove this function if there's nothing to clean before calling the remove script. + true +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + #================================================= # LOAD SETTINGS #================================================= diff --git a/scripts/install b/scripts/install index 9b32084..4369898 100644 --- a/scripts/install +++ b/scripts/install @@ -6,12 +6,17 @@ # IMPORT GENERIC HELPERS #================================================= +source _common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + ### Remove this function if there's nothing to clean before calling the remove script. + true +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -21,10 +26,21 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH -password=$YNH_APP_ARG_PASSWORD is_public=$YNH_APP_ARG_IS_PUBLIC +password=$YNH_APP_ARG_PASSWORD + with_mysql=$YNH_APP_ARG_WITH_MYSQL +### If it's a multi-instance app, meaning it can be installed several times independently +### The id of the app as stated in the manifest is available as $YNH_APP_ID +### The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) +### The app instance name is available as $YNH_APP_INSTANCE_NAME +### - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample +### - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 +### - ynhexample__{N} for the subsequent installations, with N=3,4, ... +### The app instance name is probably what interests you most, since this is +### guaranteed to be unique. This is a good unique identifier to define installation path, +### db names, ... app=$YNH_APP_INSTANCE_NAME app_nb=$YNH_APP_INSTANCE_NUMBER @@ -32,6 +48,8 @@ app_nb=$YNH_APP_INSTANCE_NUMBER # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= +### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app". +### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app" final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" @@ -66,6 +84,15 @@ ynh_app_setting_set $app final_path $final_path # CREATE A MYSQL DATABASE #================================================= +### Use these lines if you need a database for the application. +### `ynh_mysql_setup_db` will create a database, an associated user and a ramdom password. +### The password will be stored as 'mysqlpwd' into the app settings, +### and will be available as $db_pwd +### If you're not using these lines: +### - Remove the section "BACKUP THE MYSQL DATABASE" in the backup script +### - Remove also the section "REMOVE THE MYSQL DATABASE" in the remove script +### - As well as the section "RESTORE THE MYSQL DATABASE" in the restore script + if [ $with_mysql -eq 1 ]; then db_name=$(ynh_sanitize_dbid $app) ynh_app_setting_set $app db_name $db_name @@ -76,6 +103,8 @@ fi # NGINX CONFIGURATION #================================================= +### `ynh_add_nginx_config` will use the file conf/nginx.conf + # Create a dedicated nginx config ynh_add_nginx_config @@ -83,16 +112,24 @@ ynh_add_nginx_config # CREATE DEDICATED USER #================================================= -# Create a standard user (not a system user for sftp) -ynh_system_user_exists "$user" || \ - useradd -d "$final_path" -M --user-group "$user" -# Add the password to this user -chpasswd <<< "${user}:${password}" +# Create a system user +ynh_system_user_create $app #================================================= # PHP-FPM CONFIGURATION #================================================= +### `ynh_add_fpm_config` is used to set up a PHP config. +### You can remove it if your app doesn't use PHP. +### `ynh_add_fpm_config` will use the files conf/php-fpm.conf and conf/php-fpm.ini +### If you're not using these lines: +### - You can remove these files in conf/. +### - Remove the section "BACKUP THE PHP-FPM CONFIGURATION" in the backup script +### - Remove also the section "REMOVE PHP-FPM CONFIGURATION" in the remove script +### - As well as the section "RESTORE THE PHP-FPM CONFIGURATION" in the restore script +### With the reload at the end of the script. +### - And the section "PHP-FPM CONFIGURATION" in the upgrade script + # Create a dedicated php-fpm config ynh_replace_string "__USER__" "$user" "../conf/php-fpm.conf" ynh_add_fpm_config @@ -117,9 +154,12 @@ Match User ${user} systemctl reload ssh #================================================= -# FILL AND COPY SOURCE FILES +# MODIFY A CONFIG FILE #================================================= +### `ynh_replace_string` is used to replace a string in a file. +### (It's compatible with sed regular expressions syntax) + ynh_replace_string "{DOMAIN}" "$domain" ../sources/www/index.html ynh_replace_string "{USER}" "$user" ../sources/www/index.html @@ -138,11 +178,12 @@ cp -r ../sources "$final_path" # SECURE FILES AND DIRECTORIES #================================================= +### For security reason, any app should set the permissions to root: before anything else. +### Then, if write authorization is needed, any access should be given only to directories +### that really need such authorization. + # Set permissions to app files -chown -R $user: "$final_path" -# Home directory of the user needs to be owned by root to allow -# SFTP connections -chown root: "$final_path" +chown -R root: $final_path #================================================= # SETUP SSOWAT diff --git a/scripts/remove b/scripts/remove index 83e2ef3..05d2085 100644 --- a/scripts/remove +++ b/scripts/remove @@ -6,6 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= +source _common.sh source /usr/share/yunohost/helpers #================================================= @@ -15,10 +16,12 @@ source /usr/share/yunohost/helpers app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) + +db_name=$(ynh_app_setting_get $app db_name) +db_user=$db_name +final_path=$(ynh_app_setting_get $app final_path) with_mysql=$(ynh_app_setting_get $app with_mysql) user=$(ynh_app_setting_get $app user) -db_name=$(ynh_app_setting_get $app db_name) -final_path=$(ynh_app_setting_get $app final_path) #================================================= # STANDARD REMOVE @@ -28,7 +31,7 @@ final_path=$(ynh_app_setting_get $app final_path) if [ $with_mysql -eq 1 ]; then # Remove a database if it exists, along with the associated user - ynh_mysql_remove_db $db_name $db_name + ynh_mysql_remove_db $db_user $db_name fi #================================================= diff --git a/scripts/restore b/scripts/restore index 6c5a219..dca448d 100644 --- a/scripts/restore +++ b/scripts/restore @@ -2,19 +2,24 @@ #================================================= # GENERIC START -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Exit on command errors and treat access to unset variables as an error -set -eu - #================================================= # IMPORT GENERIC HELPERS #================================================= +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +ynh_clean_setup () { + #### Remove this function if there's nothing to clean before calling the remove script. + true +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + #================================================= # LOAD SETTINGS #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index abacad4..0ecf32b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -6,6 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= +source _common.sh source /usr/share/yunohost/helpers #================================================= @@ -16,8 +17,10 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) path_url=$(ynh_app_setting_get $app path) + is_public=$(ynh_app_setting_get $app is_public) final_path=$(ynh_app_setting_get $app final_path) + db_name=$(ynh_app_setting_get $app db_name) with_mysql=$(ynh_app_setting_get $app with_mysql) password=$(ynh_app_setting_get $app password) @@ -36,6 +39,15 @@ https://github.com/YunoHost-Apps/my_webapp_ynh#upgrade" # ENSURE DOWNWARD COMPATIBILITY #================================================= +# Fix is_public as a boolean value +if [ "$is_public" = "Yes" ]; then + ynh_app_setting_set $app is_public 1 + is_public=1 +elif [ "$is_public" = "No" ]; then + ynh_app_setting_set $app is_public 0 + is_public=0 +fi + # If db_name doesn't exist, create it if [ -z $db_name ]; then db_name=$(ynh_sanitize_dbid $app) @@ -52,11 +64,14 @@ fi # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_backup_before_upgrade # Backup the current version of the app +# Backup the current version of the app +ynh_backup_before_upgrade ynh_clean_setup () { - ynh_restore_upgradebackup # restore it if the upgrade fails + # restore it if the upgrade fails + ynh_restore_upgradebackup } -ynh_abort_if_errors # Exit if an error occurs during the execution of the script +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors #================================================= # CHECK THE PATH From 88d6867da5f8ef538fa695cb65aff9b0a8a2441e Mon Sep 17 00:00:00 2001 From: Yalh Date: Sat, 19 Jan 2019 03:35:52 +0100 Subject: [PATCH 2/8] Correct licence for [YEP-1.3] --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 4da5d54..b83a737 100644 --- a/manifest.json +++ b/manifest.json @@ -8,7 +8,7 @@ }, "version": "1.0", "url": "https://github.com/YunoHost-Apps/my_webapp_ynh", - "license": "GPLv3", + "license": "GPL-3.0-only", "maintainer": { "name": "YunoHost Contributors", "email": "apps@yunohost.org" From d4227ddd74ab9dc0619f063e884a72665f48b6af Mon Sep 17 00:00:00 2001 From: Yalh Date: Sat, 19 Jan 2019 03:53:40 +0100 Subject: [PATCH 3/8] adding addition exmaple_ynh files --- scripts/_common.sh | 13 ++++++ scripts/change_url | 102 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 scripts/_common.sh create mode 100644 scripts/change_url diff --git a/scripts/_common.sh b/scripts/_common.sh new file mode 100644 index 0000000..bb04a03 --- /dev/null +++ b/scripts/_common.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# ============= FUTURE YUNOHOST HELPER ============= +# Delete a file checksum from the app settings +# +# $app should be defined when calling this helper +# +# usage: ynh_remove_file_checksum file +# | arg: file - The file for which the checksum will be deleted +ynh_delete_file_checksum () { + local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_' + ynh_app_setting_delete $app $checksum_setting_name +} \ No newline at end of file diff --git a/scripts/change_url b/scripts/change_url new file mode 100644 index 0000000..f71fc77 --- /dev/null +++ b/scripts/change_url @@ -0,0 +1,102 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +old_domain=$YNH_APP_OLD_DOMAIN +old_path=$YNH_APP_OLD_PATH + +new_domain=$YNH_APP_NEW_DOMAIN +new_path=$YNH_APP_NEW_PATH + +app=$YNH_APP_INSTANCE_NAME + +#================================================= +# LOAD SETTINGS +#================================================= + +# Needed for helper "ynh_add_nginx_config" +final_path=$(ynh_app_setting_get $app final_path) + +# Add settings here as needed by your application +#db_name=$(ynh_app_setting_get "$app" db_name) +#db_pwd=$(ynh_app_setting_get $app db_pwd) + +#================================================= +# CHECK THE SYNTAX OF THE PATHS +#================================================= + +test -n "$old_path" || old_path="/" +test -n "$new_path" || new_path="/" +new_path=$(ynh_normalize_url_path $new_path) +old_path=$(ynh_normalize_url_path $old_path) + +#================================================= +# CHECK WHICH PARTS SHOULD BE CHANGED +#================================================= + +change_domain=0 +if [ "$old_domain" != "$new_domain" ] +then + change_domain=1 +fi + +change_path=0 +if [ "$old_path" != "$new_path" ] +then + change_path=1 +fi + +#================================================= +# STANDARD MODIFICATIONS +#================================================= +# MODIFY URL IN NGINX CONF +#================================================= + +nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf + +# Change the path in the nginx config file +if [ $change_path -eq 1 ] +then + # Make a backup of the original nginx config file if modified + ynh_backup_if_checksum_is_different "$nginx_conf_path" + # Set global variables for nginx helper + domain="$old_domain" + path_url="$new_path" + # Create a dedicated nginx config + ynh_add_nginx_config +fi + +# Change the domain for nginx +if [ $change_domain -eq 1 ] +then + # Delete file checksum for the old conf file location + ynh_delete_file_checksum "$nginx_conf_path" + mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf + # Store file checksum for the new config file location + ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf" +fi + +#================================================= +# SPECIFIC MODIFICATIONS +#================================================= +# ... +#================================================= + +#================================================= +# GENERIC FINALISATION +#================================================= +# RELOAD NGINX +#================================================= + +systemctl reload nginx From 18916f692b636b67bd631113b46e2d82dd6cb143 Mon Sep 17 00:00:00 2001 From: Yalh Date: Sat, 19 Jan 2019 04:31:01 +0100 Subject: [PATCH 4/8] Fix installation --- scripts/install | 9 +++++---- scripts/remove | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/scripts/install b/scripts/install index 4369898..f4aac7f 100644 --- a/scripts/install +++ b/scripts/install @@ -103,8 +103,6 @@ fi # NGINX CONFIGURATION #================================================= -### `ynh_add_nginx_config` will use the file conf/nginx.conf - # Create a dedicated nginx config ynh_add_nginx_config @@ -112,8 +110,11 @@ ynh_add_nginx_config # CREATE DEDICATED USER #================================================= -# Create a system user -ynh_system_user_create $app +# Create a standard user (not a system user for sftp) +ynh_system_user_exists "$user" || \ + useradd -d "$final_path" -M --user-group "$user" +# Add the password to this user +chpasswd <<< "${user}:${password}" #================================================= # PHP-FPM CONFIGURATION diff --git a/scripts/remove b/scripts/remove index 05d2085..86affea 100644 --- a/scripts/remove +++ b/scripts/remove @@ -25,6 +25,31 @@ user=$(ynh_app_setting_get $app user) #================================================= # STANDARD REMOVE +#================================================= +# STOP AND REMOVE SERVICE +#================================================= + +# Remove the dedicated systemd config +ynh_remove_systemd_config + +#================================================= +# REMOVE SERVICE FROM ADMIN PANEL +#================================================= + +# Remove a service from the admin panel, added by `yunohost service add` +if yunohost service status | grep -q $app +then + echo "Remove $app service" + yunohost service remove $app +fi + +#================================================= +# REMOVE DEPENDENCIES +#================================================= + +# Remove metapackage and its dependencies +ynh_remove_app_dependencies + #================================================= # REMOVE THE MYSQL DATABASE #================================================= From b0a9db465b5e2073489987a31814e9b3a16cdcc8 Mon Sep 17 00:00:00 2001 From: Yalh Date: Sat, 19 Jan 2019 05:07:11 +0100 Subject: [PATCH 5/8] Fix install --- scripts/install | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scripts/install b/scripts/install index f4aac7f..5791a3b 100644 --- a/scripts/install +++ b/scripts/install @@ -103,6 +103,8 @@ fi # NGINX CONFIGURATION #================================================= +### `ynh_add_nginx_config` will use the file conf/nginx.conf + # Create a dedicated nginx config ynh_add_nginx_config @@ -186,6 +188,22 @@ cp -r ../sources "$final_path" # Set permissions to app files chown -R root: $final_path +#================================================= +# ADVERTISE SERVICE IN ADMIN PANEL +#================================================= + +### `yunohost service add` is a CLI yunohost command to add a service in the admin panel. +### You'll find the service in the 'services' section of YunoHost admin panel. +### This CLI command would be useless if the app does not have any services (systemd or sysvinit) +### If you're not using these lines: +### - You can remove these files in conf/. +### - Remove the section "REMOVE SERVICE FROM ADMIN PANEL" in the remove script +### - As well as the section ADVERTISE SERVICE IN ADMIN PANEL" in the restore script + +yunohost service add $app --log "/var/log/$app/APP.log" +# if using yunohost version 3.2 or more in the 'manifest.json', a description can be added +#yunohost service add $app --description "$app daemon for XXX" --log "/var/log/$app/APP.log" + #================================================= # SETUP SSOWAT #================================================= From 14373bc73c764c1f7ee297a17fbebaca23b5ead1 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Sat, 19 Jan 2019 13:34:47 +0100 Subject: [PATCH 6/8] Clean scripts --- check_process | 2 +- manifest.json | 20 +++++++------- scripts/backup | 4 --- scripts/install | 69 ++++--------------------------------------------- scripts/remove | 29 ++------------------- scripts/restore | 4 --- scripts/upgrade | 2 -- 7 files changed, 18 insertions(+), 112 deletions(-) diff --git a/check_process b/check_process index a270ddb..0250537 100644 --- a/check_process +++ b/check_process @@ -17,7 +17,7 @@ multi_instance=1 incorrect_path=1 port_already_use=0 - change_url=0 + change_url=1 ;;; Levels Level 1=auto Level 2=auto diff --git a/manifest.json b/manifest.json index b83a737..39c1d6f 100644 --- a/manifest.json +++ b/manifest.json @@ -8,7 +8,7 @@ }, "version": "1.0", "url": "https://github.com/YunoHost-Apps/my_webapp_ynh", - "license": "GPL-3.0-only", + "license": "free", "maintainer": { "name": "YunoHost Contributors", "email": "apps@yunohost.org" @@ -42,15 +42,6 @@ "example": "/site", "default": "/site" }, - { - "name": "is_public", - "type": "boolean", - "ask": { - "en": "Is it a public website?", - "fr": "Est-ce un site public ?" - }, - "default": true - }, { "name": "password", "type": "password", @@ -60,6 +51,15 @@ }, "example": "myreallystrengthpassword" }, + { + "name": "is_public", + "type": "boolean", + "ask": { + "en": "Is it a public website?", + "fr": "Est-ce un site public ?" + }, + "default": true + }, { "name": "with_mysql", "type": "boolean", diff --git a/scripts/backup b/scripts/backup index be17d69..c493122 100644 --- a/scripts/backup +++ b/scripts/backup @@ -13,10 +13,6 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= -ynh_clean_setup () { - ### Remove this function if there's nothing to clean before calling the remove script. - true -} # Exit if an error occurs during the execution of the script ynh_abort_if_errors diff --git a/scripts/install b/scripts/install index 5791a3b..e4bb733 100644 --- a/scripts/install +++ b/scripts/install @@ -13,10 +13,6 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= -ynh_clean_setup () { - ### Remove this function if there's nothing to clean before calling the remove script. - true -} # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -26,21 +22,11 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH -is_public=$YNH_APP_ARG_IS_PUBLIC password=$YNH_APP_ARG_PASSWORD +is_public=$YNH_APP_ARG_IS_PUBLIC with_mysql=$YNH_APP_ARG_WITH_MYSQL -### If it's a multi-instance app, meaning it can be installed several times independently -### The id of the app as stated in the manifest is available as $YNH_APP_ID -### The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) -### The app instance name is available as $YNH_APP_INSTANCE_NAME -### - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample -### - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 -### - ynhexample__{N} for the subsequent installations, with N=3,4, ... -### The app instance name is probably what interests you most, since this is -### guaranteed to be unique. This is a good unique identifier to define installation path, -### db names, ... app=$YNH_APP_INSTANCE_NAME app_nb=$YNH_APP_INSTANCE_NUMBER @@ -48,8 +34,6 @@ app_nb=$YNH_APP_INSTANCE_NUMBER # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app". -### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app" final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" @@ -84,15 +68,6 @@ ynh_app_setting_set $app final_path $final_path # CREATE A MYSQL DATABASE #================================================= -### Use these lines if you need a database for the application. -### `ynh_mysql_setup_db` will create a database, an associated user and a ramdom password. -### The password will be stored as 'mysqlpwd' into the app settings, -### and will be available as $db_pwd -### If you're not using these lines: -### - Remove the section "BACKUP THE MYSQL DATABASE" in the backup script -### - Remove also the section "REMOVE THE MYSQL DATABASE" in the remove script -### - As well as the section "RESTORE THE MYSQL DATABASE" in the restore script - if [ $with_mysql -eq 1 ]; then db_name=$(ynh_sanitize_dbid $app) ynh_app_setting_set $app db_name $db_name @@ -103,8 +78,6 @@ fi # NGINX CONFIGURATION #================================================= -### `ynh_add_nginx_config` will use the file conf/nginx.conf - # Create a dedicated nginx config ynh_add_nginx_config @@ -122,17 +95,6 @@ chpasswd <<< "${user}:${password}" # PHP-FPM CONFIGURATION #================================================= -### `ynh_add_fpm_config` is used to set up a PHP config. -### You can remove it if your app doesn't use PHP. -### `ynh_add_fpm_config` will use the files conf/php-fpm.conf and conf/php-fpm.ini -### If you're not using these lines: -### - You can remove these files in conf/. -### - Remove the section "BACKUP THE PHP-FPM CONFIGURATION" in the backup script -### - Remove also the section "REMOVE PHP-FPM CONFIGURATION" in the remove script -### - As well as the section "RESTORE THE PHP-FPM CONFIGURATION" in the restore script -### With the reload at the end of the script. -### - And the section "PHP-FPM CONFIGURATION" in the upgrade script - # Create a dedicated php-fpm config ynh_replace_string "__USER__" "$user" "../conf/php-fpm.conf" ynh_add_fpm_config @@ -160,9 +122,6 @@ systemctl reload ssh # MODIFY A CONFIG FILE #================================================= -### `ynh_replace_string` is used to replace a string in a file. -### (It's compatible with sed regular expressions syntax) - ynh_replace_string "{DOMAIN}" "$domain" ../sources/www/index.html ynh_replace_string "{USER}" "$user" ../sources/www/index.html @@ -181,28 +140,10 @@ cp -r ../sources "$final_path" # SECURE FILES AND DIRECTORIES #================================================= -### For security reason, any app should set the permissions to root: before anything else. -### Then, if write authorization is needed, any access should be given only to directories -### that really need such authorization. - -# Set permissions to app files -chown -R root: $final_path - -#================================================= -# ADVERTISE SERVICE IN ADMIN PANEL -#================================================= - -### `yunohost service add` is a CLI yunohost command to add a service in the admin panel. -### You'll find the service in the 'services' section of YunoHost admin panel. -### This CLI command would be useless if the app does not have any services (systemd or sysvinit) -### If you're not using these lines: -### - You can remove these files in conf/. -### - Remove the section "REMOVE SERVICE FROM ADMIN PANEL" in the remove script -### - As well as the section ADVERTISE SERVICE IN ADMIN PANEL" in the restore script - -yunohost service add $app --log "/var/log/$app/APP.log" -# if using yunohost version 3.2 or more in the 'manifest.json', a description can be added -#yunohost service add $app --description "$app daemon for XXX" --log "/var/log/$app/APP.log" +chown -R $user: "$final_path" +# Home directory of the user needs to be owned by root to allow +# SFTP connections +chown root: "$final_path" #================================================= # SETUP SSOWAT diff --git a/scripts/remove b/scripts/remove index 86affea..8fa7fb4 100644 --- a/scripts/remove +++ b/scripts/remove @@ -16,40 +16,15 @@ source /usr/share/yunohost/helpers app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) +with_mysql=$(ynh_app_setting_get $app with_mysql) +user=$(ynh_app_setting_get $app user) db_name=$(ynh_app_setting_get $app db_name) db_user=$db_name final_path=$(ynh_app_setting_get $app final_path) -with_mysql=$(ynh_app_setting_get $app with_mysql) -user=$(ynh_app_setting_get $app user) #================================================= # STANDARD REMOVE -#================================================= -# STOP AND REMOVE SERVICE -#================================================= - -# Remove the dedicated systemd config -ynh_remove_systemd_config - -#================================================= -# REMOVE SERVICE FROM ADMIN PANEL -#================================================= - -# Remove a service from the admin panel, added by `yunohost service add` -if yunohost service status | grep -q $app -then - echo "Remove $app service" - yunohost service remove $app -fi - -#================================================= -# REMOVE DEPENDENCIES -#================================================= - -# Remove metapackage and its dependencies -ynh_remove_app_dependencies - #================================================= # REMOVE THE MYSQL DATABASE #================================================= diff --git a/scripts/restore b/scripts/restore index dca448d..b2c873b 100644 --- a/scripts/restore +++ b/scripts/restore @@ -13,10 +13,6 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= -ynh_clean_setup () { - #### Remove this function if there's nothing to clean before calling the remove script. - true -} # Exit if an error occurs during the execution of the script ynh_abort_if_errors diff --git a/scripts/upgrade b/scripts/upgrade index 0ecf32b..2c8e690 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -17,10 +17,8 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) path_url=$(ynh_app_setting_get $app path) - is_public=$(ynh_app_setting_get $app is_public) final_path=$(ynh_app_setting_get $app final_path) - db_name=$(ynh_app_setting_get $app db_name) with_mysql=$(ynh_app_setting_get $app with_mysql) password=$(ynh_app_setting_get $app password) From 06d1b5a5c562e9e9d053dfa18ca3710f5e652528 Mon Sep 17 00:00:00 2001 From: Yalh Date: Sat, 19 Jan 2019 19:11:54 +0100 Subject: [PATCH 7/8] Removing deprecated ynh_webpath_available --- scripts/install | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/install b/scripts/install index e4bb733..647cbf1 100644 --- a/scripts/install +++ b/scripts/install @@ -44,8 +44,6 @@ test ! -e "$final_path" || ynh_die "This path already contains a folder" # Normalize the url path syntax path_url=$(ynh_normalize_url_path $path_url) -# Check web path availability -ynh_webpath_available $domain $path_url # Register (book) web path ynh_webpath_register $app $domain $path_url From 53d69b3677ae1f38af20e7503ccc07142d82600c Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 21 Jan 2019 01:22:11 +0100 Subject: [PATCH 8/8] Update links from Jenkins to CI --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4f7d99f..32e6af5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Custom Webapp -[![Integration level](https://dash.yunohost.org/integration/my_webapp.svg)](https://ci-apps.yunohost.org/jenkins/job/my_webapp%20%28Community%29/lastBuild/consoleFull) +[![Integration level](https://dash.yunohost.org/integration/my_webapp.svg)](https://dash.yunohost.org/appci/app/my_webapp) [![Install my_webapp with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=my_webapp)