diff --git a/README.md b/README.md index f35c4c2..0297fbc 100644 --- a/README.md +++ b/README.md @@ -16,36 +16,15 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in ## Overview -## Overview [Osada](http://zotlabs.com/osada/) uses **Zot6 protocol** which is next version of **zot5 protocol**. Osada has native support for the **ActivityPub protocol** (W3C standard) as well as the more advanced features. It can inter-operate with other social networking applications and projects in either of these spaces, including **Mastodon, Pleroma, Pixelfed, PeerTube, Funkwhale, Zap, Friendica, Hubzilla,** and many more. + **Shipped version:** 23.12.17~ynh1 ## Screenshots ![Screenshot of Osada](./doc/screenshots/comment_on_posts.gif) -## Disclaimers / important information - -## This app claims following features: -- [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] Option to choose between **Mysql** and **PostgreSQL** for the Osada - -## Ldap Admin user rights, logs and failed database updates - -- **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. - -- **Failing to get admin rights**: If the admin cannot access the admin settings at `https://osada.example.com/admin` 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 hub eg. `https://osada.example.com/admin/dbsync/` and check the numbers of failled update. These updates will have to be ran manually by **phpMyAdmin**. - ## :red_circle: Antifeatures - **Upstream not maintained**: This software is not maintained anymore. Expect it to break down over time, be exposed to unfixed security breaches, etc. diff --git a/README_fr.md b/README_fr.md index 1527dfc..1d01182 100644 --- a/README_fr.md +++ b/README_fr.md @@ -16,36 +16,15 @@ Si vous n’avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) po ## Vue d’ensemble -## Overview [Osada](http://zotlabs.com/osada/) uses **Zot6 protocol** which is next version of **zot5 protocol**. Osada has native support for the **ActivityPub protocol** (W3C standard) as well as the more advanced features. It can inter-operate with other social networking applications and projects in either of these spaces, including **Mastodon, Pleroma, Pixelfed, PeerTube, Funkwhale, Zap, Friendica, Hubzilla,** and many more. + **Version incluse :** 23.12.17~ynh1 ## Captures d’écran ![Capture d’écran de Osada](./doc/screenshots/comment_on_posts.gif) -## Avertissements / informations importantes - -## This app claims following features: -- [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] Option to choose between **Mysql** and **PostgreSQL** for the Osada - -## Ldap Admin user rights, logs and failed database updates - -- **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. - -- **Failing to get admin rights**: If the admin cannot access the admin settings at `https://osada.example.com/admin` 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 hub eg. `https://osada.example.com/admin/dbsync/` and check the numbers of failled update. These updates will have to be ran manually by **phpMyAdmin**. - ## :red_circle: Fonctions indésirables - **Upstream not maintained**: This software is not maintained anymore. Expect it to break down over time, be exposed to unfixed security breaches, etc. diff --git a/check_process b/check_process deleted file mode 100755 index 9160407..0000000 --- a/check_process +++ /dev/null @@ -1,47 +0,0 @@ -;; Test complet mysql - ; Manifest - domain="domain.tld" - admin="john" - database="mysql" - ; Checks - pkg_linter=1 - setup_sub_dir=0 - setup_root=1 - setup_nourl=0 - setup_private=0 - setup_public=1 - upgrade=1 - backup_restore=1 - multi_instance=1 - port_already_use=0 - change_url=0 -;;; Options -Email= -Notification=none -;;; Upgrade options - ; commit=81e4171acaa44520d0f527e6af445f4f33f2bca0 - name=21.05.21~ynh1 - manifest_arg=domain=DOMAIN&admin=USER&database=1& - ; commit=c49f7f56b47a6a00da257ac7e4fd066dba51dcbf - name=21.05.21~ynh2 - manifest_arg=domain=DOMAIN&admin=USER&database=1& -;; Test complet postgresql - ; Manifest - domain="domain.tld" - admin="john" - database="postgresql" - ; Checks - pkg_linter=1 - setup_sub_dir=0 - setup_root=1 - setup_nourl=0 - setup_private=0 - setup_public=1 - upgrade=1 - backup_restore=1 - multi_instance=1 - port_already_use=0 - change_url=0 -;;; Options -Email= -Notification=none diff --git a/conf/app.src b/conf/app.src deleted file mode 100755 index d556888..0000000 --- a/conf/app.src +++ /dev/null @@ -1,7 +0,0 @@ -SOURCE_URL=https://codeberg.org/zot-archive/osada/archive/dc8537520e0753a98bd2e2eeb1f0a16b50b954c3.tar.gz -SOURCE_SUM=cfed73d7d4648f4fe4e567d533d3d44dce3d36e2423c7ec32e9878f743ce2144 -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.gz -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= -SOURCE_EXTRACT=true diff --git a/conf/app_addons.src b/conf/app_addons.src deleted file mode 100755 index f6cae21..0000000 --- a/conf/app_addons.src +++ /dev/null @@ -1,7 +0,0 @@ -SOURCE_URL=https://codeberg.org/zot-archive/osada-addons/archive/2a39590048b3d93795918f20dc5170e9c2a4bcde.tar.gz -SOURCE_SUM=ba2c83145d98c2948a33eb3250bc29f3116c156f936ca56e7e3051e393804be4 -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.gz -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= -SOURCE_EXTRACT=true diff --git a/conf/cron.conf b/conf/cron.conf new file mode 100755 index 0000000..26ed754 --- /dev/null +++ b/conf/cron.conf @@ -0,0 +1,2 @@ +# Run poller periodically to update Osada +*/10 * * * * __APP__ /usr/bin/php__PHPVERSION__ __INSTALL_DIR__/Zotlabs/Daemon/Master.php Cron > /dev/null 2>&1 diff --git a/conf/htconfig.sample.php b/conf/htconfig.sample.php index 25eb92f..e53f862 100644 --- a/conf/htconfig.sample.php +++ b/conf/htconfig.sample.php @@ -1,13 +1,13 @@ /dev/null 2>&1 diff --git a/doc/DISCLAIMER.md b/doc/ADMIN.md similarity index 76% rename from doc/DISCLAIMER.md rename to doc/ADMIN.md index 244b4c9..a3eea5d 100644 --- a/doc/DISCLAIMER.md +++ b/doc/ADMIN.md @@ -1,9 +1,3 @@ -## This app claims following features: -- [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] Option to choose between **Mysql** and **PostgreSQL** for the Osada ## Ldap Admin user rights, logs and failed database updates diff --git a/doc/DESCRIPTION.md b/doc/DESCRIPTION.md index 2e572f0..d7b036f 100644 --- a/doc/DESCRIPTION.md +++ b/doc/DESCRIPTION.md @@ -1,2 +1 @@ -## Overview -[Osada](http://zotlabs.com/osada/) uses **Zot6 protocol** which is next version of **zot5 protocol**. Osada has native support for the **ActivityPub protocol** (W3C standard) as well as the more advanced features. It can inter-operate with other social networking applications and projects in either of these spaces, including **Mastodon, Pleroma, Pixelfed, PeerTube, Funkwhale, Zap, Friendica, Hubzilla,** and many more. \ No newline at end of file +[Osada](http://zotlabs.com/osada/) uses **Zot6 protocol** which is next version of **zot5 protocol**. Osada has native support for the **ActivityPub protocol** (W3C standard) as well as the more advanced features. It can inter-operate with other social networking applications and projects in either of these spaces, including **Mastodon, Pleroma, Pixelfed, PeerTube, Funkwhale, Zap, Friendica, Hubzilla,** and many more. diff --git a/manifest.json b/manifest.json deleted file mode 100755 index 8e9f26e..0000000 --- a/manifest.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "name": "Osada", - "id": "osada", - "packaging_format": 1, - "description": { - "en": "Decentralized publication platform and social network", - "fr": "Plateforme de publication décentralisée et un réseau social" - }, - "version": "23.12.17~ynh1", - "url": "http://zotlabs.com/osada/", - "upstream": { - "license": "MIT", - "website": "http://zotlabs.com/osada/", - "code": "https://codeberg.org/zot-archive/osada" - }, - "license": "MIT", - "maintainer": { - "name": "Anmol Sharma", - "email": "" - }, - "requirements": { - "yunohost": ">= 11.2" - }, - "multi_instance": true, - "services": [ - "nginx", - "php7.3-fpm", - "mysql", - "postgresql" - ], - "arguments": { - "install": [ - { - "name": "domain", - "type": "domain" - }, - { - "name": "admin", - "type": "user" - }, - { - "name": "database", - "type": "select", - "ask": { - "en": "Choose the database to be used for the Osada]", - "fr": "Choisissez la database de Osada" - }, - "choices": ["mysql", "postgresql"], - "default": "mysql" - } - ] - } -} diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..02369ed --- /dev/null +++ b/manifest.toml @@ -0,0 +1,75 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json + +packaging_format = 2 + +id = "osada" +name = "Osada" +description.en = "Decentralized publication platform and social network" +description.fr = "Plateforme de publication décentralisée et un réseau social" + +version = "23.12.17~ynh1" + +maintainers = ["Anmol Sharma"] + +[upstream] +license = "MIT" +website = "http://zotlabs.com/osada/" +code = "https://codeberg.org/zot-archive/osada" + +[integration] +yunohost = ">= 11.2" +architectures = "all" +multi_instance = true +ldap = true +sso = true +disk = "50M" +ram.build = "200M" +ram.runtime = "200M" + +[install] + [install.domain] + type = "domain" + + [install.admin] + type = "user" + + [install.init_main_permission] + help.en = "If no, only person with an account on your server will be able to create forms. In all cases, visitors will be able to reply to form." + help.fr = "Si non, seule la personne disposant d'un compte sur votre serveur pourra créer des formulaires. Dans tous les cas, les visiteurs pourront répondre au formulaire." + type = "group" + default = "visitors" + +[resources] + [resources.sources] + [resources.sources.main] + url = "https://codeberg.org/zot-archive/osada/archive/dc8537520e0753a98bd2e2eeb1f0a16b50b954c3.tar.gz" + sha256 = "cfed73d7d4648f4fe4e567d533d3d44dce3d36e2423c7ec32e9878f743ce2144" + + [resources.sources.app_addons] + url = "https://codeberg.org/zot-archive/osada-addons/archive/2a39590048b3d93795918f20dc5170e9c2a4bcde.tar.gz" + sha256 = "ba2c83145d98c2948a33eb3250bc29f3116c156f936ca56e7e3051e393804be4" + + [resources.system_user] + + [resources.install_dir] + + [resources.permissions] + main.url = "/" + + [resources.apt] + packages = [ + "postgresql", + "postgresql-contrib", + + "php7.4-mbstring", + "php7.4-cli", + "php7.4-imagick", + "php7.4-xml", + "php7.4-zip", + "php7.4-pgsql", + "php7.4-json", + "php7.4-gd", + ] + + [resources.database] + type = "postgresql" diff --git a/scripts/_common.sh b/scripts/_common.sh index ac868d6..944a65e 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,12 +4,6 @@ # COMMON VARIABLES #================================================= -YNH_PHP_VERSION="7.3" - -# dependencies used by the app -pkg_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}-mysql php${YNH_PHP_VERSION}-json php${YNH_PHP_VERSION}-gd" -pg_pkg_dependencies="postgresql postgresql-contrib" - #================================================= # PERSONAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index 0aff7e9..d9da129 100755 --- a/scripts/backup +++ b/scripts/backup @@ -10,26 +10,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_print_info --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_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) - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= @@ -39,7 +19,7 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$final_path" +ynh_backup --src_path="$install_dir" #================================================= # BACKUP THE NGINX CONFIGURATION @@ -78,15 +58,7 @@ ynh_backup --src_path="/etc/cron.d/$app" # BACKUP THE DATABASE #================================================= -if [ $database = "mysql" ]; then - # Backup MySQL database - ynh_print_info --message="Backup of the MySQL database..." - ynh_mysql_dump_db --database="$db_name" > db.sql -elif [ $database = "postgresql" ]; then - # Backup PostgreSQL database - ynh_print_info --message="Backup of the PostgreSQL database..." - ynh_psql_dump_db --database="$db_name" > db.sql -fi +ynh_psql_dump_db --database="$db_name" > db.sql #================================================= # END OF SCRIPT diff --git a/scripts/change_url b/scripts/change_url new file mode 100644 index 0000000..a9df042 --- /dev/null +++ b/scripts/change_url @@ -0,0 +1,35 @@ +#!/bin/bash + +## this script is only run if actual change to domain/path is detected, if you're here either $domain or $path changed +## new location is available via $domain and $path (or $new_domain and $new_path variables if you want to be explicit) +## old values are available via, you guessed it, $old_domain and $old_path + +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# MODIFY URL IN NGINX CONF +#================================================= +ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 + +ynh_change_url_nginx_config + +#================================================= +# SPECIFIC MODIFICATIONS +#================================================= +ynh_script_progression --message="Updating a configuration file..." --weight=1 + +ynh_add_config --template="htconfig.sample.php" --destination="$install_dir/.htconfig.php" + +chmod 600 "$install_dir/.htconfig.php" +chown "$app:$app" "$install_dir/.htconfig.php" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Change of URL completed for $app" --last diff --git a/scripts/install b/scripts/install index 2e87289..26d508a 100755 --- a/scripts/install +++ b/scripts/install @@ -10,183 +10,73 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# MANAGE SCRIPT FAILURE +# INITIALIZE AND STORE SETTINGS #================================================= -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# RETRIEVE ARGUMENTS FROM THE MANIFEST -#================================================= - -domain=$YNH_APP_ARG_DOMAIN -path_url="/" -admin=$YNH_APP_ARG_ADMIN -database=$YNH_APP_ARG_DATABASE - -app=$YNH_APP_INSTANCE_NAME - email=$(ynh_user_get_info --username=$admin --key=mail) upload="256M" random_string="$(ynh_string_random --length=48)" -#================================================= -# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS -#================================================= -ynh_script_progression --message="Validating installation parameters..." - -final_path=/var/www/$app -test ! -e "$final_path" || ynh_die --message="This path already contains a folder" - -# Register (book) web path -ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url - -#================================================= -# STORE SETTINGS FROM MANIFEST -#================================================= -ynh_script_progression --message="Storing installation settings..." - -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=database --value=$database 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=random_string --value=$random_string -#================================================= -# STANDARD MODIFICATIONS -#================================================= -# INSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Installing dependencies..." - -if [ $database = "postgresql" ]; then - pkg_dependencies="$pkg_dependencies $pg_pkg_dependencies" -fi -ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." - -# Create a system user -ynh_system_user_create --username=$app --home_dir="$final_path" - -#================================================= -# CREATE A 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 - -if [ $database = "mysql" ]; then - ynh_script_progression --message="Creating a MySQL database..." - ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name - db_type=0 -elif [ $database = "postgresql" ]; then - # Create postgresql database - ynh_script_progression --message="Creating a postgresql database..." - ynh_psql_test_if_first_run - ynh_psql_setup_db --db_user=$db_user --db_name=$db_name - db_type=1 -fi - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." -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" -ynh_setup_source --dest_dir="$final_path/addon" --source_id="app_addons" -touch "$final_path/php.log" -mkdir -p "$final_path/store" -mkdir -p "$final_path/cache/smarty3" +ynh_setup_source --dest_dir="$install_dir" +ynh_setup_source --dest_dir="$install_dir/addon" --source_id="app_addons" -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" -chmod -R 775 $final_path/store $final_path/cache +touch "$install_dir/php.log" +mkdir -p "$install_dir/store" +mkdir -p "$install_dir/cache/smarty3" -#================================================= -# PHP-FPM CONFIGURATION -#================================================= -ynh_script_progression --message="Configuring PHP-FPM..." +chmod 750 "$install_dir" +chmod -R o-rwx "$install_dir" +chown -R $app:www-data "$install_dir" +chmod -R 775 $install_dir/store $install_dir/cache -# Create a dedicated PHP-FPM config -ynh_add_fpm_config -phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Configuring NGINX web server..." - -# Create a dedicated NGINX config -ynh_add_nginx_config - -#================================================= -# SPECIFIC SETUP #================================================= # PROVISION DATABASE #================================================= ynh_script_progression --message="Provisionning database..." -if [ $database = "mysql" ]; then - ynh_mysql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_name" < $final_path/install/schema_mysql.sql -elif [ $database = "postgresql" ]; then - ynh_psql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_name" < $final_path/install/schema_postgres.sql -fi +ynh_psql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_name" < "$install_dir/install/schema_postgres.sql" #================================================= # ADD A CONFIGURATION #================================================= ynh_script_progression --message="Adding a configuration file..." --weight=1 -ynh_add_config --template="../conf/htconfig.sample.php" --destination="$final_path/.htconfig.php" +ynh_add_config --template="htconfig.sample.php" --destination="$install_dir/.htconfig.php" -chmod 600 "$final_path/.htconfig.php" -chown $app:$app "$final_path/.htconfig.php" +chmod 600 "$install_dir/.htconfig.php" +chown $app:$app "$install_dir/.htconfig.php" #================================================= -# SET CRON JOB +# SYSTEM CONFIGURATION #================================================= -ynh_script_progression --message="Setuping cron job..." +ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 -# Set up cron job -ynh_add_config --template="../conf/poller-cron" --destination="/etc/cron.d/$app" -chown root: "/etc/cron.d/$app" -chmod 644 "/etc/cron.d/$app" +# Create a dedicated PHP-FPM config +ynh_add_fpm_config -#================================================= -# GENERIC FINALIZATION -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Configuring log rotation..." +# Create a dedicated NGINX config +ynh_add_nginx_config # Use logrotate to manage application logfile(s) -ynh_use_logrotate "$final_path/php.log" - -#================================================= -# SETUP FAIL2BAN -#================================================= -ynh_script_progression --message="Configuring Fail2Ban..." +ynh_use_logrotate "$install_dir/php.log" # 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" +ynh_add_fail2ban_config --logpath="$install_dir/php.log" --failregex="^.*auth\.php.*failed login attempt.*from IP .*$" --max_retry="5" -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." - -ynh_systemd_action --service_name=nginx --action=reload +# Set up cron job +ynh_add_config --template="cron.conf" --destination="/etc/cron.d/$app" +chown root: "/etc/cron.d/$app" +chmod 644 "/etc/cron.d/$app" #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 4d902eb..1b94130 100755 --- a/scripts/remove +++ b/scripts/remove @@ -12,15 +12,15 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." +#REMOVEME? ynh_script_progression --message="Loading installation settings..." -app=$YNH_APP_INSTANCE_NAME +#REMOVEME? app=$YNH_APP_INSTANCE_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=$app --key=final_path) -database=$(ynh_app_setting_get --app=$app --key=database) +#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) +#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#REMOVEME? db_user=$db_name +#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) +#REMOVEME? database=$(ynh_app_setting_get --app=$app --key=database) #================================================= # STANDARD REMOVE @@ -36,23 +36,13 @@ ynh_remove_logrotate # REMOVE THE DATABASE #================================================= -if [ $database = "mysql" ]; then - # Removing MySQL database - ynh_script_progression --message="Removing MySQL database..." - ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name -elif [ $database = "postgresql" ]; 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 APP MAIN DIR #================================================= -ynh_script_progression --message="Removing app main directory..." +#REMOVEME? ynh_script_progression --message="Removing app main directory..." # Remove the app directory securely -ynh_secure_remove --file="$final_path" +#REMOVEME? ynh_secure_remove --file="$install_dir" #================================================= # REMOVE NGINX CONFIGURATION @@ -73,10 +63,10 @@ ynh_remove_fpm_config #================================================= # REMOVE DEPENDENCIES #================================================= -ynh_script_progression --message="Removing dependencies..." +#REMOVEME? ynh_script_progression --message="Removing dependencies..." # Remove metapackage and its dependencies -ynh_remove_app_dependencies +#REMOVEME? ynh_remove_app_dependencies #================================================= # REMOVE FAIL2BAN CONFIGURATION @@ -101,10 +91,10 @@ ynh_secure_remove --file="/etc/cron.d/$app" #================================================= # REMOVE DEDICATED USER #================================================= -ynh_script_progression --message="Removing the dedicated system user..." +#REMOVEME? ynh_script_progression --message="Removing the dedicated system user..." # Delete a system user -ynh_system_user_delete --username=$app +#REMOVEME? ynh_system_user_delete --username=$app #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index fc6c5b6..cedb7ea 100755 --- a/scripts/restore +++ b/scripts/restore @@ -10,57 +10,32 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." +#REMOVEME? ynh_script_progression --message="Loading installation settings..." -app=$YNH_APP_INSTANCE_NAME +#REMOVEME? app=$YNH_APP_INSTANCE_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 -phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) -database=$(ynh_app_setting_get --app=$app --key=database) - -#================================================= -# CHECK IF THE APP CAN BE RESTORED -#================================================= -ynh_script_progression --message="Validating restoration parameters..." - -test ! -d $final_path \ - || ynh_die --message="There is already a directory: $final_path " - -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_script_progression --message="Recreating the dedicated system user..." - -# Create the dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir="$final_path" +#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) +#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path) +#REMOVEME? admin=$(ynh_app_setting_get --app=$app --key=admin) +#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) +#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#REMOVEME? db_user=$db_name +#REMOVEME? phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) +#REMOVEME? database=$(ynh_app_setting_get --app=$app --key=database) #================================================= # RESTORE THE APP MAIN DIR #================================================= ynh_script_progression --message="Restoring the app main directory..." -ynh_restore_file --origin_path="$final_path" +ynh_restore_file --origin_path="$install_dir" -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" +chmod 750 "$install_dir" +chmod -R o-rwx "$install_dir" +chown -R $app:www-data "$install_dir" #================================================= # RESTORE FAIL2BAN CONFIGURATION @@ -71,18 +46,6 @@ ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf" ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf" ynh_systemd_action --action=restart --service_name=fail2ban -#================================================= -# SPECIFIC RESTORATION -#================================================= -# REINSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Reinstalling dependencies..." - -if [ $database = "postgresql" ]; then - pkg_dependencies="$pkg_dependencies $pg_pkg_dependencies" -fi -ynh_install_app_dependencies $pkg_dependencies - #================================================= # RESTORE THE PHP-FPM CONFIGURATION #================================================= @@ -100,24 +63,10 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE THE DATABASE #================================================= -ynh_script_progression --message="Restoring the MySQL database..." +#REMOVEME? ynh_script_progression --message="Restoring the MySQL database..." + +ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" -if [ $database = "mysql" ]; 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_user --db_name=$db_name --db_pwd=$db_pwd - ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql -elif [ $database = "postgresql" ]; 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 #================================================= # RESTORE VARIOUS FILES diff --git a/scripts/upgrade b/scripts/upgrade index 6e9edba..b5962ba 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,44 +12,23 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." +#REMOVEME? ynh_script_progression --message="Loading installation settings..." -app=$YNH_APP_INSTANCE_NAME +#REMOVEME? app=$YNH_APP_INSTANCE_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 -phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) -database=$(ynh_app_setting_get --app=$app --key=database) -upload=$(ynh_app_setting_get --app=$app --key=upload) -random_string=$(ynh_app_setting_get --app=$app --key=random_string) +#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) +#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path) +#REMOVEME? admin=$(ynh_app_setting_get --app=$app --key=admin) +#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) +#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#REMOVEME? db_user=$db_name +#REMOVEME? phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) +#REMOVEME? database=$(ynh_app_setting_get --app=$app --key=database) +#REMOVEME? upload=$(ynh_app_setting_get --app=$app --key=upload) +#REMOVEME? random_string=$(ynh_app_setting_get --app=$app --key=random_string) email=$(ynh_user_get_info --username=$admin --key=mail) -#================================================= -# CHECK VERSION -#================================================= -ynh_script_progression --message="Checking version..." - -upgrade_type=$(ynh_check_app_version_changed) - -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -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 -ynh_clean_setup () { - # Restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -57,87 +36,30 @@ ynh_abort_if_errors #================================================= ynh_script_progression --message="Ensuring downward compatibility..." -# If final_path doesn't exist, create it -if [ -z "$final_path" ]; then - final_path=/var/www/$app - ynh_app_setting_set --app=$app --key=final_path --value=$final_path -fi - -# If db_name doesn't exist, create it -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 - -# Cleaning legacy permissions -if ynh_legacy_permissions_exists; then - ynh_legacy_permissions_delete_all - - ynh_app_setting_delete --app=$app --key=is_public -fi - -# Switch $database to "mysql" or "postgresql" -if [[ $database == "1" ]] 2>/dev/null; then - database="mysql" - ynh_app_setting_set --app=$app --key=database --value=$database -elif [[ $database == "2" ]] 2>/dev/null; then - database="postgresql" - ynh_app_setting_set --app=$app --key=database --value=$database -fi - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." - -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir="$final_path" +# # Switch $database to "mysql" or "postgresql" +# if [[ $database == "1" ]] 2>/dev/null; then +# database="mysql" +# ynh_app_setting_set --app=$app --key=database --value=$database +# elif [[ $database == "2" ]] 2>/dev/null; then +# database="postgresql" +# ynh_app_setting_set --app=$app --key=database --value=$database +# fi #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Upgrading source files..." -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Upgrading source files..." +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source --dest_dir="$install_dir" --full_replace=1 --keep="store/ .htconfig.php php.log" +ynh_setup_source --dest_dir="$install_dir/addon" --source_id="app_addons" - # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$final_path" --keep="store/ .htconfig.php php.log" - ynh_setup_source --dest_dir="$final_path/addon" --source_id="app_addons" -fi - -mkdir -p "$final_path/store" -mkdir -p "$final_path/cache/smarty3" -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" -chmod -R 775 $final_path/store $final_path/cache - -#================================================= -# INSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Installing dependencies..." - -if [ $database = "postgresql" ]; then - pkg_dependencies="$pkg_dependencies $pg_pkg_dependencies" -fi -ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# PHP-FPM CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading PHP-FPM configuration..." - -# Create a dedicated PHP-FPM config -ynh_add_fpm_config - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." - -# Create a dedicated NGINX config -ynh_add_nginx_config +mkdir -p "$install_dir/store" +mkdir -p "$install_dir/cache/smarty3" +chmod 750 "$install_dir" +chmod -R o-rwx "$install_dir" +chown -R $app:www-data "$install_dir" +chmod -R 775 $install_dir/store $install_dir/cache #================================================= # SPECIFIC UPGRADE @@ -146,53 +68,32 @@ ynh_add_nginx_config #================================================= ynh_script_progression --message="Updating a configuration file..." --weight=1 -if [ $database = "mysql" ]; then - db_type=0 - db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) -elif [ $database = "postgresql" ]; then - db_type=1 - db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) -fi +ynh_add_config --template="htconfig.sample.php" --destination="$install_dir/.htconfig.php" -ynh_add_config --template="../conf/htconfig.sample.php" --destination="$final_path/.htconfig.php" - -chmod 600 "$final_path/.htconfig.php" -chown $app:$app "$final_path/.htconfig.php" +chmod 600 "$install_dir/.htconfig.php" +chown $app:$app "$install_dir/.htconfig.php" #================================================= -# UPGRADE CRON JOB +# REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Upgrading cron job..." +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 -# Set up cron job -ynh_add_config --template="../conf/poller-cron" --destination="/etc/cron.d/$app" -chown root: "/etc/cron.d/$app" -chmod 644 "/etc/cron.d/$app" +# Create a dedicated PHP-FPM config +ynh_add_fpm_config -#================================================= -# GENERIC FINALIZATION -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." +# Create a dedicated NGINX config +ynh_add_nginx_config # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append -#================================================= -# UPGRADE FAIL2BAN -#================================================= -ynh_script_progression --message="Reconfiguring Fail2Ban..." - # 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" +ynh_add_fail2ban_config --logpath="$install_dir/php.log" --failregex="^.*auth\.php.*failed login attempt.*from IP .*$" --max_retry="5" -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." - -ynh_systemd_action --service_name=nginx --action=reload +# Set up cron job +ynh_add_config --template="cron.conf" --destination="/etc/cron.d/$app" +chown root: "/etc/cron.d/$app" +chmod 644 "/etc/cron.d/$app" #================================================= # END OF SCRIPT diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..94abb79 --- /dev/null +++ b/tests.toml @@ -0,0 +1,5 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json + +test_format = 1.0 + +[default]