1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/nextcloud_ynh.git synced 2024-09-03 19:55:57 +02:00

Complete refactoring

* Refactoring
* Fix upgrade script
* Fix owncloud migration + new helper ynh_handle_app_migration
* Add more informations about ynh_handle_app_migration
* Fix typos, enhance comments, fix spacing
* Rename $dependencies to $pkg_dependencies as matter of homogeneity with other apps
* [enh] Change the label during the migration
This commit is contained in:
Maniack Crudelis 2017-09-26 07:18:12 +02:00 committed by JimboJoe
parent 8f98d512b1
commit 8ea155ee6d
22 changed files with 1546 additions and 990 deletions

View file

@ -1,5 +1,4 @@
;; Test complet
auto_remove=1
; Manifest
domain="domain.tld" (DOMAIN)
path="/path" (PATH)
@ -15,21 +14,22 @@
upgrade=1
backup_restore=1
multi_instance=0
wrong_user=1
wrong_path=1
incorrect_path=1
corrupt_source=0
fail_download_source=0
port_already_use=0
final_path_already_use=0
change_url=0
;;; Levels
Level 1=auto
Level 2=auto
Level 3=auto
# Level 4: LDAP and http auth
Level 4=1
# Level 5: https://github.com/YunoHost-Apps/nextcloud_ynh/issues/58
Level 5=1
Level 6=auto
Level 7=auto
Level 8=0
Level 9=0
Level 10=0
;;; Options
Email=
Notification=none

6
conf/app.src.default Normal file
View file

@ -0,0 +1,6 @@
SOURCE_URL=https://download.nextcloud.com/server/releases/nextcloud-__VERSION__.tar.bz2
SOURCE_SUM=__SHA256_SUM__
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.bz2
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=

View file

@ -1,18 +0,0 @@
Section: misc
Priority: optional
Homepage: https://owncloud.org/
Standards-Version: 3.9.2
Package: nextcloud-deps
Version: 11.0-1
Depends: php5-gd, php5-json, php5-intl, php5-mcrypt
, php5-curl, php5-apcu, php5-imagick
, acl, tar, smbclient
Architecture: all
Description: meta package for nextcloud dependencies
Nextcloud gives you universal access to your files through a web
interface or WebDAV. It also provides a platform to easily view & sync
your contacts, calendars and bookmarks across all your devices and
enables basic editing right on the web.
.
This meta-package is only responsible of installing its dependencies.

View file

@ -1,12 +1,12 @@
location = /.well-known/carddav {
return 301 https://$server_name#PATH#/remote.php/dav;
return 301 https://$server_name__PATH__/remote.php/dav;
}
location = /.well-known/caldav {
return 301 https://$server_name#PATH#/remote.php/dav;
return 301 https://$server_name__PATH__/remote.php/dav;
}
location ^~ #LOCATION# {
alias #DESTDIR#/;
location ^~ __PATH__ {
alias __FINALPATH__/;
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
@ -28,32 +28,32 @@ location ^~ #LOCATION# {
gzip off;
# Errors pages
error_page 403 #PATH#/core/templates/403.php;
error_page 404 #PATH#/core/templates/404.php;
error_page 403 __PATH__/core/templates/403.php;
error_page 404 __PATH__/core/templates/404.php;
# The following 2 rules are only needed for the user_webfinger app.
# Uncomment it if you're planning to use this app.
#rewrite ^/.well-known/host-meta #PATH#/public.php?service=host-meta last;
#rewrite ^/.well-known/host-meta.json #PATH#/public.php?service=host-meta-json last;
#rewrite ^/.well-known/host-meta __PATH__/public.php?service=host-meta last;
#rewrite ^/.well-known/host-meta.json __PATH__/public.php?service=host-meta-json last;
location #LOCATION# {
rewrite ^ #PATH#/index.php$request_uri;
location __PATH__ {
rewrite ^ __PATH__/index.php$request_uri;
}
location = #PATH#/robots.txt {
location = __PATH__/robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ ^#PATH#/(?:build|tests|config|lib|3rdparty|templates|data)/ {
location ~ ^__PATH__/(?:build|tests|config|lib|3rdparty|templates|data)/ {
deny all;
}
location ~ ^#PATH#/(?:\.|autotest|occ|issue|indie|db_|console) {
location ~ ^__PATH__/(?:\.|autotest|occ|issue|indie|db_|console) {
deny all;
}
location ~ ^#PATH#/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
location ~ ^__PATH__/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $request_filename;
@ -61,11 +61,11 @@ location ^~ #LOCATION# {
fastcgi_param HTTPS on;
fastcgi_param modHeadersAvailable true;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_pass unix:/var/run/php5-fpm-#APP#.sock;
fastcgi_pass unix:/var/run/php5-fpm-__NAME__.sock;
fastcgi_intercept_errors on;
}
location ~ ^#PATH#/(?:updater|ocs-provider)(?:$|/) {
location ~ ^__PATH__/(?:updater|ocs-provider)(?:$|/) {
try_files $uri/ =404;
index index.php;
}
@ -89,6 +89,6 @@ location ^~ #LOCATION# {
access_log off;
}
# show YunoHost panel access
# show YunoHost panel access
include conf.d/yunohost_panel.conf.inc;
}

View file

@ -1,21 +0,0 @@
#!/bin/bash
set -u
app="#APP#"
# rename hook
hooks_dir="/etc/yunohost/hooks.d/post_user_create"
[[ -f "${hooks_dir}/50-${app}" ]] \
&& mv "${hooks_dir}/50-${app}" "${hooks_dir}/50-nextcloud"
# move yunohost app settings
apps_dir="/etc/yunohost/apps"
if [[ -d "${apps_dir}/${app}" ]]; then
yunohost app setting "$app" id -v nextcloud
mv "${apps_dir}/${app}" "${apps_dir}/nextcloud"
yunohost app ssowatconf --quiet
fi
# remove cron job
rm /etc/cron.d/owncloud-migration

13
conf/owncloud_migration Normal file
View file

@ -0,0 +1,13 @@
# File to migrate from Owncloud
# Final path
/var/www/$app
# Data directory
/home/yunohost.app/$app
# Nginx config
/etc/nginx/conf.d/$domain.d/$app.conf
# php-fpm config
/etc/php5/fpm/pool.d/$app.conf

View file

@ -0,0 +1,45 @@
#!/bin/bash
# Ending the migration process from Owncloud to Nextcloud
set -u
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
#=================================================
# SET VARIABLES
#=================================================
old_app="__OLD_APP__"
new_app="__NEW_APP__"
script_name="$0"
#=================================================
# MOVE HOOKS
#=================================================
hooks_dir="/etc/yunohost/hooks.d/"
mv "$hooks_dir/post_user_create/50-$old_app" "$hooks_dir/post_user_create/50-$new_app"
#=================================================
# DELETE OLD APP'S SETTINGS
#=================================================
ynh_secure_remove "/etc/yunohost/apps/$old_app"
yunohost app ssowatconf
#=================================================
# REMOVE THE OLD USER
#=================================================
ynh_system_user_delete $old_app
#=================================================
# DELETE THIS SCRIPT
#=================================================
echo "rm $script_name" | at now + 1 minutes

View file

