diff --git a/README.md b/README.md index 3c0f4bb..942dec7 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,20 @@ # ZAP for YunoHost -[![Integration level](https://dash.yunohost.org/integration/zap.svg)](https://dash.yunohost.org/appci/app/zap) -[![Install Nextcloud with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=zap) +![Integration level](https://dash.yunohost.org/integration/zap.svg)](https://dash.yunohost.org/appci/app/zap) ![](https://ci-apps.yunohost.org/ci/badges/zap.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/zap.maintain.svg) +[![Install Zap with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=Zap) -> *This package allow you to install ZAP quickly and simply on a YunoHost server. +> *This package allow you to install ZAP quickly and simply on a YunoHost server. If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.* -Version: 2.6 +Version: 2020-10 ### Interesting links - [YunoHost project](https://yunohost.org) - [Zap website](https://zotlabs.com/zap/) -- [Zap code on Framagit](https://framagit.org/zot/zap) -- [Zap addons on Framagit](https://framagit.org/zot/zap-addons) +- [Zap code on codeberg](https://codeberg.org/zot/zap) +- [Zap addons on codeberg](https://codeberg.org/zot/zap-addons) ## ZAP [Zap](https://zotlabs.com/zap/) is a powerful platform for creating interconnected websites featuring a decentralized identity, communications, and permissions framework built using common webserver technology. @@ -23,41 +23,33 @@ Version: 2.6 - [X] Ldap integration - [X] Multi-instance - [X] Adeed php.log in the root folder for debugging php, with logrotate applied on it (can be accesssed by **admin->logs** and entering the **php.log**). -- [X] Fail2ban - +- [X] Fail2ban +- [X] Choose between **Mysql** and +**PostgreSQL** database to be used for the Zap while installation. ## Installation -Before installing, read the [ZAP installation instructions](https://framagit.org/zot/zap/blob/master/install/INSTALL.txt) for important information about +Before installing, read the [Zap installation instructions](https://codeberg.org/zot/zap/src/branch/release/install/INSTALL.txt) for important information about: ### Register a new domain and add it to YunoHost -- Zap requires a dedicated domain, so obtain one and add it using the YunoHost admin panel. **Domains -> Add domain**. As Hubzilla uses the full domain and is installed on the root, you can create a subdomain such as zap.domain.tld. Don't forget to update your DNS if you manage them manually. +- Zap requires a dedicated domain, so obtain one and add it using the YunoHost admin panel. **Domains -> Add domain**. As Zap uses the full domain and is installed on the root, you can create a subdomain such as Zap.domain.tld. Don't forget to update your DNS if you manage them manually. -#### YunoHost >= 2.5 : -Once the dedicated domain has been added to YunoHost, go again to the admin panel, go to domains then select your domain and click on "Install Let's Encrypt certificate". +## Ldap Admin user rights, logs and failed database updates -### Install the ZAP application -Use the YunoHost admin panel to install Zap by entering the GitHub repo address in the custom app URL +- **For admin rights**: When installation is complete, you will need to visit your new hub's page and login with the **admin account username** which was entered at the time of installation process. You should then be able to create your first channel and have the **admin rights** for the hub. - https://github.com/YunoHost-Apps/zap_ynh +- **For normal YunoHost users :** Normal LDAP users can login through Ldap authentication and create there channels. -Make sure to select your new domain created by the instruction in previous section as the application domain. +- **Failing to get admin rights :** If the admin cannot access the admin settings at `https://zap.example.com/admin` or you want to grant admin rights to any other user(s) on the hub, then you have to **manually add 4096** to the **account_roles** under **accounts** for that user in the **database through phpMYAdmin**. -**For admin rights**: When installation is complete, you will need to visit your new hub's page and login with the **admin account username** which was entered at the time of installation process. You should then be able to create your first channel and have the admin rights for the hub. - -**For normal YunoHost users:** Normal LDAP users can login through Ldap authentication and create there channels. - -**If the admin cannot access the admin settings:** If the admin cannot access the admin settings at `https://zap.example.com/admin` or you want to grant admin rights to any other user(s) on the hub, then you have to **manually add 4096** to the **account_roles** under **accounts** for that user in the **database through phpMYAdmin**. - -**For logs:** Go to **admin->logs** and enter the file name **php.log**. - -**Failed Database after Upgrade:** Some times databse upgrade fails after version upgrade. You can go to your hub eg. `https://zap.example.com/admin/dbsync/` and upgrade it manually. +- **For logs :** Go to **admin->logs** and enter the file name **php.log**. +- **Failed Database after Upgrade :** Some times databse upgrade fails after version upgrade. You can go to hub eg. `https://zap.example.com/admin/dbsync/` and check the numbers of failled update. These updates will have to be ran manually by **phpMYAdmin**. #### Supported architectures -* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/zap%20%28Official%29.svg)](https://ci-apps.yunohost.org/ci/apps/zap/) -* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/zap%20%28Official%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/zap/) -* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/zap%20%28Official%29.svg)](https://ci-stretch.nohost.me/ci/apps/zap/) +* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/Zap%20%28Official%29.svg)](https://ci-apps.yunohost.org/ci/apps/zap/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/Zap%20%28Official%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/zap/) +* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/Zap%20%28Official%29.svg)](https://ci-stretch.nohost.me/ci/apps/zap/) diff --git a/check_process b/check_process index 3b35eb0..a0d9972 100644 --- a/check_process +++ b/check_process @@ -8,6 +8,7 @@ domain="domain.tld" (DOMAIN) admin="john" (USER) upload="256M" + database="1" (STRING) ; Checks pkg_linter=1 setup_sub_dir=0 @@ -37,9 +38,4 @@ Level 10=0 ;;; Options Email=anmol@datamol.org -Notification= -;;; Upgrade options - ; commit=CommitHash - name=Name and date of the commit. - manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&port=666& - +Notification=change diff --git a/check_process.default b/check_process.default new file mode 100644 index 0000000..97a2bc5 --- /dev/null +++ b/check_process.default @@ -0,0 +1,40 @@ +# See here for more information +# https://github.com/YunoHost/package_check#syntax-check_process-file + +# Move this file from check_process.default to check_process when you have filled it. + +;; Test complet + ; Manifest + domain="domain.tld" (DOMAIN) + path="/path" (PATH) + admin="john" (USER) + language="fr" + is_public=1 (PUBLIC|public=1|private=0) + password="pass" + port="666" (PORT) + ; Checks + pkg_linter=1 + setup_sub_dir=1 + setup_root=1 + setup_nourl=0 + setup_private=1 + setup_public=1 + upgrade=1 + upgrade=1 from_commit=CommitHash + backup_restore=1 + multi_instance=1 + # This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version. + # incorrect_path=1 + port_already_use=0 + change_url=1 +;;; Levels + # If the level 5 (Package linter) is forced to 1. Please add justifications here. + Level 5=auto +;;; Options +Email= +Notification=none +;;; Upgrade options + ; commit=CommitHash + name=Name and date of the commit. + manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&port=666& + diff --git a/conf/app.src b/conf/app.src index 7eccbfe..7ffa17e 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://framagit.org/zot/zap/-/archive/6de872205c2a5d606c98e60f1cea4722ae58af20/zap-6de872205c2a5d606c98e60f1cea4722ae58af20.tar.gz -SOURCE_SUM=1bd0885828c1fba68ff958ad1fc8326624c47bbe6053ef11d19c0824c267c363 +SOURCE_URL=https://codeberg.org/zot/zap/archive/29857253bcd53398cd618bcd21c0e4f8e9481393.tar.gz +SOURCE_SUM=70dcf4b9a5de944cd573b170a6bea1ea781356c78a0f15cc434ca36d25df345b SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR= diff --git a/conf/app_addons.src b/conf/app_addons.src index fc08b75..071cd18 100644 --- a/conf/app_addons.src +++ b/conf/app_addons.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://framagit.org/zot/zap-addons/-/archive/aba763a5f8ae6494e8a99d8ab7715682517a75bc/zap-addons-aba763a5f8ae6494e8a99d8ab7715682517a75bc.tar.gz -SOURCE_SUM=0658f8fc3ee9144131d06cd1817d4b4c44b57c714e4a4c533ff069a9d1ea2417 +SOURCE_URL=https://codeberg.org/zot/zap-addons/archive/87b01b8316ede942d348cd65184ddfd924c24b88.tar.gz +SOURCE_SUM=834c2684c8b4b84e48834ce31e5fc00253bc09ba8726fd804ca910759266e814 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR= diff --git a/conf/nginx.conf b/conf/nginx.conf index c305b8c..f4a4ebc 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,32 +1,32 @@ - location __PATH__ + location __PATH__ { alias __FINALPATH__/; # Force https - if ($scheme = http) - + if ($scheme = http) + { rewrite ^ https://$server_name$request_uri? permanent; } - - if (!-e $request_filename) - + + if (!-e $request_filename) + { rewrite ^(.*)$ /index.php?req=$1; } - + client_max_body_size 20m; client_body_buffer_size 128k; - + # Default indexes and catch-all index index.php; charset utf-8; - + # Example PHP configuration - location ~* \.php$ + location ~* \.php$ { try_files $uri =404; - fastcgi_pass unix:/var/run/php5-fpm.sock; + fastcgi_pass unix:/var/run/php__PHPVERSION__-fpm-__NAME__.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; @@ -34,10 +34,10 @@ # make sure webfinger and other well known services aren't blocked # by denying dot files and rewrite request to the front controller - location ^~ /.well-known/ + location ^~ /.well-known/ { allow all; - if (!-e $request_filename) + if (!-e $request_filename) { rewrite ^(.*)$ /index.php?req=$1; } @@ -51,29 +51,28 @@ # expires 30d; # try_files $uri /index.php?q=$uri&$args; # } - + # block these file types - location ~* \.(tpl|md|tgz|log|out)$ + location ~* \.(tpl|md|tgz|log|out)$ { deny all; } - + # deny access to all dot files - location ~ /\. + location ~ /\. { deny all; } - + #deny access to store - location ~ /store + location ~ /store { deny all; } - + #deny access to util location ~ /util { deny all; } } - diff --git a/conf/poller-cron b/conf/poller-cron index cd3d674..31ba32f 100644 --- a/conf/poller-cron +++ b/conf/poller-cron @@ -1,2 +1,2 @@ # Run poller periodically to update Hubzilla -*/10 * * * * __USER__ cd YNH_WWW_PATH; /usr/bin/php Zotlabs/Daemon/Master.php Cron > /dev/null 2>&1 +*/10 * * * * __USER__ cd YNH_WWW_PATH; /usr/bin/php__PHP_VERSION__ Zotlabs/Daemon/Master.php Cron > /dev/null 2>&1 \ No newline at end of file diff --git a/manifest.json b/manifest.json index f68caff..55866ad 100644 --- a/manifest.json +++ b/manifest.json @@ -3,24 +3,23 @@ "id": "zap", "packaging_format": 1, "description": { - "en": "Zap is a full featured social network application with identity/content mirroring across multiple servers (nomadic identity) but no federate with non-nomadic servers." + "en": "A fediverse server." }, - "version": "2.6~ynh1", + "version": "2020-10~ynh1", "url": "https://zotlabs.com/zap/", "license": "MIT", "maintainer": { - "name": "Anmol Sharma", - "email": "anmol@datamol.org", - "url": "https://datamol.org" + "name": "Anmol Sharma" }, "requirements": { - "yunohost": ">= 2.7.2" + "yunohost": ">= 3.8.1" }, "multi_instance": true, "services": [ "nginx", - "php7.0-fpm", - "mysql" + "php7.3-fpm", + "mysql", + "postgresql" ], "arguments": { "install" : [ @@ -40,6 +39,19 @@ "fr": "Choisissez l'administrateur de ZAP (doit ĂȘtre un utilisateur YunoHost existant)" } } + { + "name": "database", + "type": "string", + "ask": { + "en": "Choose the database to be used for the Zap [mysql:1,postgresql:2]", + "fr": "Choisissez la database de l'Zap [mysql:1,postgresql:2]" + }, + "choices": ["1", "2"], + "default": "1" + } + + + ] } } diff --git a/pull_request_template.md b/pull_request_template.md new file mode 100644 index 0000000..1128385 --- /dev/null +++ b/pull_request_template.md @@ -0,0 +1,19 @@ + +## Problem +- *Description of why you made this PR* + +## Solution +- *And how do you fix that problem* + +## PR Status +- [ ] Code finished. +- [ ] Tested with Package_check. +- [ ] Fix or enhancement tested. +- [ ] Upgrade from last version tested. +- [ ] Can be reviewed and tested. + +## Package_check results +--- +*If you have access to [App Continuous Integration for packagers](https://yunohost.org/#/packaging_apps_ci) you can provide a link to the package_check results like below, replacing '-NUM-' in this link by the PR number and USERNAME by your username on the ci-apps-dev. Or you provide a screenshot or a pastebin of the results* + +[![Build Status](https://ci-apps-dev.yunohost.org/jenkins/job/REPLACEBYYOURAPP_ynh%20PR-NUM-%20(USERNAME)/badge/icon)](https://ci-apps-dev.yunohost.org/jenkins/job/REPLACEBYYOURAPP_ynh%20PR-NUM-%20(USERNAME)/) diff --git a/scripts/_common.sh b/scripts/_common.sh index a76b808..ac5de66 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,76 +5,16 @@ #================================================= # dependencies used by the app -pkg_dependencies="php-mbstring php-cli php-imagick php-xml php-zip" +YNH_PHP_VERSION="7.3" -#================================================= -# PERSONAL HELPERS -#================================================= +extra_php_dependencies="php${YNH_PHP_VERSION}-mbstring php${YNH_PHP_VERSION}-cli php${YNH_PHP_VERSION}-imagick php${YNH_PHP_VERSION}-xml php${YNH_PHP_VERSION}-zip php${YNH_PHP_VERSION}-pgsql php${YNH_PHP_VERSION}-json php${YNH_PHP_VERSION}-gd" +# dependencies used by the app +pkg_dependencies="postgresql postgresql-contrib" #================================================= # EXPERIMENTAL HELPERS #================================================= -# Create a dedicated fail2ban config (jail and filter conf files) -# -# usage: ynh_add_fail2ban_config log_file filter [max_retry [ports]] -# | arg: log_file - Log file to be checked by fail2ban -# | arg: failregex - Failregex to be looked for by fail2ban -# | arg: max_retry - Maximum number of retries allowed before banning IP address - default: 3 -# | arg: ports - Ports blocked for a banned IP address - default: http,https -ynh_add_fail2ban_config () { - # Process parameters - logpath=$1 - failregex=$2 - max_retry=${3:-3} - ports=${4:-http,https} - - test -n "$logpath" || ynh_die "ynh_add_fail2ban_config expects a logfile path as first argument and received nothing." - test -n "$failregex" || ynh_die "ynh_add_fail2ban_config expects a failure regex as second argument and received nothing." - - finalfail2banjailconf="/etc/fail2ban/jail.d/$app.conf" - finalfail2banfilterconf="/etc/fail2ban/filter.d/$app.conf" - ynh_backup_if_checksum_is_different "$finalfail2banjailconf" 1 - ynh_backup_if_checksum_is_different "$finalfail2banfilterconf" 1 - - sudo tee $finalfail2banjailconf <&2 - echo "WARNING${fail2ban_error#*WARNING}" >&2 - fi -} - -# Remove the dedicated fail2ban config (jail and filter conf files) -# -# usage: ynh_remove_fail2ban_config -ynh_remove_fail2ban_config () { - ynh_secure_remove "/etc/fail2ban/jail.d/$app.conf" - ynh_secure_remove "/etc/fail2ban/filter.d/$app.conf" - sudo systemctl restart fail2ban -} - ynh_smart_mktemp () { local min_size="${1:-300}" # Transform the minimum size from megabytes to kilobytes @@ -91,7 +31,7 @@ ynh_smart_mktemp () { elif is_there_enough_space /var; then local tmpdir=/var elif is_there_enough_space /; then - local tmpdir=/ + local tmpdir=/ elif is_there_enough_space /home; then local tmpdir=/home else diff --git a/scripts/backup b/scripts/backup index 7a706f8..40bc780 100755 --- a/scripts/backup +++ b/scripts/backup @@ -24,68 +24,78 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_print_info "Loading installation settings..." - +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -final_path=$(ynh_app_setting_get $app final_path) -domain=$(ynh_app_setting_get $app domain) -db_name=$(ynh_app_setting_get $app db_name) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) +database=$(ynh_app_setting_get --app=$app --key=database) #================================================= # 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 "$final_path" +ynh_backup --src_path="$final_path" #================================================= # 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" #================================================= # BACKUP THE PHP-FPM CONFIGURATION #================================================= -ynh_print_info "Backing up php-fpm configuration..." +ynh_script_progression --message="Backing up php-fpm configuration..." -ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf" +ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" #================================================= -# BACKUP THE MYSQL DATABASE +# BACKUP OF THE DATABASE #================================================= -ynh_print_info "Backing up the MySQL database..." +ynh_script_progression --message="Backing up the MySQL database..." + +if [ $database -eq 1 ]; then + ynh_script_progression --message="Backup of the MySQL database..." + ynh_mysql_dump_db --database="$db_name" > db.sql +elif [ $database -eq 2 ]; then + # Removing postgresql database + ynh_script_progression --message="Backup of the postgresql database..." + ynh_psql_dump_db --database="$db_name" > db.sql +fi -ynh_mysql_dump_db "$db_name" > db.sql #================================================= # SPECIFIC BACKUP #================================================= # BACKUP LOGROTATE #================================================= -ynh_print_info "Backing up logrotate configuration..." +ynh_script_progression --message="Backing up logrotate configuration..." -ynh_backup "/etc/logrotate.d/$app" +ynh_backup --src_path="/etc/logrotate.d/$app" #================================================= -# BACKUP THE CRON FILE +# BACKUP A CRON FILE #================================================= -ynh_backup "/etc/cron.d/$app" +ynh_backup --src_path="/etc/cron.d/$app" #================================================= # BACKUP FAIL2BAN CONFIGURATION #================================================= +ynh_script_progression --message="Backing up fail2ban configuration..." -ynh_backup "/etc/fail2ban/jail.d/$app.conf" -ynh_backup "/etc/fail2ban/filter.d/$app.conf" +ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf" +ynh_backup --src_path="/etc/fail2ban/filter.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)." diff --git a/scripts/install b/scripts/install index 234cf73..7711ee0 100755 --- a/scripts/install +++ b/scripts/install @@ -30,6 +30,8 @@ admin=$YNH_APP_ARG_ADMIN email=$(sudo yunohost user info $admin | grep "mail:" | cut -d' ' -f2) upload="256M" database="1" +random_string="$(ynh_string_random)$(ynh_string_random)$(ynh_string_random)" +database=`expr $YNH_APP_ARG_DATABASE` # This is 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 @@ -46,27 +48,37 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -ynh_print_info "Validating installation parameters..." +### About --weight and --time +### ynh_script_progression will show to your final users the progression of each scripts. +### In order to do that, --weight will represent the relative time of execution compared to the other steps in the script. +### --time is a packager option, it will show you the execution time since the previous call. +### This option should be removed before releasing your app. +### Use the execution time, given by --time, to estimate the weight of a step. +### A common way to do it is to set a weight equal to the execution time in second +1. +### The execution time is given for the duration since the previous call. So the weight should be applied to this previous call. +ynh_script_progression --message="Validating installation parameters..." ### 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" +test ! -e "$final_path" || ynh_die --message="This path already contains a folder" # 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_app_setting_set $app domain $domain -ynh_app_setting_set $app path $path_url -ynh_app_setting_set $app admin $admin -ynh_app_setting_set $app email $email -ynh_app_setting_set $app upload $upload -ynh_app_setting_set $app database $database +ynh_app_setting_set --app=$app --key=domain --value=$domain +ynh_app_setting_set --app=$app --key=path --value=$path_url +ynh_app_setting_set --app=$app --key=admin --value=$admin +ynh_app_setting_set --app=$app --key=email --value=$email +ynh_app_setting_set --app=$app --key=upload --value=$upload +ynh_app_setting_set --app=$app --key=database --value=$database +ynh_app_setting_set --app=$app --key=random_string --value=$random_string + #================================================= @@ -84,12 +96,47 @@ ynh_print_info "Installing dependencies..." ### - As well as the section "REINSTALL DEPENDENCIES" in the restore script ### - And the section "UPGRADE DEPENDENCIES" in the upgrade script -ynh_install_app_dependencies $pkg_dependencies +if [ $database -eq 2 ]; then + ynh_install_app_dependencies $pkg_dependencies +fi + #================================================= -# CREATE A MYSQL DATABASE +# DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_print_info "Creating a MySQL database..." + +# 1 - Zap +ynh_script_progression --message="Setting up Zap source files..." + +### `ynh_setup_source` is used to install an app from a zip or tar.gz file, +### downloaded from an upstream source, like a git repository. +### `ynh_setup_source` use the file conf/app.src + +ynh_app_setting_set --app=$app --key=final_path --value=$final_path +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source --dest_dir="$final_path" + +# 2 - Zap Addons + +# Make addon Directory and unpack the addons to this directory +ynh_script_progression --message="Create addon directory inside root folder..." +mkdir $final_path/addon +ynh_script_progression --message="Setting up Zap addons source files..." + +ynh_setup_source --dest_dir="$final_path/addon" --source_id="app_addons" + + +# 3 - Some extra folders +ynh_script_progression --message="Creating smarty3 folder for personal data..." + +mkdir -p "${final_path}/store" +mkdir -p "${final_path}/cache/smarty3" +chmod -R 777 $final_path/store $final_path/cache + +#================================================= +# CREATE A 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. @@ -100,46 +147,34 @@ ynh_print_info "Creating a MySQL database..." ### - 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 -db_name=$(ynh_sanitize_dbid $app) -ynh_app_setting_set $app db_name $db_name -ynh_mysql_setup_db $db_name $db_name +if [ $database -eq 1 ]; then + ynh_script_progression --message="Creating a MySQL database..." + db_name=$(ynh_sanitize_dbid --db_name=$app) + db_user=$db_name + ynh_app_setting_set --app=$app --key=db_name --value=$db_name + ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name + ynh_script_progression --message="Importing database..." + ynh_mysql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_name" < $final_path/install/schema_mysql.sql +elif [ $database -eq 2 ]; then + # Create postgresql database + ynh_script_progression --message="Creating a postgresql database..." + ynh_replace_string --match_string="db_type = 0;" --replace_string="db_type = 1;" --target_file="$config" + db_name=$(ynh_sanitize_dbid --db_name=$app) + db_user=$app + ynh_psql_test_if_first_run + ynh_psql_setup_db --db_user=$db_user --db_name=$db_name + ynh_app_setting_set --app=$app --key=db_name --value=$db_name + ynh_script_progression --message="Importing database..." + ynh_psql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_name" < $final_path/install/schema_postgres.sql +else + ynh_die --message="Some problem occured in creating the database, contact maintainer" -#================================================= -# DOWNLOAD, CHECK AND UNPACK SOURCE -#================================================= - -# 1 - Zap -ynh_print_info "Setting up source files..." - -### `ynh_setup_source` is used to install an app from a zip or tar.gz file, -### downloaded from an upstream source, like a git repository. -### `ynh_setup_source` use the file conf/app.src - -ynh_app_setting_set $app final_path $final_path -# Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source "$final_path" - -# 2 - Zap Addons - -# Make addon Directory and unpack the addons to this directory -ynh_print_info "Create addon directory inside root folder..." -sudo mkdir $final_path/addon -ynh_print_info "Setting up addons source files..." -ynh_setup_source "$final_path/addon" "app_addons" - - -# 3 - Some extra folders -ynh_print_info "Creating smarty3 folder for personal data..." -sudo mkdir -p "${final_path}/store/[data]/smarty3" -sudo chmod -R 777 $final_path/store - -# Import database schema -ynh_print_info "Importing database..." -ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < $final_path/install/schema_mysql.sql +fi # Copy the template install/htconfig.sample.php to .htconfig.php -ynh_print_info "Moving .htconfig.php to root folder ..." -sudo cp $final_path/install/htconfig.sample.php $final_path/.htconfig.php +ynh_script_progression --message="Moving .htconfig.php to root of Zap ..." +config="$final_path/.htconfig.php" +cp $final_path/install/htconfig.sample.php $config # Create php.log inside for logs ynh_print_info "Create php.log for the debuging..." @@ -151,32 +186,31 @@ sudo touch "$final_path/php.log" ### `ynh_replace_string` is used to replace a string in a file. ### (It's compatible with sed regular expressions syntax) +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) +ynh_replace_string --match_string="your.mysqlhost.com" --replace_string="localhost" --target_file="$config" +ynh_replace_string --match_string= "mysqlpassword" --replace_string="$db_pwd" --target_file="$config" +ynh_replace_string --match_string="mysqlusername" --replace_string="$db_name" --target_file="$config" +ynh_replace_string --match_string= "mysqldatabasename" --replace_string="$db_name" --target_file="$config" +ynh_replace_string --match_string= "mysite.example" --replace_string="$domain" --target_file="$config" +ynh_replace_string --match_string= "if the auto install failed, put a unique random string here" --replace_string="$random_string" --target_file="$config" +sed -i "s/\['admin_email'\] = '';/\['admin_email'\] = '$email';/g" "$config" +ynh_replace_string --match_string= "//error_reporting(E_ERROR | E_WARNING | E_PARSE );" --replace_string="error_reporting(E_ERROR | E_WARNING | E_PARSE );" --target_file="$config" +ynh_replace_string --match_string= "//ini_set('error_log','php.out');" --replace_string="ini_set('error_log','php.log');" --target_file="$config" +ynh_replace_string --match_string= "//ini_set('log_errors','1');" --replace_string="ini_set('log_errors','1');" --target_file="$config" +ynh_replace_string --match_string= "//ini_set('display_errors', '0');" --replace_string="ini_set('display_errors', '0');" --target_file="$config" +sed -i "s/\['php_path'\] = 'php';/\['php_path'\] = 'php$phpversion';/g" "$config" -ynh_print_info "Replace the .htconfig.php values...." -sudo sed -i "s/your.mysqlhost.com/localhost/g" $final_path/.htconfig.php -sudo sed -i "s/mysqlpassword/$db_pwd/g" $final_path/.htconfig.php -sudo sed -i "s/mysqlusername/$db_name/g" $final_path/.htconfig.php -sudo sed -i "s/mysqldatabasename/$db_name/g" $final_path/.htconfig.php -sudo sed -i "s/mysite.example/$domain/g" $final_path/.htconfig.php -sudo sed -i "s/if the auto install failed, put a unique random string here/$(ynh_string_random)$(ynh_string_random)$(ynh_string_random)/g" $final_path/.htconfig.php -sudo sed -i "s/\['admin_email'\] = '';/\['admin_email'\] = '$email';/g" $final_path/.htconfig.php -sudo sed -i "s@//error_reporting(E_ERROR | E_WARNING | E_PARSE );@error_reporting(E_ERROR | E_WARNING | E_PARSE );@g" $final_path/.htconfig.php -sudo sed -i "s@//ini_set('error_log','php.out');@ini_set('error_log','php.log');@g" $final_path/.htconfig.php -sudo sed -i "s@//ini_set('log_errors','1');@ini_set('log_errors','1');@g" $final_path/.htconfig.php -sudo sed -i "s@//ini_set('display_errors', '0');@ini_set('display_errors', '0');@g" $final_path/.htconfig.php +# addon ldap config +ynh_script_progression --message="Push Ldap configuration to .htconfig.php..." + +cat ../conf/ldap_conf.php >> $final_path/.htconfig.php -# Addon ldap config -ynh_print_info "Push Ldap configuration to .htconfig.php..." -sudo su -c "cat ../conf/ldap_conf.php >> $final_path/.htconfig.php" -# Addon Zap protocol (currently the if zap config is not pusshed in the config file, Osada protocol is taken by default) -sudo su -c "cat ../conf/zap.php >> $final_path/.htconfig.php" #================================================= # NGINX CONFIGURATION #================================================= -ynh_print_info "Configuring nginx web server..." - +ynh_script_progression --message="Configuring nginx web server..." ### `ynh_add_nginx_config` will use the file conf/nginx.conf # Create a dedicated nginx config @@ -185,19 +219,19 @@ ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= -ynh_print_info "Configuring system user..." +ynh_script_progression --message="Configuring system user..." # Create a system user -ynh_system_user_create $app +ynh_system_user_create --username=$app #================================================= # PHP-FPM CONFIGURATION #================================================= -ynh_print_info "Configuring php-fpm..." +ynh_script_progression --message="Configuring php-fpm..." ### `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 +### `ynh_add_fpm_config` will use the files conf/php-fpm.conf ### 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 @@ -207,17 +241,18 @@ ynh_print_info "Configuring php-fpm..." ### - And the section "PHP-FPM CONFIGURATION" in the upgrade script # Create a dedicated php-fpm config -ynh_add_fpm_config +ynh_add_fpm_config --package="$extra_php_dependencies" -# Set right permissions for the app -ynh_print_info "Set the app rights..." +# Set right permissions for Zap +ynh_script_progression --message="Set right for Zap..." chown -R $app: $final_path # Set up cron job -ynh_print_info "Setting up cron job..." -ynh_replace_string "YNH_WWW_PATH" "$final_path" ../conf/poller-cron -ynh_replace_string "__USER__" "$app" ../conf/poller-cron -sudo cp ../conf/poller-cron /etc/cron.d/$app +ynh_script_progression --message="Setting up cron job..." +ynh_replace_string --match_string="YNH_WWW_PATH" --replace_string="$final_path" --target_file="../conf/poller-cron" +ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="../conf/poller-cron" +ynh_replace_string --match_string="__PHP_VERSION__" --replace_string="$phpversion" --target_file="../conf/poller-cron" +cp ../conf/poller-cron /etc/cron.d/$app #================================================= # STORE THE CONFIG FILE CHECKSUM @@ -228,12 +263,12 @@ sudo cp ../conf/poller-cron /etc/cron.d/$app ### you can make a backup of this file before modifying it again if the admin had modified it. # Calculate and store the config file checksum into the app settings -ynh_store_file_checksum "$final_path/.htconfig.php" +ynh_store_file_checksum --file="$config" #================================================= # SETUP LOGROTATE #================================================= -ynh_print_info "Configuring log rotation..." +ynh_script_progression --message="Configuring log rotation..." ### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app. ### Use this helper only if there is effectively a log file for this app. @@ -249,25 +284,25 @@ ynh_use_logrotate "$final_path/php.log" #================================================= # SETUP FAIL2BAN #================================================= -ynh_print_info "Add Fail2Ban..." -ynh_add_fail2ban_config "$final_path/php.log" "^.*auth\.php.*failed login attempt.*from IP .*$" 5 +ynh_script_progression --message="Add Fail2Ban..." +ynh_add_fail2ban_config --logpath="$final_path/php.log" --failregex="^.*auth\.php.*failed login attempt.*from IP .*$" --max_retry="5" #================================================= # SETUP SSOWAT #================================================= # As Zap is social network and have its own permission there is no need to keep Zap behind SSO -ynh_print_info "Configuring SSOwat..." -ynh_app_setting_set $app skipped_uris "/" +ynh_script_progression --message="Configuring SSOwat..." +ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" #================================================= # 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" diff --git a/scripts/remove b/scripts/remove index cb3e234..ca6bb10 100755 --- a/scripts/remove +++ b/scripts/remove @@ -12,19 +12,36 @@ 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) -db_name=$(ynh_app_setting_get $app db_name) +domain=$(ynh_app_setting_get --app=$app --key=domain) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user="$db_name" -final_path=$(ynh_app_setting_get $app final_path) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +database=$(ynh_app_setting_get --app=$app --key=database) #================================================= # STANDARD REMOVE #================================================= +#================================================= +# STANDARD REMOVE +#================================================= + +#================================================= +# REMOVE THE DATABASE +#================================================= +if [ $database -eq 1 ]; then + ynh_script_progression --message="Removing MySQL database..." + ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name +elif [ $database -eq 2 ]; then + # Removing postgresql database + ynh_script_progression --message="Removing postgresql database..." + ynh_psql_remove_db --db_user=$db_user --db_name=$db_name +fi + #================================================= # REMOVE DEPENDENCIES #================================================= @@ -32,27 +49,26 @@ ynh_print_info "Removing dependencies" # Remove metapackage and its dependencies ynh_remove_app_dependencies - #================================================= -# REMOVE THE MYSQL DATABASE +# REMOVE DEPENDENCIES #================================================= -ynh_print_info "Removing the MySQL database" +ynh_script_progression --message="Removing dependencies..." -# Remove a database if it exists, along with the associated user -ynh_mysql_remove_db $db_user $db_name +# Remove metapackage and its dependencies +ynh_remove_app_dependencies #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_print_info "Removing app main directory" +ynh_script_progression --message="Removing app main directory..." # Remove the app directory securely -ynh_secure_remove "$final_path" +ynh_secure_remove --file="$final_path" #================================================= # 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 @@ -60,7 +76,7 @@ ynh_remove_nginx_config #================================================= # REMOVE PHP-FPM CONFIGURATION #================================================= -ynh_print_info "Removing php-fpm configuration" +ynh_script_progression --message="Removing php-fpm configuration..." # Remove the dedicated php-fpm config ynh_remove_fpm_config @@ -68,7 +84,7 @@ ynh_remove_fpm_config #================================================= # REMOVE LOGROTATE CONFIGURATION #================================================= -ynh_print_info "Removing logrotate configuration" +ynh_script_progression --message="Removing logrotate configuration..." # Remove the app-specific logrotate config ynh_remove_logrotate @@ -78,11 +94,13 @@ ynh_remove_logrotate #================================================= # Remove a cron file -ynh_secure_remove "/etc/cron.d/$app" +ynh_secure_remove --file="/etc/cron.d/$app" + #================================================= # REMOVE FAIL2BAN CONFIGURATION #================================================= +ynh_script_progression --message="Removing fail2ban configuration..." ynh_remove_fail2ban_config @@ -91,13 +109,13 @@ ynh_remove_fail2ban_config #================================================= # REMOVE DEDICATED USER #================================================= -ynh_print_info "Removing the dedicated system user" +ynh_script_progression --message="Removing the dedicated system user..." # Delete a system user -ynh_system_user_delete $app +ynh_system_user_delete --username=$app #================================================= # END OF SCRIPT #================================================= -ynh_print_info "Removal of $app completed" +ynh_script_progression --message="Removal of $app completed" \ No newline at end of file diff --git a/scripts/restore b/scripts/restore index 04d3450..78267de 100755 --- a/scripts/restore +++ b/scripts/restore @@ -24,25 +24,28 @@ 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) -admin=$(ynh_app_setting_get $app admin) -final_path=$(ynh_app_setting_get $app final_path) -db_name=$(ynh_app_setting_get $app db_name) +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +admin=$(ynh_app_setting_get --app=$app --key=admin) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +database=$(ynh_app_setting_get --app=$app --key=database) +db_user=$db_name +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # 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}" test ! -d $final_path \ - || ynh_die "There is already a directory: $final_path " + || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS @@ -50,23 +53,36 @@ test ! -d $final_path \ # 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" #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_print_info "Restoring the app main directory..." +ynh_script_progression --message="Restoring the app main directory..." -ynh_restore_file "$final_path" +ynh_restore_file --origin_path="$final_path" #================================================= # RESTORE THE MYSQL DATABASE #================================================= -ynh_print_info "Restoring the MySQL database..." +ynh_script_progression --message="Restoring the MySQL database..." --time -db_pwd=$(ynh_app_setting_get $app mysqlpwd) -ynh_mysql_setup_db $db_name $db_name $db_pwd -ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql +if [ $database -eq 1 ]; then + ynh_script_progression --message="Restoring MySQL database..." + db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) + ynh_mysql_setup_db --db_user=$db_name --db_name=$db_name --db_pwd=$db_pwd + ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name < ./db.sql +elif [ $database -eq 2 ]; then + # Removing postgresql database + ynh_script_progression --message="Reinstalling dependencies..." + # Define and install dependencies + ynh_install_app_dependencies $pkg_dependencies + ynh_script_progression --message="Restoring the PostgreSQL database..." + db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) + ynh_psql_test_if_first_run + ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd + ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" +fi #================================================= # RECREATE THE DEDICATED USER @@ -79,38 +95,36 @@ ynh_system_user_create $app #================================================= # RESTORE THE PHP-FPM CONFIGURATION #================================================= +ynh_script_progression --message="Restoring PHP-FPM configuration..." -ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf" +ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" + +# Recreate a dedicated php-fpm config +ynh_add_fpm_config --package="$extra_php_dependencies" #================================================= # SPECIFIC RESTORATION #================================================= -# REINSTALL DEPENDENCIES -#================================================= -ynh_print_info "Reinstalling dependencies..." - -# Define and install dependencies -ynh_install_app_dependencies $pkg_dependencies - #================================================= # RESTORE THE CRON FILE #================================================= -ynh_restore_file "/etc/cron.d/$app" +ynh_restore_file --origin_path="/etc/cron.d/$app" #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= -ynh_restore_file "/etc/logrotate.d/$app" +ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= # RESTORE FAIL2BAN CONFIGURATION #================================================= +ynh_script_progression --message="Restoring the fail2ban configuration..." --time --weight=1 ynh_restore_file "/etc/fail2ban/jail.d/$app.conf" ynh_restore_file "/etc/fail2ban/filter.d/$app.conf" -systemctl restart fail2ban +ynh_systemd_action --action=restart --service_name=fail2ban # Make app public ynh_app_setting_set $app skipped_uris "/" @@ -120,13 +134,13 @@ ynh_app_setting_set $app skipped_uris "/" #================================================= # RELOAD NGINX AND PHP-FPM #================================================= -ynh_print_info "Reloading nginx web server and php-fpm..." +ynh_script_progression --message="Reloading nginx web server and php-fpm..." --time --weight=1 -systemctl reload php7.0-fpm -systemctl reload nginx +ynh_systemd_action --service_name=php$phpversion-fpm --action=reload +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" --time --last \ No newline at end of file diff --git a/scripts/upgrade b/scripts/upgrade index bdcf354..c373fd2 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,32 +12,34 @@ 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) -final_path=$(ynh_app_setting_get $app final_path) -upload=$(ynh_app_setting_get $app upload) -db_name=$(ynh_app_setting_get $app db_name) -db_pwd=$(ynh_app_setting_get $app mysqlpwd) +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +upload=$(ynh_app_setting_get --app=$app --key=upload) +version=$(grep STD_VERSION $final_path/boot.php | cut -c 38- | rev | cut -c 5- | rev) +last_update=$(grep update_time: /etc/yunohost/apps/$app/settings.yml | cut -c 14-) +database=$(ynh_app_setting_get --app=$app --key=database) +phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= # If db_name doesn't exist, create it -if [ -z $db_name ]; then - db_name=$(ynh_sanitize_dbid $app) - ynh_app_setting_set $app db_name $db_name +if [ -z "$db_name" ]; then + db_name=$(ynh_sanitize_dbid --db_name=$app) + ynh_app_setting_set --app=$app --key=db_name --value=$db_name 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)..." # Backup the current version of the app ynh_backup_before_upgrade @@ -61,15 +63,16 @@ tmpdir="$(ynh_smart_mktemp 6000)" cp -a "$final_path/.htconfig.php" "$tmpdir/.htconfig.php" cp -a "$final_path/store" "$tmpdir/store" cp -a "$final_path/php.log" "$tmpdir/php.log" +cp -a "$final_path/cache" "$tmpdir/cache" # Remove the app directory securely ynh_secure_remove "$final_path" # If final_path doesn't exist, create it -if [ -z $final_path ]; then +if [ -z "$final_path" ]; then final_path=/var/www/$app - ynh_app_setting_set $app final_path $final_path + ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi #================================================= @@ -78,21 +81,36 @@ fi # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Upgrading source files..." + # Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source "$final_path" -sudo cp -a "$tmpdir/store" "${final_path}" -sudo cp -a "$tmpdir/.htconfig.php" "${final_path}" -sudo cp -a "$tmpdir/php.log" "${final_path}" -sudo rm -Rf "$tmpdir" -sudo chmod -R 777 $final_path/store -sudo mkdir $final_path/addon -ynh_setup_source "$final_path/addon" "app_addons" + ynh_setup_source --dest_dir="$final_path" + + +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# DOWNLOAD, CHECK AND UNPACK SOURCE +#================================================= +ynh_script_progression --message="Upgrading source files..." + +# Download, check integrity, uncompress and patch the source from app.src + ynh_setup_source --dest_dir="$final_path" + +cp -a "$tmpdir/cache" "${final_path}" +cp -a "$tmpdir/store" "${final_path}" +cp -a "$tmpdir/.htconfig.php" "${final_path}" +cp -a "$tmpdir/php.log" "${final_path}" +rm -Rf "$tmpdir" +chmod -R 777 $final_path/store +mkdir $final_path/addon +ynh_setup_source --dest_dir="$final_path/addon" --source_id="app_addons" #================================================= # NGINX CONFIGURATION #================================================= -ynh_print_info "Upgrading nginx web server configuration..." +ynh_script_progression --message="Upgrading nginx web server configuration..." # Create a dedicated nginx config ynh_add_nginx_config @@ -100,10 +118,10 @@ ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= -ynh_print_info "Making sure dedicated system user exists..." +ynh_script_progression --message="Making sure dedicated system user exists..." # Create a dedicated user (if not existing) -ynh_system_user_create $app +ynh_system_user_create --username=$app # Set right permissions for curl install chown -R $app: $final_path @@ -114,58 +132,60 @@ chown -R $app: $final_path ynh_print_info "Upgrading php-fpm configuration..." # Create a dedicated php-fpm config -ynh_add_fpm_config - +ynh_add_fpm_config --package="$extra_php_dependencies" ### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. ### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. -ynh_backup_if_checksum_is_different "$final_path/.htconfig.php" -# Recalculate and store the config file checksum into the app settings -ynh_store_file_checksum "$final_path/.htconfig.php" +ynh_backup_if_checksum_is_different --file="$final_path/.htconfig.php" +# Recalculate and store the checksum of the file for the next upgrade. +ynh_store_file_checksum --file="$final_path/.htconfig.php" #================================================= # SETUP LOGROTATE #================================================= -ynh_print_info "Upgrading logrotate configuration..." +ynh_script_progression --message="Upgrading logrotate configuration..." # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append +# UPGRADE FAIL2BAN #================================================= -# SETUP FAIL2BAN -#================================================= -ynh_print_info "Add Fail2Ban..." -ynh_add_fail2ban_config "$final_path/php.log" "^.*auth\.php.*failed login attempt.*from IP .*$" 5 +ynh_script_progression --message="Re-configure fail2ban..." + +ynh_add_fail2ban_config --logpath="$final_path/php.log" --failregex="^.*auth\.php.*failed login attempt.*from IP .*$" --max_retry="5" # Set cron job ynh_print_info "Setting up cron job..." -ynh_replace_string "YNH_WWW_PATH" "$final_path" ../conf/poller-cron -ynh_replace_string "__USER__" "$app" ../conf/poller-cron -sudo cp ../conf/poller-cron /etc/cron.d/$app +ynh_replace_string --match_string="YNH_WWW_PATH" --replace_string="$final_path" --target_file="../conf/poller-cron" +ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="../conf/poller-cron" +ynh_replace_string --match_string="__PHP_VERSION__" --replace_string="$phpversion" --target_file="../conf/poller-cron" +sudo cp -f ../conf/poller-cron /etc/cron.d/$app #================================================= # UPGRADE DEPENDENCIES #================================================= -ynh_print_info "Upgrading dependencies..." +ynh_script_progression --message="Upgrading dependencies..." -ynh_install_app_dependencies $pkg_dependencies +if [ $database -eq 2 ]; then + ynh_install_app_dependencies $pkg_dependencies +fi #================================================= # SETUP SSOWAT #================================================= -# As Hubzilla is social network and have its own permission there is no need to keep Hubzilla behind SSO -ynh_print_info "Configuring SSOwat..." -ynh_app_setting_set $app skipped_uris "/" +# As Zap is social network and have its own permission there is no need to keep Zap behind SSO +ynh_script_progression --message="Upgrading SSOwat configuration..." +ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" #================================================= # 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"