From aeb90c0f7ef6e7b01061d36f2e2a4efe45af4f65 Mon Sep 17 00:00:00 2001 From: anmol26s <5068843+anmol26s@users.noreply.github.com> Date: Mon, 27 Apr 2020 12:07:45 +0530 Subject: [PATCH] updated sources and fixes --- README.md | 4 +- check_process | 17 ++---- conf/app.src | 4 +- conf/app_addons.src | 4 +- conf/nginx.conf | 2 +- manifest.json | 4 +- scripts/backup | 40 ++++++------- scripts/install | 135 ++++++++++++++++++++++++-------------------- scripts/remove | 48 ++++++++-------- scripts/restore | 65 +++++++++++---------- scripts/upgrade | 81 ++++++++++++++------------ 11 files changed, 210 insertions(+), 194 deletions(-) diff --git a/README.md b/README.md index 8bf38ca..52039f4 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # 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) +[![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. If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.* -Version: 20.04.18 +Version: 20.04.27 ### Interesting links diff --git a/check_process b/check_process index 3b35eb0..f94a76e 100644 --- a/check_process +++ b/check_process @@ -19,25 +19,16 @@ #upgrade=1 from_commit=CommitHash backup_restore=1 multi_instance=1 - incorrect_path=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=0 ;;; Levels - Level 1=auto - Level 2=auto - Level 3=auto -# Level 4: If the app supports LDAP and SSOwat, turn level 4 to '1' and add a link to an issue or a part of your code to show it. -# If the app does not use LDAP nor SSOwat, and can't use them, turn level 4 to 'na' and explain as well. - Level 4=1 + # If the level 5 (Package linter) is forced to 1. Please add justifications here. Level 5=auto - Level 6=auto - Level 7=auto - Level 8=0 - Level 9=0 - Level 10=0 ;;; Options Email=anmol@datamol.org -Notification= +Notification=change ;;; Upgrade options ; commit=CommitHash name=Name and date of the commit. diff --git a/conf/app.src b/conf/app.src index f54a87a..a0d674e 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://framagit.org/zot/zap/-/archive/1ad923369ef5b62090e6d85445479140be039ca9.tar.gz -SOURCE_SUM=578bd1f85111dbdad9e4182ed4bee49ca889b605 +SOURCE_URL=https://framagit.org/zot/zap/-/archive/16d06332a35f55d1bfdc89455f968f2b8079fc77/zap-16d06332a35f55d1bfdc89455f968f2b8079fc77.tar.gz +SOURCE_SUM=3b463218ff871d6891a6884f34f74e01a3b47a63bf511baeb6bc5e8d496b773d SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR= diff --git a/conf/app_addons.src b/conf/app_addons.src index 611748f..5e05fe0 100644 --- a/conf/app_addons.src +++ b/conf/app_addons.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://framagit.org/zot/zap-addons/-/archive/b4e8f161edad43583584a5dbb2ef04ccdf3717de/zap-addons-b4e8f161edad43583584a5dbb2ef04ccdf3717de.tar.gz -SOURCE_SUM=dc0155638e62773940b30c80f6994114c17ab6a829b73e9fc870171e25af9179 +SOURCE_URL=https://framagit.org/zot/zap-addons/-/archive/074dbfd024e4e6675393955b13555796e0edbf3c/zap-addons-074dbfd024e4e6675393955b13555796e0edbf3c.tar.gz +SOURCE_SUM=aba32d7e0c5d1297bd2c7199f5f21a611b7591bb0033a2af8d83eaa00c7b8c42 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR= diff --git a/conf/nginx.conf b/conf/nginx.conf index c305b8c..7ba7b4a 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -26,7 +26,7 @@ location ~* \.php$ { try_files $uri =404; - fastcgi_pass unix:/var/run/php5-fpm.sock; + fastcgi_pass unix:/var/run/php/php7.0-fpm-__NAME__.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; diff --git a/manifest.json b/manifest.json index 74f5ef6..0e25adb 100644 --- a/manifest.json +++ b/manifest.json @@ -5,7 +5,7 @@ "description": { "en": "Zap is a full featured social network application with identity/content mirroring across multiple servers (nomadic identity) federating over ActivityPub and Zot6 protocols." }, - "version": "20.04.18~ynh1", + "version": "20.04.27~ynh1", "url": "https://zotlabs.com/zap/", "license": "MIT", "maintainer": { @@ -14,7 +14,7 @@ "url": "https://datamol.org" }, "requirements": { - "yunohost": ">= 2.7.2" + "yunohost": ">= 3.5" }, "multi_instance": true, "services": [ diff --git a/scripts/backup b/scripts/backup index 7a706f8..b79bde7 100755 --- a/scripts/backup +++ b/scripts/backup @@ -24,68 +24,70 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_print_info "Loading installation settings..." +ynh_script_progression --message="Loading installation settings..." --time --weight=1 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) #================================================= # 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..." --time --weight=1 -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..." --time --weight=1 -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..." --time --weight=1 -ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf" +ynh_backup --src_path="/etc/php/7.0/fpm/pool.d/$app.conf" #================================================= # BACKUP THE MYSQL DATABASE #================================================= -ynh_print_info "Backing up the MySQL database..." +ynh_script_progression --message="Backing up the MySQL database..." --time --weight=1 -ynh_mysql_dump_db "$db_name" > db.sql +ynh_mysql_dump_db --database="$db_name" > db.sql #================================================= # SPECIFIC BACKUP #================================================= # BACKUP LOGROTATE #================================================= -ynh_print_info "Backing up logrotate configuration..." +ynh_script_progression --message="Backing up logrotate configuration..." --time --weight=1 -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..." --time --weight=1 + +ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf" +ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" -ynh_backup "/etc/fail2ban/jail.d/$app.conf" -ynh_backup "/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)." --time --last diff --git a/scripts/install b/scripts/install index 57ef909..2427464 100755 --- a/scripts/install +++ b/scripts/install @@ -31,42 +31,50 @@ email=$(sudo yunohost user info $admin | grep "mail:" | cut -d' ' -f2) upload="256M" database="1" -# 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 -# 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 you are interested the most, since this is -# guaranteed to be unique. This is a good unique identifier to define installation path, -# db names, ... +### 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 #================================================= # 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..." --time --weight=1 ### 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_script_progression --message="Storing installation settings..." --time --weight=1 -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 #================================================= @@ -74,7 +82,7 @@ ynh_app_setting_set $app database $database #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_print_info "Installing dependencies..." +ynh_script_progression --message="Installing dependencies..." --time --weight=1 ### `ynh_install_app_dependencies` allows you to add any "apt" dependencies to the package. ### Those deb packages will be installed as dependencies of this package. @@ -89,7 +97,7 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE A MYSQL DATABASE #================================================= -ynh_print_info "Creating a MySQL database..." +ynh_script_progression --message="Creating a MySQL database..." --time --weight=1 ### 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,42 +108,43 @@ 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 +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 #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= # 1 - Zap -ynh_print_info "Setting up source files..." +ynh_script_progression --message="Setting up source files..." --time --weight=1 ### `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 +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 "$final_path" +ynh_setup_source --dest_dir="$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 +mkdir $final_path/addon ynh_print_info "Setting up addons source files..." -ynh_setup_source "$final_path/addon" "app_addons" +ynh_setup_source --dest_dir="$final_path/addon" --source_id="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 $final_path/cache +mkdir -p "${final_path}/store/[data]/smarty3" +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 +ynh_mysql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < $final_path/install/schema_mysql.sql # Copy the template install/htconfig.sample.php to .htconfig.php ynh_print_info "Moving .htconfig.php to root folder ..." @@ -153,17 +162,17 @@ sudo touch "$final_path/php.log" ### (It's compatible with sed regular expressions syntax) 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 +sed -i "s/your.mysqlhost.com/localhost/g" $final_path/.htconfig.php +sed -i "s/mysqlpassword/$db_pwd/g" $final_path/.htconfig.php +sed -i "s/mysqlusername/$db_name/g" $final_path/.htconfig.php +sed -i "s/mysqldatabasename/$db_name/g" $final_path/.htconfig.php +sed -i "s/mysite.example/$domain/g" $final_path/.htconfig.php +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 +sed -i "s/\['admin_email'\] = '';/\['admin_email'\] = '$email';/g" $final_path/.htconfig.php +sed -i "s@//error_reporting(E_ERROR | E_WARNING | E_PARSE );@error_reporting(E_ERROR | E_WARNING | E_PARSE );@g" $final_path/.htconfig.php +sed -i "s@//ini_set('error_log','php.out');@ini_set('error_log','php.log');@g" $final_path/.htconfig.php +sed -i "s@//ini_set('log_errors','1');@ini_set('log_errors','1');@g" $final_path/.htconfig.php +sed -i "s@//ini_set('display_errors', '0');@ini_set('display_errors', '0');@g" $final_path/.htconfig.php # Addon ldap config ynh_print_info "Push Ldap configuration to .htconfig.php..." @@ -175,7 +184,7 @@ 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..." --time --weight=1 ### `ynh_add_nginx_config` will use the file conf/nginx.conf @@ -185,19 +194,19 @@ ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= -ynh_print_info "Configuring system user..." +ynh_script_progression --message="Configuring system user..." --time --weight=1 # 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..." --time --weight=1 ### `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 @@ -215,9 +224,9 @@ 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_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" +cp ../conf/poller-cron /etc/cron.d/$app #================================================= # STORE THE CONFIG FILE CHECKSUM @@ -228,12 +237,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="$final_path/.htconfig.php" #================================================= # SETUP LOGROTATE #================================================= -ynh_print_info "Configuring log rotation..." +ynh_script_progression --message="Configuring log rotation..." --time --weight=1 ### `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. @@ -244,30 +253,32 @@ ynh_print_info "Configuring log rotation..." ### - And the section "SETUP LOGROTATE" in the upgrade script # Use logrotate to manage application logfile(s) -ynh_use_logrotate "$final_path/php.log" +ynh_use_logrotate --logfile="$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="Configuring fail2ban..." --time --weight=1 + +# Create a dedicated fail2ban config +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..." --time --weight=1 +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..." --time --weight=1 -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" --time --last diff --git a/scripts/remove b/scripts/remove index cb3e234..4035aac 100755 --- a/scripts/remove +++ b/scripts/remove @@ -12,47 +12,47 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_print_info "Loading installation settings..." +ynh_script_progression --message="Loading installation settings..." --time --weight=1 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) +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=$app --key=final_path) #================================================= # STANDARD REMOVE #================================================= +#================================================= +# REMOVE THE MYSQL DATABASE +#================================================= +ynh_script_progression --message="Removing the MySQL database..." --time --weight=1 + +# Remove a database if it exists, along with the associated user +ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name + #================================================= # REMOVE DEPENDENCIES #================================================= -ynh_print_info "Removing dependencies" +ynh_script_progression --message="Removing dependencies..." --time --weight=1 # Remove metapackage and its dependencies ynh_remove_app_dependencies -#================================================= -# REMOVE THE MYSQL DATABASE -#================================================= -ynh_print_info "Removing the MySQL database" - -# Remove a database if it exists, along with the associated user -ynh_mysql_remove_db $db_user $db_name - #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_print_info "Removing app main directory" +ynh_script_progression --message="Removing app main directory..." --time --weight=1 # 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..." --time --weight=1 # Remove the dedicated nginx config ynh_remove_nginx_config @@ -60,7 +60,7 @@ ynh_remove_nginx_config #================================================= # REMOVE PHP-FPM CONFIGURATION #================================================= -ynh_print_info "Removing php-fpm configuration" +ynh_script_progression --message="Removing php-fpm configuration..." --time --weight=1 # Remove the dedicated php-fpm config ynh_remove_fpm_config @@ -68,7 +68,7 @@ ynh_remove_fpm_config #================================================= # REMOVE LOGROTATE CONFIGURATION #================================================= -ynh_print_info "Removing logrotate configuration" +ynh_script_progression --message="Removing logrotate configuration..." --time --weight=1 # Remove the app-specific logrotate config ynh_remove_logrotate @@ -78,12 +78,14 @@ 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..." --time --weight=1 +# Remove the dedicated fail2ban config ynh_remove_fail2ban_config #================================================= @@ -91,13 +93,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..." --time --weight=1 # 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" --time --last diff --git a/scripts/restore b/scripts/restore index f82aa7c..01ddfc6 100755 --- a/scripts/restore +++ b/scripts/restore @@ -24,25 +24,26 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_print_info "Loading settings..." +ynh_script_progression --message="Loading settings..." --time --weight=1 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) +db_user=$db_name #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_print_info "Validating restoration parameters..." +ynh_script_progression --message="Validating restoration parameters..." --time --weight=1 -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,45 +51,46 @@ 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..." --time --weight=1 -ynh_restore_file "$final_path" -sudo chmod -R 777 $final_path/cache +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 --weight=1 + +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd +ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql -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 #================================================= # RECREATE THE DEDICATED USER #================================================= -ynh_print_info "Recreating the dedicated system user..." +ynh_script_progression --message="Recreating the dedicated system user..." --time --weight=1 # Create the dedicated user (if not existing) -ynh_system_user_create $app +ynh_system_user_create --username=$app #================================================= # RESTORE THE PHP-FPM CONFIGURATION #================================================= -ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf" +ynh_restore_file --origin_path="/etc/php/7.0/fpm/pool.d/$app.conf" + #================================================= # SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_print_info "Reinstalling dependencies..." +ynh_script_progression --message="Reinstalling dependencies..." --time --weight=1 # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies @@ -97,37 +99,38 @@ 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 "/" +ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" #================================================= # GENERIC FINALIZATION #================================================= # 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=php7.0-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 diff --git a/scripts/upgrade b/scripts/upgrade index 30a2526..4be29c9 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,32 +12,32 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_print_info "Loading installation settings..." +ynh_script_progression --message="Loading installation settings..." --time --weight=1 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) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) #================================================= # 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)..." --time --weight=1 # Backup the current version of the app ynh_backup_before_upgrade @@ -62,14 +62,19 @@ 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" +if [ -z $final_path/cache ]; then + mkdir $final_path/cache + chmod -R 777 $final_path/cache +fi +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 #================================================= @@ -80,19 +85,21 @@ fi # 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" +cp -a "$tmpdir/store" "${final_path}" +cp -a "$tmpdir/.htconfig.php" "${final_path}" +cp -a "$tmpdir/php.log" "${final_path}" +cp -a "$tmpdir/cache" "${final_path}" +rm -Rf "$tmpdir" +chmod -R 777 $final_path/store +chmod -R 777 $final_path/cache +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..." --time --weight=1 # Create a dedicated nginx config ynh_add_nginx_config @@ -100,10 +107,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..." --time --weight=1 # 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 @@ -111,7 +118,7 @@ chown -R $app: $final_path #================================================= # PHP-FPM CONFIGURATION #================================================= -ynh_print_info "Upgrading php-fpm configuration..." +ynh_script_progression --message="Upgrading php-fpm configuration..." --time --weight=1 # Create a dedicated php-fpm config ynh_add_fpm_config @@ -119,23 +126,24 @@ ynh_add_fpm_config ### 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/CONFIG_FILE" +# 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..." --time --weight=1 # 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="Reconfiguring fail2ban..." --time --weight=1 + +# Create a dedicated fail2ban config +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..." @@ -149,8 +157,7 @@ sudo cp ../conf/poller-cron /etc/cron.d/$app ynh_print_info "Upgrading dependencies..." ynh_install_app_dependencies $pkg_dependencies -sudo mkdir $final_path/cache -sudo chmod -R 777 $final_path/cache + #================================================= # SETUP SSOWAT @@ -162,12 +169,12 @@ ynh_app_setting_set $app skipped_uris "/" #================================================= # RELOAD NGINX #================================================= -ynh_print_info "Reloading nginx web server..." +ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 -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" --time --last