diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6f9a98b --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +tests.toml.example linguist-language=toml +config_panel.toml.example linguist-language=toml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..783a4ae --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*~ +*.sw[op] diff --git a/README.md b/README.md index 6229f03..3fbff60 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,10 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in ## Overview -File sharing platform +Cells V4 now provides secure, cloud-native, scalable, self-hosted, open-core document sharing and collaboration without putting your data at risk. -**Shipped version:** 3.0.9~ynh1 + +**Shipped version:** 4.2.1~ynh1 ## Screenshots @@ -27,7 +28,7 @@ File sharing platform ## Documentation and resources * Official app website: -* Official admin documentation: +* Official admin documentation: * Upstream app code repository: * YunoHost documentation for this app: * Report a bug: diff --git a/README_fr.md b/README_fr.md index e320feb..4bacd74 100644 --- a/README_fr.md +++ b/README_fr.md @@ -16,9 +16,12 @@ Si vous n’avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) po ## Vue d’ensemble +Favorisez la collaboration entre les équipes sans mettre vos données en danger. +Pydio Cells est un logiciel de partage de documents opencore, auto-hébergé, avec la sécurité pour ADN. + Plateforme de partage de fichiers -**Version incluse :** 3.0.9~ynh1 +**Version incluse :** 4.2.1~ynh1 ## Captures d’écran @@ -27,7 +30,7 @@ Plateforme de partage de fichiers ## Documentations et ressources * Site officiel de l’app : -* Documentation officielle de l’admin : +* Documentation officielle de l’admin : * Dépôt de code officiel de l’app : * Documentation YunoHost pour cette app : * Signaler un bug : diff --git a/check_process b/check_process deleted file mode 100644 index 0b52ab7..0000000 --- a/check_process +++ /dev/null @@ -1,21 +0,0 @@ -;; Test complet - ; Manifest - domain="domain.tld" - admin="john" - password="1Strong-Password" - ; Checks - pkg_linter=1 - setup_sub_dir=0 - setup_root=1 - setup_nourl=0 - setup_private=0 - setup_public=1 - upgrade=1 - #upgrade=1 from_commit=CommitHash - 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 100644 index d6af588..0000000 --- a/conf/app.src +++ /dev/null @@ -1,6 +0,0 @@ -SOURCE_URL=https://download.pydio.com/pub/cells/release/3.0.9/linux-amd64/cells -SOURCE_SUM=4272ca1e10f2ca08d08d7d08d440d4b6e3d09ba37235f54bdbac1ac7c29b2aaa -SOURCE_SUM_PRG=sha256sum -SOURCE_IN_SUBDIR=false -SOURCE_FILENAME=cells -SOURCE_EXTRACT=false diff --git a/conf/install-conf.yml b/conf/install-conf.yml index c353510..8c030ab 100644 --- a/conf/install-conf.yml +++ b/conf/install-conf.yml @@ -19,4 +19,4 @@ dbtcpname: __DB_NAME__ dbtcpuser: __DB_USER__ dbtcppassword: __DB_PWD__ -dsfolder: __DATADIR__ \ No newline at end of file +dsfolder: __DATA_DIR__ diff --git a/conf/nginx.conf b/conf/nginx.conf index 33263fe..ed70286 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,5 +1,4 @@ location / { - proxy_pass https://localhost:__PORT__; # Include SSOWAT user panel. diff --git a/conf/systemd.service b/conf/systemd.service index 461e17f..36716ab 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -3,16 +3,16 @@ Description=Pydio Cells Documentation=https://pydio.com Wants=network-online.target After=network-online.target -AssertFileIsExecutable=__FINALPATH__/cells +AssertFileIsExecutable=__INSTALL_DIR__/cells [Service] User=__APP__ Group=__APP__ -WorkingDirectory=__DATADIR__/ +WorkingDirectory=__INSTALL_DIR__/ PermissionsStartOnly=true AmbientCapabilities=CAP_NET_BIND_SERVICE -ExecStart=__FINALPATH__/cells start +ExecStart=__INSTALL_DIR__/cells start Restart=on-failure StandardOutput=journal StandardError=inherit @@ -24,8 +24,8 @@ SuccessExitStatus=0 # Add environment variables Environment=CELLS_ENABLE_METRICS=false -# Environment=CELLS_WORKING_DIR=__FINALPATH__ -# Environment=CELLS_DATA_DIR=__DATADIR__ +# Environment=CELLS_WORKING_DIR=__INSTALL_DIR__ +# Environment=CELLS_DATA_DIR=__DATA_DIR__ [Install] WantedBy=multi-user.target diff --git a/doc/DESCRIPTION.md b/doc/DESCRIPTION.md index e69de29..0a8bbb2 100644 --- a/doc/DESCRIPTION.md +++ b/doc/DESCRIPTION.md @@ -0,0 +1 @@ +Cells V4 now provides secure, cloud-native, scalable, self-hosted, open-core document sharing and collaboration without putting your data at risk. diff --git a/doc/DESCRIPTION_fr.md b/doc/DESCRIPTION_fr.md new file mode 100644 index 0000000..fbec72c --- /dev/null +++ b/doc/DESCRIPTION_fr.md @@ -0,0 +1,2 @@ +Favorisez la collaboration entre les équipes sans mettre vos données en danger. +Pydio Cells est un logiciel de partage de documents opencore, auto-hébergé, avec la sécurité pour ADN. diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md deleted file mode 100644 index e69de29..0000000 diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 2e56cc3..0000000 --- a/manifest.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "name": "Pydio", - "id": "pydio", - "packaging_format": 1, - "description": { - "en": "File sharing platform", - "fr": "Plateforme de partage de fichiers" - }, - "version": "3.0.9~ynh1", - "url": "https://pydio.com", - "upstream": { - "license": "AGPL-3.0-or-later", - "website": "https://pydio.com", - "admindoc": "https://pydio.com/en/docs/", - "code": "https://github.com/pydio/cells" - }, - "license": "AGPL-3.0-or-later", - "maintainer": { - "name": "julienmalik", - "email": "julien.malik@paraiso.me", - "url": "https://github.com/julienmalik" - }, - "requirements": { - "yunohost": ">= 11.1.21" - }, - "multi_instance": true, - "services": [ - "nginx", - "mysql" - ], - "arguments": { - "install": [ - { - "name": "domain", - "type": "domain" - }, - { - "name": "admin", - "type": "user" - }, - { - "name": "password", - "type": "password" - } - ] - } -} diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..13a132c --- /dev/null +++ b/manifest.toml @@ -0,0 +1,82 @@ +packaging_format = 2 + +id = "pydio" +name = "Pydio" +description.en = "A file sharing platform" +description.fr = "Une plateforme de partage de fichiers" + +version = "4.2.1~ynh1" + +maintainers = ["salamandar"] + +[upstream] +# NB: Only the "license" key is mandatory. Remove entries for which there's no relevant data +license = "AGPL-3.0" +website = "https://pydio.com" +# demo = "https://demo.example.com" +admindoc = "https://pydio.com/en/docs" +# userdoc = "https://yunohost.org/apps" +code = "https://github.com/pydio/cells" +cpe = "cpe:2.3:a:pydio:cells" +fund = "https://pydio.com/en/pricing" + +[integration] +yunohost = ">= 11.1.14" +architectures = ["amd64", "armhf", "arm64"] +multi_instance = true +ldap = false +sso = false +disk = "50M" +ram.build = "50M" +ram.runtime = "50M" + +[install] + [install.domain] + type = "domain" + + [install.init_main_permission] + # this is a generic question - ask strings are automatically handled by YunoHost's core + # This won't be saved as setting and will instead be used to initialize the SSOwat permission + type = "group" + default = "visitors" + + [install.admin] + type = "user" + + [install.password] + type = "password" + +[resources] + # See the packaging documentation for the full set + # of explanation regarding the behavior and properties for each of those + + [resources.sources] + + [resources.sources.main] + in_subdir = false + amd64.url = "https://download.pydio.com/pub/cells/release/4.2.1/linux-amd64/pydio-cells-4.2.1-linux-amd64.zip" + amd64.sha256 = "76caea1aca6c408fb43be49dc5e2193ccf5db9add449476a188bc725c5989849" + + armhf.url = "https://download.pydio.com/pub/cells/release/4.2.1/linux-arm/pydio-cells-4.2.1-linux-arm.zip" + armhf.sha256 = "153ffd514911a164dad82e23007b2db2ebcc2c6d55d7727675e2312186eb6123" + + arm64.url = "https://download.pydio.com/pub/cells/release/4.2.1/linux-arm64/pydio-cells-4.2.1-linux-arm64.zip" + arm64.sha256 = "0f348ff4e48db5c9231873c75bc6493c66ba790876ec7acf0b71d64a9bbb2f4a" + + [resources.system_user] + + [resources.install_dir] + + [resources.data_dir] + group = "www-data:rwx" + + [resources.permissions] + main.url = "/" + + [resources.ports] + + [resources.apt] + packages = "mariadb-server" + + [resources.database] + type = "mysql" diff --git a/scripts/_common.sh b/scripts/_common.sh index 82e3b11..944a65e 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,9 +4,6 @@ # COMMON VARIABLES #================================================= -# dependencies used by the app -#pkg_dependencies="acl" - #================================================= # PERSONAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup old mode 100644 new mode 100755 index 44e4951..503270b --- a/scripts/backup +++ b/scripts/backup @@ -10,28 +10,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_clean_setup () { - true -} -# 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) -datadir=$(ynh_app_setting_get --app=$app --key=datadir) - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= @@ -41,13 +19,14 @@ 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 DATA DIR #================================================= -ynh_backup --src_path="$datadir" --is_big +# Only relevant if there is a "data_dir" resource for this app +ynh_backup --src_path="$data_dir" --is_big #================================================= # BACKUP THE NGINX CONFIGURATION @@ -55,8 +34,21 @@ ynh_backup --src_path="$datadir" --is_big ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= +# BACKUP FAIL2BAN CONFIGURATION +#================================================= + +# ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf" +# ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" + #================================================= # SPECIFIC BACKUP +#================================================= +# BACKUP LOGROTATE +#================================================= + +# ynh_backup --src_path="/etc/logrotate.d/$app" + #================================================= # BACKUP SYSTEMD #================================================= @@ -68,6 +60,9 @@ ynh_backup --src_path="/etc/systemd/system/$app.service" #================================================= ynh_print_info --message="Backing up the MySQL database..." +### (However, things like MySQL dumps *do* take some time to run, though the +### copy of the generated dump to the archive still happens later) + ynh_mysql_dump_db --database="$db_name" > db.sql #================================================= diff --git a/scripts/change_url b/scripts/change_url new file mode 100644 index 0000000..f0964a6 --- /dev/null +++ b/scripts/change_url @@ -0,0 +1,47 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# STANDARD MODIFICATIONS +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" + +#================================================= +# MODIFY URL IN NGINX CONF +#================================================= +ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 + +ynh_change_url_nginx_config + +#================================================= +# SPECIFIC MODIFICATIONS +#================================================= +# ... +#================================================= + +#================================================= +# GENERIC FINALISATION +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Change of URL completed for $app" --last diff --git a/scripts/config b/scripts/config new file mode 100644 index 0000000..dca69fb --- /dev/null +++ b/scripts/config @@ -0,0 +1,102 @@ +#!/bin/bash +# In simple cases, you don't need a config script. + +# With a simple config_panel.toml, you can write in the app settings, in the +# upstream config file or replace complete files (logo ...) and restart services. + +# The config scripts allows you to go further, to handle specific cases +# (validation of several interdependent fields, specific getter/setter for a value, +# display dynamic informations or choices, pre-loading of config type .cube... ). + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source /usr/share/yunohost/helpers + +ynh_abort_if_errors + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) + +#================================================= +# SPECIFIC GETTERS FOR TOML SHORT KEY +#================================================= + +get__amount() { + # Here we can imagine to have an API call to stripe to know the amount of donation during a month + local amount = 200 + + # It's possible to change some properties of the question by overriding it: + if [ $amount -gt 100 ] + then + cat << EOF +style: success +value: $amount +ask: + en: A lot of donation this month: **$amount €** +EOF + else + cat << EOF +style: danger +value: $amount +ask: + en: Not so much donation this month: $amount € +EOF + fi +} + +get__prices() { + local prices = "$(grep "DONATION\['" "$install_dir/settings.py" | sed -r "s@^DONATION\['([^']*)'\]\['([^']*)'\] = '([^']*)'@\1/\2/\3@g" | sed -z 's/\n/,/g;s/,$/\n/')" + if [ "$prices" == "," ]; + then + # Return YNH_NULL if you prefer to not return a value at all. + echo YNH_NULL + else + echo $prices + fi +} + + +#================================================= +# SPECIFIC VALIDATORS FOR TOML SHORT KEYS +#================================================= +validate__publishable_key() { + + # We can imagine here we test if the key is really a publisheable key + (is_secret_key $publishable_key) && + echo 'This key seems to be a secret key' +} + +#================================================= +# SPECIFIC SETTERS FOR TOML SHORT KEYS +#================================================= +set__prices() { + + #--------------------------------------------- + # IMPORTANT: setter are trigger only if a change is detected + #--------------------------------------------- + for price in $(echo $prices | sed "s/,/ /"); do + frequency=$(echo $price | cut -d/ -f1) + currency=$(echo $price | cut -d/ -f2) + price_id=$(echo $price | cut -d/ -f3) + sed "d/DONATION\['$frequency'\]\['$currency'\]" "$install_dir/settings.py" + + echo "DONATION['$frequency']['$currency'] = '$price_id'" >> "$install_dir/settings.py" + done + + #--------------------------------------------- + # IMPORTANT: to be able to upgrade properly, you have to saved the value in settings too + #--------------------------------------------- + ynh_app_setting_set $app prices $prices +} + +#================================================= +# GENERIC FINALIZATION +#================================================= +ynh_app_config_run $1 diff --git a/scripts/install b/scripts/install old mode 100644 new mode 100755 index 986f1ee..d92e899 --- a/scripts/install +++ b/scripts/install @@ -10,178 +10,58 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_clean_setup () { - ynh_clean_check_starting -} -# 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 -password=$YNH_APP_ARG_PASSWORD - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# 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 - -#================================================= -# STANDARD MODIFICATIONS -#================================================= -# FIND AND OPEN A PORT -#================================================= -ynh_script_progression --message="Finding an available port..." - -# Find an available port -port=$(ynh_find_port --port=8080) -ynh_app_setting_set --app=$app --key=port --value=$port - -# Optional: Expose this port publicly -# (N.B.: you only need to do this if the app actually needs to expose the port publicly. -# If you do this and the app doesn't actually need you are CREATING SECURITY HOLES IN THE SERVER !) - -# Open the port -# ynh_script_progression --message="Configuring firewall..." -# ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port - -#================================================= -# 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 MYSQL DATABASE -#================================================= -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 - +# APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC) #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." +ynh_script_progression --message="Setting up source files..." --weight=1 -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="$install_dir" -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" -chmod +x "$final_path/cells" +chown -R "$app:www-data" "$install_dir" #================================================= -# NGINX CONFIGURATION +# SYSTEM CONFIGURATION #================================================= -ynh_script_progression --message="Configuring NGINX web server..." +ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 -# Create a dedicated NGINX config ynh_add_nginx_config +ynh_add_systemd_config + +yunohost service add "$app" --description="Pydio - A file sharing platform" --log="/var/log/$app/$app.log" + +# ynh_use_logrotate + +# Create a dedicated Fail2Ban config +# ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" + #================================================= -# SPECIFIC SETUP -#================================================= -# CREATE DATA DIRECTORY -#================================================= -ynh_script_progression --message="Creating a data directory..." - -datadir=/home/yunohost.app/$app -ynh_app_setting_set --app=$app --key=datadir --value=$datadir - -mkdir -p $datadir - -chmod 750 "$datadir" -chmod -R o-rwx "$datadir" -chown -R $app:www-data "$datadir" - +# APP INITIAL CONFIGURATION #================================================= # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Adding a configuration file..." +ynh_script_progression --message="Configuring Pydio..." --weight=1 -ynh_add_config --template="../conf/install-conf.yml" --destination="$final_path/install-conf.yml" -ynh_delete_file_checksum --file="$final_path/install-conf.yml" +ynh_add_config --template="install-conf.yml" --destination="$install_dir/install-conf.yml" -pushd "$final_path" - ynh_exec_as $app ./cells configure --cli --yaml "$final_path/install-conf.yml" -popd +pushd "$install_dir" || ynh_die + ynh_exec_as "$app" ./cells configure --cli --yaml "$install_dir/install-conf.yml" +popd || ynh_die -ynh_secure_remove --file="$final_path/install-conf.yml" - -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Configuring a systemd service..." - -# Create a dedicated systemd config -ynh_add_systemd_config +ynh_secure_remove --file="$install_dir/install-conf.yml" +ynh_delete_file_checksum --file="$install_dir/install-conf.yml" #================================================= # GENERIC FINALIZATION -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." - -yunohost service add $app - #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression --message="Starting a systemd service..." --weight=1 -# Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Restart done" - -#================================================= -# SETUP SSOWAT -#================================================= -ynh_script_progression --message="Configuring permissions..." - -# Everyone can access the app. -# The "main" permission is automatically created before the install script. -ynh_permission_update --permission="main" --add="visitors" - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." - -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" #================================================= # END OF SCRIPT #================================================= - -ynh_script_progression --message="Installation of $app completed" +ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove old mode 100644 new mode 100755 index 909874e..8686684 --- a/scripts/remove +++ b/scripts/remove @@ -10,102 +10,27 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# LOAD SETTINGS +# REMOVE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -port=$(ynh_app_setting_get --app=$app --key=port) -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) -datadir=$(ynh_app_setting_get --app=$app --key=datadir) - -#================================================= -# STANDARD REMOVE -#================================================= -# REMOVE SERVICE INTEGRATION IN YUNOHOST +# REMOVE SYSTEMD SERVICE #================================================= +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 -# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status $app >/dev/null -then - ynh_script_progression --message="Removing $app service integration..." - yunohost service remove $app +if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then + ynh_script_progression --message="Removing $app service integration..." --weight=1 + yunohost service remove "$app" fi -#================================================= -# STOP AND REMOVE SERVICE -#================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." - -# Remove the dedicated systemd config ynh_remove_systemd_config -#================================================= -# REMOVE THE MYSQL DATABASE -#================================================= -ynh_script_progression --message="Removing the MySQL database..." - -# Remove a database if it exists, along with the associated user -ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name - -#================================================= -# REMOVE APP MAIN DIR -#================================================= -ynh_script_progression --message="Removing app main directory..." - -# Remove the app directory securely -ynh_secure_remove --file="$final_path" - -#================================================= -# REMOVE DATA DIR -#================================================= - -# Remove the data directory if --purge option is used -if [ "${YNH_APP_PURGE:-0}" -eq 1 ] -then - ynh_script_progression --message="Removing app data directory..." - ynh_secure_remove --file="$datadir" -fi - -#================================================= -# REMOVE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." - -# Remove the dedicated NGINX config ynh_remove_nginx_config -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." +# ynh_remove_logrotate -# Remove metapackage and its dependencies -ynh_remove_app_dependencies - -#================================================= -# SPECIFIC REMOVE -#================================================= -# REMOVE VARIOUS FILES -#================================================= -ynh_script_progression --message="Removing various files..." - -#================================================= -# GENERIC FINALIZATION -#================================================= -# REMOVE DEDICATED USER -#================================================= -ynh_script_progression --message="Removing the dedicated system user..." - -# Delete a system user -ynh_system_user_delete --username=$app +# ynh_remove_fail2ban_config #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" +ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore old mode 100644 new mode 100755 index 39b0fde..105e37c --- a/scripts/restore +++ b/scripts/restore @@ -10,123 +10,62 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_clean_setup () { - ynh_clean_check_starting -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -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) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -db_user=$db_name -datadir=$(ynh_app_setting_get --app=$app --key=datadir) - -#================================================= -# 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 -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the NGINX web server configuration..." - -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" - -#================================================= -# 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" - #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." +ynh_script_progression --message="Restoring the app main directory..." --weight=1 -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" +chown -R "$app:www-data" "$install_dir" #================================================= # RESTORE THE DATA DIRECTORY #================================================= -ynh_script_progression --message="Restoring the data directory..." +ynh_script_progression --message="Restoring the data directory..." --weight=1 -ynh_restore_file --origin_path="$datadir" --not_mandatory +ynh_restore_file --origin_path="$data_dir" --not_mandatory -mkdir -p $datadir +# (Same as for install dir) +chown -R "$app:www-data" "$data_dir" -chmod 750 "$datadir" -chmod -R o-rwx "$datadir" -chown -R $app:www-data "$datadir" - -#================================================= -# SPECIFIC RESTORATION #================================================= # RESTORE THE MYSQL DATABASE #================================================= -ynh_script_progression --message="Restoring the MySQL database..." +ynh_script_progression --message="Restoring the MySQL database..." --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 +ynh_mysql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql #================================================= -# RESTORE SYSTEMD +# RESTORE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Restoring the systemd configuration..." +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 + +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/etc/systemd/system/$app.service" -systemctl enable $app.service --quiet +systemctl enable "$app.service" --quiet -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." +yunohost service add "$app" --description="Pydio - A file sharing platform" --log="/var/log/$app/$app.log" -yunohost service add $app +# ynh_restore_file --origin_path="/etc/logrotate.d/$app" -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a systemd service..." - -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Restart done" +# 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 #================================================= # GENERIC FINALIZATION #================================================= -# RELOAD NGINX +# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE #================================================= -ynh_script_progression --message="Reloading NGINX web server..." +ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade old mode 100644 new mode 100755 index bed3926..9663ef9 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,131 +9,88 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -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) -port=$(ynh_app_setting_get --app=$app --key=port) -datadir=$(ynh_app_setting_get --app=$app --key=datadir) - -#================================================= -# CHECK 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 () { - ynh_clean_check_starting - # 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 -#================================================= -# STOP SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Stopping a systemd service..." - -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" - #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." - -# Cleaning legacy permissions -if ynh_legacy_permissions_exists; then - ynh_legacy_permissions_delete_all - - ynh_app_setting_delete --app=$app --key=is_public -fi +ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 #================================================= -# CREATE DEDICATED USER +# STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." +ynh_script_progression --message="Stopping a systemd service..." --weight=1 -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir="$final_path" +ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log" +#================================================= +# "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD...) #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Upgrading source files..." +if [ "$upgrade_type" == "UPGRADE_APP" ]; then + ynh_script_progression --message="Upgrading source files..." --weight=1 # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$final_path" + ynh_setup_source --dest_dir="$install_dir" fi -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" -chmod +x "$final_path/cells" +chown -R "$app:www-data" "$install_dir" #================================================= -# NGINX CONFIGURATION +# REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 -# Create a dedicated NGINX config ynh_add_nginx_config -#================================================= -# SPECIFIC UPGRADE -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Upgrading systemd configuration..." - -# Create a dedicated systemd config ynh_add_systemd_config -#================================================= -# GENERIC FINALIZATION -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." +yunohost service add "$app" --description="Pydio - A file sharing platform" --log="/var/log/$app/$app.log" -yunohost service add $app +# ynh_use_logrotate --non-append + +# ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" + +#================================================= +# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...) +#================================================= +# UPDATE A CONFIG FILE +#================================================= +ynh_script_progression --message="Updating a configuration file..." --weight=1 + +### Same as during install +### +### The file will automatically be backed-up if it's found to be manually modified (because +### ynh_add_config keeps track of the file's checksum) + +ynh_add_config --template="some_config_file" --destination="$install_dir/some_config_file" + +# FIXME: this should be handled by the core in the future +# You may need to use chmod 600 instead of 400, +# for example if the app is expected to be able to modify its own config +chmod 400 "$install_dir/some_config_file" +chown $app:$app "$install_dir/some_config_file" + +### For more complex cases where you want to replace stuff using regexes, +### you shoud rely on ynh_replace_string (which is basically a wrapper for sed) +### When doing so, you also need to manually call ynh_store_file_checksum +### +### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$install_dir/some_config_file" +### ynh_store_file_checksum --file="$install_dir/some_config_file" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Restart done" - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." - -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" +ynh_script_progression --message="Upgrade of $app completed" --last diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..d9de67f --- /dev/null +++ b/tests.toml @@ -0,0 +1,10 @@ +test_format = 1.0 + +[default] + + # The test IDs to be used in only/exclude statements are: install.root, install.subdir, + # install.nourl, install.multi, backup_restore, upgrade, upgrade.someCommitId change_url + exclude = ["install.subdir", "install.nourl", "change_url"] + + # test_upgrade_from.00a1a6e7.name = "Upgrade from 5.4" + # test_upgrade_from.00a1a6e7.args.foo = "bar"