@ -1,68 +1,395 @@
[#POOLNAME#]
; The address on which to accept FastCGI requests.
listen = /var/run/php5-fpm-#POOLNAME#.sock
; Start a new pool named 'www'.
; the variable $pool can we used in any directive and will be replaced by the
; pool name ('www' here)
[__NAMETOCHANGE__]
; Set permissions for unix socket, if one is used.
; Per pool prefix
; It only applies on the following directives:
; - 'slowlog'
; - 'listen' (unixsocket)
; - 'chroot'
; - 'chdir'
; - 'php_values'
; - 'php_admin_values'
; When not set, the global prefix (or /usr) applies instead.
; Note: This directive can also be relative to the global prefix.
; Default Value: none
;prefix = /path/to/pools/$pool
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = __USER__
group = __USER__
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses on a
; specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php5-fpm-__NAMETOCHANGE__.sock
; Set listen(2) backlog. A value of '-1' means unlimited.
; Default Value: 128 (-1 on FreeBSD and OpenBSD)
;listen.backlog = 128
; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions.
; Default Values: user and group are set as the running user
; mode is set to 0660
listen.owner = www-data
listen.group = www-data
listen.mode = 0600
;listen.mode = 0660
; List of ipv4 addresses of FastCGI clients which are allowed to connect.
; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
; must be separated by a comma. If this value is left blank, connections will be
; accepted from any ip address.
; Default Value: any
;listen.allowed_clients = 127.0.0.1
; Unix user/group of processes.
user = #USER#
group = #GROUP#
; Specify the nice(2) priority to apply to the pool processes (only if set)
; The value can vary from -19 (highest priority) to 20 (lower priority)
; Note: - It will only work if the FPM master process is launched as root
; - The pool processes will inherit the master process priority
; unless it specified otherwise
; Default Value: no set
; priority = -19
; Choose how the process manager will control the number of child processes.
; Possible Values:
; static - a fixed number (pm.max_children) of child processes;
; dynamic - the number of child processes are set dynamically based on the
; following directives. With this process management, there will be
; always at least 1 children.
; pm.max_children - the maximum number of children that can
; be alive at the same time.
; pm.start_servers - the number of children created on startup.
; pm.min_spare_servers - the minimum number of children in 'idle'
; state (waiting to process). If the number
; of 'idle' processes is less than this
; number then some children will be created.
; pm.max_spare_servers - the maximum number of children in 'idle'
; state (waiting to process). If the number
; of 'idle' processes is greater than this
; number then some children will be killed.
; ondemand - no children are created at startup. Children will be forked when
; new requests will connect. The following parameter are used:
; pm.max_children - the maximum number of children that
; can be alive at the same time.
; pm.process_idle_timeout - The number of seconds after which
; an idle process will be killed.
; Note: This value is mandatory.
pm = dynamic
; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes to be created when pm is set to 'dynamic'.
pm.max_children = 6
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI. The below defaults are based on a server without much resources. Don't
; forget to tweak pm.* to fit your needs.
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
; Note: This value is mandatory.
pm.max_children = 10
; The number of child processes created on startup.
pm.start_servers = 3
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 2
; The desired minimum number of idle server processes.
pm.min_spare_servers = 3
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 1
; The desired maximum number of idle server processes.
pm.max_spare_servers = 5
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 3
; The number of seconds after which an idle process will be killed.
; Note: Used only when pm is set to 'ondemand'
; Default Value: 10s
;pm.process_idle_timeout = 10s;
; The number of requests each child process should execute before respawning.
; This can be useful to work around memory leaks in 3rd party libraries. For
; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
; Default Value: 0
pm.max_requests = 500
; The URI to view the FPM status page. If this value is not set, no URI will be
; recognized as a status page.
pm.status_path = /fpm-status
; recognized as a status page. It shows the following informations:
; pool - the name of the pool;
; process manager - static, dynamic or ondemand;
; start time - the date and time FPM has started;
; start since - number of seconds since FPM has started;
; accepted conn - the number of request accepted by the pool;
; listen queue - the number of request in the queue of pending
; connections (see backlog in listen(2));
; max listen queue - the maximum number of requests in the queue
; of pending connections since FPM has started;
; listen queue len - the size of the socket queue of pending connections;
; idle processes - the number of idle processes;
; active processes - the number of active processes;
; total processes - the number of idle + active processes;
; max active processes - the maximum number of active processes since FPM
; has started;
; max children reached - number of times, the process limit has been reached,
; when pm tries to start more children (works only for
; pm 'dynamic' and 'ondemand');
; Value are updated in real time.
; Example output:
; pool: www
; process manager: static
; start time: 01/Jul/2011:17:53:49 +0200
; start since: 62636
; accepted conn: 190460
; listen queue: 0
; max listen queue: 1
; listen queue len: 42
; idle processes: 4
; active processes: 11
; total processes: 15
; max active processes: 12
; max children reached: 0
;
; By default the status page output is formatted as text/plain. Passing either
; 'html', 'xml' or 'json' in the query string will return the corresponding
; output syntax. Example:
; http://www.foo.bar/status
; http://www.foo.bar/status?json
; http://www.foo.bar/status?html
; http://www.foo.bar/status?xml
;
; By default the status page only outputs short status. Passing 'full' in the
; query string will also return status for each pool process.
; Example:
; http://www.foo.bar/status?full
; http://www.foo.bar/status?json&full
; http://www.foo.bar/status?html&full
; http://www.foo.bar/status?xml&full
; The Full status returns for each process:
; pid - the PID of the process;
; state - the state of the process (Idle, Running, ...);
; start time - the date and time the process has started;
; start since - the number of seconds since the process has started;
; requests - the number of requests the process has served;
; request duration - the duration in µs of the requests;
; request method - the request method (GET, POST, ...);
; request URI - the request URI with the query string;
; content length - the content length of the request (only with POST);
; user - the user (PHP_AUTH_USER) (or '-' if not set);
; script - the main script called (or '-' if not set);
; last request cpu - the %cpu the last request consumed
; it's always 0 if the process is not in Idle state
; because CPU calculation is done when the request
; processing has terminated;
; last request memory - the max amount of memory the last request consumed
; it's always 0 if the process is not in Idle state
; because memory calculation is done when the request
; processing has terminated;
; If the process is in Idle state, then informations are related to the
; last request the process has served. Otherwise informations are related to
; the current request being served.
; Example output:
; ************************
; pid: 31330
; state: Running
; start time: 01/Jul/2011:17:53:49 +0200
; start since: 63087
; requests: 12808
; request duration: 1250261
; request method: GET
; request URI: /test_mem.php?N=10000
; content length: 0
; user: -
; script: /home/fat/web/docs/php/test_mem.php
; last request cpu: 0.00
; last request memory: 0
;
; Note: There is a real-time FPM status monitoring sample web page available
; It's available in: ${prefix}/share/fpm/status.html
;
; Note: The value must start with a leading slash (/). The value can be
; anything, but it may not be a good idea to use the .php extension or it
; may conflict with a real PHP file.
; Default Value: not set
;pm.status_path = /status
; The ping URI to call the monitoring page of FPM. If this value is not set, no
; URI will be recognized as a ping page.
ping.path = /ping
; URI will be recognized as a ping page. This could be used to test from outside
; that FPM is alive and responding, or to
; - create a graph of FPM availability (rrd or such);
; - remove a server from a group if it is not responding (load balancing);
; - trigger alerts for the operating team (24/7).
; Note: The value must start with a leading slash (/). The value can be
; anything, but it may not be a good idea to use the .php extension or it
; may conflict with a real PHP file.
; Default Value: not set
;ping.path = /ping
; The timeout for serving a single request after which the worker process will
; be killed.
request_terminate_timeout = 1d
; This directive may be used to customize the response of a ping request. The
; response is formatted as text/plain with a 200 response code.
; Default Value: pong
;ping.response = pong
; The access log file
; Default: not set
;access.log = log/$pool.access.log
; The access log format.
; The following syntax is allowed
; %%: the '%' character
; %C: %CPU used by the request
; it can accept the following format:
; - %{user}C for user CPU only
; - %{system}C for system CPU only
; - %{total}C for user + system CPU (default)
; %d: time taken to serve the request
; it can accept the following format:
; - %{seconds}d (default)
; - %{miliseconds}d
; - %{mili}d
; - %{microseconds}d
; - %{micro}d
; %e: an environment variable (same as $_ENV or $_SERVER)
; it must be associated with embraces to specify the name of the env
; variable. Some exemples:
; - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e
; - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e
; %f: script filename
; %l: content-length of the request (for POST request only)
; %m: request method
; %M: peak of memory allocated by PHP
; it can accept the following format:
; - %{bytes}M (default)
; - %{kilobytes}M
; - %{kilo}M
; - %{megabytes}M
; - %{mega}M
; %n: pool name
; %o: ouput header
; it must be associated with embraces to specify the name of the header:
; - %{Content-Type}o
; - %{X-Powered-By}o
; - %{Transfert-Encoding}o
; - ....
; %p: PID of the child that serviced the request
; %P: PID of the parent of the child that serviced the request
; %q: the query string
; %Q: the '?' character if query string exists
; %r: the request URI (without the query string, see %q and %Q)
; %R: remote IP address
; %s: status (response code)
; %t: server time the request was received
; it can accept a strftime(3) format:
; %d/%b/%Y:%H:%M:%S %z (default)
; %T: time the log has been written (the request has finished)
; it can accept a strftime(3) format:
; %d/%b/%Y:%H:%M:%S %z (default)
; %u: remote user
;
; Default: "%R - %u %t \"%m %r\" %s"
;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"
; The log file for slow requests
; Default Value: not set
; Note: slowlog is mandatory if request_slowlog_timeout is set
slowlog = /var/log/nginx/__NAMETOCHANGE__.slow.log
; The timeout for serving a single request after which a PHP backtrace will be
; dumped to the 'slowlog' file. A value of '0s' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
request_slowlog_timeout = 5s
; The log file for slow requests.
slowlog = /var/log/nginx/#POOLNAME#.slow.log
; The timeout for serving a single request after which the worker process will
; be killed. This option should be used when the 'max_execution_time' ini option
; does not stop script execution for some reason. A value of '0' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
request_terminate_timeout = 1d
; Set open file descriptor rlimit.
rlimit_files = 4096
; Default Value: system defined value
;rlimit_files = 1024
; Set max core size rlimit.
rlimit_core = 0
; Possible Values: 'unlimited' or an integer greater or equal to 0
; Default Value: system defined value
;rlimit_core = 0
; Chroot to this directory at the start. This value must be defined as an
; absolute path. When this value is not set, chroot is not used.
; Note: you can prefix with '$prefix' to chroot to the pool prefix or one
; of its subdirectories. If the pool prefix is not set, the global prefix
; will be used instead.
; Note: chrooting is a great security feature and should be used whenever
; possible. However, all PHP paths will be relative to the chroot
; (error_log, sessions.save_path, ...).
; Default Value: not set
;chroot =
; Chdir to this directory at the start.
chdir = #DESTDIR#
; Note: relative path can be used.
; Default Value: current directory or / when chroot
chdir = __FINALPATH__
; Redirect worker stdout and stderr into main error log.
; Redirect worker stdout and stderr into main error log. If not set, stdout and
; stderr will be redirected to /dev/null according to FastCGI specs.
; Note: on highloaded environement, this can cause some delay in the page
; process time (several ms).
; Default Value: no
catch_workers_output = yes
; Do not clear environment in FPM workers.
clear_env = no
; Limits the extensions of the main script FPM will allow to parse. This can
; prevent configuration mistakes on the web server side. You should only limit
; FPM to .php extensions to prevent malicious users to use other extensions to
; exectute php code.
; Note: set an empty value to allow all extensions.
; Default Value: .php
;security.limit_extensions = .php .php3 .php4 .php5
; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
; the current environment.
; Default Value: clean env
;env[HOSTNAME] = $HOSTNAME
;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmp
; Additional php.ini defines, specific to this pool of workers. These settings
; overwrite the values previously defined in the php.ini. The directives are the
; same as the PHP SAPI:
; php_value/php_flag - you can set classic ini defines which can
; be overwritten from PHP call 'ini_set'.
; php_admin_value/php_admin_flag - these directives won't be overwritten by
; PHP call 'ini_set'
; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no.
; Defining 'extension' will load the corresponding shared extension from
; extension_dir. Defining 'disable_functions' or 'disable_classes' will not
; overwrite previously defined php.ini values, but will append the new value
; instead.
; Note: path INI options can be relative and will be expanded with the prefix
; (pool, global or /usr)
; Default Value: nothing is defined by default except the values in php.ini and
; specified at startup with the -d argument
;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com
;php_flag[display_errors] = off
;php_admin_value[error_log] = /var/log/fpm-php.www.log
;php_admin_flag[log_errors] = on
;php_admin_value[memory_limit] = 32M
; Additional php.ini defines, specific to this pool of workers.
php_value[upload_max_filesize] = 10G

View file

@ -1,27 +1,27 @@
{
"packaging_format": 1,
"id": "nextcloud",
"name": "Nextcloud",
"packaging_format": 1,
"description": {
"en": "Access & share your files, calendars, contacts, mail & more from any device, on your terms",
"fr": "Consultez et partagez vos fichiers, agendas, carnets d'adresses, emails et bien plus depuis les appareils de votre choix, sous vos conditions"
},
"version": "12.0.2",
"url": "https://nextcloud.com",
"license": "AGPL-3",
"version": "12.0.2",
"maintainer": {
"name": "-",
"email": "-"
},
"requirements": {
"yunohost": ">= 2.7.2"
},
"multi_instance": false,
"services": [
"nginx",
"php5-fpm",
"mysql"
],
"requirements": {
"yunohost": ">= 2.6.0"
},
"arguments": {
"install" : [
{

View file

@ -1,49 +1,51 @@
#
# Common variables
#
APPNAME="nextcloud"
#=================================================
# COMMON VARIABLES
#=================================================
# Nextcloud version
LAST_VERSION=$(grep "VERSION=" "upgrade.d/upgrade.last.sh" | cut -d= -f2)
pkg_dependencies="php5-gd php5-json php5-intl php5-mcrypt php5-curl php5-apcu php5-imagick acl tar smbclient"
# Package name for Nextcloud dependencies
DEPS_PKG_NAME="nextcloud-deps"
#=================================================
# COMMON HELPERS
#=================================================
# App package root directory should be the parent folder
PKGDIR=$(cd ../; pwd)
#
# Common helpers
#
# Download and extract Nextcloud sources to the given directory
# usage: extract_nextcloud DESTDIR [AS_USER]
extract_nextcloud() {
# Remote URL to fetch Nextcloud tarball
NEXTCLOUD_SOURCE_URL="https://download.nextcloud.com/server/releases/nextcloud-${VERSION}.tar.bz2"
local DESTDIR=$1
local AS_USER=${2:-admin}
# retrieve and extract Roundcube tarball
nc_tarball="/tmp/nextcloud.tar.bz2"
rm -f "$nc_tarball"
wget -q -O "$nc_tarball" "$NEXTCLOUD_SOURCE_URL" \
|| ynh_die "Unable to download Nextcloud tarball"
echo "$NEXTCLOUD_SOURCE_SHA256 $nc_tarball" | sha256sum -c >/dev/null \
|| ynh_die "Invalid checksum of downloaded tarball"
exec_as "$AS_USER" tar xjf "$nc_tarball" -C "$DESTDIR" --strip-components 1 \
|| ynh_die "Unable to extract Nextcloud tarball"
rm -f "$nc_tarball"
# apply patches
(cd "$DESTDIR" \
&& for p in ${PKGDIR}/patches/*.patch; do \
exec_as "$AS_USER" patch -p1 < $p; done) \
|| ynh_die "Unable to apply patches to Nextcloud"
# Execute a command with occ
exec_occ() {
(cd "$final_path" && exec_as "$app" \
php occ --no-interaction --no-ansi "$@")
}
# Create the external storage for the home folders and enable sharing
create_home_external_storage() {
local mount_id=`exec_occ files_external:create --output=json \
'Home' 'local' 'null::null' -c 'datadir=/home/$user' || true`
! [[ $mount_id =~ ^[0-9]+$ ]] \
&& echo "Unable to create external storage" >&2 \
|| exec_occ files_external:option "$mount_id" enable_sharing true
}
# Rename a MySQL database and user
# Usage: rename_mysql_db DBNAME DBUSER DBPASS NEW_DBNAME_AND_USER
rename_mysql_db() {
local db_name=$1 db_user=$2 db_pwd=$3 new_db_name=$4
local sqlpath="/tmp/${db_name}-$(date '+%s').sql"
# Dump the old database
mysqldump -u "$db_user" -p"$db_pwd" --no-create-db "$db_name" > "$sqlpath"
# Create the new database and user
ynh_mysql_create_db "$new_db_name" "$new_db_name" "$db_pwd"
ynh_mysql_connect_as "$new_db_name" "$db_pwd" "$new_db_name" < "$sqlpath"
# Remove the old database
ynh_mysql_remove_db $db_name $db_name
ynh_secure_remove "$sqlpath"
}
#=================================================
# COMMON HELPERS -- SHOULD BE ADDED TO YUNOHOST
#=================================================
# Execute a command as another user
# usage: exec_as USER COMMAND [ARG ...]
exec_as() {
@ -53,222 +55,259 @@ exec_as() {
if [[ $USER = $(whoami) ]]; then
eval "$@"
else
# use sudo twice to be root and be allowed to use another user
sudo sudo -u "$USER" "$@"
sudo -u "$USER" "$@"
fi
}
# Execute a command with occ as a given user from a given directory
# usage: exec_occ WORKDIR AS_USER COMMAND [ARG ...]
exec_occ() {
local WORKDIR=$1
local AS_USER=$2
shift 2
(cd "$WORKDIR" && exec_as "$AS_USER" \
php occ --no-interaction --no-ansi "$@")
}
# Create the external storage for the home folders and enable sharing
# usage: create_home_external_storage OCC_COMMAND
create_home_external_storage() {
local OCC=$1
local mount_id=`$OCC files_external:create --output=json \
'Home' 'local' 'null::null' -c 'datadir=/home/$user' || true`
! [[ $mount_id =~ ^[0-9]+$ ]] \
&& echo "Unable to create external storage" 1>&2 \
|| $OCC files_external:option "$mount_id" enable_sharing true
}
# Check if an URL is already handled
# usage: is_url_handled URL
is_url_handled() {
local OUTPUT=($(curl -k -s -o /dev/null \
local output=($(curl -k -s -o /dev/null \
-w 'x%{redirect_url} %{http_code}' "$1"))
# it's handled if it does not redirect to the SSO nor return 404
[[ ! ${OUTPUT[0]} =~ \/yunohost\/sso\/ && ${OUTPUT[1]} != 404 ]]
# It's handled if it does not redirect to the SSO nor return 404
[[ ! ${output[0]} =~ \/yunohost\/sso\/ && ${output[1]} != 404 ]]
}
# Rename a MySQL database and user
# usage: rename_mysql_db DBNAME DBUSER DBPASS NEW_DBNAME NEW_DBUSER
rename_mysql_db() {
local DBNAME=$1 DBUSER=$2 DBPASS=$3 NEW_DBNAME=$4 NEW_DBUSER=$5
local SQLPATH="/tmp/${DBNAME}-$(date '+%s').sql"
# Make the main steps to migrate an app to its fork.
#
# This helper has to be used for an app which needs to migrate to a new name or a new fork
# (like owncloud to nextcloud or zerobin to privatebin).
#
# This helper will move the files of an app to its new name
# or recreate the things it can't move.
#
# To specify which files it has to move, you have to create a "migration file", stored in ../conf
# This file is a simple list of each file it has to move,
# except that file names must reference the $app variable instead of the real name of the app,
# and every instance-specific variables (like $domain).
# $app is especially important because it's this variable which will be used to identify the old place and the new one for each file.
#
# If a database exists for this app, it will be dumped and then imported in a newly created database, with a new name and new user.
# Don't forget you have to then apply these changes to application-specific settings (depends on the packaged application)
#
# Same things for an existing user, a new one will be created.
# But the old one can't be removed unless it's not used. See below.
#
# If you have some dependencies for your app, it's possible to change the fake debian package which manages them.
# You have to fill the $pkg_dependencies variable, and then a new fake package will be created and installed,
# and the old one will be removed.
# If you don't have a $pkg_dependencies variable, the helper can't know what the app dependencies are.
#
# The app settings.yml will be modified as follows:
# - finalpath will be changed according to the new name (but only if the existing $final_path contains the old app name)
# - The checksums of php-fpm and nginx config files will be updated too.
# - If there is a $db_name value, it will be changed.
# - And, of course, the ID will be changed to the new name too.
#
# Finally, the $app variable will take the value of the new name.
# The helper will set the $migration_process variable to 1 if a migration has been successfully handled.
#
# You have to handle by yourself all the migrations not done by this helper, like configuration or special values in settings.yml
# Also, at the end of the upgrade script, you have to add a post_migration script to handle all the things the helper can't do during YunoHost upgrade (mostly for permission reasons),
# especially remove the old user, move some hooks and remove the old configuration directory
# To launch this script, you have to move it elsewhere and start it after the upgrade script.
# `cp ../conf/$script_post_migration /tmp`
# `(cd /tmp; echo "/tmp/$script_post_migration" | at now + 2 minutes)`
#
# usage: ynh_handle_app_migration migration_id migration_list
# | arg: migration_id - ID from which to migrate
# | arg: migration_list - File specifying every file to move (one file per line)
ynh_handle_app_migration () {
#=================================================
# LOAD SETTINGS
#=================================================
# dump the old database
mysqldump -u "$DBUSER" -p"$DBPASS" --no-create-db "$DBNAME" > "$SQLPATH"
# create the new database and user
ynh_mysql_create_db "$NEW_DBNAME" "$NEW_DBUSER" "$DBPASS"
ynh_mysql_connect_as "$NEW_DBUSER" "$DBPASS" "$NEW_DBNAME" < "$SQLPATH"
# remove the old database
ynh_mysql_drop_db "$DBNAME"
ynh_mysql_drop_user "$DBUSER"
rm "$SQLPATH"
}
SECURE_REMOVE () { # Suppression de dossier avec vérification des variables
chaine="$1" # L'argument doit être donné entre quotes simple '', pour éviter d'interpréter les variables.
no_var=0
while (echo "$chaine" | grep -q '\$') # Boucle tant qu'il y a des $ dans la chaine
do
no_var=1
global_var=$(echo "$chaine" | cut -d '$' -f 2) # Isole la première variable trouvée.
only_var=\$$(expr "$global_var" : '\([A-Za-z0-9_]*\)') # Isole complètement la variable en ajoutant le $ au début et en gardant uniquement le nom de la variable. Se débarrasse surtout du / et d'un éventuel chemin derrière.
real_var=$(eval "echo ${only_var}") # `eval "echo ${var}` permet d'interpréter une variable contenue dans une variable.
if test -z "$real_var" || [ "$real_var" = "/" ]; then
echo "Variable $only_var is empty, suppression of $chaine cancelled." >&2
return 1
fi
chaine=$(echo "$chaine" | sed "s@$only_var@$real_var@") # remplace la variable par sa valeur dans la chaine.
done
if [ "$no_var" -eq 1 ]
then
if [ -e "$chaine" ]; then
echo "Delete directory $chaine"
sudo rm -rf "$chaine"
fi
return 0
else
echo "No detected variable." >&2
return 1
fi
}
#=================================================
# FUTURE YUNOHOST HELPERS - TO BE REMOVED LATER
#=================================================
# Use logrotate to manage the logfile
#
# usage: ynh_use_logrotate [logfile]
# | arg: logfile - absolute path of logfile
#
# If no argument provided, a standard directory will be use. /var/log/${app}
# You can provide a path with the directory only or with the logfile.
# /parentdir/logdir/
# /parentdir/logdir/logfile.log
#
# It's possible to use this helper several times, each config will added to same logrotate config file.
ynh_use_logrotate () {
if [ "$#" -gt 0 ]; then
if [ "$(echo ${1##*.})" == "log" ]; then # Keep only the extension to check if it's a logfile
logfile=$1 # In this case, focus logrotate on the logfile
else
logfile=$1/.log # Else, uses the directory and all logfile into it.
fi
else
logfile="/var/log/${app}/.log" # Without argument, use a defaut directory in /var/log
fi
cat > ./${app}-logrotate << EOF # Build a config file for logrotate
$logfile {
# Rotate if the logfile exceeds 100Mo
size 100M
# Keep 12 old log maximum
rotate 12
# Compress the logs with gzip
compress
# Compress the log at the next cycle. So keep always 2 non compressed logs
delaycompress
# Copy and truncate the log to allow to continue write on it. Instead of move the log.
copytruncate
# Do not do an error if the log is missing
missingok
# Not rotate if the log is empty
notifempty
# Keep old logs in the same dir
noolddir
}
EOF
sudo mkdir -p $(dirname "$logfile") # Create the log directory, if not exist
cat ${app}-logrotate | sudo tee -a /etc/logrotate.d/$app > /dev/null # Append this config to the others for this app. If a config file already exist
}
# Remove the app's logrotate config.
#
# usage: ynh_remove_logrotate
ynh_remove_logrotate () {
if [ -e "/etc/logrotate.d/$app" ]; then
sudo rm "/etc/logrotate.d/$app"
fi
}
# Calculate and store a file checksum into the app settings
#
# $app should be defined when calling this helper
#
# usage: ynh_store_file_checksum file
# | arg: file - The file on which the checksum will performed, then stored.
ynh_store_file_checksum () {
local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_'
ynh_app_setting_set $app $checksum_setting_name $(sudo md5sum "$1" | cut -d' ' -f1)
}
# Verify the checksum and backup the file if it's different
# This helper is primarily meant to allow to easily backup personalised/manually
# modified config files.
#
# $app should be defined when calling this helper
#
# usage: ynh_backup_if_checksum_is_different file [compress]
# | arg: file - The file on which the checksum test will be perfomed.
# | arg: compress - 1 to compress the backup instead of a simple copy
# A compression is needed for a file which will be analyzed even if its name is different.
#
# | ret: Return the name a the backup file, or nothing
ynh_backup_if_checksum_is_different () {
local file=$1
local compress_backup=${2:-0} # If $2 is empty, compress_backup will set at 0
local checksum_setting_name=checksum_${file//[\/ ]/_} # Replace all '/' and ' ' by '_'
local checksum_value=$(ynh_app_setting_get $app $checksum_setting_name)
if [ -n "$checksum_value" ]
then # Proceed only if a value was stored into the app settings
if ! echo "$checksum_value $file" | sudo md5sum -c --status
then # If the checksum is now different
backup_file="$file.backup.$(date '+%d.%m.%y_%Hh%M,%Ss')"
if [ $compress_backup -eq 1 ]
then
sudo tar --create --gzip --file "$backup_file.tar.gz" "$file" # Backup the current file and compress
backup_file="$backup_file.tar.gz"
else
sudo cp -a "$file" "$backup_file" # Backup the current file
fi
echo "File $file has been manually modified since the installation or last upgrade. So it has been duplicated in $backup_file" >&2
echo "$backup_file" # Return the name of the backup file
fi
fi
}
# Create a dedicated php-fpm config
final_path=$1
# usage: ynh_add_fpm_config
ynh_add_fpm_config () {
finalphpconf="/etc/php5/fpm/pool.d/$app.conf"
ynh_backup_if_checksum_is_different "$finalphpconf" 1
sudo cp ../conf/php-fpm.conf "$finalphpconf"
ynh_replace_string "__NAMETOCHANGE__" "$app" "$finalphpconf"
ynh_replace_string "__FINALPATH__" "$final_path" "$finalphpconf"
ynh_replace_string "__USER__" "$app" "$finalphpconf"
sudo chown root: "$finalphpconf"
ynh_store_file_checksum "$finalphpconf"
if [ -e "../conf/php-fpm.ini" ]
then
finalphpini="/etc/php5/fpm/conf.d/20-$app.ini"
ynh_backup_if_checksum_is_different "$finalphpini" 1
sudo cp ../conf/php-fpm.ini "$finalphpini"
sudo chown root: "$finalphpini"
ynh_store_file_checksum "$finalphpini"
fi
sudo systemctl reload php5-fpm
}
# Remove the dedicated php-fpm config
#
# usage: ynh_remove_fpm_config
ynh_remove_fpm_config () {
ynh_secure_remove "/etc/php5/fpm/pool.d/$app.conf"
ynh_secure_remove "/etc/php5/fpm/conf.d/20-$app.ini" 2>&1
sudo systemctl reload php5-fpm
old_app=$YNH_APP_INSTANCE_NAME
local old_app_id=$YNH_APP_ID
local old_app_number=$YNH_APP_INSTANCE_NUMBER
# Get the id from which to migrate
local migration_id="$1"
# And the file with the paths to move
local migration_list="$2"
# Get the new app id in the manifest
local new_app_id=$(grep \"id\": ../manifest.json | cut -d\" -f4)
if [ $old_app_number -eq 1 ]; then
local new_app=$new_app_id
else
local new_app=${new_app_id}__${old_app_number}
fi
#=================================================
# CHECK IF IT HAS TO MIGRATE
#=================================================
migration_process=0
if [ "$old_app_id" == "$new_app_id" ]
then
# If the 2 id are the same
# No migration to do.
echo 0
return 0
else
if [ "$old_app_id" != "$migration_id" ]
then
# If the new app is not the authorized id, fail.
ynh_die "Incompatible application for migration from $old_app_id to $new_app_id"
fi
echo "Migrate from $old_app_id to $new_app_id" >&2
#=================================================
# CHECK IF THE MIGRATION CAN BE DONE
#=================================================
# TODO Handle multi instance apps...
# Check that there is not already an app installed for this id.
(yunohost app list --installed -f "$new_app" | grep -q id) \
&& ynh_die "$new_app is already installed"
#=================================================
# CHECK THE LIST OF FILES TO MOVE
#=================================================
local temp_migration_list="$(tempfile)"
# Build the list by removing blank lines and comment lines
sed '/^#.*\|^$/d' "../conf/$migration_list" > "$temp_migration_list"
# Check if there is no file in the destination
local file_to_move=""
while read file_to_move
do
# Replace all occurences of $app by $new_app in each file to move.
local move_to_destination="${file_to_move//\$app/$new_app}"
test -e "$move_to_destination" && ynh_die "A file named $move_to_destination already exists."
done < "$temp_migration_list"
#=================================================
# COPY YUNOHOST SETTINGS FOR THIS APP
#=================================================
local settings_dir="/etc/yunohost/apps"
cp -a "$settings_dir/$old_app" "$settings_dir/$new_app"
# Replace the old id by the new one
ynh_replace_string "\(^id: .*\)$old_app" "\1$new_app" "$settings_dir/$new_app/settings.yml"
# INFO: There a special behavior with yunohost app setting:
# if the id given in argument does not match with the id
# stored in the config file, the config file will be purged.
# That's why we use sed instead of app setting here.
# https://github.com/YunoHost/yunohost/blob/c6b5284be8da39cf2da4e1036a730eb5e0515096/src/yunohost/app.py#L1316-L1321
# Change the label if it's simply the name of the app
old_label=$(ynh_app_setting_get $new_app label)
if [ "${old_label,,}" == "$old_app_id" ]
then
# Build the new label from the id of the app. With the first character as upper case
new_label=$(echo $new_app_id | cut -c1 | tr [:lower:] [:upper:])$(echo $new_app_id | cut -c2-)
ynh_app_setting_set $new_app label $new_label
fi
#=================================================
# MOVE FILES TO THE NEW DESTINATION
#=================================================
while read file_to_move
do
# Replace all occurence of $app by $new_app in each file to move.
move_to_destination="$(eval echo "${file_to_move//\$app/$new_app}")"
local real_file_to_move="$(eval echo "${file_to_move//\$app/$old_app}")"
echo "Move file $real_file_to_move to $move_to_destination" >&2
mv "$real_file_to_move" "$move_to_destination"
done < "$temp_migration_list"
#=================================================
# UPDATE SETTINGS KNOWN ENTRIES
#=================================================
# Replace nginx checksum
ynh_replace_string "\(^checksum__etc_nginx.*\)_$old_app" "\1_$new_app/" "$settings_dir/$new_app/settings.yml"
# Replace php5-fpm checksums
ynh_replace_string "\(^checksum__etc_php5.*[-_]\)$old_app" "\1$new_app/" "$settings_dir/$new_app/settings.yml"
# Replace final_path
ynh_replace_string "\(^final_path: .*\)$old_app" "\1$new_app" "$settings_dir/$new_app/settings.yml"
#=================================================
# MOVE THE DATABASE
#=================================================
db_pwd=$(ynh_app_setting_get $old_app mysqlpwd)
db_name=$(ynh_app_setting_get $old_app db_name)
# Check if a database exists before trying to move it
local mysql_root_password=$(cat $MYSQL_ROOT_PWD_FILE)
if [ -n "$db_name" ] && mysqlshow -u root -p$mysql_root_password | grep -q "^| $db_name"
then
new_db_name=$(ynh_sanitize_dbid $new_app)
echo "Rename the database $db_name to $new_db_name" >&2
local sql_dump="/tmp/${db_name}-$(date '+%s').sql"
# Dump the old database
ynh_mysql_dump_db "$db_name" > "$sql_dump"
# Create a new database
ynh_mysql_setup_db $new_db_name $new_db_name $db_pwd
# Then restore the old one into the new one
ynh_mysql_connect_as $new_db_name $db_pwd $new_db_name < "$sql_dump"
# Remove the old database
ynh_mysql_remove_db $db_name $db_name
# And the dump
ynh_secure_remove "$sql_dump"
# Update the value of $db_name
db_name=$new_db_name
ynh_app_setting_set $new_app db_name $db_name
fi
#=================================================
# CREATE A NEW USER
#=================================================
# Check if the user exists on the system
if ynh_system_user_exists "$old_app"
then
echo "Create a new user $new_app to replace $old_app" >&2
ynh_system_user_create $new_app
fi
#=================================================
# CHANGE THE FAKE DEPENDENCIES PACKAGE
#=================================================
# Check if a variable $pkg_dependencies exists
# If this variable doesn't exist, this part shall be managed in the upgrade script.
if [ -n "${pkg_dependencies:-}" ]
then
# Define the name of the package
local old_package_name="${old_app//_/-}-ynh-deps"
local new_package_name="${new_app//_/-}-ynh-deps"
if ynh_package_is_installed "$old_package_name"
then
# Install a new fake package
app=$new_app
ynh_install_app_dependencies $pkg_dependencies
# Then remove the old one
app=$old_app
ynh_remove_app_dependencies
fi
fi
#=================================================
# UPDATE THE ID OF THE APP
#=================================================
app=$new_app
# Set migration_process to 1 to inform that an upgrade has been made
migration_process=1
fi
}

View file

@ -1,48 +1,86 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit on command errors and treat access to unset variables as an error
set -eu
# Get multi-instances specific variables
app=$YNH_APP_INSTANCE_NAME
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Set app specific variables
dbname=$app
dbuser=$app
# Source app helpers
if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
source /usr/share/yunohost/helpers
# Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
#=================================================
# LOAD SETTINGS
#=================================================
# Copy the app source files
DESTDIR="/var/www/$app"
ynh_backup "$DESTDIR" "www"
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path)
domain=$(ynh_app_setting_get $app domain)
db_name=$(ynh_app_setting_get $app db_name)
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup "$final_path"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE PHP-FPM CONFIGURATION
#=================================================
ynh_backup "/etc/php5/fpm/pool.d/$app.conf"
ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
ynh_mysql_dump_db "$db_name" > db.sql
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
#=================================================
ynh_backup "/etc/logrotate.d/$app"
#=================================================
# BACKUP THE CRON FILE
#=================================================
ynh_backup "/etc/cron.d/$app"
#=================================================
# BACKUP THE DATA DIRECTORY
#=================================================
# Copy the data directory
backup_core_only=$(ynh_app_setting_get "$app" backup_core_only)
if [ -z $backup_core_only ] # Si backup_core_only a une valeur dans le fichier settings.yml, ne sauvegarde pas le dossier data
# If backup_core_only have any value in the settings.yml file, do not backup the data directory
if [ -z $backup_core_only ]
then
DATADIR="/home/yunohost.app/${app}/data"
ynh_backup "$DATADIR" "data" 1
ynh_backup "/home/yunohost.app/${app}/data"
else
echo "Data dir will not saved, because backup_core_only is set." >&2
fi
# Copy the conf files
mkdir ./conf
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "conf/nginx.conf"
ynh_backup "/etc/php5/fpm/pool.d/${app}.conf" "conf/php-fpm.conf"
ynh_backup "/etc/cron.d/${app}" "conf/cron"
# Dump the database
mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./db.sql
# Copy the control file of the dependency package
# FIXME: find a way to retrieve package name from _common.sh?
dpkg-query -s nextcloud-deps > ./nextcloud-deps.control
# Backup the logrotate configuration file
ynh_backup "/etc/logrotate.d/$app" "logrotate"

View file

@ -1,192 +1,273 @@
#!/bin/bash
set -eu
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Retrieve arguments
domain=$1
path=${2%/}
admin=$3
user_home=$4
# Load common variables
source ./_common.sh
# Set app specific variables
app=$APPNAME
dbname=$app
dbuser=$app
# Source app helpers
source _common.sh
source /usr/share/yunohost/helpers
# Comments of this code was deleted, because it were in french...
if [ "${path:0:1}" != "/" ] && [ ${#path} -gt 0 ]; then
path="/$path"
fi
if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then
path="${path:0:${#path}-1}"
fi
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# TODO: Check domain/path availability with app helper
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|| ynh_die "The path ${domain}${path} is not available for app installation."
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
# Check user parameter
ynh_user_exists "$admin" \
|| ynh_die "The chosen admin user does not exist."
ynh_app_setting_set $app admin_user $admin
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
# Check destination directory
DESTDIR="/var/www/$app"
[[ -d $DESTDIR ]] && ynh_die \
"The destination directory '$DESTDIR' already exists.\
You should safely delete it before installing this app."
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
user_home=$YNH_APP_ARG_USER_HOME
# Define app's data directory
DATADIR="/home/yunohost.app/${app}/data"
app=$YNH_APP_INSTANCE_NAME
# Install dependencies
ynh_package_install_from_equivs ../conf/${DEPS_PKG_NAME}.control \
|| ynh_die "Unable to install dependencies"
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
# Generate random password
dbpass=$(ynh_string_random)
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Initialize database
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
# Create a system account for Nextcloud
sudo useradd -c "$app system account" \
-d /var/lib/$app --system --user-group $app \
|| ynh_die "Unable to create $app system account"
# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path
ynh_webpath_register $app $domain $path_url
# Set system group in hooks
sed -i "s@#GROUP#@${app}@g" ../hooks/post_user_create
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
# Create app folders
sudo mkdir -p "$DESTDIR" "$DATADIR"
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path_url
ynh_app_setting_set $app admin $admin
ynh_app_setting_set $app user_home $user_home
# Copy Nextcloud configuration file
nc_conf="${DESTDIR}/config.json"
sed -i "s@#DOMAIN#@${domain}@g" ../conf/config.json
sed -i "s@#DATADIR#@${DATADIR}@g" ../conf/config.json
sudo cp ../conf/config.json "$nc_conf"
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
# Copy and set nginx configuration
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
sed -i "s@#APP#@${app}@g" ../conf/nginx.conf
sed -i "s@#PATH#@${path}@g" ../conf/nginx.conf
sed -i "s@#LOCATION#@${path:-/}@g" ../conf/nginx.conf
sed -i "s@#DESTDIR#@${DESTDIR}@g" ../conf/nginx.conf
# do not serve .well-known if it's already served on the domain
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
ynh_mysql_setup_db $db_name $db_name
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# Load the last available version
source upgrade.d/upgrade.last.sh
# Create an app.src for the last version of nextcloud
cp ../conf/app.src.default ../conf/app.src
ynh_replace_string "__VERSION__" "$next_version" "../conf/app.src"
ynh_replace_string "__SHA256_SUM__" "$nextcloud_source_sha256" "../conf/app.src"
ynh_app_setting_set $app final_path $final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
# Do not serve .well-known if it's already served on the domain
if is_url_handled "https://${domain}/.well-known/caldav" ; then
sed -ri '/^location = \/\.well\-known\/(caldav|carddav) \{/,/\}/d' \
../conf/nginx.conf
sed -ri '/^location = \/\.well\-known\/(caldav|carddav) \{/,/\}/d' \
"../conf/nginx.conf"
fi
sudo cp ../conf/nginx.conf "$nginx_conf"
# Copy and set php-fpm configuration
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
sed -i "s@#USER#@${app}@g" ../conf/php-fpm.conf
sed -i "s@#GROUP#@${app}@g" ../conf/php-fpm.conf
sed -i "s@#POOLNAME#@${app}@g" ../conf/php-fpm.conf
sed -i "s@#DESTDIR#@${DESTDIR}/@g" ../conf/php-fpm.conf
sudo cp ../conf/php-fpm.conf "$phpfpm_conf"
sudo chown root: $phpfpm_conf
sudo chmod 644 $phpfpm_conf
# Handle root path, avoid double slash.
# Temporary fix, in waiting for an upgrade of the helper. (#361)
path_url_slash_less=${path_url%/}
ynh_replace_string "__PATH__/" "$path_url_slash_less/" "../conf/nginx.conf"
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
# Create a dedicated php-fpm config
ynh_add_fpm_config
# occ helper for the current installation
_exec_occ() {
exec_occ "$DESTDIR" "$app" $@
}
#=================================================
# SPECIFIC SETUP
#=================================================
# CREATE THE DATA DIRECTORY
#=================================================
# Set app folders ownership
sudo chown -R $app: "$DESTDIR" "$DATADIR"
# Define app's data directory
datadir="/home/yunohost.app/${app}/data"
# Create app folders
mkdir -p "$datadir"
# Retrieve Nextcloud sources
VERSION=$LAST_VERSION
NEXTCLOUD_SOURCE_SHA256=$(grep "NEXTCLOUD_SOURCE_SHA256=" "upgrade.d/upgrade.last.sh" | cut -d= -f2)
extract_nextcloud "$DESTDIR" "$app"
#=================================================
# INSTALL NEXTCLOUD
#=================================================
# Set write access for the following commands
chown -R $app: "$final_path" "$datadir"
# Install Nextcloud using a temporary admin user
_exec_occ maintenance:install \
--database "mysql" --database-name "$dbname" \
--database-user "$dbuser" --database-pass "$dbpass" \
exec_occ maintenance:install \
--database "mysql" --database-name "$db_name" \
--database-user "$db_name" --database-pass "$db_pwd" \
--admin-user "admin" --admin-pass "$(ynh_string_random 6)" \
--data-dir "$DATADIR" \
--data-dir "$datadir" \
|| ynh_die "Unable to install Nextcloud"
#=================================================
# CONFIGURE NEXTCLOUD
#=================================================
nc_conf="${final_path}/config.json"
cp ../conf/config.json "$nc_conf"
ynh_replace_string "#DOMAIN#" "$domain" "$nc_conf"
ynh_replace_string "#DATADIR#" "$datadir" "$nc_conf"
# Ensure that UpdateNotification app is disabled
_exec_occ app:disable updatenotification
exec_occ app:disable updatenotification
# Enable plugins and set Nextcloud configuration
_exec_occ app:enable user_ldap
_exec_occ ldap:create-empty-config
_exec_occ config:import "$nc_conf"
sudo rm -f "$nc_conf"
# Enable plugins
exec_occ app:enable user_ldap
exec_occ ldap:create-empty-config
# Check LDAP configuratio to see if everything worked well
_exec_occ ldap:test-config \'\' \
# Load the config file in nextcloud
exec_occ config:import "$nc_conf"
# Then remove it
rm -f "$nc_conf"
#=================================================
# CHECK THE LDAP CONFIG
#=================================================
# Check LDAP configuration to see if everything worked well
exec_occ ldap:test-config \'\' \
|| ynh_die "An error occured during LDAP configuration"
#=================================================
# MOUNT HOME FOLDERS AS EXTERNAL STORAGE
#=================================================
# Enable External Storage and create local mount to home folder
if [[ $user_home -eq 1 ]]; then
_exec_occ app:enable files_external
create_home_external_storage '_exec_occ'
if [ $user_home -eq 1 ]; then
exec_occ app:enable files_external
create_home_external_storage
fi
#=================================================
# ALLOW USERS TO DISCONNECT FROM NEXTCLOUD
#=================================================
# Add dynamic logout URL to the config
_exec_occ config:system:get logout_url >/dev/null 2>&1 \
|| sudo su -c "echo \"
exec_occ config:system:get logout_url >/dev/null 2>&1 \
|| echo "
//-YunoHost-
// set logout_url according to main domain
\\\$main_domain = exec('cat /etc/yunohost/current_host');
\\\$CONFIG['logout_url'] = 'https://'.\\\$main_domain.'/yunohost/sso/?action=logout';
\$main_domain = exec('cat /etc/yunohost/current_host');
\$CONFIG['logout_url'] = 'https://'.\$main_domain.'/yunohost/sso/?action=logout';
//-YunoHost-
\" >> ${DESTDIR}/config/config.php" -- $app
" >> "${final_path}/config/config.php"
# Set the user as admin and delete admin user
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" \
#=================================================
# REMOVE THE TEMPORARY ADMIN AND SET THE TRUE ONE
#=================================================
# Set the user as admin
ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" \
<<< "INSERT INTO oc_group_user VALUES ('admin','$admin');"
_exec_occ user:delete admin
# And delete admin user
exec_occ user:delete admin
#=================================================
# STORE THE CHECKSUM OF THE CONFIG FILE
#=================================================
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "${final_path}/config/config.php"
#=================================================
# ADD A CRON JOB
#=================================================
cron_path="/etc/cron.d/$app"
cp -a ../conf/nextcloud.cron "$cron_path"
ynh_replace_string "#USER#" "$app" "$cron_path"
ynh_replace_string "#DESTDIR#" "$final_path" "$cron_path"
exec_occ background:cron
#=================================================
# CONFIGURE THE HOOK FILE FOR USER CREATE
#=================================================
# Set system group in hooks
ynh_replace_string "#GROUP#" "$app" ../hooks/post_user_create
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Fix app ownerships & permissions
chown -R $app: "$final_path" "$datadir"
find ${final_path}/ -type f -print0 | xargs -0 chmod 0644
find ${final_path}/ -type d -print0 | xargs -0 chmod 0755
find ${datadir}/ -type f -print0 | xargs -0 chmod 0640
find ${datadir}/ -type d -print0 | xargs -0 chmod 0750
chmod 640 "${final_path}/config/config.php"
chmod 755 /home/yunohost.app
# Iterate over users to extend their home folder permissions - for the external
# storage plugin usage - and create relevant Nextcloud directories
for u in $(ynh_user_list); do
sudo mkdir -p "${DATADIR}/${u}"
sudo setfacl -m g:$app:rwx "/home/$u" || true
mkdir -p "${datadir}/${u}"
setfacl -m g:$app:rwx "/home/$u" || true
done
# Fix app ownerships & permissions
sudo chown -R $app: "$DESTDIR" "$DATADIR"
sudo find ${DESTDIR}/ -type f -print0 | sudo xargs -0 chmod 0644
sudo find ${DESTDIR}/ -type d -print0 | sudo xargs -0 chmod 0755
sudo find ${DATADIR}/ -type f -print0 | sudo xargs -0 chmod 0640
sudo find ${DATADIR}/ -type d -print0 | sudo xargs -0 chmod 0750
sudo chmod 640 "${DESTDIR}/config/config.php"
sudo chmod 755 /home/yunohost.app
#=================================================
# SETUP LOGROTATE
#=================================================
# Store app settings
ynh_app_setting_set "$app" user_home "$user_home"
ynh_app_setting_set "$app" mysqlpwd "$dbpass"
# Use logrotate to manage application logfile
ynh_use_logrotate "/home/yunohost.app/nextcloud/data/nextcloud.log"
# Set SSOwat rules
ynh_app_setting_set "$app" unprotected_uris "/"
ynh_app_setting_set "$app" skipped_regex \
#=================================================
# SETUP SSOWAT
#=================================================
ynh_app_setting_set $app unprotected_uris "/"
ynh_app_setting_set $app skipped_regex \
"$(sed 's/[\.\-]/\%&/g' <<< $domain)/%.well%-known/.*"
# Reload services
sudo service php5-fpm restart || true
sudo service nginx reload || true
#=================================================
# RELOAD NGINX
#=================================================
# Add cron job
cron_path="/etc/cron.d/$app"
sed -i "s@#USER#@${app}@g" ../conf/nextcloud.cron
sed -i "s@#DESTDIR#@${DESTDIR}@g" ../conf/nextcloud.cron
sudo cp ../conf/nextcloud.cron "$cron_path"
sudo chmod 644 "$cron_path"
_exec_occ background:cron
# Setup log rotation
ynh_use_logrotate "/home/yunohost.app/nextcloud/data/nextcloud.log"
systemctl reload nginx

View file

@ -1,50 +1,92 @@
#!/bin/bash
# Load common variables and helpers
source ./_common.sh
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Source app helpers
source _common.sh
source /usr/share/yunohost/helpers
# Set app specific variables
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
dbname=$app
dbuser=$app
# Remove cron job
# TODO: Ensure that cron job is not running
sudo rm -f "/etc/cron.d/${app}"
domain=$(ynh_app_setting_get $app domain)
db_name=$(ynh_app_setting_get $app db_name)
final_path=$(ynh_app_setting_get $app final_path)
# Drop MySQL database and user
ynh_mysql_drop_db "$dbname"
ynh_mysql_drop_user "$dbuser"
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE DEPENDENCIES
#=================================================
# Retrieve domain from app settings
domain=$(ynh_app_setting_get "$app" domain)
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
# Delete app directory and configurations
[[ "/var/www" =~ "/var/www/${app}" ]] \
|| (test -n "$app" && sudo rm -r "/var/www/${app}" )
#=================================================
# REMOVE THE MYSQL DATABASE
#=================================================
sudo rm -f "/etc/php5/fpm/pool.d/${app}.conf"
[[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf"
# Remove a database if it exists, along with the associated user
ynh_mysql_remove_db $db_name $db_name
# Reload services
sudo service php5-fpm reload
sudo service nginx reload
#=================================================
# REMOVE APP MAIN DIR
#=================================================
# Remove app dependencies
ynh_package_autoremove "$DEPS_PKG_NAME"
# Remove the app directory securely
ynh_secure_remove "$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
# Remove the dedicated nginx config
ynh_remove_nginx_config
#=================================================
# REMOVE PHP-FPM CONFIGURATION
#=================================================
# Remove the dedicated php-fpm config
ynh_remove_fpm_config
#=================================================
# REMOVE LOGROTATE CONFIGURATION
#=================================================
# Remove the app-specific logrotate config
ynh_remove_logrotate
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE THE CRON FILE
#=================================================
# Remove a cron file
# TODO: Ensure that cron job is not running (How !?)
ynh_secure_remove "/etc/cron.d/$app"
#=================================================
# CLEAN ACL IN HOME DIRECTORIES
#=================================================
# Clean home folders ACLs
for i in $(ls /home); do
[[ ! $i == yunohost.* ]] \
&& sudo setfacl -x g:$app:rwx >/dev/null 2>&1
&& setfacl -x g:$app:rwx 2>&1
done
# Remove the user account
id "$app" >/dev/null 2>&1 \
&& sudo deluser --quiet --remove-home "$app" >/dev/null
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
# Remove logrotate configuration
ynh_remove_logrotate
# Delete a system user
ynh_system_user_delete $app

View file

@ -1,96 +1,138 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit on command errors and treat access to unset variables as an error
set -eu
# Get multi-instances specific variables
app=$YNH_APP_INSTANCE_NAME
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Set app specific variables
dbname=$app
dbuser=$app
# Source app helpers
if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
source /usr/share/yunohost/helpers
# Retrieve old app settings
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
#=================================================
# LOAD SETTINGS
#=================================================
# TODO: Check domain/path availability with app helper
# Temporarily conditioned, see https://dev.yunohost.org/issues/593
if [ ${#path} -gt 1 ]; then
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|| ynh_die "The path ${domain}${path} is not available for app installation."
fi
app=$YNH_APP_INSTANCE_NAME
# Check destination directory
DESTDIR="/var/www/$app"
[[ -d $DESTDIR ]] && ynh_die \
"The destination directory '$DESTDIR' already exists.\
You should safely delete it before restoring this app."
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
# Define app's data directory
DATADIR="/home/yunohost.app/${app}/data"
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
# Check configuration files
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
[[ -f $nginx_conf ]] && ynh_die \
"The NGINX configuration already exists at '${nginx_conf}'.
You should safely delete it before restoring this app."
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
[[ -f $phpfpm_conf ]] && ynh_die \
"The PHP FPM configuration already exists at '${phpfpm_conf}'.
You should safely delete it before restoring this app."
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
# Install dependencies
ynh_package_install_from_equivs ./nextcloud-deps.control \
|| ynh_die "Unable to install dependencies"
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
# Create a system account for Nextcloud
sudo useradd -c "$app system account" \
-d /var/lib/$app --system --user-group $app \
|| ynh_die "Unable to create $app system account"
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
# Restore the app files
sudo cp -a ./www "$DESTDIR"
sudo mkdir -p "$DATADIR"
if [ -d ./data ] # Le dossier data est restauré seulement si il existe. Si le backup a été fait avec l'option backup_core_only, ce dossier n'a pas été sauvegardé.
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_restore_file "$final_path"
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
ynh_mysql_setup_db $db_name $db_name $db_pwd
ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
# Create the dedicated user (if not existing)
ynh_system_user_create $app
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf"
ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# RESTORE THE CRON FILE
#=================================================
ynh_restore_file "/etc/cron.d/$app"
#=================================================
# BACKUP THE LOGROTATE CONFIGURATION
#=================================================
ynh_restore_file "/etc/logrotate.d/$app"
#=================================================
# RESTORE THE DATA DIRECTORY
#=================================================
# The data directory will be restored only if it exists in the backup archive
# So only if it was backup previously.
if [ -d "$YNH_BACKUP_DIR/data" ]
then
sudo cp -a ./data/. "$DATADIR"
datadir="/home/yunohost.app/${app}/data"
ynh_restore_file "$datadir"
fi
ynh_app_setting_delete $app backup_core_only # Retire l'option backup_core_only du fichier settings.yml le cas échéant
# Remove the option backup_core_only if it's in the settings.yml file
ynh_app_setting_delete $app backup_core_only
# Create and restore the database
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./db.sql
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Fix app ownerships & permissions
chown -R $app: "$final_path" "$datadir"
chmod 640 "${final_path}/config/config.php"
chmod 755 /home/yunohost.app
# Iterate over users to extend their home folder permissions - for the external
# storage plugin usage - and create relevant Nextcloud directories
for u in $(ynh_user_list); do
sudo mkdir -p "${DATADIR}/${u}"
sudo setfacl -m g:$app:rwx "/home/$u" || true
mkdir -p "${datadir}/${u}"
setfacl -m g:$app:rwx "/home/$u" || true
done
# Fix app ownerships & permissions
sudo chown -R $app: "$DESTDIR" "$DATADIR"
sudo find ${DESTDIR}/ -type f -print0 | sudo xargs -0 chmod 0644
sudo find ${DESTDIR}/ -type d -print0 | sudo xargs -0 chmod 0755
sudo find ${DATADIR}/ -type f -print0 | sudo xargs -0 chmod 0640
sudo find ${DATADIR}/ -type d -print0 | sudo xargs -0 chmod 0750
sudo chmod 640 "${DESTDIR}/config/config.php"
sudo chmod 755 /home/yunohost.app
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
# Restore configuration files
sudo cp -a ./conf/nginx.conf "$nginx_conf"
sudo cp -a ./conf/php-fpm.conf "$phpfpm_conf"
# Restore cron job
sudo cp -a ./conf/cron "/etc/cron.d/${app}"
# Restore logrotate configuration file
sudo cp -a ./logrotate /etc/logrotate.d/$app
# Reload services
sudo service php5-fpm restart || true
sudo service nginx reload || true
systemctl reload php5-fpm
systemctl reload nginx

View file

@ -1,251 +1,374 @@
#!/bin/bash
# Load common variables and helpers
source ./_common.sh
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Source app helpers
source _common.sh
source /usr/share/yunohost/helpers
# Set app specific variables
app=$APPNAME
real_app=$YNH_APP_INSTANCE_NAME # real_app prendra la valeur nextcloud ou owncloud dans le cas d'une migration
dbname=$app
dbuser=$app
#=================================================
# LOAD SETTINGS
#=================================================
# Backup the current version of the app, restore it if the upgrade fails
backup_number=1
old_backup_number=2
if sudo yunohost backup list | grep -q $real_app-before-upgrade1 > /dev/null 2>&1; then # Vérifie l'existence d'une archive déjà numéroté à 1.
backup_number=2 # Et passe le numéro de l'archive à 2
old_backup_number=1
fi
ynh_app_setting_set $app backup_core_only 1 # Indique au backup/restore de ne pas sauvegarder le dossier de data, uniquement le core de nextcloud.
app=$YNH_APP_INSTANCE_NAME
if [ "$(cat /var/www/$real_app/version.php | grep OC_VersionString | cut -d\' -f2)" \> "11.0.0" ]
then # Pas de backup avant la version suivant 11.0.0 (soit 11.0.1), car le backup incluera les dossiers data.
sudo yunohost backup create --ignore-hooks --apps $real_app --name $real_app-before-upgrade$backup_number # Créer un backup différent de celui existant.
if [ "$?" -eq 0 ]; then # Si le backup est un succès, supprime l'archive précédente.
if sudo yunohost backup list | grep -q $real_app-before-upgrade$old_backup_number > /dev/null 2>&1; then # Vérifie l'existence de l'ancienne archive avant de la supprimer, pour éviter une erreur.
sudo yunohost backup delete $real_app-before-upgrade$old_backup_number > /dev/null
fi
else # Si le backup a échoué
ynh_die "Backup failed, the upgrade process was aborted."
fi
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
admin=$(ynh_app_setting_get $app admin)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
user_home=$(ynh_app_setting_get $app user_home)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# If db_name doesn't exist, create it
if [ -z $db_name ]; then
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
fi
EXIT_PROPERLY () {
exit_code=$?
if [ "$exit_code" -eq 0 ]; then
ynh_app_setting_delete $real_app backup_core_only
exit 0 # Quitte sans erreur si le script se termine correctement.
fi
trap '' EXIT
set +eu
echo "Upgrade failed." >&2
if sudo yunohost backup list | grep -q $real_app-before-upgrade$backup_number > /dev/null 2>&1; then # Vérifie l'existence de l'archive avant de supprimer l'application et de restaurer
sudo yunohost app remove $real_app # Supprime l'application avant de la restaurer.
sudo yunohost backup restore --ignore-hooks $real_app-before-upgrade$backup_number --apps $real_app --force # Restore the backup if upgrade failed
ynh_die "The app was restored to the way it was before the failed upgrade."
fi
}
set -eu
trap EXIT_PROPERLY EXIT
# Migrate from ownCloud to Nextcloud
if [[ $YNH_APP_INSTANCE_NAME != $app ]]; then # Si le nom de l'app donné lors de la commande n'est pas nextcloud, vérifie si c'est owncloud pour lancer la migration.
[[ $YNH_APP_ID == owncloud ]] \
|| ynh_die "Incompatible application to migrate to Nextcloud"
# real_app=$YNH_APP_INSTANCE_NAME # real_app prend le nom de owncloud.
./upgrade.d/owncloud.sh # Prépare la migration de owncloud vers nextcloud.
else
real_app=$app
# handle old migrations from ownCloud
curr_dbname=$(sudo cat "/var/www/${app}/config/config.php" \
| grep dbname | sed "s|.*=> '\(.*\)'.*|\1|g") # Prend le nom de la bdd dans le fichier de config
if [[ $curr_dbname != $dbname ]]; then # Si le nom de la base de donnée n'est pas nextcloud, renomme la base de donnée.
curr_dbuser=$(sudo cat "/var/www/${app}/config/config.php" \
| grep dbuser | sed "s|.*=> '\(.*\)'.*|\1|g") # Prend le nom d'utilisateur de la bdd
dbpass=$(ynh_app_setting_get "$real_app" mysqlpwd)
# rename the MySQL database
rename_mysql_db "$curr_dbname" "$curr_dbuser" "$dbpass" "$dbname" "$dbuser"
sudo sed -ri "s#^(\s*'dbname' =>).*,#\1 '${dbname}',#" \
"/var/www/${app}/config/config.php"
sudo sed -ri "s#^(\s*'dbuser' =>).*,#\1 '${dbuser}',#" \
"/var/www/${app}/config/config.php"
fi
# If final_path doesn't exist, create it
if [ -z $final_path ]; then
final_path=/var/www/$app
ynh_app_setting_set $app final_path $final_path
fi
# Retrieve app settings
domain=$(ynh_app_setting_get "$real_app" domain)
path=$(ynh_app_setting_get "$real_app" path)
path=${path%/}
dbpass=$(ynh_app_setting_get "$real_app" mysqlpwd)
user_home=$(ynh_app_setting_get "$real_app" user_home)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
# Check destination directory
DESTDIR="/var/www/$app"
[[ ! -d $DESTDIR ]] && ynh_die \
"The destination directory '$DESTDIR' does not exist.\
The app is not correctly installed, you should remove it first."
# Made a backup only after the version 11.0.0
# Before, the datas will be always saved.
# Check app's data directory
DATADIR="/home/yunohost.app/${app}/data"
[[ ! -d $DATADIR ]] && ynh_die \
"The data directory '$DATADIR' does not exist.\
The app is not correctly installed, you should remove it first."
# Get the current version number of nextcloud/owncloud
current_version=$(grep OC_VersionString "$final_path/version.php" | cut -d\' -f2)
current_major_version=${current_version%%.*}
# Upgrade dependencies
ynh_package_install_from_equivs ../conf/${DEPS_PKG_NAME}.control \
|| ynh_die "Unable to upgrade dependencies"
if [ $current_major_version -gt 11 ]
then
# Inform the backup/restore process that it should not save the data directory
ynh_app_setting_set $app backup_core_only 1
# FIXME: Delete current nginx configuration to be able to check if
# .well-known is already served. See https://dev.yunohost.org/issues/400
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
sudo rm -f "$nginx_conf"
sudo service nginx reload
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# Remove the post migration script before its execution !
ynh_secure_remove "/tmp/owncloud_post_migration.sh" 2>&1
# Copy and set nginx configuration
sed -i "s@#APP#@${app}@g" ../conf/nginx.conf
sed -i "s@#PATH#@${path}@g" ../conf/nginx.conf
sed -i "s@#LOCATION#@${path:-/}@g" ../conf/nginx.conf
sed -i "s@#DESTDIR#@${DESTDIR}@g" ../conf/nginx.conf
# do not serve .well-known if it's already served on the domain
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
fi
# Exit if an error occurs during the script execution
ynh_abort_if_errors
#=================================================
# HANDLE MIGRATION FROM OWNCLOUD
#=================================================
ynh_handle_app_migration "owncloud" "owncloud_migration"
if [ $migration_process -eq 1 ]
then
# If a migration has been perform
# Reload some values changed by the migration process
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
# Remove the old fake package for owncloud.
# Its name is specific, so the migration process can't remove it
ynh_package_autopurge owncloud-deps
# Change the database access in the config
ynh_replace_string "\('dbname' =>\).*" "\1 '$db_name'," "$final_path/config/config.php"
ynh_replace_string "\('dbuser' =>\).*" "\1 '$db_name'," "$final_path/config/config.php"
# Change the path of the data directory
ynh_replace_string "\('dbuser' =>\).*" "\1 '$db_name'," "$final_path/config/config.php"
ynh_replace_string "\('datadirectory' =>.*\)$old_app" "\1$app" "$final_path/config/config.php"
fi
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# NGINX CONFIGURATION
#=================================================
# Delete current nginx configuration to be able to check if .well-known is already served.
ynh_remove_nginx_config
ynh_app_setting_delete $app "checksum__etc_nginx_conf.d_$domain.d_$app.conf" || true
# Do not serve .well-known if it's already served on the domain
if is_url_handled "https://${domain}/.well-known/caldav" ; then
sed -ri '/^location = \/\.well\-known\/(caldav|carddav) \{/,/\}/d' \
../conf/nginx.conf
sed -ri '/^location = \/\.well\-known\/(caldav|carddav) \{/,/\}/d' \
"../conf/nginx.conf"
fi
sudo cp ../conf/nginx.conf "$nginx_conf"
# Copy and set php-fpm configuration
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
sed -i "s@#USER#@${app}@g" ../conf/php-fpm.conf
sed -i "s@#GROUP#@${app}@g" ../conf/php-fpm.conf
sed -i "s@#POOLNAME#@${app}@g" ../conf/php-fpm.conf
sed -i "s@#DESTDIR#@${DESTDIR}/@g" ../conf/php-fpm.conf
sudo cp ../conf/php-fpm.conf "$phpfpm_conf"
sudo chown root: $phpfpm_conf
sudo chmod 644 $phpfpm_conf
# Handle root path, avoid double slash.
# Temporary fix, in waiting for an upgrade of the helper. (#361)
path_url_slash_less=${path_url%/}
ynh_replace_string "__PATH__/" "$path_url_slash_less/" "../conf/nginx.conf"
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
# Create a dedicated php-fpm config
ynh_add_fpm_config
# Set system group in hooks
sed -i "s@#GROUP#@${app}@g" ../hooks/post_user_create
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
# occ helper for the current installation
_exec_occ() {
exec_occ "$DESTDIR" "$app" $@ # Appel de php occ avec les droits de l'user nextcloud. A noter que ce n'est là que la déclaration de la fonction qui sera appelée plus tard.
}
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# SPECIFIC UPGRADE
#=================================================
# MAKE SEQUENTIAL UPGRADES FROM EACH MAJOR
# VERSION TO THE NEXT ONE
#=================================================
# Effectue les mises à majeures une à une. Le saut de mise à jour n'étant pas supporté.
major_version=${LAST_VERSION%%.*} # La version majeure correspond à la première partie du numéro de version.
actual_version=$(cat "$DESTDIR/version.php" | grep OC_VersionString | cut -d\' -f2) # Relève le numéro de version de l'instance nextcloud installée
actual_major_version=${actual_version%%.*}
_exec_occ -V # Affiche la version
while [ "$major_version" -ne "$actual_major_version" ]; do # Si la version majeure actuelle ne correspond à la dernière version majeure.
./upgrade.d/upgrade.$actual_major_version.sh # Exécute la mise à jour vers la version majeure suivante
actual_version=$(cat "$DESTDIR/version.php" | grep OC_VersionString | cut -d\' -f2) # Relève le nouveau numéro de version, après mise à jour.
actual_major_version=${actual_version%%.*}
_exec_occ -V # Affiche la version
# Load the last available version
source upgrade.d/upgrade.last.sh
last_version=$next_version
# Define app's data directory
datadir="/home/yunohost.app/${app}/data"
# Set write access for the following commands
chown -R $app: "$final_path" "$datadir"
# Print the current version number of nextcloud
exec_occ -V
# While the current version is not the last version, do an upgrade
while [ "$last_version" != "$current_version" ]
do
# The major version is the first part of the version number
# major_version=${next_version%%.*}
major_version=${last_version%%.*}
current_major_version=${current_version%%.*}
# If the current version has the same major version than the next one,
# then it's the last upgrade to do
if [ "$major_version" -eq "$current_major_version" ]; then
current_major_version=last
fi
# Load the value for this version
source upgrade.d/upgrade.$current_major_version.sh
echo -e "\nUpgrade to nextcloud $next_version" >&2
# Create an app.src for this version of nextcloud
cp ../conf/app.src.default ../conf/app.src
ynh_replace_string "__VERSION__" "$next_version" "../conf/app.src"
ynh_replace_string "__SHA256_SUM__" "$nextcloud_source_sha256" "../conf/app.src"
# Create a temporary directory
tmpdir=$(mktemp -d)
# Install the next nextcloud version in $tmpdir
ynh_setup_source "$tmpdir"
# Enable maintenance mode
exec_occ maintenance:mode --on
# Backup the config file in the temp dir
cp -a "$final_path/config/config.php" "$tmpdir/config/config.php"
# Backup 3rd party applications from the current nextcloud
# But do not overwrite if there is any upgrade
cp -a --update "$final_path/apps" "$tmpdir/apps"
# Replace the old nextcloud by the new one
ynh_secure_remove "$final_path"
mv "$tmpdir" "$final_path"
# Set write access for the following commands
chown -R $app: "$final_path" "$datadir"
# Upgrade Nextcloud (SUCCESS = 0, UP_TO_DATE = 3)
exec_occ maintenance:mode --off
exec_occ upgrade \
|| ([[ $? -eq 3 ]] || ynh_die "Unable to upgrade Nextcloud")
# Get the new current version number
current_version=$(grep OC_VersionString "$final_path/version.php" | cut -d\' -f2)
current_major_version=${current_version%%.*}
# Print the current version number of nextcloud
exec_occ -V
done
if [ "$LAST_VERSION" != "$actual_version" ] # Si la version actuelle ne correspond à la dernière version, une mise à jour est nécessaire pour passer à la dernière version mineure.
then
./upgrade.d/upgrade.last.sh # Exécute la mise à jour vers la dernière version prise en charge.
fi
#=================================================
# CONFIGURE NEXTCLOUD
#=================================================
# Verify the checksum and backup the file if it's different
ynh_backup_if_checksum_is_different "${final_path}/config/config.php"
nc_conf="${final_path}/config.json"
cp ../conf/config.json "$nc_conf"
ynh_replace_string "#DOMAIN#" "$domain" "$nc_conf"
ynh_replace_string "#DATADIR#" "$datadir" "$nc_conf"
# Ensure that UpdateNotification app is disabled
_exec_occ app:disable updatenotification
exec_occ app:disable updatenotification
# Enable plugins and set Nextcloud configuration
_exec_occ app:enable user_ldap
nc_conf="${DESTDIR}/config.json"
_exec_occ config:import "$nc_conf"
sudo rm -f "$nc_conf"
# Enable plugins
exec_occ app:enable user_ldap
# Guess user_home value if empty
if [[ -z "${user_home:-}" ]]; then # user_home correspond au champs "Access the users home folder from Nextcloud?" du manifest
sudo cat "${DATADIR}/mount.json" >/dev/null 2>&1 \
&& user_home=1 \
|| user_home=0 # Test l'existence du fichier mount.json pour connaître la valeur de user_home, dans le cas où la valeur ne serait pas renseignée. (Mais ce fichier semble ne plus exister...)
ynh_app_setting_set "$real_app" user_home "$user_home"
fi
# Load the config file in nextcloud
exec_occ config:import "$nc_conf"
# Then remove it
rm -f "$nc_conf"
# Enable External Storage and create local mount to home folder as needed
if [[ ${user_home} -eq 1 ]]; then
_exec_occ app:enable files_external
_exec_occ files_external:list --output=json \
| grep -q '"storage":"\\\\OC\\\\Files\\\\Storage\\\\Local"' \
|| create_home_external_storage '_exec_occ'
fi
#=================================================
# ALLOW USERS TO DISCONNECT FROM NEXTCLOUD
#=================================================
# Add dynamic logout URL to the config
# TODO: if changes are made to this section, replace it with new one.
_exec_occ config:system:get logout_url >/dev/null 2>&1 \
|| sudo su -c "echo \"
exec_occ config:system:get logout_url >/dev/null 2>&1 \
|| echo "
//-YunoHost-
// set logout_url according to main domain
\\\$main_domain = exec('cat /etc/yunohost/current_host');
\\\$CONFIG['logout_url'] = 'https://'.\\\$main_domain.'/yunohost/sso/?action=logout';
\$main_domain = exec('cat /etc/yunohost/current_host');
\$CONFIG['logout_url'] = 'https://'.\$main_domain.'/yunohost/sso/?action=logout';
//-YunoHost-
\" >> ${DESTDIR}/config/config.php" -- $app
" >> "${final_path}/config/config.php"
#=================================================
# MOUNT HOME FOLDERS AS EXTERNAL STORAGE
#=================================================
# Enable External Storage and create local mount to home folder as needed
if [ $user_home -eq 1 ]; then
exec_occ app:enable files_external
exec_occ files_external:list --output=json \
| grep -q '"storage":"\\\\OC\\\\Files\\\\Storage\\\\Local"' \
|| create_home_external_storage
fi
#=================================================
# STORE THE CHECKSUM OF THE CONFIG FILE
#=================================================
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "${final_path}/config/config.php"
#=================================================
# UPDATE THE CRON JOB
#=================================================
cron_path="/etc/cron.d/$app"
cp -a ../conf/nextcloud.cron "$cron_path"
ynh_replace_string "#USER#" "$app" "$cron_path"
ynh_replace_string "#DESTDIR#" "$final_path" "$cron_path"
exec_occ background:cron
#=================================================
# UPDATE THE HOOK FILE FOR USER CREATE
#=================================================
# Set system group in hooks
ynh_replace_string "#GROUP#" "$app" ../hooks/post_user_create
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Fix app ownerships & permissions
chown -R $app: "$final_path" "$datadir"
find ${final_path}/ -type f -print0 | xargs -0 chmod 0644
find ${final_path}/ -type d -print0 | xargs -0 chmod 0755
find ${datadir}/ -type f -print0 | xargs -0 chmod 0640
find ${datadir}/ -type d -print0 | xargs -0 chmod 0750
chmod 640 "${final_path}/config/config.php"
chmod 755 /home/yunohost.app
# Iterate over users to extend their home folder permissions - for the external
# storage plugin usage - and create relevant Nextcloud directories
for u in $(ynh_user_list); do
sudo mkdir -p "${DATADIR}/${u}"
sudo setfacl -m g:$app:rwx "/home/$u" || true
mkdir -p "${datadir}/${u}"
setfacl -m g:$app:rwx "/home/$u" || true
done
# Fix app ownerships & permissions
sudo find ${DESTDIR}/ -type f -print0 | sudo xargs -0 chmod 0644
sudo find ${DESTDIR}/ -type d -print0 | sudo xargs -0 chmod 0755
sudo find ${DATADIR}/ -type f -print0 | sudo xargs -0 chmod 0640
sudo find ${DATADIR}/ -type d -print0 | sudo xargs -0 chmod 0750
sudo chmod 640 "${DESTDIR}/config/config.php"
sudo chmod 755 /home/yunohost.app
#=================================================
# WARNING ABOUT THIRD-PARTY APPS
#=================================================
# Set SSOwat rules
ynh_app_setting_set "$real_app" unprotected_uris "/"
ynh_app_setting_set "$real_app" skipped_regex \
# Warn about possible disabled apps
echo "Note that if you've installed some third-parties Nextcloud applications, \
they are probably disabled and you'll have to manually enable them again." >&2
#=================================================
# SETUP LOGROTATE
#=================================================
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP SSOWAT
#=================================================
ynh_app_setting_set $app unprotected_uris "/"
ynh_app_setting_set $app skipped_regex \
"$(sed 's/[\.\-]/\%&/g' <<< $domain)/%.well%-known/.*"
# Reload services
sudo service php5-fpm restart || true
sudo service nginx reload || true
#=================================================
# RELOAD NGINX
#=================================================
# Add cron job
cron_path="/etc/cron.d/$app"
sed -i "s@#USER#@${app}@g" ../conf/nextcloud.cron
sed -i "s@#DESTDIR#@${DESTDIR}@g" ../conf/nextcloud.cron
sudo cp ../conf/nextcloud.cron "$cron_path"
sudo chmod 644 "$cron_path"
_exec_occ background:cron
systemctl reload nginx
# Finish ownCloud migration
if [[ $real_app != $app ]]; then
echo "ownCloud has been successfully migrated to Nextcloud! \
#=================================================
# FINISH MIGRATION PROCESS
#=================================================
if [ $migration_process -eq 1 ]
then
echo "ownCloud has been successfully migrated to Nextcloud! \
A last scheduled operation will run in a couple of minutes to finish the \
migration in YunoHost side. Do not proceed any application operation while \
you don't see Nextcloud as installed." >&2
# install cron job and script for final migration step
script_path="/usr/local/sbin/owncloud-migration.sh"
sed -i "s@#APP#@${real_app}@g" ../conf/owncloud-migration.sh
sudo cp ../conf/owncloud-migration.sh "$script_path"
sudo chmod 755 "$script_path"
cron_path="/etc/cron.d/owncloud-migration"
echo "*/1 * * * * root $script_path" | sudo tee "$cron_path" >/dev/null
sudo chmod 644 "$cron_path"
# Execute a post migration script after the end of this upgrade.
# Mainly for some cleaning
script_post_migration=owncloud_post_migration.sh
ynh_replace_string "__OLD_APP__" "$old_app" ../conf/$script_post_migration
ynh_replace_string "__NEW_APP__" "$app" ../conf/$script_post_migration
cp ../conf/$script_post_migration /tmp
chmod +x /tmp/$script_post_migration
(cd /tmp; echo "/tmp/$script_post_migration > /tmp/$script_post_migration.log 2>&1" | at now + 2 minutes)
fi
# Setup log rotation
if [ ! -f "/etc/logrotate.d/$app" ]; then
# Don't change the logrotate conf file if already existing
# (the helper only appends the log file configuration)
ynh_use_logrotate "/home/yunohost.app/nextcloud/data/nextcloud.log"
fi
# Warn about possible disabled apps
echo "Note that if you've installed some third-parties Nextcloud applications, \
they are probably disabled and you'll have to manually activate them again." >&2

View file

@ -1,64 +0,0 @@
#!/bin/bash
# Préparation à la migration de owncloud 9 vers nextcloud.
# La migration sera effective lors de la mise à joru qui suivra
# Load common variables and helpers
source ./_common.sh
# Source app helpers
source /usr/share/yunohost/helpers
# Set app specific variables
app=$APPNAME
dbname=$app
dbuser=$app
# check that Nextcloud is not already installed
(sudo yunohost app list --installed -f "$app" | grep -q id) \
&& ynh_die "Nextcloud is already installed"
echo "Migration to nextcloud." >&2
# retrieve ownCloud app settings
real_app=$YNH_APP_INSTANCE_NAME # real_app prend le nom de owncloud.
domain=$(ynh_app_setting_get "$real_app" domain)
oc_dbpass=$(ynh_app_setting_get "$real_app" mysqlpwd)
oc_dbname=$real_app
oc_dbuser=$real_app
# remove nginx and php-fpm configuration files
sudo rm -f \
"/etc/nginx/conf.d/${domain}.d/${real_app}.conf" \
"/etc/php5/fpm/pool.d/${real_app}.conf" \
"/etc/cron.d/${real_app}"
# reload services to disable php-fpm and nginx config for ownCloud
sudo service php5-fpm reload || true
sudo service nginx reload || true
# remove dependencies package
ynh_package_remove owncloud-deps || true
# clean new destination and data directories
DESTDIR="/var/www/$app"
DATADIR="/home/yunohost.app/${app}/data"
SECURE_REMOVE '$DESTDIR' # Supprime le dossier de nextcloud dans /var/www le cas échéant
SECURE_REMOVE '/home/yunohost.app/$app' # Et dans yunohost.app
# rename ownCloud folders
sudo mv "/var/www/$real_app" "$DESTDIR" # Puis renomme les dossiers de owncloud en nextcloud
sudo mv "/home/yunohost.app/$real_app" "/home/yunohost.app/$app"
sudo sed -ri "s#^(\s*'datadirectory' =>).*,#\1 '${DATADIR}',#" \
"/var/www/${app}/config/config.php" # Change l'emplacement du dossier de data dans le fichier de config
# rename the MySQL database
rename_mysql_db "$oc_dbname" "$oc_dbuser" "$oc_dbpass" "$dbname" "$dbuser"
sudo sed -ri "s#^(\s*'dbname' =>).*,#\1 '${dbname}',#" \
"/var/www/${app}/config/config.php"
sudo sed -ri "s#^(\s*'dbuser' =>).*,#\1 '${dbuser}',#" \
"/var/www/${app}/config/config.php"
# rename ownCloud system group and account
sudo groupmod -n "$app" "$real_app"
sudo usermod -l "$app" "$real_app"

View file

@ -1,18 +1,7 @@
#!/bin/bash
# Version cible de la mise à jour de Nextcloud
VERSION="11.0.0"
next_version="11.0.0"
# Nextcloud tarball checksum
NEXTCLOUD_SOURCE_SHA256="5bdfcb36c5cf470b9a6679034cabf88bf1e50a9f3e47c08d189cc2280b621429"
# Load common variables and helpers
source ./_common.sh
# Source app helpers
source /usr/share/yunohost/helpers
# Load common upgrade function
source ./upgrade.d/upgrade.generic.sh
COMMON_UPGRADE # Met à jour Nextcloud vers la version suivante
nextcloud_source_sha256="5bdfcb36c5cf470b9a6679034cabf88bf1e50a9f3e47c08d189cc2280b621429"

View file

@ -1,18 +1,7 @@
#!/bin/bash
# Version cible de la mise à jour de Nextcloud
VERSION="12.0.0"
next_version="12.0.0"
# Nextcloud tarball checksum
NEXTCLOUD_SOURCE_SHA256="1b9d9cf05e657cd564a552b418fbf42d669ca51e0fd1f1f118fe44cbf93a243f"
# Load common variables and helpers
source ./_common.sh
# Source app helpers
source /usr/share/yunohost/helpers
# Load common upgrade function
source ./upgrade.d/upgrade.generic.sh
COMMON_UPGRADE # Met à jour Nextcloud vers la version suivante
nextcloud_source_sha256="1b9d9cf05e657cd564a552b418fbf42d669ca51e0fd1f1f118fe44cbf93a243f"

View file

@ -1,18 +1,7 @@
#!/bin/bash
# Version cible de la mise à jour de Nextcloud
VERSION="10.0.2"
next_version="10.0.2"
# Nextcloud tarball checksum
NEXTCLOUD_SOURCE_SHA256="a687a818778413484f06bb23b4e98589c73729fe2aa9feb1bf5584e3bd37103c"
# Load common variables and helpers
source ./_common.sh
# Source app helpers
source /usr/share/yunohost/helpers
# Load common upgrade function
source ./upgrade.d/upgrade.generic.sh
COMMON_UPGRADE # Met à jour Nextcloud vers la version suivante
nextcloud_source_sha256="a687a818778413484f06bb23b4e98589c73729fe2aa9feb1bf5584e3bd37103c"

View file

@ -1,53 +0,0 @@
#!/bin/bash
# Fonction rassemblant les opérations communes de mise à jour.
# occ helper for the current installation
_exec_occ() {
exec_occ "$DESTDIR" "$app" $@ # Appel de php occ avec les droits de l'user nextcloud. A noter que ce n'est là que la déclaration de la fonction qui sera appelée plus tard.
}
COMMON_UPGRADE () {
app=$APPNAME
DESTDIR="/var/www/$app"
DATADIR="/home/yunohost.app/$app/data"
domain=$(ynh_app_setting_get "$YNH_APP_INSTANCE_NAME" domain) # Utilise $YNH_APP_INSTANCE_NAME au lieu de $app pour utiliser la config de owncloud en cas de migration
echo -e "\nUpdate to nextcloud $VERSION" >&2
# Retrieve new Nextcloud sources in a temporary directory
TMPDIR=$(mktemp -d)
# Set temp folder ownership
sudo chown -R $app: "$TMPDIR"
extract_nextcloud "$TMPDIR" "$app" # Télécharge nextcloud, vérifie sa somme de contrôle et le décompresse.
# Copy Nextcloud configuration file
sed -i "s@#DOMAIN#@${domain}@g" ../conf/config.json
sed -i "s@#DATADIR#@${DATADIR}@g" ../conf/config.json
sudo cp ../conf/config.json "${TMPDIR}/config.json"
# Enable maintenance mode
_exec_occ maintenance:mode --on
# Copy config and 3rd party applications from current directory
sudo cp -a "${DESTDIR}/config/config.php" "${TMPDIR}/config/config.php"
for a in $(sudo ls "${DESTDIR}/apps"); do
[[ ! -d "${TMPDIR}/apps/$a" ]] \
&& sudo cp -a "${DESTDIR}/apps/$a" "${TMPDIR}/apps/$a"
done
# Rename existing app directory and move new one
SECURE_REMOVE '$DESTDIR' # Supprime le dossier actuel de nextcloud
sudo mv "$TMPDIR" "$DESTDIR" # Et le remplace par la nouvelle version du dossier temporaire
sudo chmod +x "$DESTDIR"
# Set app folders ownership
sudo chown -R $app: "$DESTDIR" "$DATADIR"
# Upgrade Nextcloud (SUCCESS = 0, UP_TO_DATE = 3)
# TODO: Restore old directory in case of failure?
_exec_occ maintenance:mode --off
_exec_occ upgrade \
|| ([[ $? -eq 3 ]] || ynh_die "Unable to upgrade Nextcloud")
}

View file

@ -1,18 +1,7 @@
#!/bin/bash
# Version cible de la mise à jour de Nextcloud
VERSION=12.0.2
# Last available nextcloud version
next_version="12.0.2"
# Nextcloud tarball checksum sha256
NEXTCLOUD_SOURCE_SHA256=eb34d6cb9f55ee84bf2ad847b4b08cdb925321848ffa2264a9b1566e7b21a17c
# Load common variables and helpers
source ./_common.sh
# Source app helpers
source /usr/share/yunohost/helpers
# Load common upgrade function
source ./upgrade.d/upgrade.generic.sh
COMMON_UPGRADE # Met à jour Nextcloud vers la version suivante
nextcloud_source_sha256="eb34d6cb9f55ee84bf2ad847b4b08cdb925321848ffa2264a9b1566e7b21a17c"