From fb6378100b3d16fad389378d117bee299efc2697 Mon Sep 17 00:00:00 2001
From: oufmilo <44617467+oufmilo@users.noreply.github.com>
Date: Tue, 14 Feb 2023 10:09:35 +0100
Subject: [PATCH 01/11] Update README.md
---
README.md | 1 -
1 file changed, 1 deletion(-)
diff --git a/README.md b/README.md
index c71ae4f..6809796 100644
--- a/README.md
+++ b/README.md
@@ -44,7 +44,6 @@ c6c35779-af3a-4091-b330-c026610920d6
* Official app website:
* Official admin documentation:
* Upstream app code repository:
-* YunoHost documentation for this app:
* Report a bug:
## Developer info
From df0421b94e213678b52ec7f81e24eeecada6345a Mon Sep 17 00:00:00 2001
From: yunohost-bot
Date: Tue, 14 Feb 2023 09:09:38 +0000
Subject: [PATCH 02/11] Auto-update README
---
README.md | 2 ++
README_fr.md | 1 +
2 files changed, 3 insertions(+)
diff --git a/README.md b/README.md
index 6809796..c0c7962 100644
--- a/README.md
+++ b/README.md
@@ -6,6 +6,7 @@ It shall NOT be edited by hand.
# BookWyrm for YunoHost
[](https://dash.yunohost.org/appci/app/bookwyrm)  
+
[](https://install-app.yunohost.org/?app=bookwyrm)
*[Lire ce readme en français.](./README_fr.md)*
@@ -44,6 +45,7 @@ c6c35779-af3a-4091-b330-c026610920d6
* Official app website:
* Official admin documentation:
* Upstream app code repository:
+* YunoHost documentation for this app:
* Report a bug:
## Developer info
diff --git a/README_fr.md b/README_fr.md
index 0e6d9c6..8641247 100644
--- a/README_fr.md
+++ b/README_fr.md
@@ -6,6 +6,7 @@ It shall NOT be edited by hand.
# BookWyrm pour YunoHost
[](https://dash.yunohost.org/appci/app/bookwyrm)  
+
[](https://install-app.yunohost.org/?app=bookwyrm)
*[Read this readme in english.](./README.md)*
From 7d8a483193d882140577131d631e46e931ff75f5 Mon Sep 17 00:00:00 2001
From: oufmilo <44617467+oufmilo@users.noreply.github.com>
Date: Fri, 17 Feb 2023 18:52:53 +0100
Subject: [PATCH 03/11] Packaging V2
---
check_process | 25 -------
conf/.env.production | 2 +-
conf/bookwyrm-beat.service | 6 +-
conf/bookwyrm-server.service | 6 +-
conf/bookwyrm-worker.service | 6 +-
conf/nginx.conf | 4 +-
doc/DISCLAIMER.md | 11 ---
doc/DISCLAIMER_fr.md | 11 ---
manifest.json | 65 ----------------
manifest.toml | 67 +++++++++++++++++
scripts/_common.sh | 3 -
scripts/backup | 31 +-------
scripts/install | 140 ++++-------------------------------
scripts/remove | 48 +-----------
scripts/restore | 64 ++--------------
scripts/upgrade | 69 +++--------------
16 files changed, 113 insertions(+), 445 deletions(-)
delete mode 100644 check_process
delete mode 100644 doc/DISCLAIMER.md
delete mode 100644 doc/DISCLAIMER_fr.md
delete mode 100644 manifest.json
create mode 100644 manifest.toml
diff --git a/check_process b/check_process
deleted file mode 100644
index 0d5791b..0000000
--- a/check_process
+++ /dev/null
@@ -1,25 +0,0 @@
-;; Test complet
- ; Manifest
- domain="domain.tld"
- is_public=1
- language="fr-fr"
- admin="john"
- ; Checks
- pkg_linter=1
- setup_sub_dir=0
- setup_root=1
- setup_nourl=0
- setup_private=1
- setup_public=1
- upgrade=1
- # 0.5.3ynh1
- upgrade=1 from_commit=2292d0d68f5ba9e48f4cbb6105db64b4da4eba74
- backup_restore=1
- multi_instance=0
- change_url=0
-;;; Options
-Email=oufmilo@protonmail.com
-Notification=all
-;;; Upgrade options
- ; commit=2292d0d68f5ba9e48f4cbb6105db64b4da4eba74
- name=0.5.3~ynh1
\ No newline at end of file
diff --git a/conf/.env.production b/conf/.env.production
index 222eb53..c05bcbf 100644
--- a/conf/.env.production
+++ b/conf/.env.production
@@ -15,7 +15,7 @@ DEFAULT_LANGUAGE="English"
## Leave unset to allow all hosts
#ALLOWED_HOSTS="localhost,127.0.0.1,[::1]"
-MEDIA_ROOT=__FINALPATH__/images/
+MEDIA_ROOT=__INSTALL_DIR__/images/
# Database configuration
PGPORT=5432
diff --git a/conf/bookwyrm-beat.service b/conf/bookwyrm-beat.service
index 49a1ba7..71e574f 100644
--- a/conf/bookwyrm-beat.service
+++ b/conf/bookwyrm-beat.service
@@ -7,9 +7,9 @@ PartOf=__APP__.target
[Service]
User=__APP__
Group=__APP__
-WorkingDirectory=__FINALPATH__/
-EnvironmentFile=__FINALPATH__/.env
-ExecStart=__FINALPATH__/venv/bin/celery -A celerywyrm beat -l INFO --scheduler django_celery_beat.schedulers:DatabaseScheduler
+WorkingDirectory=__INSTALL_DIR__/
+EnvironmentFile=__INSTALL_DIR__/.env
+ExecStart=__INSTALL_DIR__/venv/bin/celery -A celerywyrm beat -l INFO --scheduler django_celery_beat.schedulers:DatabaseScheduler
NoNewPrivileges=yes
PrivateTmp=yes
diff --git a/conf/bookwyrm-server.service b/conf/bookwyrm-server.service
index 289fe6a..568143c 100644
--- a/conf/bookwyrm-server.service
+++ b/conf/bookwyrm-server.service
@@ -7,9 +7,9 @@ PartOf=__APP__.target
[Service]
User=__APP__
Group=__APP__
-WorkingDirectory=__FINALPATH__/
-EnvironmentFile=__FINALPATH__/.env
-ExecStart=__FINALPATH__/venv/bin/gunicorn bookwyrm.wsgi:application --bind 127.0.0.1:__PORT__
+WorkingDirectory=__INSTALL_DIR__/
+EnvironmentFile=__INSTALL_DIR__/.env
+ExecStart=__INSTALL_DIR__/venv/bin/gunicorn bookwyrm.wsgi:application --bind 127.0.0.1:__PORT__
[Install]
WantedBy=multi-user.target
diff --git a/conf/bookwyrm-worker.service b/conf/bookwyrm-worker.service
index 6bec4bd..739c43d 100644
--- a/conf/bookwyrm-worker.service
+++ b/conf/bookwyrm-worker.service
@@ -7,9 +7,9 @@ PartOf=__APP__.target
[Service]
User=__APP__
Group=__APP__
-WorkingDirectory=__FINALPATH__/
-EnvironmentFile=__FINALPATH__/.env
-ExecStart=__FINALPATH__/venv/bin/celery -A celerywyrm worker -l info -Q high_priority,medium_priority,low_priority
+WorkingDirectory=__INSTALL_DIR__/
+EnvironmentFile=__INSTALL_DIR__/.env
+ExecStart=__INSTALL_DIR__/venv/bin/celery -A celerywyrm worker -l info -Q high_priority,medium_priority,low_priority
NoNewPrivileges=yes
PrivateTmp=yes
diff --git a/conf/nginx.conf b/conf/nginx.conf
index 8ad14a9..4f85de8 100644
--- a/conf/nginx.conf
+++ b/conf/nginx.conf
@@ -8,9 +8,9 @@ location __PATH__/ {
}
location /images/ {
- alias __FINALPATH__/images/;
+ alias __INSTALL_DIR__/images/;
}
location /static/ {
- alias __FINALPATH__/static/;
+ alias __INSTALL_DIR__/static/;
}
diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md
deleted file mode 100644
index d29e6a3..0000000
--- a/doc/DISCLAIMER.md
+++ /dev/null
@@ -1,11 +0,0 @@
-This project is still young and isn't, at the moment, very stable, so please proceed with caution when running in production.
-
-Generate the admin code with `sudo -u bookwyrm /var/www/bookwyrm/venv/bin/python3 /var/www/bookwyrm/manage.py admin_code`,
-and copy the admin code to use when you create your admin account. You can get your code
-at any time by re-running that command. Here's an example output:
-```
-*******************************************
-Use this code to create your admin account:
-c6c35779-af3a-4091-b330-c026610920d6
-*******************************************
-```
\ No newline at end of file
diff --git a/doc/DISCLAIMER_fr.md b/doc/DISCLAIMER_fr.md
deleted file mode 100644
index 14042b6..0000000
--- a/doc/DISCLAIMER_fr.md
+++ /dev/null
@@ -1,11 +0,0 @@
-Ce projet est encore jeune et n'est pas, pour le moment, très stable, faites preuve de prudence lors de son utilisation en production.
-
-Générez le code administrateur avec `sudo -u bookwyrm /var/www/bookwyrm/venv/bin/python3 /var/www/bookwyrm/manage.py admin_code`,
-et copiez le code administrateur à utiliser lors de la création de votre compte administrateur. Vous pouvez obtenir votre code
-à tout moment en réexécutant cette commande. Voici un exemple de sortie :
-```
-*******************************************
-Use this code to create your admin account:
-c6c35779-af3a-4091-b330-c026610920d6
-*******************************************
-```
diff --git a/manifest.json b/manifest.json
deleted file mode 100644
index 2e1a619..0000000
--- a/manifest.json
+++ /dev/null
@@ -1,65 +0,0 @@
-{
- "name": "BookWyrm",
- "id": "bookwyrm",
- "packaging_format": 1,
- "description": {
- "en": "Platform for social reading",
- "fr": "Plateforme de lecture sociale"
- },
- "version": "0.5.4~ynh1",
- "url": "https://github.com/bookwyrm-social/bookwyrm",
- "upstream": {
- "license": "AGPL-3.0-or-later",
- "website": "https://joinbookwyrm.com/fr/",
- "demo": "https://joinbookwyrm.com/fr/",
- "admindoc": "https://docs.joinbookwyrm.com/",
- "code": "https://github.com/bookwyrm-social/bookwyrm"
- },
- "license": "AGPL-3.0-or-later",
- "maintainer": {
- "name": "oufmilo"
- },
- "requirements": {
- "yunohost": ">= 11.0.9"
- },
- "multi_instance": true,
- "services": [
- "nginx",
- "postgresql"
- ],
- "arguments": {
- "install": [
- {
- "name": "domain",
- "type": "domain"
- },
- {
- "name": "is_public",
- "type": "boolean",
- "default": true
- },
- {
- "name": "language",
- "type": "string",
- "ask": {
- "en": "Choose the application language",
- "fr": "Choisissez la langue de l'application"
- },
- "choices": [
- "de-de",
- "en-us",
- "es-es",
- "fr-fr",
- "it-it",
- "pt-pt",
- "zh-hans"
- ],
- "default": "fr-fr"
- },
- {
- "name": "admin",
- "type": "user"
- }
- ]
- }
-}
diff --git a/manifest.toml b/manifest.toml
new file mode 100644
index 0000000..49cdcd7
--- /dev/null
+++ b/manifest.toml
@@ -0,0 +1,67 @@
+packaging_format = 2
+
+id = "bookwyrm"
+name = "BookWyrm"
+description.en = "Platform for social reading"
+description.fr = "Plateforme de lecture sociale"
+
+version = "0.5.4~ynh1"
+
+maintainers = ["oufmilo"]
+
+[upstream]
+license = "AGPL-3.0-or-later"
+website = "https://joinbookwyrm.com/fr/"
+demo = "https://joinbookwyrm.com/fr/"
+admindoc = "https://docs.joinbookwyrm.com/"
+code = "https://github.com/bookwyrm-social/bookwyrm"
+
+[integration]
+yunohost = ">= 11.0.9"
+architectures = "all"
+multi_instance = true
+ldap = "not_relevant"
+sso = "not_relevant"
+disk = "50M"
+ram.build = "50M"
+ram.runtime = "50M"
+
+[install]
+ [install.domain]
+ # this is a generic question - ask strings are automatically handled by Yunohost's core
+ type = "domain"
+ full_domain = true
+
+ [install.init_main_permission]
+ type = "group"
+ default = "visitors"
+
+ [install.language]
+ ask.en = "Choose the application language"
+ ask.fr = "Choisissez la langue de l'application"
+ type = "string"
+ choices = ["de-de", "en-us", "es-es", "fr-fr", "it-it", "pt-pt", "zh-hans"]
+ default = "fr-fr"
+
+ [install.admin]
+ # this is a generic question - ask strings are automatically handled by Yunohost's core
+ type = "user"
+
+[resources]
+ [resources.system_user]
+
+ [resources.install_dir]
+
+ [resources.data_dir]
+
+ [resources.permissions]
+ main.url = "/"
+
+ [resources.ports]
+ main.default = 8000
+
+ [resources.apt]
+ packages = "postgresql, postgresql-contrib, python3-venv, libpq-dev"
+
+ [resources.database]
+ type = "postgresql"
\ No newline at end of file
diff --git a/scripts/_common.sh b/scripts/_common.sh
index 2bccbe6..944a65e 100644
--- a/scripts/_common.sh
+++ b/scripts/_common.sh
@@ -4,9 +4,6 @@
# COMMON VARIABLES
#=================================================
-# dependencies used by the app
-pkg_dependencies="postgresql postgresql-contrib python3-venv libpq-dev"
-
#=================================================
# PERSONAL HELPERS
#=================================================
diff --git a/scripts/backup b/scripts/backup
index d66eaf1..3eef96b 100755
--- 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 () {
- ### Remove this function if there's nothing to clean before calling the remove script.
- true
-}
-# Exit if an error occurs during the execution of the script
-ynh_abort_if_errors
-
-#=================================================
-# LOAD SETTINGS
-#=================================================
-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)
-
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
@@ -41,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
@@ -58,13 +36,6 @@ ynh_backup --src_path="/etc/systemd/system/${app}-server.service"
ynh_backup --src_path="/etc/systemd/system/${app}-worker.service"
ynh_backup --src_path="/etc/systemd/system/$app.target"
-#=================================================
-# BACKUP THE POSTGRESQL DATABASE
-#=================================================
-ynh_print_info --message="Backing up the PostgreSQL database..."
-
-ynh_psql_dump_db --database="$db_name" > db.sql
-
#=================================================
# END OF SCRIPT
#=================================================
diff --git a/scripts/install b/scripts/install
index a994bb8..34b09cb 100755
--- a/scripts/install
+++ b/scripts/install
@@ -9,131 +9,43 @@
source _common.sh
source /usr/share/yunohost/helpers
-#=================================================
-# MANAGE SCRIPT FAILURE
-#=================================================
-
-ynh_clean_setup () {
- ### Remove this function if there's nothing to clean before calling the remove script.
- true
-}
-# Exit if an error occurs during the execution of the script
-ynh_abort_if_errors
-
-#=================================================
-# RETRIEVE ARGUMENTS FROM THE MANIFEST
-#=================================================
-
-domain=$YNH_APP_ARG_DOMAIN
-path_url="/"
-is_public=$YNH_APP_ARG_IS_PUBLIC
-language=$YNH_APP_ARG_LANGUAGE
-admin=$YNH_APP_ARG_ADMIN
-
-app=$YNH_APP_INSTANCE_NAME
-
-admin_mail=$(ynh_user_get_info --username=$admin --key=username)
-key=$(ynh_string_random --length=32)
-
-#=================================================
-# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
-#=================================================
-ynh_script_progression --message="Validating installation parameters..." --weight=1
-
-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..." --weight=1
-
-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=language --value=$language
-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..." --weight=1
-
-port=$(ynh_find_port --port=8000)
-ynh_app_setting_set --app=$app --key=port --value=$port
-
-#=================================================
-# INSTALL DEPENDENCIES
-#=================================================
-ynh_script_progression --message="Installing dependencies..." --weight=1
-
-ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
-
-#=================================================
-# CREATE DEDICATED USER
-#=================================================
-ynh_script_progression --message="Configuring system user..." --weight=1
-
-# Create a system user
-ynh_system_user_create --username=$app --home_dir="$final_path"
-
-#=================================================
-# CREATE A POSTGRESQL DATABASE
-#=================================================
-ynh_script_progression --message="Creating a PostgreSQL database..." --weight=1
-
-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_psql_test_if_first_run
-ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
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"
+# Set permissions to app files
+chmod -R o-rwx "$install_dir"
+chown -R $app:www-data "$install_dir"
#=================================================
# CONFIGURE THEN INSTALL SCRIPT AND DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing service script..." --weight=1
-ynh_add_config --template="../conf/.env.production" --destination="$final_path/.env"
-chmod 600 $final_path/.env
-chown $app:www-data "$final_path/.env"
+ynh_add_config --template="../conf/.env.production" --destination="$install_dir/.env"
+chmod 600 $install_dir/.env
+chown $app:www-data "$install_dir/.env"
-set -a; source "$final_path/.env"; set +a
+set -a; source "$install_dir/.env"; set +a
-mkdir "$final_path/venv"
-python3 -m venv "$final_path/venv"
-$final_path/venv/bin/pip3 install -r "$final_path/requirements.txt"
+mkdir "$install_dir/venv"
+python3 -m venv "$install_dir/venv"
+$install_dir/venv/bin/pip3 install -r "$install_dir/requirements.txt"
#=================================================
# INITIALIZE DATABASE
#=================================================
ynh_script_progression --message="Initializing database..." --weight=1
-$final_path/venv/bin/python3 "$final_path/manage.py" migrate
-$final_path/venv/bin/python3 "$final_path/manage.py" initdb
-$final_path/venv/bin/python3 "$final_path/manage.py" collectstatic --no-input
+$install_dir/venv/bin/python3 "$install_dir/manage.py" migrate
+$install_dir/venv/bin/python3 "$install_dir/manage.py" initdb
+$install_dir/venv/bin/python3 "$install_dir/manage.py" collectstatic --no-input
-#=================================================
-# SET PERMISSIONS ON BOOKWYRM DIRECTORY
-#=================================================
-
-chown -R $app:www-data $final_path
#=================================================
# NGINX CONFIGURATION
@@ -176,30 +88,6 @@ ynh_systemd_action --service_name="${app}-beat" --action="start" --log_path="sys
ynh_systemd_action --service_name="${app}-server" --action="start" --log_path="systemd" --line_match="Booting worker with pid"
ynh_systemd_action --service_name="${app}-worker" --action="start" --log_path="systemd" --line_match="ready"
-#=================================================
-# SETUP SSOWAT
-#=================================================
-ynh_script_progression --message="Configuring permissions..." --weight=1
-
-
-if [ $is_public -eq 1 ]
-then
- # Everyone can access the app.
- # The "main" permission is automatically created before the install script.
- ynh_permission_update --permission="main" --add="visitors"
-fi
-
-ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin
-
-ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true"
-
-#=================================================
-# RELOAD NGINX
-#=================================================
-ynh_script_progression --message="Reloading NGINX web server..." --weight=1
-
-ynh_systemd_action --service_name=nginx --action=reload
-
#=================================================
# END OF SCRIPT
#=================================================
diff --git a/scripts/remove b/scripts/remove
index 1101469..804edb6 100644
--- a/scripts/remove
+++ b/scripts/remove
@@ -9,18 +9,6 @@
source _common.sh
source /usr/share/yunohost/helpers
-#=================================================
-# LOAD SETTINGS
-#=================================================
-ynh_script_progression --message="Loading installation settings..." --weight=1
-
-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)
#=================================================
# STANDARD REMOVE
@@ -51,29 +39,13 @@ ynh_remove_systemd_config --service="${app}-worker"
ynh_secure_remove --file="/etc/systemd/system/$app.target"
-#=================================================
-# REMOVE LOGROTATE CONFIGURATION
-#=================================================
-ynh_script_progression --message="Removing logrotate configuration..." --weight=1
-
-# Remove the app-specific logrotate config
-ynh_remove_logrotate
-
-#=================================================
-# REMOVE THE POSTGRESQL DATABASE
-#=================================================
-ynh_script_progression --message="Removing the PostgreSQL database..." --weight=1
-
-# Remove a database if it exists, along with the associated user
-ynh_psql_remove_db --db_user=$db_user --db_name=$db_name
-
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing app main directory..." --weight=1
# Remove the app directory securely
-ynh_secure_remove --file="$final_path"
+ynh_secure_remove --file="$install_dir"
#=================================================
# REMOVE NGINX CONFIGURATION
@@ -83,24 +55,6 @@ 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..." --weight=1
-
-# Remove metapackage and its dependencies
-ynh_remove_app_dependencies
-
-#=================================================
-# GENERIC FINALIZATION
-#=================================================
-# REMOVE DEDICATED USER
-#=================================================
-ynh_script_progression --message="Removing the dedicated system user..." --weight=1
-
-# Delete a system user
-ynh_system_user_delete --username=$app
-
#=================================================
# END OF SCRIPT
#=================================================
diff --git a/scripts/restore b/scripts/restore
index 9ef1b92..f77b896 100644
--- a/scripts/restore
+++ b/scripts/restore
@@ -10,38 +10,13 @@
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
-#=================================================
-# MANAGE SCRIPT FAILURE
-#=================================================
-
-ynh_clean_setup () {
- #### Remove this function if there's nothing to clean before calling the remove script.
- true
-}
-# Exit if an error occurs during the execution of the script
-ynh_abort_if_errors
-
-#=================================================
-# LOAD SETTINGS
-#=================================================
-ynh_script_progression --message="Loading installation settings..." --weight=1
-
-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
-db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
-
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..." --weight=1
-test ! -d $final_path \
- || ynh_die --message="There is already a directory: $final_path "
+test ! -d $install_dir \
+ || ynh_die --message="There is already a directory: $install_dir "
#=================================================
# STANDARD RESTORATION STEPS
@@ -52,43 +27,16 @@ 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..." --weight=1
-
-# 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..." --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"
-
-#=================================================
-# SPECIFIC RESTORATION
-#=================================================
-# REINSTALL DEPENDENCIES
-#=================================================
-ynh_script_progression --message="Reinstalling dependencies..." --weight=1
-
-# Define and install dependencies
-ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
-
-#=================================================
-# RESTORE THE POSTGRESQL DATABASE
-#=================================================
-ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1
-
-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
+chmod 750 "$install_dir"
+chmod -R o-rwx "$install_dir"
+chown -R $app:www-data "$install_dir"
#=================================================
# RESTORE SYSTEMD
diff --git a/scripts/upgrade b/scripts/upgrade
index 20361dd..1b4c054 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -9,42 +9,12 @@
source _common.sh
source /usr/share/yunohost/helpers
-#=================================================
-# LOAD SETTINGS
-#=================================================
-ynh_script_progression --message="Loading installation settings..." --weight=1
-
-app=$YNH_APP_INSTANCE_NAME
-
-domain=$(ynh_app_setting_get --app=$app --key=domain)
-path_url=$(ynh_app_setting_get --app=$app --key=path)
-language=$(ynh_app_setting_get --app=$app --key=language)
-admin=$(ynh_app_setting_get --app=$app --key=admin)
-final_path=$(ynh_app_setting_get --app=$app --key=final_path)
-port=$(ynh_app_setting_get --app=$app --key=port)
-
-admin_mail=$(ynh_user_get_info --username=$admin --key=username)
-
#=================================================
# 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)..." --weight=1
-
-# 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
#=================================================
@@ -56,21 +26,6 @@ ynh_systemd_action --action="stop" --service_name="${app}-beat" --log_path="syst
ynh_systemd_action --action="stop" --service_name="${app}-server" --log_path="systemd" --line_match="Stopped"
ynh_systemd_action --action="stop" --service_name="${app}-worker" --log_path="systemd" --line_match="Stopped"
-#=================================================
-# UPGRADE DEPENDENCIES
-#=================================================
-ynh_script_progression --message="Upgrading dependencies..." --weight=1
-
-ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
-
-#=================================================
-# CREATE DEDICATED USER
-#=================================================
-ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
-
-# Create a dedicated user (if not existing)
-ynh_system_user_create --username=$app --home_dir="$final_path"
-
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
@@ -80,12 +35,12 @@ 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" --keep=".env"
+ ynh_setup_source --dest_dir="$install_dir" --keep=".env"
fi
-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"
#=================================================
@@ -93,25 +48,25 @@ chown -R $app:www-data "$final_path"
#=================================================
ynh_script_progression --message="Installing service script..." --weight=1
-ynh_secure_remove --file="$final_path/venv"
-mkdir "$final_path/venv"
-python3 -m venv "$final_path/venv"
-$final_path/venv/bin/pip3 install -r "$final_path/requirements.txt"
+ynh_secure_remove --file="$install_dir/venv"
+mkdir "$install_dir/venv"
+python3 -m venv "$install_dir/venv"
+$install_dir/venv/bin/pip3 install -r "$install_dir/requirements.txt"
#=================================================
# Update DATABASE
#=================================================
ynh_script_progression --message="Upgrading database..." --weight=1
-$final_path/venv/bin/python3 "$final_path/manage.py" migrate
-$final_path/venv/bin/python3 "$final_path/manage.py" collectstatic --no-input
-$final_path/venv/bin/python3 "$final_path/manage.py" populate_streams
+$install_dir/venv/bin/python3 "$install_dir/manage.py" migrate
+$install_dir/venv/bin/python3 "$install_dir/manage.py" collectstatic --no-input
+$install_dir/venv/bin/python3 "$install_dir/manage.py" populate_streams
#=================================================
# SET PERMISSIONS ON BOOKWYRM DIRECTORY
#=================================================
-chown -R $app:www-data $final_path
+chown -R $app:www-data $install_dir
#=================================================
# NGINX CONFIGURATION
From bba51877b0c17c5f5987628845431ece4abf4186 Mon Sep 17 00:00:00 2001
From: oufmilo <44617467+oufmilo@users.noreply.github.com>
Date: Sun, 19 Feb 2023 21:14:18 +0100
Subject: [PATCH 04/11] Fix V2 + add tests.toml
---
manifest.toml | 2 +-
scripts/restore | 8 --------
tests.toml | 20 ++++++++++++++++++++
3 files changed, 21 insertions(+), 9 deletions(-)
create mode 100644 tests.toml
diff --git a/manifest.toml b/manifest.toml
index 49cdcd7..0d2985b 100644
--- a/manifest.toml
+++ b/manifest.toml
@@ -19,7 +19,7 @@ code = "https://github.com/bookwyrm-social/bookwyrm"
[integration]
yunohost = ">= 11.0.9"
architectures = "all"
-multi_instance = true
+multi_instance = false
ldap = "not_relevant"
sso = "not_relevant"
disk = "50M"
diff --git a/scripts/restore b/scripts/restore
index f77b896..5a70b03 100644
--- a/scripts/restore
+++ b/scripts/restore
@@ -10,14 +10,6 @@
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
-#=================================================
-# CHECK IF THE APP CAN BE RESTORED
-#=================================================
-ynh_script_progression --message="Validating restoration parameters..." --weight=1
-
-test ! -d $install_dir \
- || ynh_die --message="There is already a directory: $install_dir "
-
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
diff --git a/tests.toml b/tests.toml
new file mode 100644
index 0000000..0988045
--- /dev/null
+++ b/tests.toml
@@ -0,0 +1,20 @@
+test_format = 1.0
+
+[default]
+
+ # ------------
+ # Tests to run
+ # ------------
+
+ exclude = ["change_url"]
+
+ # -------------------------------
+ # Default args to use for install
+ # -------------------------------
+
+
+ # -------------------------------
+ # Commits to test upgrade from
+ # -------------------------------
+
+ test_upgrade_from.2292d0d.name = "Upgrade from 0.5.3"
\ No newline at end of file
From 13286776f18725f790e9015a89b1cda40a575923 Mon Sep 17 00:00:00 2001
From: oufmilo <44617467+oufmilo@users.noreply.github.com>
Date: Sun, 19 Feb 2023 21:25:44 +0100
Subject: [PATCH 05/11] Fix install + upgrade
---
scripts/install | 3 +++
scripts/upgrade | 7 -------
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/scripts/install b/scripts/install
index 34b09cb..d89d281 100755
--- a/scripts/install
+++ b/scripts/install
@@ -10,6 +10,9 @@ source _common.sh
source /usr/share/yunohost/helpers
+admin_mail=$(ynh_user_get_info --username=$admin --key=username)
+key=$(ynh_string_random --length=32)
+
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
diff --git a/scripts/upgrade b/scripts/upgrade
index 1b4c054..df7ad2c 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -108,13 +108,6 @@ ynh_systemd_action --service_name="${app}-beat" --action="start" --log_path="sys
ynh_systemd_action --service_name="${app}-server" --action="start" --log_path="systemd" --line_match="Booting worker with pid"
ynh_systemd_action --service_name="${app}-worker" --action="start" --log_path="systemd" --line_match="ready"
-#=================================================
-# RELOAD NGINX
-#=================================================
-ynh_script_progression --message="Reloading NGINX web server..." --weight=1
-
-ynh_systemd_action --service_name=nginx --action=reload
-
#=================================================
# END OF SCRIPT
#=================================================
From 9e8b43a8e237c6b4236ff18cdbbe90fe516d0734 Mon Sep 17 00:00:00 2001
From: oufmilo <44617467+oufmilo@users.noreply.github.com>
Date: Sun, 19 Feb 2023 21:27:20 +0100
Subject: [PATCH 06/11] Fix upgrade
---
scripts/upgrade | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/scripts/upgrade b/scripts/upgrade
index df7ad2c..b5203b6 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -9,6 +9,12 @@
source _common.sh
source /usr/share/yunohost/helpers
+#=================================================
+# LOAD SETTINGS
+#=================================================
+
+admin_mail=$(ynh_user_get_info --username=$admin --key=username)
+
#=================================================
# CHECK VERSION
#=================================================
From 2ccf4073e485cb3b70c3a89358f93b8d8bcf6062 Mon Sep 17 00:00:00 2001
From: oufmilo <44617467+oufmilo@users.noreply.github.com>
Date: Mon, 20 Feb 2023 00:08:32 +0100
Subject: [PATCH 07/11] Fix restore
---
scripts/restore | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/scripts/restore b/scripts/restore
index 5a70b03..d30364a 100644
--- a/scripts/restore
+++ b/scripts/restore
@@ -10,6 +10,10 @@
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
+db_name=$(ynh_app_setting_get --app=$app --key=db_name)
+db_user=$db_name
+db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
+
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
@@ -19,6 +23,15 @@ ynh_script_progression --message="Restoring the NGINX web server configuration..
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
+#=================================================
+# RESTORE THE POSTGRESQL DATABASE
+#=================================================
+ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1
+
+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
+
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
From 5039100ef2bf0ea35e8188aa59293b93f8faeeb8 Mon Sep 17 00:00:00 2001
From: oufmilo <44617467+oufmilo@users.noreply.github.com>
Date: Mon, 20 Feb 2023 00:12:35 +0100
Subject: [PATCH 08/11] Fix
---
scripts/restore | 4 ----
1 file changed, 4 deletions(-)
diff --git a/scripts/restore b/scripts/restore
index d30364a..2e544a4 100644
--- a/scripts/restore
+++ b/scripts/restore
@@ -11,8 +11,6 @@ source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
-db_user=$db_name
-db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
#=================================================
# STANDARD RESTORATION STEPS
@@ -28,8 +26,6 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1
-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
#=================================================
From 744db2a70c6aabe2771f57c9dc295621a12987be Mon Sep 17 00:00:00 2001
From: oufmilo <44617467+oufmilo@users.noreply.github.com>
Date: Mon, 20 Feb 2023 00:53:19 +0100
Subject: [PATCH 09/11] Fix backup
---
scripts/backup | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/scripts/backup b/scripts/backup
index 3eef96b..5d28395 100755
--- a/scripts/backup
+++ b/scripts/backup
@@ -36,6 +36,13 @@ ynh_backup --src_path="/etc/systemd/system/${app}-server.service"
ynh_backup --src_path="/etc/systemd/system/${app}-worker.service"
ynh_backup --src_path="/etc/systemd/system/$app.target"
+#=================================================
+# BACKUP THE POSTGRESQL DATABASE
+#=================================================
+ynh_print_info --message="Backing up the PostgreSQL database..."
+
+ynh_psql_dump_db --database="$db_name" > db.sql
+
#=================================================
# END OF SCRIPT
#=================================================
From 40ffd76b5a45c257e4fa32e775eb4f5d52737495 Mon Sep 17 00:00:00 2001
From: oufmilo <44617467+oufmilo@users.noreply.github.com>
Date: Mon, 20 Feb 2023 01:25:40 +0100
Subject: [PATCH 10/11] Fix service
---
conf/bookwyrm-server.service | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/conf/bookwyrm-server.service b/conf/bookwyrm-server.service
index 568143c..a221c32 100644
--- a/conf/bookwyrm-server.service
+++ b/conf/bookwyrm-server.service
@@ -11,5 +11,35 @@ WorkingDirectory=__INSTALL_DIR__/
EnvironmentFile=__INSTALL_DIR__/.env
ExecStart=__INSTALL_DIR__/venv/bin/gunicorn bookwyrm.wsgi:application --bind 127.0.0.1:__PORT__
+NoNewPrivileges=yes
+PrivateTmp=yes
+PrivateDevices=yes
+RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK
+RestrictNamespaces=yes
+RestrictRealtime=yes
+DevicePolicy=closed
+ProtectClock=yes
+ProtectHostname=yes
+ProtectProc=invisible
+ProtectSystem=full
+ProtectControlGroups=yes
+ProtectKernelModules=yes
+ProtectKernelTunables=yes
+LockPersonality=yes
+SystemCallArchitectures=native
+SystemCallFilter=~@clock @debug @module @mount @obsolete @reboot @setuid @swap @cpu-emulation @privileged
+
+# Denying access to capabilities that should not be relevant for webapps
+# Doc: https://man7.org/linux/man-pages/man7/capabilities.7.html
+CapabilityBoundingSet=~CAP_RAWIO CAP_MKNOD
+CapabilityBoundingSet=~CAP_AUDIT_CONTROL CAP_AUDIT_READ CAP_AUDIT_WRITE
+CapabilityBoundingSet=~CAP_SYS_BOOT CAP_SYS_TIME CAP_SYS_MODULE CAP_SYS_PACCT
+CapabilityBoundingSet=~CAP_LEASE CAP_LINUX_IMMUTABLE CAP_IPC_LOCK
+CapabilityBoundingSet=~CAP_BLOCK_SUSPEND CAP_WAKE_ALARM
+CapabilityBoundingSet=~CAP_SYS_TTY_CONFIG
+CapabilityBoundingSet=~CAP_MAC_ADMIN CAP_MAC_OVERRIDE
+CapabilityBoundingSet=~CAP_NET_ADMIN CAP_NET_BROADCAST CAP_NET_RAW
+CapabilityBoundingSet=~CAP_SYS_ADMIN CAP_SYS_PTRACE CAP_SYSLOG
+
[Install]
WantedBy=multi-user.target
From eb963dbb0ec0bcbe9df47ea1c7508f663c750f3a Mon Sep 17 00:00:00 2001
From: oufmilo <44617467+oufmilo@users.noreply.github.com>
Date: Mon, 20 Feb 2023 01:50:49 +0100
Subject: [PATCH 11/11] Update bookwyrm-server.service
---
conf/bookwyrm-server.service | 30 ------------------------------
1 file changed, 30 deletions(-)
diff --git a/conf/bookwyrm-server.service b/conf/bookwyrm-server.service
index a221c32..568143c 100644
--- a/conf/bookwyrm-server.service
+++ b/conf/bookwyrm-server.service
@@ -11,35 +11,5 @@ WorkingDirectory=__INSTALL_DIR__/
EnvironmentFile=__INSTALL_DIR__/.env
ExecStart=__INSTALL_DIR__/venv/bin/gunicorn bookwyrm.wsgi:application --bind 127.0.0.1:__PORT__
-NoNewPrivileges=yes
-PrivateTmp=yes
-PrivateDevices=yes
-RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK
-RestrictNamespaces=yes
-RestrictRealtime=yes
-DevicePolicy=closed
-ProtectClock=yes
-ProtectHostname=yes
-ProtectProc=invisible
-ProtectSystem=full
-ProtectControlGroups=yes
-ProtectKernelModules=yes
-ProtectKernelTunables=yes
-LockPersonality=yes
-SystemCallArchitectures=native
-SystemCallFilter=~@clock @debug @module @mount @obsolete @reboot @setuid @swap @cpu-emulation @privileged
-
-# Denying access to capabilities that should not be relevant for webapps
-# Doc: https://man7.org/linux/man-pages/man7/capabilities.7.html
-CapabilityBoundingSet=~CAP_RAWIO CAP_MKNOD
-CapabilityBoundingSet=~CAP_AUDIT_CONTROL CAP_AUDIT_READ CAP_AUDIT_WRITE
-CapabilityBoundingSet=~CAP_SYS_BOOT CAP_SYS_TIME CAP_SYS_MODULE CAP_SYS_PACCT
-CapabilityBoundingSet=~CAP_LEASE CAP_LINUX_IMMUTABLE CAP_IPC_LOCK
-CapabilityBoundingSet=~CAP_BLOCK_SUSPEND CAP_WAKE_ALARM
-CapabilityBoundingSet=~CAP_SYS_TTY_CONFIG
-CapabilityBoundingSet=~CAP_MAC_ADMIN CAP_MAC_OVERRIDE
-CapabilityBoundingSet=~CAP_NET_ADMIN CAP_NET_BROADCAST CAP_NET_RAW
-CapabilityBoundingSet=~CAP_SYS_ADMIN CAP_SYS_PTRACE CAP_SYSLOG
-
[Install]
WantedBy=multi-user.target