diff --git a/.gitignore b/.gitignore index c539227..3ed2386 100644 --- a/.gitignore +++ b/.gitignore @@ -129,10 +129,6 @@ publish/ *.pubxml *.publishproj -# NuGet Packages Directory -## TODO: If you have NuGet Package Restore enabled, uncomment the next line -#packages/ - # Windows Azure Build Output csx *.build.csdef @@ -224,3 +220,4 @@ pip-log.txt .directory *-swp +auto_update_config.sh diff --git a/README.md b/README.md index e772c94..50e215a 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Seafile is an open Source Cloud Storage application. It's a Enterprise file sync and share platform with high reliability and performance. It's a file hosting platform with high reliability and performance. Put files on your own server. Sync and share files across different devices, or access all the files as a virtual disk. -**Shipped version:** 9.0.9~ynh1 +**Shipped version:** 11.0.9~ynh1 **Demo:** diff --git a/README_es.md b/README_es.md index ef8f6f1..b2b35aa 100644 --- a/README_es.md +++ b/README_es.md @@ -20,8 +20,7 @@ Seafile is an open Source Cloud Storage application. It's a Enterprise file sync and share platform with high reliability and performance. It's a file hosting platform with high reliability and performance. Put files on your own server. Sync and share files across different devices, or access all the files as a virtual disk. - -**Versión actual:** 9.0.9~ynh1 +**Versión actual:** 11.0.9~ynh1 **Demo:** diff --git a/README_eu.md b/README_eu.md index 4449b52..2a43b19 100644 --- a/README_eu.md +++ b/README_eu.md @@ -20,8 +20,7 @@ Seafile is an open Source Cloud Storage application. It's a Enterprise file sync and share platform with high reliability and performance. It's a file hosting platform with high reliability and performance. Put files on your own server. Sync and share files across different devices, or access all the files as a virtual disk. - -**Paketatutako bertsioa:** 9.0.9~ynh1 +**Paketatutako bertsioa:** 11.0.9~ynh1 **Demoa:** diff --git a/README_fr.md b/README_fr.md index cfaf77c..59620e5 100644 --- a/README_fr.md +++ b/README_fr.md @@ -20,8 +20,7 @@ Seafile is an open Source Cloud Storage application. It's a Enterprise file sync and share platform with high reliability and performance. It's a file hosting platform with high reliability and performance. Put files on your own server. Sync and share files across different devices, or access all the files as a virtual disk. - -**Version incluse :** 9.0.9~ynh1 +**Version incluse :** 11.0.9~ynh1 **Démo :** diff --git a/README_gl.md b/README_gl.md index 5fe8c28..a952419 100644 --- a/README_gl.md +++ b/README_gl.md @@ -20,8 +20,7 @@ Seafile is an open Source Cloud Storage application. It's a Enterprise file sync and share platform with high reliability and performance. It's a file hosting platform with high reliability and performance. Put files on your own server. Sync and share files across different devices, or access all the files as a virtual disk. - -**Versión proporcionada:** 9.0.9~ynh1 +**Versión proporcionada:** 11.0.9~ynh1 **Demo:** diff --git a/README_it.md b/README_it.md new file mode 100644 index 0000000..30a05c2 --- /dev/null +++ b/README_it.md @@ -0,0 +1,59 @@ + + +# Seafile per YunoHost + +[![Livello di integrazione](https://dash.yunohost.org/integration/seafile.svg)](https://dash.yunohost.org/appci/app/seafile) ![Stato di funzionamento](https://ci-apps.yunohost.org/ci/badges/seafile.status.svg) ![Stato di manutenzione](https://ci-apps.yunohost.org/ci/badges/seafile.maintain.svg) + +[![Installa Seafile con YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=seafile) + +*[Leggi questo README in altre lingue.](./ALL_README.md)* + +> *Questo pacchetto ti permette di installare Seafile su un server YunoHost in modo semplice e veloce.* +> *Se non hai YunoHost, consulta [la guida](https://yunohost.org/install) per imparare a installarlo.* + +## Panoramica + +Seafile is an open Source Cloud Storage application. + +It's a Enterprise file sync and share platform with high reliability and performance. It's a file hosting platform with high reliability and performance. Put files on your own server. Sync and share files across different devices, or access all the files as a virtual disk. + + +**Versione pubblicata:** 9.0.9~ynh2 + +**Prova:** + +## Screenshot + +![Screenshot di Seafile](./doc/screenshots/mobile-ios-client.jpg) +![Screenshot di Seafile](./doc/screenshots/drive-client.png) +![Screenshot di Seafile](./doc/screenshots/file-locking.jpg) +![Screenshot di Seafile](./doc/screenshots/access-logs.jpg) +![Screenshot di Seafile](./doc/screenshots/file-history.png) +![Screenshot di Seafile](./doc/screenshots/wiki_en.png) +![Screenshot di Seafile](./doc/screenshots/sharing-dialog.png) +![Screenshot di Seafile](./doc/screenshots/sync-client.jpg) + +## Documentazione e risorse + +- Sito web ufficiale dell’app: +- Documentazione ufficiale per gli amministratori: +- Repository upstream del codice dell’app: +- Store di YunoHost: +- Segnala un problema: + +## Informazioni per sviluppatori + +Si prega di inviare la tua pull request alla [branch di `testing`](https://github.com/YunoHost-Apps/seafile_ynh/tree/testing). + +Per provare la branch di `testing`, si prega di procedere in questo modo: + +```bash +sudo yunohost app install https://github.com/YunoHost-Apps/seafile_ynh/tree/testing --debug +o +sudo yunohost app upgrade seafile -u https://github.com/YunoHost-Apps/seafile_ynh/tree/testing --debug +``` + +**Maggiori informazioni riguardo il pacchetto di quest’app:** diff --git a/README_zh_Hans.md b/README_zh_Hans.md index f2f2955..2712623 100644 --- a/README_zh_Hans.md +++ b/README_zh_Hans.md @@ -20,8 +20,7 @@ Seafile is an open Source Cloud Storage application. It's a Enterprise file sync and share platform with high reliability and performance. It's a file hosting platform with high reliability and performance. Put files on your own server. Sync and share files across different devices, or access all the files as a virtual disk. - -**分发版本:** 9.0.9~ynh1 +**分发版本:** 11.0.9~ynh1 **演示:** diff --git a/auto_update/auto_update.sh b/auto_update/auto_update.sh new file mode 100644 index 0000000..e3ae750 --- /dev/null +++ b/auto_update/auto_update.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +set -eu + +readonly app_name=seafile + +get_from_manifest() { + result=$(python3 <&1 | tee "${app_name}_build_temp.log" + return "${PIPESTATUS[0]}" +} + +app_prev_version="$(get_from_manifest ".version" | cut -d'~' -f1)" +app_version="$app_prev_version" + +if check_app_version +then + set +eu + upgrade_app + res=$? + set -eu + if [ $res -eq 0 ]; then + result="Success" + else + result="Failed" + fi + msg="Build: $app_name version $app_version" + + echo "$msg" | mail.mailutils --content-type="text/plain; charset=UTF-8" -A "${app_name}_build_temp.log" -s "Autoupgrade $app_name : $result" "$notify_email" +fi diff --git a/auto_update/auto_update_config_example.sh b/auto_update/auto_update_config_example.sh new file mode 100644 index 0000000..daecfc8 --- /dev/null +++ b/auto_update/auto_update_config_example.sh @@ -0,0 +1 @@ +notify_email="hello@world.tld" diff --git a/conf/ccnet.conf b/conf/ccnet.conf index a26426a..49a0f82 100644 --- a/conf/ccnet.conf +++ b/conf/ccnet.conf @@ -9,9 +9,3 @@ USER = __DB_USER__ PASSWD = __DB_PWD__ DB = ccnetdb CONNECTION_CHARSET = utf8 - -[LDAP] -HOST = ldap://localhost:389 -BASE = ou=users,dc=yunohost,dc=org -LOGIN_ATTR = mail -FILTER = permission=cn=__APP__.main,ou=permission,dc=yunohost,dc=org diff --git a/conf/gunicorn.conf.py b/conf/gunicorn.conf.py index 7880d8f..533a73e 100644 --- a/conf/gunicorn.conf.py +++ b/conf/gunicorn.conf.py @@ -7,7 +7,7 @@ workers = 5 bind = "127.0.0.1:__PORT_SEAHUB__" # Pid -pids_dir = '__INSTALL_DIR__/pids' +pids_dir = '/opt/seafile/pids' pidfile = os.path.join(pids_dir, 'seahub.pid') # for file upload, we need a longer timeout value (default is only 30s, too short) diff --git a/conf/nginx.conf b/conf/nginx.conf index 4c1959a..65d8abb 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,32 +1,54 @@ + location __PATH__ { - proxy_redirect http:// https://; proxy_pass http://127.0.0.1:__PORT_SEAHUB__; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Host $server_name; - proxy_read_timeout 1200s; - # used for view/edit office file via Office Online Server + proxy_read_timeout 1200s; client_max_body_size 0; - access_log /var/log/nginx/seahub.access.log; - error_log /var/log/nginx/seahub.error.log; + access_log /var/log/nginx/seahub.access.log; + error_log /var/log/nginx/seahub.error.log; include conf.d/yunohost_panel.conf.inc; } +location __PATH__/media/ { + alias __SEAFILE_CODE__/seahub/media/; +} + +location __PATH__/media/avatars/ { + alias __DATA_DIR__/seahub-data/avatars/; +} + location /seafhttp/ { proxy_pass http://127.0.0.1:__PORT_FILESERVER__/; - client_max_body_size 0; proxy_connect_timeout 36000s; proxy_read_timeout 36000s; proxy_send_timeout 36000s; + + client_max_body_size 0; + proxy_request_buffering off; + + access_log /var/log/nginx/seafhttp.access.log; + error_log /var/log/nginx/seafhttp.error.log; } +location /notification/ping { + proxy_pass http://127.0.0.1:8083/ping; + access_log /var/log/nginx/notification.access.log; + error_log /var/log/nginx/notification.error.log; +} -location __PATH__/media/ { - alias __INSTALL_DIR__/seafile-server-latest/seahub/media/; +location /notification { + proxy_pass http://127.0.0.1:8083/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + access_log /var/log/nginx/notification.access.log; + error_log /var/log/nginx/notification.error.log; } location /seafdav { @@ -36,8 +58,10 @@ location /seafdav { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Host $server_name; proxy_set_header X-Forwarded-Proto $scheme; + proxy_read_timeout 1200s; client_max_body_size 0; + proxy_request_buffering off; access_log /var/log/nginx/seafdav.access.log; error_log /var/log/nginx/seafdav.error.log; diff --git a/conf/seafevents.conf b/conf/seafevents.conf new file mode 100644 index 0000000..8cfa634 --- /dev/null +++ b/conf/seafevents.conf @@ -0,0 +1,18 @@ +[DATABASE] +type = mysql +host = 127.0.0.1 +port = 3306 +username = __DB_USER__ +password = __DB_PWD__ +name = seahubdb + +[STATISTICS] +## must be "true" to enable statistics +enabled = false + +[SEAHUB EMAIL] +## must be "true" to enable user email notifications when there are new unread notifications +enabled = true + +## interval of sending Seahub email. Can be s(seconds), m(minutes), h(hours), d(days) +interval = 1d diff --git a/conf/seafile.conf b/conf/seafile.conf index 68793a7..a684aa8 100644 --- a/conf/seafile.conf +++ b/conf/seafile.conf @@ -7,6 +7,8 @@ max_upload_size=1000 # Set maximum download directory size to 200M. max_download_dir_size=1000 +use_go_fileserver = true + [database] type = mysql host = 127.0.0.1 @@ -15,3 +17,13 @@ user = __DB_USER__ password = __DB_PWD__ db_name = __DB_NAME__ connection_charset = utf8 + +[memcached] +memcached_options = --SERVER=127.0.0.1 --POOL-MIN=10 --POOL-MAX=100 + +[notification] +enabled = true +host = 127.0.0.1 +port = __PORT_NOTIFICATIONSERVER__ +log_level = info +jwt_private_key = __JWT_PRIVATE_KEY_NOTIFICATION_SERVER__ diff --git a/conf/seafile.service b/conf/seafile.service index 5e2fb37..9ccea1c 100644 --- a/conf/seafile.service +++ b/conf/seafile.service @@ -5,11 +5,15 @@ After=mysql.service [Service] Type=forking -ExecStart=/opt/yunohost/__APP__/seafile-server-latest/seafile.sh start -ExecStop=/opt/yunohost/__APP__/seafile-server-latest/seafile.sh stop +ExecStart=/opt/seafile/seafile-server-__SEAFILE_VERSION__/seafile.sh start +ExecStop=/opt/seafile/seafile-server-__SEAFILE_VERSION__/seafile.sh stop User=__APP__ Group=__APP__ +# Config releated to run in docker provied file system +RootDirectory=__INSTALL_DIR__/seafile_image +BindPaths=__SYSTEMD_SEAFILE_BIND_MOUNT__ + # Sandboxing options to harden security # Details for these options: https://www.freedesktop.org/software/systemd/man/systemd.exec.html NoNewPrivileges=yes diff --git a/conf/seahub.service b/conf/seahub.service index b81a4d4..e274bea 100644 --- a/conf/seahub.service +++ b/conf/seahub.service @@ -4,11 +4,15 @@ After=network.target seafile.service [Service] Type=forking -ExecStart=/opt/yunohost/__APP__/seafile-server-latest/seahub.sh start -ExecStop=/opt/yunohost/__APP__/seafile-server-latest/seahub.sh stop +ExecStart=/opt/seafile/seafile-server-__SEAFILE_VERSION__/seahub.sh start +ExecStop=/opt/seafile/seafile-server-__SEAFILE_VERSION__/seahub.sh stop User=__APP__ Group=__APP__ +# Config releated to run in docker provied file system +RootDirectory=__INSTALL_DIR__/seafile_image +BindPaths=__SYSTEMD_SEAFILE_BIND_MOUNT__ + # Sandboxing options to harden security # Details for these options: https://www.freedesktop.org/software/systemd/man/systemd.exec.html NoNewPrivileges=yes diff --git a/conf/seahub_settings.py b/conf/seahub_settings.py index e924bef..4c72450 100644 --- a/conf/seahub_settings.py +++ b/conf/seahub_settings.py @@ -1,44 +1,399 @@ -SECRET_KEY = "__SEAHUB_SECRET_KEY__" +# -*- coding: utf-8 -*- + +SECRET_KEY = "{{ seahub_secret_key }}" DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'seahubdb', - 'USER': '__DB_USER__', - 'PASSWORD': '__DB_PWD__', + 'USER': '{{ db_user }}', + 'PASSWORD': '{{ db_pwd }}', 'HOST': '127.0.0.1', 'PORT': '3306', - 'OPTIONS': { - 'init_command': 'SET storage_engine=INNODB', - } + 'OPTIONS': {'charset': 'utf8mb4'}, } } -SERVICE_URL = "https://__DOMAIN____PATH__" -FILE_SERVER_ROOT = "https://__DOMAIN__/seafhttp" -SITE_ROOT = "__PATH2__" -SERVE_STATIC = False -MEDIA_URL = "__PATH2__media/" -COMPRESS_URL = MEDIA_URL -STATIC_URL = MEDIA_URL + 'assets/' -EMAIL_USE_TLS = False -EMAIL_HOST = "localhost" -EMAIL_HOST_USER = "__APP__@__DOMAIN__" -EMAIL_HOST_PASSWORD = "" -EMAIL_PORT = "25" -DEFAULT_FROM_EMAIL = "__APP__@__DOMAIN__" -SERVER_EMAIL = "__APP__@__DOMAIN__" -LOGIN_URL = '__PATH2__accounts/login/' -ENABLE_WIKI = True -ALLOWED_HOSTS = ['__DOMAIN__'] -ENABLE_REMOTE_USER_AUTHENTICATION = True -REMOTE_USER_HEADER = 'HTTP_EMAIL' -REMOTE_USER_CREATE_UNKNOWN_USER = False -REMOTE_USER_PROTECTED_PATH = ['__PATH__', '__PATH2__accounts/login'] -TIME_ZONE = "__TIME_ZONE__" CACHES = { 'default': { 'BACKEND': 'django_pylibmc.memcached.PyLibMCCache', 'LOCATION': '127.0.0.1:11211', }, } + +FILE_SERVER_ROOT = "https://{{ domain }}/seafhttp" +SERVE_STATIC = False +MEDIA_URL = "{{ path2 }}media/" +COMPRESS_URL = MEDIA_URL +STATIC_URL = MEDIA_URL + 'assets/' +LOGIN_URL = '{{ path2 }}accounts/login/' + +# +# LDAP +# + +ENABLE_LDAP = True +# The URL of LDAP server +LDAP_SERVER_URL = 'ldap://localhost:389' + +# The root node of users who can log in to Seafile in the LDAP server +LDAP_BASE_DN = 'ou=users,dc=yunohost,dc=org' + +# DN of the administrator used to query the LDAP server for information. +# For OpenLDAP, it maybe cn=admin,dc=example,dc=com +LDAP_ADMIN_DN = '' # Need to leave empty to work with anonymous authentication + +# Password of LDAP_ADMIN_DN +LDAP_ADMIN_PASSWORD = '' # Need to leave empty to work with anonymous authentication + +# Identify the source of the user, used in +# the table social_auth_usersocialauth, defaults to 'ldap' +LDAP_PROVIDER = 'ldap' + +# User's attribute used to log in to Seafile. +# It should be a unique identifier for the user in LDAP server. +# Learn more about this id from the descriptions at begining of this section. +LDAP_LOGIN_ATTR = 'mail' + +# LDAP user's contact_email attribute +LDAP_CONTACT_EMAIL_ATTR = 'mail' + +# LDAP user's role attribute +LDAP_USER_ROLE_ATTR = '' + +# For sync user's first name +LDAP_USER_FIRST_NAME_ATTR = 'givenName' + +# For sync user's last name +LDAP_USER_LAST_NAME_ATTR = 'sn' + +# Whether to reverse the user's first and last name +LDAP_USER_NAME_REVERSE = False + +# Additional filter conditions, users who meet the filter conditions can log in, otherwise they cannot log in +LDAP_FILTER = 'permission=cn={{ app }}.main,ou=permission,dc=yunohost,dc=org' + +# +# SSO +# + +ENABLE_REMOTE_USER_AUTHENTICATION = True +REMOTE_USER_HEADER = 'HTTP_EMAIL' +REMOTE_USER_CREATE_UNKNOWN_USER = False +REMOTE_USER_PROTECTED_PATH = ['{{ path }}', '{{ path2 }}accounts/login', '{{ path2 }}sso'] + +# +# Security settings +# + +# For security consideration, please set to match the host/domain of your site, e.g., ALLOWED_HOSTS = ['.example.com']. +# Please refer https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts for details. +ALLOWED_HOSTS = ['{{ domain }}'] + +# Whether to use a secure cookie for the CSRF cookie +# https://docs.djangoproject.com/en/3.2/ref/settings/#csrf-cookie-secure +CSRF_COOKIE_SECURE = True + +# The value of the SameSite flag on the CSRF cookie +# https://docs.djangoproject.com/en/3.2/ref/settings/#csrf-cookie-samesite +CSRF_COOKIE_SAMESITE = 'Strict' + +# https://docs.djangoproject.com/en/3.2/ref/settings/#csrf-trusted-origins +CSRF_TRUSTED_ORIGINS = ['https://{{ domain }}'] + +# +# User options +# + +# Enalbe or disalbe registration on web. Default is `False`. +# ENABLE_SIGNUP = False + +# Activate or deactivate user when registration complete. Default is `True`. +# If set to `False`, new users need to be activated by admin in admin panel. +# ACTIVATE_AFTER_REGISTRATION = True + +# Whether to send email when a system admin adding a new member. Default is `True`. +# SEND_EMAIL_ON_ADDING_SYSTEM_MEMBER = True + +# Whether to send email when a system admin resetting a user's password. Default is `True`. +# SEND_EMAIL_ON_RESETTING_USER_PASSWD = True + +# Send system admin notify email when user registration is complete. Default is `False`. +# NOTIFY_ADMIN_AFTER_REGISTRATION = False + +# Remember days for login. Default is 7 +# LOGIN_REMEMBER_DAYS = 7 + +# Attempt limit before showing a captcha when login. +# LOGIN_ATTEMPT_LIMIT = 3 + +# deactivate user account when login attempts exceed limit +# Since version 5.1.2 or pro 5.1.3 +# FREEZE_USER_ON_LOGIN_FAILED = False + +# Age of cookie, in seconds (default: 2 weeks). +# SESSION_COOKIE_AGE = 60 * 60 * 24 * 7 * 2 + +# Whether a user's session cookie expires when the Web browser is closed. +# SESSION_EXPIRE_AT_BROWSER_CLOSE = False + +# Whether to save the session data on every request. Default is `False` +# SESSION_SAVE_EVERY_REQUEST = False + +# Whether enable the feature "published library". Default is `False` +# Since 6.1.0 CE +ENABLE_WIKI = True + +# In old version, if you use Single Sign On, the password is not saved in Seafile. +# Users can't use WebDAV because Seafile can't check whether the password is correct. +# Since version 6.3.8, you can enable this option to let user's to specific a password for WebDAV login. +# Users login via SSO can use this password to login in WebDAV. +# Enable the feature. pycryptodome should be installed first. +# sudo pip install pycryptodome==3.12.0 +ENABLE_WEBDAV_SECRET = False + +# Since version 7.0.9, you can force a full user to log in with a two factor authentication. +# The prerequisite is that the administrator should 'enable two factor authentication' in the 'System Admin -> Settings' page. +# Then you can add the following configuration information to the configuration file. +# ENABLE_FORCE_2FA_TO_ALL_USERS = False + +# +# Library options +# + +# if enable create encrypted library +# ENABLE_ENCRYPTED_LIBRARY = True + +# version for encrypted library +# should only be `2` or `4`. +# version 3 is insecure (using AES128 encryption) so it's not recommended any more. +# ENCRYPTED_LIBRARY_VERSION = 2 + +# mininum length for password of encrypted library +# REPO_PASSWORD_MIN_LENGTH = 8 + +# force use password when generate a share/upload link (since version 8.0.9) +# SHARE_LINK_FORCE_USE_PASSWORD = False + +# mininum length for password for share link (since version 4.4) +# SHARE_LINK_PASSWORD_MIN_LENGTH = 8 + +# LEVEL for the password of a share/upload link +# based on four types of input: +# num, upper letter, lower letter, other symbols +# '3' means password must have at least 3 types of the above. (since version 8.0.9) +# SHARE_LINK_PASSWORD_STRENGTH_LEVEL = 3 + +# Default expire days for share link (since version 6.3.8) +# Once this value is configured, the user can no longer generate an share link with no expiration time. +# If the expiration value is not set when the share link is generated, the value configured here will be used. +# SHARE_LINK_EXPIRE_DAYS_DEFAULT = 5 + +# minimum expire days for share link (since version 6.3.6) +# SHARE_LINK_EXPIRE_DAYS_MIN should be less than SHARE_LINK_EXPIRE_DAYS_DEFAULT (If the latter is set). +# SHARE_LINK_EXPIRE_DAYS_MIN = 3 # default is 0, no limit. + +# maximum expire days for share link (since version 6.3.6) +# SHARE_LINK_EXPIRE_DAYS_MIN should be greater than SHARE_LINK_EXPIRE_DAYS_DEFAULT (If the latter is set). +# SHARE_LINK_EXPIRE_DAYS_MAX = 8 # default is 0, no limit. + +# Default expire days for upload link (since version 7.1.6) +# Once this value is configured, the user can no longer generate an upload link with no expiration time. +# If the expiration value is not set when the upload link is generated, the value configured here will be used. +# UPLOAD_LINK_EXPIRE_DAYS_DEFAULT = 5 + +# minimum expire days for upload link (since version 7.1.6) +# UPLOAD_LINK_EXPIRE_DAYS_MIN should be less than UPLOAD_LINK_EXPIRE_DAYS_DEFAULT (If the latter is set). +# UPLOAD_LINK_EXPIRE_DAYS_MIN = 3 # default is 0, no limit. + +# maximum expire days for upload link (since version 7.1.6) +# UPLOAD_LINK_EXPIRE_DAYS_MAX should be greater than UPLOAD_LINK_EXPIRE_DAYS_DEFAULT (If the latter is set). +# UPLOAD_LINK_EXPIRE_DAYS_MAX = 8 # default is 0, no limit. + +# force user login when view file/folder share link (since version 6.3.6) +# SHARE_LINK_LOGIN_REQUIRED = False + +# enable water mark when view(not edit) file in web browser (since version 6.3.6) +# ENABLE_WATERMARK = True + +# Disable sync with any folder. Default is `False` +# NOTE: since version 4.2.4 +# DISABLE_SYNC_WITH_ANY_FOLDER = False + +# Enable or disable library history setting +# ENABLE_REPO_HISTORY_SETTING = True + +# Enable or disable normal user to create organization libraries +# Since version 5.0.5 +# ENABLE_USER_CREATE_ORG_REPO = True + +# Enable or disable user share library to any group +# Since version 6.2.0 +# ENABLE_SHARE_TO_ALL_GROUPS = True + +# Enable or disable user to clean trash (default is True) +# Since version 6.3.6 +# ENABLE_USER_CLEAN_TRASH = True + +# Add a report abuse button on download links. (since version 7.1.0) +# Users can report abuse on the share link page, fill in the report type, contact information, and description. +# Default is false. +# ENABLE_SHARE_LINK_REPORT_ABUSE = False + +# +# Online preview +# + +# Whether to use pdf.js to view pdf files online. Default is `True`, you can turn it off. +# NOTE: since version 1.4. +# USE_PDFJS = True + +# Online preview maximum file size, defaults to 30M. +# FILE_PREVIEW_MAX_SIZE = 30 * 1024 * 1024 + +# Extensions of previewed text files. +# NOTE: since version 6.1.1 +# TEXT_PREVIEW_EXT = """ac, am, bat, c, cc, cmake, cpp, cs, css, diff, el, h, html, +# htm, java, js, json, less, make, org, php, pl, properties, py, rb, +# scala, script, sh, sql, txt, text, tex, vi, vim, xhtml, xml, log, csv, +# groovy, rst, patch, go""" + +# Enable or disable thumbnails +# NOTE: since version 4.0.2 +# ENABLE_THUMBNAIL = True + +# Seafile only generates thumbnails for images smaller than the following size. +# Since version 6.3.8 pro, suport the psd online preview. +# THUMBNAIL_IMAGE_SIZE_LIMIT = 30 # MB + +# Enable or disable thumbnail for video. ffmpeg and moviepy should be installed first. +# For details, please refer to https://manual.seafile.com/deploy/video_thumbnails.html +# NOTE: this option is deprecated in version 7.1 +# ENABLE_VIDEO_THUMBNAIL = False + +# Use the frame at 5 second as thumbnail +# NOTE: this option is deprecated in version 7.1 +# THUMBNAIL_VIDEO_FRAME_TIME = 5 + +# Absolute filesystem path to the directory that will hold thumbnail files. +# THUMBNAIL_ROOT = '/haiwen/seahub-data/thumbnail/thumb/' + +# Default size for picture preview. Enlarge this size can improve the preview quality. +# NOTE: since version 6.1.1 +# THUMBNAIL_SIZE_FOR_ORIGINAL = 1024 + +# +# Other options +# + +# This is outside URL for Seahub(Seafile Web). +# The domain part (i.e., www.example.com) will be used in generating share links and download/upload file via web. +# Note: Outside URL means "if you use Nginx, it should be the Nginx's address" +# Note: SERVICE_URL is moved to seahub_settings.py since 9.0.0 +SERVICE_URL = "https://{{ domain }}{{ path }}" + +# Disable settings via Web interface in system admin->settings +# Default is True +# Since 5.1.3 +# ENABLE_SETTINGS_VIA_WEB = True + +# Choices can be found here: +# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name +# although not all choices may be available on all operating systems. +# If running in a Windows environment this must be set to the same as your +# system time zone. +TIME_ZONE = "{{ time_zone }}" + +# Language code for this installation. All choices can be found here: +# http://www.i18nguy.com/unicode/language-identifiers.html +# Default language for sending emails. +LANGUAGE_CODE = '{{ language }}' + +# Custom language code choice. +# LANGUAGES = ( ) + +# Set this to your website/company's name. This is contained in email notifications and welcome message when user login for the first time. +SITE_NAME = 'Seafile' + +# Browser tab's title +SITE_TITLE = 'Private Seafile' + +# If you don't want to run seahub website on your site's root path, set this option to your preferred path. +# e.g. setting it to '/seahub/' would run seahub on http://example.com/seahub/. +SITE_ROOT = "{{ path2 }}" + +# Max number of files when user upload file/folder. +# Since version 6.0.4 +# MAX_NUMBER_OF_FILES_FOR_FILEUPLOAD = 500 + +# Control the language that send email. Default to user's current language. +# Since version 6.1.1 +# SHARE_LINK_EMAIL_LANGUAGE = '' + +# Interval for browser requests unread notifications +# Since PRO 6.1.4 or CE 6.1.2 +# UNREAD_NOTIFICATIONS_REQUEST_INTERVAL = 3 * 60 # seconds + +# Get web api auth token on profile page. +# ENABLE_GET_AUTH_TOKEN_BY_SESSION = True + +# Since 8.0.6 CE/PRO version. +# Url redirected to after user logout Seafile. +# Usually configured as Single Logout url. +LOGOUT_REDIRECT_URL = 'https://{{ domain }}/yunohost/sso/?action=logout' + +# Enable system admin add T&C, all users need to accept terms before using. Defaults to `False`. +# Since version 6.0 +# ENABLE_TERMS_AND_CONDITIONS = False + +# Enable two factor authentication for accounts. Defaults to `False`. +# Since version 6.0 +# ENABLE_TWO_FACTOR_AUTH = False + +# Enable user select a template when he/she creates library. +# When user select a template, Seafile will create folders releated to the pattern automaticly. +# Since version 6.0 +# LIBRARY_TEMPLATES = { +# 'Technology': ['/Develop/Python', '/Test'], +# 'Finance': ['/Current assets', '/Fixed assets/Computer'] +# } + +# Enable a user to change password in 'settings' page. Default to `True` +# Since version 6.2.11 +# ENABLE_CHANGE_PASSWORD = True + +# If show contact email when search user. +# ENABLE_SHOW_CONTACT_EMAIL_WHEN_SEARCH_USER = True + +# +# Mail +# + +EMAIL_USE_TLS = True +EMAIL_HOST = "{{ domain }}" +EMAIL_HOST_USER = "{{ app }}" +EMAIL_HOST_PASSWORD = "{{ mail_pwd }}" +EMAIL_PORT = "587" +REPLACE_FROM_EMAIL = True +ADD_REPLY_TO_HEADER = True +DEFAULT_FROM_EMAIL = "{{ app }}@{{ domain }}" +SERVER_EMAIL = "{{ app }}@{{ domain }}" + +# +# RESTful API +# + +# API throttling related settings. Enlarger the rates if you got 429 response code during API calls. +# REST_FRAMEWORK = { +# 'DEFAULT_THROTTLE_RATES': { +# 'ping': '600/minute', +# 'anon': '5/minute', +# 'user': '300/minute', +# }, +# 'UNICODE_JSON': False, +# } + +# Throtting whitelist used to disable throttle for certain IPs. +# e.g. REST_FRAMEWORK_THROTTING_WHITELIST = ['127.0.0.1', '192.168.1.1'] +# Please make sure `REMOTE_ADDR` header is configured in Nginx conf according to https://manual.seafile.com/deploy/deploy_with_nginx.html. +# REST_FRAMEWORK_THROTTING_WHITELIST = [] diff --git a/manifest.toml b/manifest.toml index 1b3f721..cb2c69e 100644 --- a/manifest.toml +++ b/manifest.toml @@ -5,7 +5,7 @@ name = "Seafile" description.en = "Open Source Cloud Storage" description.fr = "Stockage Cloud Open Source" -version = "9.0.9~ynh1" +version = "11.0.9~ynh1" maintainers = ["Josué Tille"] @@ -18,13 +18,13 @@ code = "https://github.com/haiwen/seafile-server" cpe = "cpe:2.3:a:seafile:seafile" [integration] -yunohost = ">= 11.2.3" -architectures = ["amd64", "arm64", "armhf"] +yunohost = ">= 11.2.13" +architectures = ["amd64", "arm64"] multi_instance = false ldap = true sso = true -disk = "1G" -ram.build = "500M" +disk = "1.5G" +ram.build = "0M" ram.runtime = "500M" [install] @@ -66,9 +66,8 @@ ram.runtime = "500M" [resources.install_dir] dir = "/opt/yunohost/__APP__" - owner = "__APP__:rwX" - group = "__APP__:rX" - subdirs = ["installed", "logs"] + owner = "__APP__:rwx" + group = "www-data:rx" [resources.data_dir] dir = "/home/yunohost.app/__APP__" @@ -83,6 +82,13 @@ ram.runtime = "500M" file_server.show_tile = false file_server.protected = true + notification_server.url = "__DOMAIN__/notification" + notification_server.label = "Notification server" + notification_server.allowed = "visitors" + notification_server.auth_header = false + notification_server.show_tile = false + notification_server.protected = true + webdav.url = "__DOMAIN__/seafdav" webdav.label = "Webdav" webdav.allowed = "visitors" @@ -90,6 +96,13 @@ ram.runtime = "500M" webdav.protected = true webdav.show_tile = false + notification.url = "__DOMAIN__/notification" + notification.label = "Client-notification" + notification.allowed = "visitors" + notification.auth_header = false + notification.protected = true + notification.show_tile = false + media.url = "/media" media.label = "Media" media.allowed = "visitors" @@ -100,23 +113,22 @@ ram.runtime = "500M" [resources.ports] seahub.default = 8000 fileserver.default = 8082 + notificationserver.default = 8083 webdav.default = 8080 [resources.sources.main] - amd64.url = "https://s3.eu-central-1.amazonaws.com/download.seadrive.org/seafile-server_9.0.9_x86-64.tar.gz" - amd64.sha256 = "db76bb33572ad0a6860470e907bed4ed780aa17d9e022226d99448a7f9e4ba74" - arm64.url = "https://github.com/haiwen/seafile-rpi/releases/download/v9.0.9/seafile-server-9.0.9-bullseye-arm64v8l.tar.gz" - arm64.sha256 = "c58f5d6b741dec240be9d75d6e617102b7adbfeba98cbd866732822bf9ca10b7" - armhf.url = "https://github.com/haiwen/seafile-rpi/releases/download/v9.0.9/seafile-server-9.0.9-bullseye-arm32v7l.tar.gz" - armhf.sha256 = "171fcf08b726d452e1c4cd22dadb9f8f5cf6848424ebc1e04cde5be34ef3d7f6" + format = "docker" + extract = true + prefetch = false + + amd64.url = "seafileltd/seafile-mc:11.0.9" + amd64.sha256 = "564f122eae31e96c24be12c25affec7618fa574abf2ba381fadb8467e8e4ad4e" + + arm64.url = "seafileltd/seafile-mc:11.0.9" + arm64.sha256 = "57a78b0f80e8ecf272fca5fc3f2aff685239849f222bd358fbac4be0d4b280a2" [resources.apt] - packages = ["expect", "ffmpeg", - "python3", "python3-venv", "python3-setuptools", "python3-pip", "python3-dev", - "python3-requests", "python3-scipy", "python3-matplotlib", - "mariadb-server", "libmariadb-dev-compat", "libmariadb-dev", - "memcached", "libmemcached-dev", - "libjpeg62-turbo-dev", "zlib1g-dev", "libffi-dev"] + packages = ["mariadb-server", "memcached"] [resources.database] type = "mysql" diff --git a/scripts/_common.sh b/scripts/_common.sh index c557a8b..f65469b 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -2,89 +2,88 @@ # SET ALL CONSTANTS #================================================= -time_zone=$(cat /etc/timezone) -python_version="$(python3 -V | cut -d' ' -f2 | cut -d. -f1-2)" +readonly time_zone="$(cat /etc/timezone)" +readonly python_version="$(python3 -V | cut -d' ' -f2 | cut -d. -f1-2)" +systemd_seafile_bind_mount="$data_dir/seafile-data:/opt/seafile/seafile-data " +systemd_seafile_bind_mount+="$data_dir/seahub-data:/opt/seafile/seahub-data " +systemd_seafile_bind_mount+="/var/log/$app:/opt/seafile/logs " +systemd_seafile_bind_mount+="$install_dir/conf:/opt/seafile/conf " +systemd_seafile_bind_mount+="$install_dir/ccnet:/opt/seafile/ccnet " +systemd_seafile_bind_mount+="/proc " +systemd_seafile_bind_mount+="/dev" + +# Create special path with / at the end +if [[ "$path" == '/' ]] +then + readonly path2="$path" +else + readonly path2="$path/" +fi + +if [ "${LANG:0:2}" == C. ]; then + readonly language=en +else + readonly language="${LANG:0:2}" +fi #================================================= # DEFINE ALL COMMON FONCTIONS #================================================= -install_dependance() { - ynh_add_swap --size=2000 - - # Clean venv is it was on python3 with old version in case major upgrade of debian - if [ ! -e $install_dir/venv/bin/python3 ] || [ ! -e $install_dir/venv/lib/python$python_version ]; then - ynh_secure_remove --file=$install_dir/venv/bin - ynh_secure_remove --file=$install_dir/venv/lib - ynh_secure_remove --file=$install_dir/venv/lib64 - ynh_secure_remove --file=$install_dir/venv/include - ynh_secure_remove --file=$install_dir/venv/share - ynh_secure_remove --file=$install_dir/venv/pyvenv.cfg - fi - - # Create venv if it don't exist - test -e $install_dir/venv/bin/python3 || python3 -m venv $install_dir/venv - - u_arg='u' - set +$u_arg; - source $install_dir/venv/bin/activate - set -$u_arg; - - # Note that we install imageio to force the dependance, without this imageio 2.8 is installed and it need python3.5 - if [ $(lsb_release --codename --short) == "bookworm" ]; then - # Fix cffi installtion issue cf: https://github.com/haiwen/seahub/issues/5166 - pip3 install --upgrade 'cffi==1.15.1' - sed -e "s|1.14.0|1.15.1|" -i $install_dir/seafile-server-$seafile_version/seahub/thirdpart/cffi/__init__.py - else - pip3 install --upgrade cffi==1.14.0 - fi - if [ -n "$(uname -m | grep x86_64)" ]; then - py_dependancy="django==3.2.* Pillow<10.0.0 pylibmc captcha jinja2 SQLAlchemy<2 django-pylibmc django-simple-captcha python3-ldap mysqlclient pycryptodome==3.12.0 lxml python3-ldap" - else - py_dependancy="lxml python3-ldap" - fi - pip3 install --upgrade --timeout=3600 $py_dependancy - - set +$u_arg; - deactivate - set -$u_arg; - ynh_del_swap - - # Create symbolic link to venv package on seahub - ls $install_dir/venv/lib/python$python_version/site-packages | while read f; do - if [ ! -e "$install_dir/seafile-server-$seafile_version/seahub/thirdpart/$f" ]; then - ln -s ../../../venv/lib/python$python_version/site-packages/$f $install_dir/seafile-server-$seafile_version/seahub/thirdpart/$f - fi - done +run_seafile_cmd() { + ynh_exec_warn_less systemd-run --wait --uid="$app" --gid="$app" \ + --property=RootDirectory="$install_dir"/seafile_image \ + --property="BindPaths=$systemd_seafile_bind_mount" \ + $@ } -mv_expect_scripts() { - expect_scripts_dir=$(mktemp -d) - cp expect_scripts/* $expect_scripts_dir - chmod u=rwx,o= -R $expect_scripts_dir - chown $YNH_APP_ID -R $expect_scripts_dir +install_source() { + ynh_setup_source_custom --dest_dir="$install_dir"/seafile_image --full_replace + mkdir -p "$install_dir"/seafile_image/opt/seafile/{seafile-data,seahub-data,conf,ccnet,logs} + grep "^$app:x" /etc/passwd | sed "s|$install_dir|/opt/seafile|" >> "$install_dir"/seafile_image/etc/passwd + grep "^$app:x" /etc/group >> "$install_dir"/seafile_image/etc/group + grep "^$app:x" /etc/group- >> "$install_dir"/seafile_image/etc/group- + grep "^$app:" /etc/shadow >> "$install_dir"/seafile_image/etc/shadow } set_permission() { - chown -R $YNH_APP_ID:$YNH_APP_ID $install_dir - chmod -R u+rwX,g-wx,o= $install_dir - setfacl -m user:www-data:rX $install_dir - setfacl -m user:www-data:rX $install_dir/seafile-server-$seafile_version - # At install time theses directory are not available - test -e $install_dir/seafile-server-latest/seahub && setfacl -m user:www-data:rX $install_dir/seafile-server-latest/seahub - test -e $install_dir/seafile-server-latest/seahub/media && setfacl -R -m user:www-data:rX $install_dir/seafile-server-latest/seahub/media - test -e $install_dir/seahub-data && setfacl -R -m user:www-data:rX $install_dir/seahub-data + chown -R "$app:$app" "$install_dir"/{conf,ccnet} + chmod -R u+rwX,g-w,o= "$install_dir"/{conf,ccnet} + chown -R "$app:$app" "$install_dir"/seafile_image/opt/seafile + chmod -R u+rwX,g-w,o= "$install_dir"/seafile_image/opt/seafile - find $data_dir \( \! -perm -o= \ - -o \! -user $YNH_APP_ID \ - -o \! -group $YNH_APP_ID \) \ - -exec chown $YNH_APP_ID:$YNH_APP_ID {} \; \ + # Allow to www-data to each dir between /opt/yunohost/seafile and /opt/yunohost/seafile/seafile_image/opt/seafile/seahub/media + local dir_path='' + while read -r -d/ dir_name; do + dir_path+="$dir_name/" + if [[ "$dir_path" == "$install_dir"* ]] && [ -e "$dir_path" ]; then + setfacl -m user:www-data:rX "$dir_path" + fi + done <<< "$seafile_code/seahub/media" + test -e "$install_dir/seafile_image/opt/seafile/seahub-data" && setfacl -m user:www-data:rX "$install_dir/seafile_image/opt/seafile/seahub-data" + test -e "$seafile_code/seahub/media" && setfacl -R -m user:www-data:rX "$seafile_code/seahub/media" + + # At install time theses directory are not available + test -e "$install_dir"/seahub-data && setfacl -m user:www-data:rX "$data_dir" + test -e "$install_dir"/seahub-data && setfacl -R -m user:www-data:rX "$data_dir"/seahub-data + + find "$data_dir" \( \! -perm -o= \ + -o \! -user "$app" \ + -o \! -group "$app" \) \ + -exec chown "$app:$app" {} \; \ -exec chmod o= {} \; } clean_url_in_db_config() { sql_request='DELETE FROM `constance_config` WHERE `constance_key`= "SERVICE_URL"' - ynh_mysql_execute_as_root --sql "$sql_request" --database seahubdb + ynh_mysql_execute_as_root --sql="$sql_request" --database=seahubdb sql_request='DELETE FROM `constance_config` WHERE `constance_key`= "FILE_SERVER_ROOT"' - ynh_mysql_execute_as_root --sql "$sql_request" --database seahubdb + ynh_mysql_execute_as_root --sql="$sql_request" --database=seahubdb +} + +ensure_vars_set() { + if [ -z "${jwt_private_key_notification_server:-}" ]; then + jwt_private_key_notification_server=$(ynh_string_random -l 32) + ynh_app_setting_set --app="$app" --key=jwt_private_key_notification_server --value="$jwt_private_key_notification_server" + fi } diff --git a/scripts/backup b/scripts/backup index b5a8e07..c5d9791 100644 --- a/scripts/backup +++ b/scripts/backup @@ -11,10 +11,10 @@ source ../settings/scripts/_common.sh # Source YunoHost helpers source /usr/share/yunohost/helpers -# retrieve useful param seafile_version=$(ynh_app_upstream_version) +seafile_code="$install_dir/seafile_image/opt/seafile/seafile-server-$seafile_version" -if [[ ! "$(systemctl status seafile)" =~ "Active: inactive (dead)" ]] || [[ ! "$(systemctl status seahub)" =~ "Active: failed (Result: signal)" ]]; then +if systemctl is-active seafile --quiet || systemctl is-active seahub --quiet; then ynh_print_warn --message="It's hightly recommended to make your backup when the service is stopped. Please stop seafile service and seahub service with this command before to run the backup 'systemctl stop seafile.service seahub.service'" fi @@ -24,20 +24,23 @@ fi # # Backup app files ynh_print_info --message="Backing up code..." -ynh_backup --src_path $install_dir +ynh_backup --src_path="$install_dir" ynh_print_info --message="Backing up user data..." -ynh_backup --src_path=$data_dir --dest_path="data" --is_big=1 +ynh_backup --src_path="$data_dir" --dest_path="data" --is_big=1 ynh_print_info --message="Backing up configuration..." -ynh_backup --src_path /etc/nginx/conf.d/$domain.d/${app}.conf -ynh_backup --src_path /etc/systemd/system/seafile.service -ynh_backup --src_path /etc/systemd/system/seahub.service -ynh_backup --src_path /etc/fail2ban/jail.d/$app.conf -ynh_backup --src_path /etc/fail2ban/filter.d/$app.conf +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/${app}.conf" +ynh_backup --src_path=/etc/systemd/system/seafile.service +ynh_backup --src_path=/etc/systemd/system/seahub.service +ynh_backup --src_path=/etc/fail2ban/jail.d/"$app".conf +ynh_backup --src_path=/etc/fail2ban/filter.d/"$app".conf + +# Backup logs +ynh_backup --src_path="/var/log/$app" # Backup mysql ynh_print_info --message="Backing up database" -ynh_mysql_dump_db --database $db_name > ${YNH_CWD}/seafiledb.dmp -ynh_mysql_dump_db --database ccnetdb > ${YNH_CWD}/ccnetdb.dmp -ynh_mysql_dump_db --database seahubdb > ${YNH_CWD}/seahubdb.dmp +ynh_mysql_dump_db --database="$db_name" > "${YNH_CWD}"/seafiledb.dmp +ynh_mysql_dump_db --database=ccnetdb > "${YNH_CWD}"/ccnetdb.dmp +ynh_mysql_dump_db --database=seahubdb > "${YNH_CWD}"/seahubdb.dmp ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/change_url b/scripts/change_url index 7b0649d..cdbb140 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -11,45 +11,8 @@ source ./_common.sh # Source YunoHost helpers source /usr/share/yunohost/helpers -path=$new_path -domain=$new_domain - -# Create special path with / at the end -if [[ $path == '/' ]] -then - path2=$path -else - path2=$path"/" -fi - -# Patch helper - -ynh_change_url_nginx_config() { - local old_nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf - local new_nginx_conf_path=/etc/nginx/conf.d/$new_domain.d/$app.conf - - # Change the domain for NGINX - if [ $change_domain -eq 1 ] - then - ynh_delete_file_checksum --file="$old_nginx_conf_path" - mv "$old_nginx_conf_path" "$new_nginx_conf_path" - ynh_store_file_checksum --file="$new_nginx_conf_path" - fi - - # Change the path in the NGINX config file - if [ $change_path -eq 1 ] - then - # Make a backup of the original NGINX config file if modified - ynh_backup_if_checksum_is_different --file="$new_nginx_conf_path" - # Set global variables for NGINX helper - path="$new_path" - path_url="$new_path" - # Create a dedicated NGINX config - ynh_add_nginx_config - fi - - ynh_systemd_action --service_name=nginx --action=reload -} +seafile_version="$(ynh_app_upstream_version)" +seafile_code="$install_dir/seafile_image/opt/seafile/seafile-server-$seafile_version" #================================================= # STANDARD MODIFICATIONS @@ -65,8 +28,8 @@ ynh_change_url_nginx_config ynh_script_progression --message="Stoping services..." # Stop service before any change -ynh_systemd_action --service_name seafile --action stop -ynh_systemd_action --service_name seahub --action stop +ynh_systemd_action --service_name=seafile --action=stop +ynh_systemd_action --service_name=seahub --action=stop sleep 2 pkill -f seafile-controller || true pkill -f seaf-server || true @@ -76,14 +39,14 @@ pkill -f seahub || true ynh_script_progression --message="Updating seafile configuration..." # Update Seafile Config -ynh_add_config --template=seahub_settings.py --destination=$install_dir/conf/seahub_settings.py -ynh_add_config --template=ccnet.conf --destination=$install_dir/conf/ccnet.conf -ynh_add_config --template=gunicorn.conf.py --destination=$install_dir/conf/gunicorn.conf.py -ynh_add_config --template=seafdav.conf --destination=$install_dir/conf/seafdav.conf +ynh_add_config --jinja --template=seahub_settings.py --destination="$install_dir"/conf/seahub_settings.py +ynh_add_config --template=ccnet.conf --destination="$install_dir"/conf/ccnet.conf +ynh_add_config --template=gunicorn.conf.py --destination="$install_dir"/conf/gunicorn.conf.py +ynh_add_config --template=seafdav.conf --destination="$install_dir"/conf/seafdav.conf # Update permissions -ynh_permission_url --permission=file_server --url=$domain/seafhttp -ynh_permission_url --permission=webdav --url=$domain/seafdav +ynh_permission_url --permission=file_server --url="$domain"/seafhttp +ynh_permission_url --permission=webdav --url="$domain"/seafdav # Clean url in config in DB clean_url_in_db_config @@ -93,8 +56,8 @@ sleep 2 # Reload services ynh_script_progression --message="Starting services..." -ynh_systemd_action --service_name seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log -ynh_systemd_action --service_name seahub -l "Started Seafile hub." -p "systemd" +ynh_systemd_action --service_name=seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log +ynh_systemd_action --service_name=seahub -l "Started Seafile hub." -p "systemd" sleep 2 -ynh_script_progression --message="Change of URL completed for $app" --time --last +ynh_script_progression --message="Change of URL completed for $app" --time=--last diff --git a/scripts/expect_scripts/install.exp b/scripts/expect_scripts/install.exp deleted file mode 100644 index b370f52..0000000 --- a/scripts/expect_scripts/install.exp +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/expect -set timeout 10 - -set seafile_dir [lindex $argv 0] -set server_name [lindex $argv 1] -set domain [lindex $argv 2] -set fileserver_port [lindex $argv 3] -set db_name [lindex $argv 4] -set db_pwd [lindex $argv 5] - -spawn $seafile_dir/setup-seafile-mysql.sh - -expect "Press ENTER to continue" -send "\r"; - -expect "What is the name of the server? It will be displayed on the client." -send "$server_name\r"; - -expect "What is the ip or domain of the server?" -send "$domain\r"; - -expect "Which port do you want to use for the seafile fileserver?" -send "$fileserver_port\r"; - -expect "Use existing ccnet/seafile/seahub databases" -send "2\r"; - -expect "What is the host of mysql server?" -send "localhost\r"; - -expect "What is the port of mysql server?" -send "3306\r"; - -expect "Which mysql user to use for seafile?" -send "seafile\r"; - -expect "What is the password for mysql user" -send "$db_pwd\r"; - -expect "Enter the existing database name for ccnet:" -send "ccnetdb\r"; - -expect "Enter the existing database name for seafile:" -send "$db_name\r"; - -expect "Enter the existing database name for seahub:" -send "seahubdb\r"; - -expect "Press ENTER to continue, or Ctrl-C to abort" -send "\r"; - -interact - -wait diff --git a/scripts/expect_scripts/minor-upgrade.exp b/scripts/expect_scripts/minor-upgrade.exp deleted file mode 100644 index 0d3cd97..0000000 --- a/scripts/expect_scripts/minor-upgrade.exp +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/expect -set timeout 5 - -set seafile_dir [lindex $argv 0] -set mysql_password [lindex $argv 1] - -spawn $seafile_dir/upgrade/minor-upgrade.sh - -expect "to contiune" -send "\r"; - -interact diff --git a/scripts/expect_scripts/upgrade_4.2.1.exp b/scripts/expect_scripts/upgrade_4.2.1.exp deleted file mode 100644 index 39d921f..0000000 --- a/scripts/expect_scripts/upgrade_4.2.1.exp +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/expect -set timeout 5 - -set seafile_dir [lindex $argv 0] - -spawn $seafile_dir/upgrade/upgrade_4.1_4.2.sh - -expect "to contiune" -send "\r"; - -interact diff --git a/scripts/expect_scripts/upgrade_4.3.2.exp b/scripts/expect_scripts/upgrade_4.3.2.exp deleted file mode 100644 index 1e5ae01..0000000 --- a/scripts/expect_scripts/upgrade_4.3.2.exp +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/expect -set timeout 5 - -set seafile_dir [lindex $argv 0] - -spawn $seafile_dir/upgrade/upgrade_4.2_4.3.sh - -expect "to contiune" -send "\r"; - -interact diff --git a/scripts/expect_scripts/upgrade_4.4.3.exp b/scripts/expect_scripts/upgrade_4.4.3.exp deleted file mode 100644 index 1738a74..0000000 --- a/scripts/expect_scripts/upgrade_4.4.3.exp +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/expect -set timeout 5 - -set seafile_dir [lindex $argv 0] - -spawn $seafile_dir/upgrade/upgrade_4.3_4.4.sh - -expect "to contiune" -send "\r"; - -interact diff --git a/scripts/expect_scripts/upgrade_5.0.3.exp b/scripts/expect_scripts/upgrade_5.0.3.exp deleted file mode 100644 index 397deed..0000000 --- a/scripts/expect_scripts/upgrade_5.0.3.exp +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/expect -set timeout 5 - -set seafile_dir [lindex $argv 0] - -spawn $seafile_dir/upgrade/upgrade_4.4_5.0.sh - -expect "to contiune" -send "\r"; - -interact diff --git a/scripts/expect_scripts/upgrade_5.1.exp b/scripts/expect_scripts/upgrade_5.1.exp deleted file mode 100644 index 5f82501..0000000 --- a/scripts/expect_scripts/upgrade_5.1.exp +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/expect -set timeout 5 - -set seafile_dir [lindex $argv 0] - -spawn $seafile_dir/upgrade/upgrade_5.0_5.1.sh - -expect "to contiune" -send "\r"; - -interact diff --git a/scripts/expect_scripts/upgrade_6.0.exp b/scripts/expect_scripts/upgrade_6.0.exp deleted file mode 100644 index b5a3143..0000000 --- a/scripts/expect_scripts/upgrade_6.0.exp +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/expect -set timeout 5 - -set seafile_dir [lindex $argv 0] - -spawn $seafile_dir/upgrade/upgrade_5.1_6.0.sh - -expect "to contiune" -send "\r"; - -interact diff --git a/scripts/expect_scripts/upgrade_6.1.exp b/scripts/expect_scripts/upgrade_6.1.exp deleted file mode 100644 index fd50049..0000000 --- a/scripts/expect_scripts/upgrade_6.1.exp +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/expect -set timeout 5 - -set seafile_dir [lindex $argv 0] - -spawn $seafile_dir/upgrade/upgrade_6.0_6.1.sh - -expect "to contiune" -send "\r"; - -interact diff --git a/scripts/expect_scripts/upgrade_6.2.exp b/scripts/expect_scripts/upgrade_6.2.exp deleted file mode 100644 index cf80453..0000000 --- a/scripts/expect_scripts/upgrade_6.2.exp +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/expect -set timeout 5 - -set seafile_dir [lindex $argv 0] - -spawn $seafile_dir/upgrade/upgrade_6.1_6.2.sh - -expect "to contiune" -send "\r"; - -interact diff --git a/scripts/expect_scripts/upgrade_6.3.exp b/scripts/expect_scripts/upgrade_6.3.exp deleted file mode 100644 index 13a5f44..0000000 --- a/scripts/expect_scripts/upgrade_6.3.exp +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/expect -set timeout 5 - -set seafile_dir [lindex $argv 0] - -spawn $seafile_dir/upgrade/upgrade_6.2_6.3.sh - -expect "to contiune" -send "\r"; - -interact diff --git a/scripts/expect_scripts/upgrade_7.0.exp b/scripts/expect_scripts/upgrade_7.0.exp deleted file mode 100644 index 271cf59..0000000 --- a/scripts/expect_scripts/upgrade_7.0.exp +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/expect -set timeout 5 - -set seafile_dir [lindex $argv 0] - -spawn $seafile_dir/upgrade/upgrade_6.3_7.0.sh - -expect "to contiune" -send "\r"; - -interact diff --git a/scripts/expect_scripts/upgrade_7.1.exp b/scripts/expect_scripts/upgrade_7.1.exp deleted file mode 100644 index fbc63c7..0000000 --- a/scripts/expect_scripts/upgrade_7.1.exp +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/expect -set timeout 5 - -set seafile_dir [lindex $argv 0] - -spawn $seafile_dir/upgrade/upgrade_7.0_7.1.sh - -expect "to contiune" -send "\r"; - -sleep 10; - -send "\r"; - -sleep 1; - -send "\r"; - -interact diff --git a/scripts/expect_scripts/upgrade_8.0.exp b/scripts/expect_scripts/upgrade_8.0.exp deleted file mode 100644 index 6c86c2b..0000000 --- a/scripts/expect_scripts/upgrade_8.0.exp +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/expect -set timeout 5 - -set seafile_dir [lindex $argv 0] - -spawn $seafile_dir/upgrade/upgrade_8.0_9.0.sh - -expect "to contiune" -send "\r"; - -interact diff --git a/scripts/expect_scripts/upgrade_9.0.exp b/scripts/expect_scripts/upgrade_9.0.exp deleted file mode 100644 index 0816a57..0000000 --- a/scripts/expect_scripts/upgrade_9.0.exp +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/expect -set timeout 5 - -set seafile_dir [lindex $argv 0] - -spawn $seafile_dir/upgrade/upgrade_7.1_8.0.sh - -expect "to contiune" -send "\r"; - -interact diff --git a/scripts/experimental_helper.sh b/scripts/experimental_helper.sh index 26538a9..e69de29 100644 --- a/scripts/experimental_helper.sh +++ b/scripts/experimental_helper.sh @@ -1,99 +0,0 @@ -#!/bin/bash - -# Add swap -# -# usage: ynh_add_swap --size=SWAP in Mb -# | arg: -s, --size= - Amount of SWAP to add in Mb. -ynh_add_swap () { - # Declare an array to define the options of this helper. - declare -Ar args_array=( [s]=size= ) - local size - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - - local swap_max_size=$(( $size * 1024 )) - - local free_space=$(df --output=avail / | sed 1d) - # Because we don't want to fill the disk with a swap file, divide by 2 the available space. - local usable_space=$(( $free_space / 2 )) - - SD_CARD_CAN_SWAP=${SD_CARD_CAN_SWAP:-0} - - # Swap on SD card only if it's is specified - if ynh_is_main_device_a_sd_card && [ "$SD_CARD_CAN_SWAP" == "0" ] - then - ynh_print_warn --message="The main mountpoint of your system '/' is on an SD card, swap will not be added to prevent some damage of this one, but that can cause troubles for the app $app. If you still want activate the swap, you can relaunch the command preceded by 'SD_CARD_CAN_SWAP=1'" - return - fi - - # Compare the available space with the size of the swap. - # And set a acceptable size from the request - if [ $usable_space -ge $swap_max_size ] - then - local swap_size=$swap_max_size - elif [ $usable_space -ge $(( $swap_max_size / 2 )) ] - then - local swap_size=$(( $swap_max_size / 2 )) - elif [ $usable_space -ge $(( $swap_max_size / 3 )) ] - then - local swap_size=$(( $swap_max_size / 3 )) - elif [ $usable_space -ge $(( $swap_max_size / 4 )) ] - then - local swap_size=$(( $swap_max_size / 4 )) - else - echo "Not enough space left for a swap file" >&2 - local swap_size=0 - fi - - # If there's enough space for a swap, and no existing swap here - if [ $swap_size -ne 0 ] && [ ! -e /swap_$app ] - then - # Create file - truncate -s 0 /swap_$app - - # set the No_COW attribute on the swapfile with chattr - chattr +C /swap_$app || true - - # Preallocate space for the swap file, fallocate may sometime not be used, use dd instead in this case - if ! fallocate -l ${swap_size}K /swap_$app - then - dd if=/dev/zero of=/swap_$app bs=1024 count=${swap_size} - fi - chmod 0600 /swap_$app - # Create the swap - mkswap /swap_$app - # And activate it - swapon /swap_$app || true - # Then add an entry in fstab to load this swap at each boot. - echo -e "/swap_$app swap swap defaults 0 0 #Swap added by $app" >> /etc/fstab - fi -} - -ynh_del_swap () { - # If there a swap at this place - if [ -e /swap_$app ] - then - # Clean the fstab - sed -i "/#Swap added by $app/d" /etc/fstab - # Desactive the swap file - swapoff /swap_$app || true - # And remove it - rm /swap_$app - fi -} - -# Check if the device of the main mountpoint "/" is an SD card -# -# [internal] -# -# return 0 if it's an SD card, else 1 -ynh_is_main_device_a_sd_card () { - local main_device=$(lsblk --output PKNAME --noheadings $(findmnt / --nofsroot --uniq --output source --noheadings --first-only)) - - if echo $main_device | grep --quiet "mmc" && [ $(tail -n1 /sys/block/$main_device/queue/rotational) == "0" ] - then - return 0 - else - return 1 - fi -} diff --git a/scripts/install b/scripts/install index a81d5f6..b883257 100644 --- a/scripts/install +++ b/scripts/install @@ -7,80 +7,113 @@ # Import common cmd source ./experimental_helper.sh source ./_common.sh +source ./ynh_setup_source # Source YunoHost helpers source /usr/share/yunohost/helpers seafile_version=$(ynh_app_upstream_version) +seafile_code="$install_dir/seafile_image/opt/seafile/seafile-server-$seafile_version" -# Create special path with / at the end -if [[ $path == '/' ]] -then - path2=$path -else - path2=$path"/" -fi +ensure_vars_set #================================================= # STANDARD MODIFICATIONS #================================================= ynh_script_progression --message="Creating base directory..." -ln -s $data_dir $install_dir/seafile-data + +if [ -n "$(ls -A "$data_dir")" ]; then + old_data_dir_path="${data_dir}_$(date '+%Y%m%d.%H%M%S')" + ynh_print_warn "Data directory was not empty. Data was moved to $old_data_dir_path" + mkdir -p "$old_data_dir_path" + mv -t "$old_data_dir_path" "$data_dir"/* +fi + +mkdir -p /var/log/"$app" +mkdir -p "$data_dir"/{seafile-data,seahub-data} +mkdir -p "$install_dir"/{conf,ccnet} # Download new version from sources ynh_script_progression --message="Installing sources files..." --weight=7 -ynh_setup_source --dest_dir=$install_dir/seafile-server-$seafile_version - -ynh_script_progression --message="Installing python dependancies..." -install_dependance +install_source # init databases ynh_script_progression --message="Configuring MySQL database..." db_user=seafile -db_helper=ynh_"mysql"_setup_db -$db_helper --db_user $db_user --db_name ccnetdb --db_pwd "$db_pwd" -$db_helper --db_user $db_user --db_name seahubdb --db_pwd "$db_pwd" +ynh_''mysql_setup_db --db_user="$db_user" --db_name=ccnetdb --db_pwd="$db_pwd" +ynh_''mysql_setup_db --db_user="$db_user" --db_name=seahubdb --db_pwd="$db_pwd" ynh_script_progression --message="Configuring application..." --weight=3 # Run install script -mv_expect_scripts -chmod +x $install_dir/seafile-server-$seafile_version/setup-seafile-mysql.sh set_permission -sudo -u $YNH_APP_ID $expect_scripts_dir/install.exp "$install_dir/seafile-server-$seafile_version" "$server_name" "$domain" "$port_fileserver" "$db_name" "$db_pwd" - -sleep 3 +ynh_replace_special_string --match_string='seafile_config.seafile_dir = seafile_config.validate_seafile_dir(seafile_dir)' \ + --replace_string='seafile_config.seafile_dir = seafile_dir' \ + --target_file="$seafile_code/setup-seafile-mysql.py" +ynh_replace_special_string --match_string="Utils.error('Ccnet config dir \\\"%s\\\" already exists.' % ccnet_config.ccnet_dir)" \ + --replace_string='patched = 1' \ + --target_file="$seafile_code/setup-seafile-mysql.py" +run_seafile_cmd bash "/opt/seafile/seafile-server-$seafile_version/setup-seafile-mysql.sh" auto \ + --server-name "$server_name" \ + --server-ip "$domain" \ + --fileserver-port "$port_fileserver" \ + --use-existing-db 1 \ + --mysql-host localhost \ + --mysql-port 3306 \ + --mysql-user "$db_user" \ + --mysql-user-passwd "$db_pwd" \ + -s "$db_name" \ + -c ccnetdb \ + -b seahubdb # Retrive values from auto generated config file -seahub_secret_key=$(grep -P 'SECRET_KEY\s*=\s*".+"' $install_dir/conf/seahub_settings.py | cut -d'"' -f2) -ynh_app_setting_set --app $app --key seahub_secret_key --value $seahub_secret_key +seahub_secret_key=$(grep -P 'SECRET_KEY\s*=\s*".+"' "$install_dir"/conf/seahub_settings.py | cut -d'"' -f2) +ynh_app_setting_set --app="$app" --key=seahub_secret_key --value="$seahub_secret_key" # Update seafile config files -ynh_add_config --template=seahub_settings.py --destination=$install_dir/conf/seahub_settings.py -ynh_add_config --template=seafile.conf --destination=$install_dir/conf/seafile.conf -ynh_add_config --template=ccnet.conf --destination=$install_dir/conf/ccnet.conf -ynh_add_config --template=gunicorn.conf.py --destination=$install_dir/conf/gunicorn.conf.py -ynh_add_config --template=seafdav.conf --destination=$install_dir/conf/seafdav.conf +ynh_add_config --jinja --template=seahub_settings.py --destination="$install_dir"/conf/seahub_settings.py +ynh_add_config --template=seafile.conf --destination="$install_dir"/conf/seafile.conf +ynh_add_config --template=ccnet.conf --destination="$install_dir"/conf/ccnet.conf +ynh_add_config --template=gunicorn.conf.py --destination="$install_dir"/conf/gunicorn.conf.py +ynh_add_config --template=seafdav.conf --destination="$install_dir"/conf/seafdav.conf +ynh_add_config --template=seafevents.conf --destination="$install_dir"/conf/seafevents.conf # Configure admin info # It will be used the first start -admin_email=$(ynh_user_get_info --username $admin --key 'mail') +admin_email=$(ynh_user_get_info --username="$admin" --key='mail') cp ../conf/create_admin.json $install_dir/conf/admin.txt -ynh_replace_string --match_string __ADMIN__ --replace_string $admin_email --target_file $install_dir/conf/admin.txt -ynh_replace_special_string --match_string __PASSWORD__ --replace_string $admin_password --target_file $install_dir/conf/admin.txt +ynh_replace_string --match_string=__ADMIN__ --replace_string="$admin_email" --target_file=$install_dir/conf/admin.txt +ynh_replace_special_string --match_string=__PASSWORD__ --replace_string="$admin_password" --target_file=$install_dir/conf/admin.txt + +# Use symlink to store data +if [ -e "$install_dir"/seafile-data ]; then + mv -t "$data_dir"/seafile-data "$install_dir"/seafile-data/* + ynh_secure_remove --file="$install_dir"/seafile-data +fi +if [ -e "$install_dir"/seahub-data ]; then + mv -t "$data_dir"/seahub-data "$install_dir"/seahub-data/* + ynh_secure_remove --file="$install_dir"/seahub-data +fi +if [ -e "$install_dir"/logs ]; then + mv -t /var/log/"$app" "$install_dir"/logs/* + ynh_secure_remove --file="$install_dir"/logs +fi +ln -s "$data_dir"/seafile-data "$install_dir"/seafile-data +ln -s "$data_dir"/seahub-data "$install_dir"/seahub-data +ln -s /var/log/"$app" "$install_dir"/logs # Fix local warning -ynh_replace_string --match_string en_US.UTF-8 --replace_string ${LANG:-'en_US.UTF-8'} --target_file $install_dir/seafile-server-$seafile_version/seahub.sh +ynh_replace_string --match_string=en_US.UTF-8 --replace_string="${LANG:-'en_US.UTF-8'}" --target_file="$seafile_code/seahub.sh" # Add Seafile Server to startup ynh_script_progression --message="Configuring a systemd service..." -ynh_add_systemd_config --service seafile --template seafile.service -ynh_add_systemd_config --service seahub --template seahub.service +ynh_add_systemd_config --service=seafile --template=seafile.service +ynh_add_systemd_config --service=seahub --template=seahub.service # register yunohost service -yunohost service add seafile -yunohost service add seahub +yunohost service add seafile --description 'Main service for seafile server.' +yunohost service add seahub --description 'Seafile server web interface.' # Config nginx ynh_script_progression --message="Configuring nginx..." @@ -88,12 +121,10 @@ ynh_add_nginx_config # Add logrotate ynh_script_progression --message="Configuring log rotation..." -ynh_use_logrotate --logfile $install_dir/logs -ln -s $install_dir/logs /var/log/seafile +ynh_use_logrotate --logfile=/var/log/"$app" # Add fail2ban ynh_script_progression --message="Configuring fail2ban..." -touch $install_dir/logs/seahub.log ynh_add_fail2ban_config --use_template #================================================= @@ -108,9 +139,9 @@ set_permission sleep 3 ynh_script_progression --message="Starting seafile services..." -ynh_systemd_action --service_name seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log +ynh_systemd_action --service_name=seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log sleep 2 -ynh_systemd_action --service_name seahub -l "Started Seafile hub." -p "systemd" +ynh_systemd_action --service_name=seahub -l "Started Seafile hub." -p "systemd" sleep 2 ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove index aafe721..dd8fbd5 100644 --- a/scripts/remove +++ b/scripts/remove @@ -11,6 +11,9 @@ source ./_common.sh # Source YunoHost helpers source /usr/share/yunohost/helpers +seafile_version="$(ynh_app_upstream_version)" +seafile_code="$install_dir/seafile_image/opt/seafile/seafile-server-$seafile_version" + #================================================= # STANDARD REMOVE #================================================= @@ -18,8 +21,8 @@ source /usr/share/yunohost/helpers ynh_script_progression --message="Stoping services..." # Stop all services -ynh_systemd_action --service_name seafile --action stop -ynh_systemd_action --service_name seahub --action stop +ynh_systemd_action --service_name=seafile --action=stop +ynh_systemd_action --service_name=seahub --action=stop # Force to kill all process in case of a process is not stoped cleanly pkill -f seafile-controller || true @@ -27,11 +30,9 @@ pkill -f seaf-server || true pkill -f ccnet-server || true pkill -f seahub || true -ynh_script_progression --message="Removing logs..." -ynh_secure_remove --file=/var/log/seafile ynh_script_progression --message="Removing code..." -ynh_secure_remove --file=/var/www/$app -ynh_secure_remove --file=/opt/yunohost/$app +ynh_secure_remove --file=/var/www/"$app" +ynh_secure_remove --file=/opt/yunohost/"$app" # Remove databases ynh_script_progression --message="Removing databases..." @@ -41,8 +42,8 @@ $db_helper --db_name seahubdb --db_user seafile # Remove systemd service ynh_script_progression --message="Removing systemd units..." -ynh_remove_systemd_config --service seafile -ynh_remove_systemd_config --service seahub +ynh_remove_systemd_config --service=seafile +ynh_remove_systemd_config --service=seahub # Remove nginx config ynh_script_progression --message="Removing nginx configuration..." diff --git a/scripts/restore b/scripts/restore index b88f319..95587b1 100644 --- a/scripts/restore +++ b/scripts/restore @@ -11,10 +11,10 @@ source ../settings/scripts/_common.sh # Source YunoHost helpers source /usr/share/yunohost/helpers -ynh_script_progression --message="Loading settings..." +seafile_version="$(ynh_app_upstream_version)" +seafile_code="$install_dir/seafile_image/opt/seafile/seafile-server-$seafile_version" -# Retrieve arguments -seafile_version=$(ynh_app_upstream_version) +ynh_script_progression --message="Loading settings..." #================================================= # STANDARD RESTORATION STEPS @@ -27,8 +27,8 @@ ynh_restore # Restore mysql dump ynh_script_progression --message="Restoring database..." --weight=3 db_helper=ynh_"mysql"_setup_db -$db_helper --db_user $db_user --db_name ccnetdb --db_pwd "$db_pwd" -$db_helper --db_user $db_user --db_name seahubdb --db_pwd "$db_pwd" +$db_helper --db_user "$db_user" --db_name ccnetdb --db_pwd "$db_pwd" +$db_helper --db_user "$db_user" --db_name seahubdb --db_pwd "$db_pwd" su -c "mysql -u ${app} -p$db_pwd $db_name < ${YNH_CWD}/seafiledb.dmp" su -c "mysql -u ${app} -p$db_pwd ccnetdb < ${YNH_CWD}/ccnetdb.dmp" su -c "mysql -u ${app} -p$db_pwd seahubdb < ${YNH_CWD}/seahubdb.dmp" @@ -39,8 +39,8 @@ su -c "mysql -u ${app} -p$db_pwd seahubdb < ${YNH_CWD}/seahubdb.dmp" # Add logrotate ynh_script_progression --message="Configuring log rotation..." -ynh_use_logrotate --logfile $install_dir/logs -ln -s $install_dir/logs /var/log/seafile +mkdir -p /var/log/"$app" +ynh_use_logrotate --logfile="$install_dir"/logs # Set all permissions ynh_script_progression --message="Protecting directory..." @@ -54,8 +54,8 @@ systemctl enable seahub --quiet # Add Seafile to YunoHost's monitored services ynh_script_progression --message="Register seafile service..." -yunohost service add seafile -yunohost service add seahub +yunohost service add seafile --description 'Main service for seafile server.' +yunohost service add seahub --description 'Seafile server web interface.' ynh_script_progression --message="Reloading services..." @@ -70,8 +70,8 @@ sleep 5 # Restart service ynh_script_progression --message="Starting seafile services..." --weight=3 -ynh_systemd_action --service_name seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log -ynh_systemd_action --service_name seahub -l "Started Seafile hub." -p "systemd" +ynh_systemd_action --service_name=seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log +ynh_systemd_action --service_name=seahub -l "Started Seafile hub." -p "systemd" sleep 2 ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index 995c446..4b037bd 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,40 +7,26 @@ # Import common cmd source ./experimental_helper.sh source ./_common.sh +source ./ynh_setup_source # Source YunoHost helpers source /usr/share/yunohost/helpers -# Retrieve arguments -installed_version=${YNH_APP_CURRENT_VERSION/~ynh*/} -seafile_version=$(ynh_app_upstream_version) +seafile_version="$(ynh_app_upstream_version)" +installed_version="${YNH_APP_CURRENT_VERSION/~ynh*/}" -# Create special path with / at the end -if [[ $path == '/' ]] -then - path2=$path -else - path2=$path"/" -fi +seafile_code="$install_dir/seafile_image/opt/seafile/seafile-server-$seafile_version" -if [ "$YNH_APP_CURRENT_VERSION" == '-' ]; then +ensure_vars_set + +if [ "$YNH_APP_CURRENT_VERSION" == '-' ] || ynh_compare_current_package_version --comparison=le --version='7.0~ynh1'; then ynh_die "Upgrade from this version not supported" fi ynh_script_progression --message="Stoping services..." -# stop seafile server -if [ -e /etc/init.d/seafile-server ] -then - # Old init script support - systemctl stop seafile-server --quiet - systemctl disable seafile-server --quiet - ynh_secure_remove --file=/etc/init.d/seafile-server - yunohost service remove seafile-server -else - ynh_systemd_action --service_name seafile --action stop - ynh_systemd_action --service_name seahub --action stop -fi +ynh_systemd_action --service_name=seafile --action=stop +ynh_systemd_action --service_name=seahub --action=stop sleep 5 pkill -f seafile-controller || true pkill -f seaf-server || true @@ -56,46 +42,76 @@ if mysqlshow | grep -q seafiledb; then $mysqlconn -e "RENAME TABLE seafiledb.$name to $db_name.$name"; done; $mysqlconn -e "DROP DATABASE seafiledb" + ynh_replace_string --match_string='db_name = seafiledb' --replace_string='db_name = seafile' --target_file="$install_dir"/conf/seafile.conf + sed -i "s|password\s*=\s*.*^|password = $db_pwd|g" "$install_dir"/conf/seafile.conf fi # Set missing settings -if [ -z ${seahub_secret_key:-} ]; then - seahub_secret_key=$(grep -P 'SECRET_KEY\s*=\s*".+"' $install_dir/conf/seahub_settings.py | cut -d'"' -f2) - ynh_app_setting_set --app $app --key seahub_secret_key --value $seahub_secret_key +if [ -z "${seahub_secret_key:-}" ]; then + seahub_secret_key="$(grep -P 'SECRET_KEY\s*=\s*".+"' "$install_dir"/conf/seahub_settings.py | cut -d'"' -f2)" + ynh_app_setting_set --app="$app" --key=seahub_secret_key --value="$seahub_secret_key" fi +# # Update data dir if needed +# + +# Create link to /home/yunohost.app/seafile/seafile-data in case of old install with data dir defined in config instead of symlink +# Also update link if not pointing to correct path if [ ! -L /home/yunohost.app/seafile-data ] || \ - [ $(readlink $install_dir/seafile-data) = '/home/yunohost.app/seafile-data' ]; then - mv $install_dir/seafile-data $install_dir/seafile-data$(date '+%Y%m%d.%H%M%S') - ln -s $data_dir $install_dir/seafile-data + [ "$(readlink "$install_dir"/seafile-data)" != "$data_dir/seafile-data" ]; then + mv "$install_dir"/seafile-data "$install_dir/seafile-data_$(date '+%Y%m%d.%H%M%S')" + ln -s "$data_dir"/seafile-data "$install_dir"/seafile-data fi + +# Move if needed old /home/yunohost.app/seafile-data dir to /home/yunohost.app/seafile/seafile-data if [ -e /home/yunohost.app/seafile-data ]; then - if [ -e $data_dir ]; then - mv $data_dir $data_dir$(date '+%Y%m%d.%H%M%S') + if [ -e "$data_dir" ]; then + mv "$data_dir" "${data_dir}_$(date '+%Y%m%d.%H%M%S')" fi - mv /home/yunohost.app/seafile-data $data_dir + mkdir -p "$data_dir" + mv /home/yunohost.app/seafile-data "$data_dir"/ +fi + +# In case of seafile-data content was directly stored in /home/yunohost.app/seafile +if [ -e "$data_dir"/storage ]; then + mkdir -p "$data_dir"/seafile-data + mv -t "$data_dir"/seafile-data "$data_dir"/{commits,fs,httptemp,library-template,storage,tmpfiles,webdavtmp} || true # In case of some of dir don't exist +fi + +# Move seahub data to /home/yunohost.app/seafile/seahub-data +if [ ! -L "$install_dir"/seahub-data ]; then + if [ -e "$data_dir"/seahub-data ]; then + mv "$data_dir"/seahub-data "$data_dir/seahub-data_$(date '+%Y%m%d.%H%M%S')" + fi + mv "$install_dir"/seahub-data "$data_dir"/ + ln -s "$data_dir"/seahub-data "$install_dir"/seahub-data +fi + +# Move logs storage to /var/log/seafile +if [ ! -L "$install_dir"/logs ]; then + if [ -e /var/log/"$app" ]; then + mv /var/log/"$app" /var/log/"${app}_$(date '+%Y%m%d.%H%M%S')" + fi + mv "$install_dir"/logs /var/log/"${app}" + ln -s /var/log/"${app}" "$install_dir"/logs fi ynh_script_progression --message="Upgrading source files..." --weight=6 # Download new version from sources ynh_script_progression --message="Installing sources files..." --weight=7 -ynh_setup_source --dest_dir=$install_dir/seafile-server-$seafile_version - -ynh_script_progression --message="Installing python dependancies..." -install_dependance +if [ "$YNH_APP_UPGRADE_TYPE" == UPGRADE_APP ]; then + install_source +fi ynh_script_progression --message="Configuring application..." # permission to execute update script and expect helper -mv_expect_scripts set_permission -chmod u+x,o= $install_dir/seafile-server-$seafile_version/upgrade/upgrade_*.sh -chmod u+x,o= $install_dir/seafile-server-$seafile_version/upgrade/minor-upgrade.sh # do the upgrade ( the ";&" syntax mean when it go in the first case which is true it do all the next case) -case $installed_version in +case "$installed_version" in "4."* ) # Update seafile by script ynh_die "Upgrade form the version 4.x was removed. Upgrade from this version won't be supported any more." @@ -109,42 +125,54 @@ case $installed_version in ;& "7.0"* ) # Fix file comment - pushd $install_dir/seafile-server-$seafile_version - sudo -u $YNH_APP_ID $install_dir/seafile-server-$seafile_version/seahub.sh python-env python3 seahub/manage.py migrate_file_comment - popd + run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/seahub.sh" python-env python3 "/opt/seafile/seafile-server-$seafile_version/seahub/manage.py" migrate_file_comment # Update seafile by script - sudo -u $YNH_APP_ID $expect_scripts_dir/upgrade_7.1.exp $install_dir/seafile-server-$seafile_version + ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$seafile_code/upgrade/upgrade_7.0_7.1.sh" + run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/upgrade/upgrade_7.0_7.1.sh" # Fix seafile data link. Look like that the upgrade script of seafile don't always work correctly - if [ -e $install_dir/seafile-data ]; then + if [ -e "$install_dir"/seafile-data ]; then old_data_dir_path="$install_dir/seafile-data$(date '+%Y%m%d.%H%M%S')" mv "$install_dir/seafile-data" "$old_data_dir_path" fi - ln -s $data_dir $install_dir/seafile-data + ln -s "$data_dir" "$install_dir"/seafile-data ;& "7.1."* ) - sudo -u $YNH_APP_ID $expect_scripts_dir/upgrade_8.0.exp $install_dir/seafile-server-$seafile_version + ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$seafile_code/upgrade/upgrade_8.0_9.0.sh" + run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/upgrade/upgrade_8.0_9.0.sh" ;& "8.0."* ) - sudo -u $YNH_APP_ID $expect_scripts_dir/upgrade_9.0.exp $install_dir/seafile-server-$seafile_version + ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$seafile_code/upgrade/upgrade_7.1_8.0.sh" + run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/upgrade/upgrade_7.1_8.0.sh" +;& +"9."* ) + ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$seafile_code/upgrade/upgrade_8.0_9.0.sh" + run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/upgrade/upgrade_8.0_9.0.sh" +;& +"10."* ) + ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$seafile_code/upgrade/upgrade_9.0_10.0.sh" + run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/upgrade/upgrade_9.0_10.0.sh" + run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/seahub.sh" python-env python3 "/opt/seafile/seafile-server-$seafile_version/migrate_ldapusers.py" ;& esac -sudo -u $YNH_APP_ID $expect_scripts_dir/minor-upgrade.exp $install_dir/seafile-server-$seafile_version +ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$seafile_code/upgrade/minor-upgrade.sh" +run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/upgrade/minor-upgrade.sh" # Clean url in config in DB clean_url_in_db_config # Update seafile config files -ynh_add_config --template=seahub_settings.py --destination=$install_dir/conf/seahub_settings.py -ynh_add_config --template=seafile.conf --destination=$install_dir/conf/seafile.conf -ynh_add_config --template=ccnet.conf --destination=$install_dir/conf/ccnet.conf -ynh_add_config --template=gunicorn.conf.py --destination=$install_dir/conf/gunicorn.conf.py -ynh_add_config --template=seafdav.conf --destination=$install_dir/conf/seafdav.conf +ynh_add_config --jinja --template=seahub_settings.py --destination="$install_dir"/conf/seahub_settings.py +ynh_add_config --template=seafile.conf --destination="$install_dir"/conf/seafile.conf +ynh_add_config --template=ccnet.conf --destination="$install_dir"/conf/ccnet.conf +ynh_add_config --template=gunicorn.conf.py --destination="$install_dir"/conf/gunicorn.conf.py +ynh_add_config --template=seafdav.conf --destination="$install_dir"/conf/seafdav.conf +ynh_add_config --template=seafevents.conf --destination="$install_dir"/conf/seafevents.conf # Fix local warning -ynh_replace_string --match_string en_US.UTF-8 --replace_string ${LANG:-'en_US.UTF-8'} --target_file $install_dir/seafile-server-$seafile_version/seahub.sh +ynh_replace_string --match_string=en_US.UTF-8 --replace_string="${LANG:-'en_US.UTF-8'}" --target_file="$seafile_code/seahub.sh" #================================================= # STANDARD UPGRADE STEPS @@ -155,8 +183,8 @@ ynh_add_nginx_config 'seahub_port fileserver_port webdav_port' # Add Seafile Server to startup ynh_script_progression --message="Updating systemd units..." -ynh_add_systemd_config --service seafile --template seafile.service -ynh_add_systemd_config --service seahub --template seahub.service +ynh_add_systemd_config --service=seafile --template=seafile.service +ynh_add_systemd_config --service=seahub --template=seahub.service #================================================= # GENERIC FINALIZATION @@ -168,7 +196,7 @@ set_permission # Add logrotate ynh_script_progression --message="Configuring log rotation..." -ynh_use_logrotate --logfile $install_dir/logs --nonappend +ynh_use_logrotate --logfile=/var/log/"$app" --nonappend # Add fail2ban ynh_script_progression --message="Configuring fail2ban..." --weight=10 @@ -176,25 +204,25 @@ ynh_add_fail2ban_config --use_template # register yunohost service ynh_script_progression --message="Register seafile service..." -yunohost service add seafile -yunohost service add seahub +yunohost service add seafile --description 'Main service for seafile server.' +yunohost service add seahub --description 'Seafile server web interface.' # delete seafile cache # restart seafile server ynh_script_progression --message="Starting seafile services..." --weight=3 sleep 5 -ynh_systemd_action --service_name memcached.service -p "systemd" -ynh_systemd_action --service_name seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log -ynh_systemd_action --service_name seahub -l "Started Seafile hub." -p "systemd" +ynh_systemd_action --service_name=memcached.service -p "systemd" +ynh_systemd_action --service_name=seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log +ynh_systemd_action --service_name=seahub -l "Started Seafile hub." -p "systemd" sleep 2 # remove old version files ynh_script_progression --message="Cleaning system and updating settings..." -ls $install_dir | grep "seafile-server-" | egrep -v "(${seafile_version//./\\.})|(latest)" | \ -while read f -do - ynh_secure_remove --file=$install_dir/$f +for f in "$install_dir"/seafile-server-*;do + if [[ ! "$f" =~ ${seafile_version//./\\.}|latest ]]; then + ynh_secure_remove --file="$f" + fi done ynh_script_progression --message="Upgrade of $app completed" --last diff --git a/scripts/ynh_setup_source b/scripts/ynh_setup_source new file mode 100644 index 0000000..70a58f0 --- /dev/null +++ b/scripts/ynh_setup_source @@ -0,0 +1,242 @@ +# Download, check integrity, uncompress and patch the source from app.src +# +# Requires YunoHost version 2.6.4 or higher. +ynh_setup_source_custom() { + # Declare an array to define the options of this helper. + local legacy_args=dsk + local -A args_array=([d]=dest_dir= [s]=source_id= [k]=keep= [r]=full_replace=) + local dest_dir + local source_id + local keep + local full_replace + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + keep="${keep:-}" + full_replace="${full_replace:-0}" + + if test -e $YNH_APP_BASEDIR/manifest.toml && cat $YNH_APP_BASEDIR/manifest.toml | toml_to_json | jq -e '.resources.sources' >/dev/null + then + source_id="${source_id:-main}" + local sources_json=$(cat $YNH_APP_BASEDIR/manifest.toml | toml_to_json | jq ".resources.sources[\"$source_id\"]") + if jq -re ".url" <<< "$sources_json" + then + local arch_prefix="" + else + local arch_prefix=".$YNH_ARCH" + fi + + local src_url="$(jq -r "$arch_prefix.url" <<< "$sources_json" | sed 's/^null$//')" + local src_sum="$(jq -r "$arch_prefix.sha256" <<< "$sources_json" | sed 's/^null$//')" + local src_sumprg="sha256sum" + local src_format="$(jq -r ".format" <<< "$sources_json" | sed 's/^null$//')" + local src_in_subdir="$(jq -r ".in_subdir" <<< "$sources_json" | sed 's/^null$//')" + local src_extract="$(jq -r ".extract" <<< "$sources_json" | sed 's/^null$//')" + local src_platform="$(jq -r ".platform" <<< "$sources_json" | sed 's/^null$//')" + local src_rename="$(jq -r ".rename" <<< "$sources_json" | sed 's/^null$//')" + + [[ -n "$src_url" ]] || ynh_die "No URL defined for source $source_id$arch_prefix ?" + [[ -n "$src_sum" ]] || ynh_die "No sha256 sum defined for source $source_id$arch_prefix ?" + + if [[ -z "$src_format" ]] + then + if [[ "$src_url" =~ ^.*\.zip$ ]] || [[ "$src_url" =~ ^.*/zipball/.*$ ]] + then + src_format="zip" + elif [[ "$src_url" =~ ^.*\.tar\.gz$ ]] || [[ "$src_url" =~ ^.*\.tgz$ ]] || [[ "$src_url" =~ ^.*/tar\.gz/.*$ ]] || [[ "$src_url" =~ ^.*/tarball/.*$ ]] + then + src_format="tar.gz" + elif [[ "$src_url" =~ ^.*\.tar\.xz$ ]] + then + src_format="tar.xz" + elif [[ "$src_url" =~ ^.*\.tar\.bz2$ ]] + then + src_format="tar.bz2" + elif [[ -z "$src_extract" ]] + then + src_extract="false" + fi + fi + else + source_id="${source_id:-app}" + local src_file_path="$YNH_APP_BASEDIR/conf/${source_id}.src" + + # Load value from configuration file (see above for a small doc about this file + # format) + local src_url=$(grep 'SOURCE_URL=' "$src_file_path" | cut --delimiter='=' --fields=2-) + local src_sum=$(grep 'SOURCE_SUM=' "$src_file_path" | cut --delimiter='=' --fields=2-) + local src_sumprg=$(grep 'SOURCE_SUM_PRG=' "$src_file_path" | cut --delimiter='=' --fields=2-) + local src_format=$(grep 'SOURCE_FORMAT=' "$src_file_path" | cut --delimiter='=' --fields=2-) + local src_in_subdir=$(grep 'SOURCE_IN_SUBDIR=' "$src_file_path" | cut --delimiter='=' --fields=2-) + local src_rename=$(grep 'SOURCE_FILENAME=' "$src_file_path" | cut --delimiter='=' --fields=2-) + local src_extract=$(grep 'SOURCE_EXTRACT=' "$src_file_path" | cut --delimiter='=' --fields=2-) + local src_platform=$(grep 'SOURCE_PLATFORM=' "$src_file_path" | cut --delimiter='=' --fields=2-) + fi + + # Default value + src_sumprg=${src_sumprg:-sha256sum} + src_in_subdir=${src_in_subdir:-true} + src_format=${src_format:-tar.gz} + src_format=$(echo "$src_format" | tr '[:upper:]' '[:lower:]') + src_extract=${src_extract:-true} + + if [[ "$src_extract" != "true" ]] && [[ "$src_extract" != "false" ]] + then + ynh_die "For source $source_id, expected either 'true' or 'false' for the extract parameter" + fi + + + # (Unused?) mecanism where one can have the file in a special local cache to not have to download it... + local local_src="/opt/yunohost-apps-src/${YNH_APP_ID}/${source_id}" + + # Gotta use this trick with 'dirname' because source_id may contain slashes x_x + mkdir -p $(dirname /var/cache/yunohost/download/${YNH_APP_ID}/${source_id}) + src_filename="/var/cache/yunohost/download/${YNH_APP_ID}/${source_id}" + + if [ "$src_format" = "docker" ]; then + src_platform="${src_platform:-"linux/$YNH_ARCH"}" + # BEGIN APP CUSTOMIZATION + if [ "$YNH_ARCH" == arm64 ]; then + src_platform="linux/$YNH_ARCH/v8" + fi + # END APP CUSTOMIZATION + else + if test -e "$local_src"; then + cp $local_src $src_filename + fi + + [ -n "$src_url" ] || ynh_die "Couldn't parse SOURCE_URL from $src_file_path ?" + + # If the file was prefetched but somehow doesn't match the sum, rm and redownload it + if [ -e "$src_filename" ] && ! echo "${src_sum} ${src_filename}" | ${src_sumprg} --check --status + then + rm -f "$src_filename" + fi + + # Only redownload the file if it wasnt prefetched + if [ ! -e "$src_filename" ] + then + # NB. we have to declare the var as local first, + # otherwise 'local foo=$(false) || echo 'pwet'" does'nt work + # because local always return 0 ... + local out + # Timeout option is here to enforce the timeout on dns query and tcp connect (c.f. man wget) + out=$(wget --tries 3 --no-dns-cache --timeout 900 --no-verbose --output-document=$src_filename $src_url 2>&1) \ + || ynh_die --message="$out" + fi + + # Check the control sum + if ! echo "${src_sum} ${src_filename}" | ${src_sumprg} --check --status + then + local actual_sum="$(${src_sumprg} ${src_filename} | cut --delimiter=' ' --fields=1)" + local actual_size="$(du -hs ${src_filename} | cut --fields=1)" + rm -f ${src_filename} + ynh_die --message="Corrupt source for ${src_url}: Expected sha256sum to be ${src_sum} but got ${actual_sum} (size: ${actual_size})." + fi + fi + + # Keep files to be backup/restored at the end of the helper + # Assuming $dest_dir already exists + rm -rf /var/cache/yunohost/files_to_keep_during_setup_source/ + if [ -n "$keep" ] && [ -e "$dest_dir" ]; then + local keep_dir=/var/cache/yunohost/files_to_keep_during_setup_source/${YNH_APP_ID} + mkdir -p $keep_dir + local stuff_to_keep + for stuff_to_keep in $keep; do + if [ -e "$dest_dir/$stuff_to_keep" ]; then + mkdir --parents "$(dirname "$keep_dir/$stuff_to_keep")" + cp --archive "$dest_dir/$stuff_to_keep" "$keep_dir/$stuff_to_keep" + fi + done + fi + + if [ "$full_replace" -eq 1 ]; then + ynh_secure_remove --file="$dest_dir" + fi + + # Extract source into the app dir + mkdir --parents "$dest_dir" + + if [ -n "${install_dir:-}" ] && [ "$dest_dir" == "$install_dir" ]; then + _ynh_apply_default_permissions $dest_dir + fi + if [ -n "${final_path:-}" ] && [ "$dest_dir" == "$final_path" ]; then + _ynh_apply_default_permissions $dest_dir + fi + + if [[ "$src_extract" == "false" ]]; then + if [[ -z "$src_rename" ]] + then + mv $src_filename $dest_dir + else + mv $src_filename $dest_dir/$src_rename + fi + elif [[ "$src_format" == "docker" ]]; then + "$YNH_HELPERS_DIR/vendor/docker-image-extract/docker-image-extract" -p $src_platform -o $dest_dir $src_url 2>&1 + elif [[ "$src_format" == "zip" ]]; then + # Zip format + # Using of a temp directory, because unzip doesn't manage --strip-components + if $src_in_subdir; then + local tmp_dir=$(mktemp --directory) + unzip -quo $src_filename -d "$tmp_dir" + cp --archive $tmp_dir/*/. "$dest_dir" + ynh_secure_remove --file="$tmp_dir" + else + unzip -quo $src_filename -d "$dest_dir" + fi + ynh_secure_remove --file="$src_filename" + else + local strip="" + if [ "$src_in_subdir" != "false" ]; then + if [ "$src_in_subdir" == "true" ]; then + local sub_dirs=1 + else + local sub_dirs="$src_in_subdir" + fi + strip="--strip-components $sub_dirs" + fi + if [[ "$src_format" =~ ^tar.gz|tar.bz2|tar.xz$ ]]; then + tar --extract --file=$src_filename --directory="$dest_dir" $strip + else + ynh_die --message="Archive format unrecognized." + fi + ynh_secure_remove --file="$src_filename" + fi + + # Apply patches + if [ -d "$YNH_APP_BASEDIR/sources/patches/" ]; then + local patches_folder=$(realpath $YNH_APP_BASEDIR/sources/patches/) + if (($(find $patches_folder -type f -name "${source_id}-*.patch" 2>/dev/null | wc --lines) > "0")); then + pushd "$dest_dir" + for p in $patches_folder/${source_id}-*.patch; do + echo $p + patch --strip=1 <$p || ynh_print_warn --message="Packagers /!\\ patch $p failed to apply" + done + popd + fi + fi + + # Add supplementary files + if test -e "$YNH_APP_BASEDIR/sources/extra_files/${source_id}"; then + cp --archive $YNH_APP_BASEDIR/sources/extra_files/$source_id/. "$dest_dir" + fi + + # Keep files to be backup/restored at the end of the helper + # Assuming $dest_dir already exists + if [ -n "$keep" ]; then + local keep_dir=/var/cache/yunohost/files_to_keep_during_setup_source/${YNH_APP_ID} + local stuff_to_keep + for stuff_to_keep in $keep; do + if [ -e "$keep_dir/$stuff_to_keep" ]; then + mkdir --parents "$(dirname "$dest_dir/$stuff_to_keep")" + + # We add "--no-target-directory" (short option is -T) to handle the special case + # when we "keep" a folder, but then the new setup already contains the same dir (but possibly empty) + # in which case a regular "cp" will create a copy of the directory inside the directory ... + # resulting in something like /var/www/$app/data/data instead of /var/www/$app/data + # cf https://unix.stackexchange.com/q/94831 for a more elaborate explanation on the option + cp --archive --no-target-directory "$keep_dir/$stuff_to_keep" "$dest_dir/$stuff_to_keep" + fi + done + fi + rm -rf /var/cache/yunohost/files_to_keep_during_setup_source/ +} diff --git a/tests.toml b/tests.toml index b413fc7..88b42ba 100644 --- a/tests.toml +++ b/tests.toml @@ -20,6 +20,7 @@ test_format = 1.0 # Commits to test upgrade from # ------------------------------- - test_upgrade_from.b5fd940.name = "Pre packaging v2" - test_upgrade_from.3ce35d3.name = "Version 7.1 Old version for CI 4 branch" - test_upgrade_from.97c0b2f.name = "Version 8.x Old version for CI 5 branch" + test_upgrade_from.ef7eb6f.name = "Pre packaging v2 (Old_version_for_CI_6 branch)" + test_upgrade_from.8d41482.name = "Version 7.1 (Old_version_for_CI_4 branch)" + test_upgrade_from.c11c24b.name = "Version 8.x (Old_version_for_CI_5 branch)" + test_upgrade_from.7a4d00a.name = "Version 9.x"