diff --git a/check_process b/check_process index bda783c..4b43fcc 100644 --- a/check_process +++ b/check_process @@ -5,36 +5,45 @@ ;; Test complet auto_remove=1 - ; Manifest - domain="domain.tld" (DOMAIN) - #path="/_matrix/static/" (PATH) + ; pre-install + # synapse parameters + domain="domain.tld" + path="/_matrix/static/" + is_public=1 + server_name="domain2.tld" + jitsi_server="jitsi.riot.im" #admin="john" (USER) #language="en" - is_public=1 (PUBLIC|public=1|private=0) #password="pass" #port="666" (PORT) + sudo yunohost tools update --apps + sudo yunohost domain add $domain --admin-password $PASSWORD + sudo yunohost domain add $server_name --admin-password $PASSWORD + sudo yunohost app install https://github.com/YunoHost-Apps/synapse_ynh/tree/testing -a "domain=$domain&server_name=$server_name&is_public=$is_public&jitsi_server=$jitsi_server" --force +# sudo yunohost app install https://github.com/tituspijean/zerotier_ynh --force + ; Manifest + # mautrix_whatsapp manifest parameters + port="8449" (PORT) + synapsenumber="1" whatsappbot="whatsappbot" - botadmin="@johndoe:domain.tld" - botusers="@johndoe:domain.tld" - ; pre-install - sudo yunohost app fetchlist - #sudo yunohost domain add baikaldomain.tld --admin-password $PASSWORD - sudo yunohost app install synapse -a "domain=domain.tld&server_name="Same than the domain"&is_public=1" + bot_is_synapse_admin="Yes" + botadmin="@johndoe:synapsedomain.tld" (USER) + botusers="@johndoe:synapsedomain.tld" ; Checks pkg_linter=1 - setup_sub_dir=1 - setup_root=1 - setup_nourl=0 + setup_sub_dir=0 + setup_root=0 + setup_nourl=1 setup_private=0 setup_public=1 - upgrade=0 + upgrade=1 #upgrade=1 from_commit=CommitHash - backup_restore=0 + backup_restore=1 multi_instance=1 # This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version. # incorrect_path=1 - port_already_use=0 + port_already_use=1 change_url=0 ;;; Levels # If the level 5 (Package linter) is forced to 1. Please add justifications here. diff --git a/conf/app.src b/conf/app.src index c9c820b..f82591e 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://github.com/tulir/mautrix-whatsapp/archive/44bb623e7a7486a0cdd13fd67b2aaca2ddba20ce.zip -SOURCE_SUM=d661ed3c79514f6c636176981caffaa8fa5d71c35fc3d2a3a9ffcc12cdb46294 + SOURCE_URL=https://github.com/tulir/mautrix-whatsapp/archive/v0.1.4.zip +SOURCE_SUM=341e7d39dc5bcfb257e7a3793a5b2a00fed3f9a0a9c3695e0bd987ef3da2ffbd SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=zip SOURCE_IN_SUBDIR=true diff --git a/conf/nginx.conf b/conf/nginx.conf deleted file mode 100644 index f2277ea..0000000 --- a/conf/nginx.conf +++ /dev/null @@ -1,33 +0,0 @@ -#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; -location __PATH__/ { - - # Path to source - alias __FINALPATH__/ ; - - # Force usage of https - if ($scheme = http) { - rewrite ^ https://$server_name$request_uri? permanent; - } - -### Example PHP configuration (remove it if not used) - index index.php; - - # Common parameter to increase upload size limit in conjunction with dedicated php-fpm file - #client_max_body_size 50M; - - try_files $uri $uri/ index.php; - location ~ [^/]\.php(/|$) { - fastcgi_split_path_info ^(.+?\.php)(/.*)$; - fastcgi_pass unix:/var/run/php/php7.0-fpm-__NAME__.sock; - - fastcgi_index index.php; - include fastcgi_params; - fastcgi_param REMOTE_USER $remote_user; - fastcgi_param PATH_INFO $fastcgi_path_info; - fastcgi_param SCRIPT_FILENAME $request_filename; - } -### End of PHP configuration part - - # Include SSOWAT user panel. - include conf.d/yunohost_panel.conf.inc; -} diff --git a/conf/php-fpm.conf b/conf/php-fpm.conf deleted file mode 100644 index ab5dca9..0000000 --- a/conf/php-fpm.conf +++ /dev/null @@ -1,430 +0,0 @@ -; Start a new pool named 'www'. -; the variable $pool can be used in any directive and will be replaced by the -; pool name ('www' here) -[__NAMETOCHANGE__] - -; Per pool prefix -; It only applies on the following directives: -; - 'access.log' -; - '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 IPv4 address on -; a specific port; -; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on -; a specific port; -; 'port' - to listen on a TCP socket to all addresses -; (IPv6 and IPv4-mapped) on a specific port; -; '/path/to/unix/socket' - to listen on a unix socket. -; Note: This value is mandatory. -listen = /var/run/php/php7.0-fpm-__NAMETOCHANGE__.sock - -; Set listen(2) backlog. -; Default Value: 511 (-1 on FreeBSD and OpenBSD) -;listen.backlog = 511 - -; 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 = 0660 -; When POSIX Access Control Lists are supported you can set them using -; these options, value is a comma separated list of user/group names. -; When set, listen.owner and listen.group are ignored -;listen.acl_users = -;listen.acl_groups = - -; List of addresses (IPv4/IPv6) 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 - -; 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 -; process.priority = -19 - -; Set the process dumpable flag (PR_SET_DUMPABLE prctl) even if the process user -; or group is differrent than the master process user. It allows to create process -; core dump and ptrace the process for the pool user. -; Default Value: no -; process.dumpable = yes - -; 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 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 = 5 - -; The number of child processes created on startup. -; 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. -; 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. -; 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. 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: /usr/share/php/7.0/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. 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 - -; 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: output 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) -; The strftime(3) format must be encapsuled in a %{}t tag -; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t -; %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) -; The strftime(3) format must be encapsuled in a %{}t tag -; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t -; %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 = log/$pool.log.slow - -; 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 = 0 - -; 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. -; Default Value: system defined value -;rlimit_files = 1024 - -; Set max core size rlimit. -; 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. -; Note: relative path can be used. -; Default Value: current directory or / when chroot -chdir = __FINALPATH__ - -; 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 - -; Clear environment in FPM workers -; Prevents arbitrary environment variables from reaching FPM worker processes -; by clearing the environment in workers before env vars specified in this -; pool configuration are added. -; Setting to "no" will make all environment variables available to PHP code -; via getenv(), $_ENV and $_SERVER. -; Default Value: yes -;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 -; execute php code. -; Note: set an empty value to allow all extensions. -; Default Value: .php -;security.limit_extensions = .php .php3 .php4 .php5 .php7 - -; 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 - -; Common values to change to increase file upload limit -; php_admin_value[upload_max_filesize] = 50M -; php_admin_value[post_max_size] = 50M -; php_admin_flag[mail.add_x_header] = Off - -; Other common parameters -; php_admin_value[max_execution_time] = 600 -; php_admin_value[max_input_time] = 300 -; php_admin_value[memory_limit] = 256M -; php_admin_flag[short_open_tag] = On diff --git a/manifest.json b/manifest.json index 832da81..a8aaccd 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "A WhatsApp puppeting bridge for Matrix/Synapse.", "fr": "Passerelle WhatsApp pour Matrix/Synapse." }, - "version": "1.0~ynh1", + "version": "0.1.4~ynh1", "url": "https://github.com/tulir/mautrix-whatsapp", "license": "AGPL3", "maintainer": { @@ -15,12 +15,9 @@ "url": "https://github.com/Gredin67/mautrix_whatsapp_ynh" }, "requirements": { - "yunohost": ">= 3.5" + "yunohost": ">= 4.0" }, "multi_instance": true, - "services": [ - "matrix-synapse" - ], "arguments": { "install": [ { @@ -78,6 +75,15 @@ }, "default": "Yes" }, + { + "name": "encryption", + "type": "bool", + "ask": { + "en": "Enable end-to-bridge encryption ?", + "fr": "Activer le chiffrement entre synapse et le bridge ?" + }, + "default": "false" + }, { "name": "botadmin", "type": "string", diff --git a/scripts/_common.sh b/scripts/_common.sh index 471f4f6..693250c 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,8 +5,8 @@ #================================================= # dependencies used by the app -pkg_dependencies="" -GO_VERSION="1.11" +pkg_dependencies="ffmpeg,g++" +GO_VERSION="1.14" GO_PATH="/usr/lib/go-$GO_VERSION/bin" #================================================= diff --git a/scripts/_ynh_install_extra_app_dependencies b/scripts/_ynh_install_extra_app_dependencies deleted file mode 100644 index 5c22d36..0000000 --- a/scripts/_ynh_install_extra_app_dependencies +++ /dev/null @@ -1,334 +0,0 @@ -#!/bin/bash - -# From PR https://github.com/YunoHost/yunohost/pull/881 -# ynh_install_app_dependencies has a different name to not be override by source /usr/share/yunohost/helpers - -# Define and install dependencies with a equivs control file -# -# This helper can/should only be called once per app -# -# example : ynh_install_app_dependencies dep1 dep2 "dep3|dep4|dep5" -# -# usage: ynh_install_app_dependencies dep [dep [...]] -# | arg: dep - the package name to install in dependence. Writing "dep3|dep4|dep5" can be used to specify alternatives. For example : dep1 dep2 "dep3|dep4|dep5" will require to install dep1 and dep 2 and (dep3 or dep4 or dep5). -# -# Requires YunoHost version 2.6.4 or higher. -MODIFIED_ynh_install_app_dependencies () { - local dependencies=$@ - # Add a comma for each space between packages. But not add a comma if the space separate a version specification. (See below) - dependencies="$(echo "$dependencies" | sed 's/\([^\<=\>]\)\ \([^(]\)/\1, \2/g')" - local dependencies=${dependencies//|/ | } - local manifest_path="../manifest.json" - if [ ! -e "$manifest_path" ]; then - manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place - fi - - local version=$(grep '\"version\": ' "$manifest_path" | cut -d '"' -f 4) # Retrieve the version number in the manifest file. - if [ ${#version} -eq 0 ]; then - version="1.0" - fi - local dep_app=${app//_/-} # Replace all '_' by '-' - - # Handle specific versions - if [[ "$dependencies" =~ [\<=\>] ]] - then - # Replace version specifications by relationships syntax - # https://www.debian.org/doc/debian-policy/ch-relationships.html - # Sed clarification - # [^(\<=\>] ignore if it begins by ( or < = >. To not apply twice. - # [\<=\>] matches < = or > - # \+ matches one or more occurence of the previous characters, for >= or >>. - # [^,]\+ matches all characters except ',' - # Ex: 'package>=1.0' will be replaced by 'package (>= 1.0)' - dependencies="$(echo "$dependencies" | sed 's/\([^(\<=\>]\)\([\<=\>]\+\)\([^,]\+\)/\1 (\2 \3)/g')" - fi - - # - # Epic ugly hack to fix the goddamn dependency nightmare of sury - # Sponsored by the "Djeezusse Fokin Kraiste Why Do Adminsys Has To Be So Fucking Complicated I Should Go Grow Potatoes Instead Of This Shit" collective - # https://github.com/YunoHost/issues/issues/1407 - # - # If we require to install php dependency - if echo $dependencies | grep -q 'php'; - then - # And we have packages from sury installed (7.0.33-10+weirdshiftafter instead of 7.0.33-0 on debian) - if dpkg --list | grep "php7.0" | grep -q -v "7.0.33-0+deb9" - then - # And sury ain't already installed - if ! grep -nrq "sury" /etc/apt/sources.list* - then - # Re-add sury - ynh_install_extra_repo --repo="https://packages.sury.org/php/ $(lsb_release -sc) main" --key="https://packages.sury.org/php/apt.gpg" --name=extra_php_version - - # Pin this sury repository to prevent sury of doing shit - ynh_pin_repo --package="*" --pin="origin \"packages.sury.org\"" --priority=200 --name=extra_php_version - ynh_pin_repo --package="php7.0*" --pin="origin \"packages.sury.org\"" --priority=600 --name=extra_php_version --append - fi - fi - fi - - cat > /tmp/${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build -Section: misc -Priority: optional -Package: ${dep_app}-ynh-deps -Version: ${version} -Depends: ${dependencies} -Architecture: all -Description: Fake package for ${app} (YunoHost app) dependencies - This meta-package is only responsible of installing its dependencies. -EOF - ynh_package_install_from_equivs /tmp/${dep_app}-ynh-deps.control \ - || ynh_die --message="Unable to install dependencies" # Install the fake package and its dependencies - rm /tmp/${dep_app}-ynh-deps.control - ynh_app_setting_set --app=$app --key=apt_dependencies --value="$dependencies" -} - -# Add dependencies to install with ynh_install_app_dependencies -# -# [internal] -# -# usage: ynh_add_app_dependencies --package=phpversion [--replace] -# | arg: -p, --package - Packages to add as dependencies for the app. -# | arg: -r, --replace - Replace dependencies instead of adding to existing ones. -ynh_add_app_dependencies () { - # Declare an array to define the options of this helper. - local legacy_args=pr - declare -Ar args_array=( [p]=package= [r]=replace) - local package - local replace - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - replace=${replace:-0} - - local current_dependencies="" - if [ $replace -eq 0 ] - then - local dep_app=${app//_/-} # Replace all '_' by '-' - if ynh_package_is_installed --package="${dep_app}-ynh-deps" - then - current_dependencies="$(dpkg-query --show --showformat='${Depends}' ${dep_app}-ynh-deps) " - fi - - current_dependencies=${current_dependencies// | /|} - fi - - MODIFIED_ynh_install_app_dependencies "${current_dependencies}${package}" -} - -# Install packages from an extra repository properly. -# -# usage: ynh_install_extra_app_dependencies --repo="repo" --package="dep1 dep2" [--key=key_url] [--name=name] -# | arg: -r, --repo - Complete url of the extra repository. -# | arg: -p, --package - The packages to install from this extra repository -# | arg: -k, --key - url to get the public key. -# | arg: -n, --name - Name for the files for this repo, $app as default value. -ynh_install_extra_app_dependencies () { - # Declare an array to define the options of this helper. - local legacy_args=rpkn - declare -Ar args_array=( [r]=repo= [p]=package= [k]=key= [n]=name= ) - local repo - local package - local key - local name - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - name="${name:-$app}" - key=${key:-} - - # Set a key only if asked - if [ -n "$key" ] - then - key="--key=$key" - fi - # Add an extra repository for those packages - ynh_install_extra_repo --repo="$repo" $key --priority=995 --name=$name - - # Install requested dependencies from this extra repository. - ynh_add_app_dependencies --package="$package" - - # Remove this extra repository after packages are installed - ynh_remove_extra_repo --name=$app -} - -# Add an extra repository correctly, pin it and get the key. -# -# [internal] -# -# usage: ynh_install_extra_repo --repo="repo" [--key=key_url] [--priority=priority_value] [--name=name] [--append] -# | arg: -r, --repo - Complete url of the extra repository. -# | arg: -k, --key - url to get the public key. -# | arg: -p, --priority - Priority for the pin -# | arg: -n, --name - Name for the files for this repo, $app as default value. -# | arg: -a, --append - Do not overwrite existing files. -ynh_install_extra_repo () { - # Declare an array to define the options of this helper. - local legacy_args=rkpna - declare -Ar args_array=( [r]=repo= [k]=key= [p]=priority= [n]=name= [a]=append ) - local repo - local key - local priority - local name - local append - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - name="${name:-$app}" - append=${append:-0} - key=${key:-} - priority=${priority:-} - - if [ $append -eq 1 ] - then - append="--append" - wget_append="tee -a" - else - append="" - wget_append="tee" - fi - - # Split the repository into uri, suite and components. - # Remove "deb " at the beginning of the repo. - repo="${repo#deb }" - - # Get the uri - local uri="$(echo "$repo" | awk '{ print $1 }')" - - # Get the suite - local suite="$(echo "$repo" | awk '{ print $2 }')" - - # Get the components - local component="${repo##$uri $suite }" - - # Add the repository into sources.list.d - ynh_add_repo --uri="$uri" --suite="$suite" --component="$component" --name="$name" $append - - # Pin the new repo with the default priority, so it won't be used for upgrades. - # Build $pin from the uri without http and any sub path - local pin="${uri#*://}" - pin="${pin%%/*}" - # Set a priority only if asked - if [ -n "$priority" ] - then - priority="--priority=$priority" - fi - ynh_pin_repo --package="*" --pin="origin \"$pin\"" $priority --name="$name" $append - - # Get the public key for the repo - if [ -n "$key" ] - then - mkdir -p "/etc/apt/trusted.gpg.d" - wget -q "$key" -O - | gpg --dearmor | $wget_append /etc/apt/trusted.gpg.d/$name.gpg > /dev/null - fi - - # Update the list of package with the new repo - ynh_package_update -} - -# Remove an extra repository and the assiociated configuration. -# -# [internal] -# -# usage: ynh_remove_extra_repo [--name=name] -# | arg: -n, --name - Name for the files for this repo, $app as default value. -ynh_remove_extra_repo () { - # Declare an array to define the options of this helper. - local legacy_args=n - declare -Ar args_array=( [n]=name= ) - local name - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - name="${name:-$app}" - - ynh_secure_remove "/etc/apt/sources.list.d/$name.list" - ynh_secure_remove "/etc/apt/preferences.d/$name" - ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.gpg" - ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.asc" - - # Update the list of package to exclude the old repo - ynh_package_update -} - -# Add a repository. -# -# [internal] -# -# usage: ynh_add_repo --uri=uri --suite=suite --component=component [--name=name] [--append] -# | arg: -u, --uri - Uri of the repository. -# | arg: -s, --suite - Suite of the repository. -# | arg: -c, --component - Component of the repository. -# | arg: -n, --name - Name for the files for this repo, $app as default value. -# | arg: -a, --append - Do not overwrite existing files. -# -# Example for a repo like deb http://forge.yunohost.org/debian/ stretch stable -# uri suite component -# ynh_add_repo --uri=http://forge.yunohost.org/debian/ --suite=stretch --component=stable -# -ynh_add_repo () { - # Declare an array to define the options of this helper. - local legacy_args=uscna - declare -Ar args_array=( [u]=uri= [s]=suite= [c]=component= [n]=name= [a]=append ) - local uri - local suite - local component - local name - local append - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - name="${name:-$app}" - append=${append:-0} - - if [ $append -eq 1 ] - then - append="tee -a" - else - append="tee" - fi - - mkdir -p "/etc/apt/sources.list.d" - # Add the new repo in sources.list.d - echo "deb $uri $suite $component" \ - | $append "/etc/apt/sources.list.d/$name.list" -} - -# Pin a repository. -# -# [internal] -# -# usage: ynh_pin_repo --package=packages --pin=pin_filter [--priority=priority_value] [--name=name] [--append] -# | arg: -p, --package - Packages concerned by the pin. Or all, *. -# | arg: -i, --pin - Filter for the pin. -# | arg: -p, --priority - Priority for the pin -# | arg: -n, --name - Name for the files for this repo, $app as default value. -# | arg: -a, --append - Do not overwrite existing files. -# -# See https://manpages.debian.org/stretch/apt/apt_preferences.5.en.html for information about pinning. -# -ynh_pin_repo () { - # Declare an array to define the options of this helper. - local legacy_args=pirna - declare -Ar args_array=( [p]=package= [i]=pin= [r]=priority= [n]=name= [a]=append ) - local package - local pin - local priority - local name - local append - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - package="${package:-*}" - priority=${priority:-50} - name="${name:-$app}" - append=${append:-0} - - if [ $append -eq 1 ] - then - append="tee -a" - else - append="tee" - fi - - mkdir -p "/etc/apt/preferences.d" - echo "Package: $package -Pin: $pin -Pin-Priority: $priority -" \ - | $append "/etc/apt/preferences.d/$name" -} diff --git a/scripts/backup b/scripts/backup index d985aba..5070d20 100755 --- a/scripts/backup +++ b/scripts/backup @@ -29,8 +29,8 @@ ynh_script_progression --message="Loading installation settings..." --time --wei app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get --app=$app --key=final_path) -domain=$(ynh_app_setting_get --app=$app --key=domain) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#domain=$(ynh_app_setting_get --app=$app --key=domain) +mautrix_whatsapp_db_name=$(ynh_app_setting_get --app=$app --key=mautrix_whatsapp_db_name) #================================================= # STANDARD BACKUP STEPS @@ -39,7 +39,7 @@ db_name=$(ynh_app_setting_get --app=$app --key=db_name) #================================================= ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/log.log" #================================================= # BACKUP THE APP MAIN DIR @@ -49,33 +49,11 @@ ynh_script_progression --message="Backing up the main app directory..." --time - ynh_backup --src_path="$final_path" #================================================= -# BACKUP THE NGINX CONFIGURATION +# BACKUP THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Backing up nginx web server configuration..." --time --weight=1 +ynh_script_progression --message="Backing up the PostgreSQL database..." --time --weight=1 -ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" - -#================================================= -# BACKUP THE PHP-FPM CONFIGURATION -#================================================= -ynh_script_progression --message="Backing up php-fpm configuration..." --time --weight=1 - -ynh_backup --src_path="/etc/php/7.0/fpm/pool.d/$app.conf" - -#================================================= -# BACKUP THE MYSQL DATABASE -#================================================= -ynh_script_progression --message="Backing up the MySQL database..." --time --weight=1 - -ynh_mysql_dump_db --database="$db_name" > db.sql - -#================================================= -# BACKUP FAIL2BAN CONFIGURATION -#================================================= -ynh_script_progression --message="Backing up fail2ban configuration..." --time --weight=1 - -ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf" -ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" +ynh_psql_dump_db --database="$mautrix_whatsapp_db_name" > ${YNH_CWD}/dump.sql #================================================= # SPECIFIC BACKUP @@ -84,27 +62,22 @@ ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" #================================================= ynh_script_progression --message="Backing up logrotate configuration..." --time --weight=1 -ynh_backup --src_path="/etc/logrotate.d/$app" +ynh_backup --src_path="/var/log/$app" #================================================= # BACKUP SYSTEMD #================================================= ynh_script_progression --message="Backing up systemd configuration..." --time --weight=1 +#ynh_backup --src_path="/etc/default/$app" ynh_backup --src_path="/etc/systemd/system/$app.service" -#================================================= -# BACKUP A CRON FILE -#================================================= - -ynh_backup --src_path="/etc/cron.d/$app" - #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --time --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/log.log" #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index e8b24fc..6947e59 100755 --- a/scripts/install +++ b/scripts/install @@ -7,8 +7,6 @@ #================================================= source _common.sh -#source /opt/yunohost/mautrix-whatsapp/_ynh_install_extra_app_dependencies -source _ynh_install_extra_app_dependencies source /usr/share/yunohost/helpers #================================================= @@ -26,28 +24,14 @@ ynh_abort_if_errors # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -#domain=$YNH_APP_ARG_DOMAIN -#path_url=$YNH_APP_ARG_PATH port=$YNH_APP_ARG_PORT synapsenumber=$YNH_APP_ARG_SYNAPSENUMBER whatsappbot=$YNH_APP_ARG_WHATSAPPBOT bot_is_synapse_admin=$YNH_APP_ARG_BOT_IS_SYNAPSE_ADMIN +encryption=$YNH_APP_ARG_BOT_IS_SYNAPSE_ADMIN botadmin=$YNH_APP_ARG_BOTADMIN botusers=$YNH_APP_ARG_BOTUSERS -#is_public=$YNH_APP_ARG_IS_PUBLIC -#language=$YNH_APP_ARG_LANGUAGE -#password=$YNH_APP_ARG_PASSWORD -### If it's a multi-instance app, meaning it can be installed several times independently -### The id of the app as stated in the manifest is available as $YNH_APP_ID -### The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) -### The app instance name is available as $YNH_APP_INSTANCE_NAME -### - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample -### - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 -### - ynhexample__{N} for the subsequent installations, with N=3,4, ... -### The app instance name is probably what interests you most, since this is -### guaranteed to be unique. This is a good unique identifier to define installation path, -### db names, ... app=$YNH_APP_INSTANCE_NAME # ToDo check (in manifest?) if the selected synapse instance is not already connected to a mautrix_whatsapp bridge @@ -60,6 +44,7 @@ fi server_name=$(ynh_app_setting_get --app $synapse_instance --key server_name) domain=$(ynh_app_setting_get --app $synapse_instance --key domain) synapse_config_path="/etc/matrix-$synapse_instance" +app_service_registration_path="/etc/matrix-$synapse_instance/app-service" synapse_name="matrix-$synapse_instance" synapse_user="matrix-$synapse_instance" synapse_db_name="matrix_$synapse_instance" @@ -73,71 +58,38 @@ mautrix_whatsapp_user=$app mautrix_whatsapp_db_name=$app mautrix_whatsapp_db_user=$app upstream_version=$(ynh_app_upstream_version) -#report_stats="false" -#allow_public_rooms="false" -#default_domain_value="Same than the domain" #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -### About --weight and --time -### ynh_script_progression will show to your final users the progression of each scripts. -### In order to do that, --weight will represent the relative time of execution compared to the other steps in the script. -### --time is a packager option, it will show you the execution time since the previous call. -### This option should be removed before releasing your app. -### Use the execution time, given by --time, to estimate the weight of a step. -### A common way to do it is to set a weight equal to the execution time in second +1. -### The execution time is given for the duration since the previous call. So the weight should be applied to this previous call. -ynh_script_progression --message="Validating installation parameters..." --time --weight=1 +ynh_script_progression --message="Validating installation parameters..." --weight=1 -### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app". -### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app" final_path=/opt/yunohost/$app test ! -e "$final_path" || ynh_die --message="This path already contains a folder" -# Register (book) web path -#ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url - #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_script_progression --message="Storing installation settings..." --time --weight=1 +ynh_script_progression --message="Storing installation settings..." --weight=7 ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=server_name --value=$server_name ynh_app_setting_set --app=$app --key=port --value=$port -#ynh_app_setting_set --app=$app --key=path --value=$path_url ynh_app_setting_set --app=$app --key=whatsappbot --value=$whatsappbot +ynh_app_setting_set --app=$app --key=synapse_instance --value=$synapse_instance +ynh_app_setting_set --app=$app --key=app_service_registration_path --value=$app_service_registration_path ynh_app_setting_set --app=$app --key=bot_is_synapse_admin --value=$bot_is_synapse_admin +ynh_app_setting_set --app=$app --key=encryption --value=$encryption +ynh_app_setting_set --app=$app --key=mautrix_whatsapp_db_name --value=$mautrix_whatsapp_db_name ynh_app_setting_set --app=$app --key=botadmin --value=$botadmin ynh_app_setting_set --app=$app --key=botusers --value=$botusers ynh_app_setting_set --app=$app --key=mautrix_version --value=$upstream_version ynh_app_setting_set --app=$app --key=final_path --value=$final_path -#ynh_app_setting_set --app=$app --key=is_public --value=$is_public -#ynh_app_setting_set --app=$app --key=language --value=$language - -#================================================= -# STANDARD MODIFICATIONS -#================================================= -## FIND AND OPEN A PORT -##================================================= -#ynh_script_progression --message="Configuring firewall..." --time --weight=1 -# -#### Use these lines if you have to open a port for the application -#### `ynh_find_port` will find the first available port starting from the given port. -#### If you're not using these lines: -#### - Remove the section "CLOSE A PORT" in the remove script -# -## Find a free port -#port=$(ynh_find_port --port=8095) -## Open this port -#ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port -#ynh_app_setting_set --app=$app --key=port --value=$port #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." --time --weight=1 +ynh_script_progression --message="Installing dependencies..." --weight=97 ### `ynh_install_app_dependencies` allows you to add any "apt" dependencies to the package. ### Those deb packages will be installed as dependencies of this package. @@ -147,7 +99,8 @@ ynh_script_progression --message="Installing dependencies..." --time --weight=1 ### - As well as the section "REINSTALL DEPENDENCIES" in the restore script ### - And the section "UPGRADE DEPENDENCIES" in the upgrade script -ynh_install_extra_app_dependencies --repo="http://http.debian.net/debian stretch-backports main" --package="golang" +ynh_install_extra_app_dependencies --repo="http://http.debian.net/debian buster-backports main" --package="golang" +ynh_install_extra_app_dependencies --repo="http://http.debian.net/debian buster-backports main" --package="libolm-dev" #ynh_install_extra_app_dependencies --repo="http://http.debian.net/debian $(lsb_release -sc)" --package="golang-1.11" ynh_install_app_dependencies $pkg_dependencies @@ -155,7 +108,7 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE A POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Creating a PostgreSQL database..." --weight=4 +ynh_script_progression --message="Creating a PostgreSQL database..." --weight=3 ynh_print_OFF mautrix_whatsapp_db_pwd=$(ynh_string_random --length=30) @@ -173,7 +126,7 @@ ynh_psql_execute_as_root \ #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." --time --weight=1 +ynh_script_progression --message="Setting up source files..." --weight=3 ### `ynh_setup_source` is used to install an app from a zip or tar.gz file, ### downloaded from an upstream source, like a git repository. @@ -194,13 +147,25 @@ ynh_setup_source --dest_dir="$final_path" #================================================= # BUILD GO #================================================= +ynh_script_progression --message="Build with golang..." --time --weight=194 # Build mautrix-whatsapp base_directory=$PWD export GOPATH="$final_path"_src export GOCACHE="$GOPATH"/.cache/go-build cd $final_path -go build + +if [ $encryption = true ] +then +# build with libolm3 end-to-bridge encryption +./build.sh +else +# build without end-to-bridge encryption +./build.sh -tags nocrypto +fi +# build with libolm2 encryption +# ./build.sh -tags nosas + cd $base_directory #================================================= @@ -214,35 +179,12 @@ ynh_system_user_create --username=$mautrix_whatsapp_user #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Configuring a systemd service..." --time --weight=1 - -### `ynh_systemd_config` is used to configure a systemd script for an app. -### It can be used for apps that use sysvinit (with adaptation) or systemd. -### Have a look at the app to be sure this app needs a systemd script. -### `ynh_systemd_config` will use the file conf/systemd.service -### If you're not using these lines: -### - You can remove those files in conf/. -### - Remove the section "BACKUP SYSTEMD" in the backup script -### - Remove also the section "STOP AND REMOVE SERVICE" in the remove script -### - As well as the section "RESTORE SYSTEMD" in the restore script -### - And the section "SETUP SYSTEMD" in the upgrade script +ynh_script_progression --message="Configuring a systemd service..." --time --weight=20 # Create systemd config for mautrix-whatsapp #cp ../conf/default_mautrix-whatsapp /etc/default/$app ynh_add_systemd_config --service=$app -#================================================= -# SPECIFIC SETUP -#================================================= - -#cd $final_path -#echo 'export PATH=$PATH:/usr/lib/go-1.11/bin/' >> /etc/profile -#source /etc/profile -#export PATH=$PATH:$GO_PATH -#go build -#$GO_PATH/go build - - #================================================= #================================================= @@ -252,9 +194,6 @@ ynh_add_systemd_config --service=$app #Copy example-config.yaml to config.yaml cp $final_path/example-config.yaml $final_path/config.yaml -### `ynh_replace_string` is used to replace a string in a file. -### (It's compatible with sed regular expressions syntax) - #Update the config to your liking. #You need to make sure that the address and domain field point to your homeserver. @@ -307,13 +246,7 @@ ynh_replace_string --match_string="uri: mautrix-whatsapp.db" --replace_string="u # On startup, the bridge will try to create these communities, add all of the specific user's # portals to the community, and invite the Matrix user to it. # (Note that, by default, non-admins might not have your homeserver's permission to create communities.) - if [ "$bot_is_synapse_admin" = "Yes" ] - then - ynh_psql_execute_as_root --database=$synapse_db_name --sql="UPDATE users SET admin = 1 WHERE name = '@$whatsappbot:$server_name';" - #ynh_psql_connect_as --user=$synapse_db_user --database=$synapse_db_name <<< "UPDATE users SET admin = 1 WHERE name = '@$whatsappbot:$server_name';" - fi - #su --command="psql matrix_synapse" postgres <<< "UPDATE users SET admin = 1 WHERE name = '@$whatsappbot:$server_name'" - + # Maximum number of connections. Mostly relevant for Postgres. #ynh_replace_string --match_string="max_open_conns: 20" --replace_string="max_open_conns: 20" --target_file="$final_path/config.yaml" #ynh_replace_string --match_string="max_idle_conns: 2" --replace_string="max_idle_conns: 2" --target_file="$final_path/config.yaml" @@ -334,7 +267,7 @@ ynh_replace_string --match_string="uri: mautrix-whatsapp.db" --replace_string="u # "@admin:example.com": admin ynh_replace_string --match_string="@admin:example.com" --replace_string="$botadmin" --target_file="$final_path/config.yaml" # "example.com": user -if [ "$botusers" = "domain" ] +if [ "$botusers" = "local" ] then ynh_replace_string --match_string="example.com" --replace_string="$server_name" --target_file="$final_path/config.yaml" elif [ "$botusers" = "admin" ] @@ -348,12 +281,15 @@ fi # relaybot: # # Whether or not relaybot support is enabled. # enabled: false +ynh_replace_string --match_string="enabled: false" --replace_string="enabled: true" --target_file="$final_path/config.yaml" # # The management room for the bot. This is where all status notifications are posted and # # in this room, you can use `!wa ` instead of `!wa relaybot `. Omitting # # the command prefix completely like in user management rooms is not possible. # management: !foo:example.com +ynh_replace_string --match_string="management: !foo:example.com" --replace_string="management: !highwaytohell:$server_name" --target_file="$final_path/config.yaml" # # List of users to invite to all created rooms that include the relaybot. # invites: [] +#ynh_replace_string --match_string="invites: []" --replace_string='invites: ['"$botadmin"']' --target_file="$final_path/config.yaml" # # The formats to use when sending messages to WhatsApp via the relaybot. # message_formats: # m.text: "{{ .Sender.Displayname }}: {{ .Message }}" @@ -386,22 +322,23 @@ fi #print_level: debug ynh_replace_string --match_string="print_level: debug" --replace_string="print_level: warn" --target_file="$final_path/config.yaml" -cd $final_path +#cd $final_path #Generate the appservice registration file by running ./mautrix-whatsapp -g. #You can use the -c and -r flags to change the location of the config and registration files. They default to config.yaml and registration.yaml respectively. -$final_path/mautrix-whatsapp -g -r $synapse_config_path/$app-registration.yaml -cd $base_directory +#mkdir -p $app_service_registration_path +$final_path/mautrix-whatsapp -g -c $final_path/config.yaml -r $app_service_registration_path/$app.yaml #Add the path to the registration file (registration.yaml by default) to your synapse homeserver.yaml under app_service_config_files. -# A list of application service config files to use -# -#app_service_config_files: -# - app_service_1.yaml -# - "/etc/matrix-synapse/registration.yaml" -ynh_replace_string --match_string="#app_service_config_files:" --replace_string="app_service_config_files:" --target_file="$synapse_config_path/homeserver.yaml" -ynh_replace_string --match_string="# - app_service_1.yaml" --replace_string=" - '$synapse_config_path/$app-registration.yaml'" --target_file="$synapse_config_path/homeserver.yaml" -#You will then need to restart the synapse server. Remember to restart it every time the registration file is regenerated. +#cd $base_directory +#cp ../conf/$app.yaml $app_service_registration_path + +#$as_token=; +#$hs_token=; +#ynh_replace_string --match_string=__AS_TOKEN__ --replace_string="$as_token" --target_file=$app_service_registration_path/$app.yaml +#ynh_replace_string --match_string=__HS_TOKEN__ --replace_string="$hs_token" --target_file=$app_service_registration_path/$app.yaml +/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh \ + || ynh_die "Synapse can't restart with the appservice configuration" +# Handled by synapse: synapse_ynh adds all registration files added in $app_service_registration_path to the app_service_config_files list - #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= @@ -411,8 +348,8 @@ ynh_replace_string --match_string="# - app_service_1.yaml" --replace_string=" ### you can make a backup of this file before modifying it again if the admin had modified it. # Calculate and store the config file checksum into the app settings +ynh_store_file_checksum --file="$app_service_registration_path/$app.yaml" ynh_store_file_checksum --file="$final_path/config.yaml" -ynh_store_file_checksum --file="$synapse_config_path/homeserver.yaml" #================================================= # GENERIC FINALIZATION @@ -425,40 +362,16 @@ ynh_store_file_checksum --file="$synapse_config_path/homeserver.yaml" ### that really need such authorization. # Set permissions to app files -#chown -R root: $final_path +chown -R root: $final_path # WARNING : theses command are used in INSTALL, UPGRADE, RESTORE # For any update do it in all files chown $mautrix_whatsapp_user:root -R $final_path -#chmod 770 $final_path/Coturn_config_rotate.sh -#chown $mautrix_whatsapp_user:root -R /var/lib/$app -#chown $mautrix_whatsapp_user:root -R /var/log/$app -#chown $mautrix_whatsapp_user:root -R /etc/$app -#chmod u=rwX,g=rX,o= -R /etc/$app -#chmod 600 /etc/matrix-$app/$server_name.signing.key -#setfacl -R -m user:turnserver:rX /etc/matrix-$app -#setfacl -R -m user:turnserver:rwX /var/log/matrix-$app - -chown $synapse_config_path/$app-registration.yaml --reference="$synapse_config_path/homeserver.yaml" -chmod u=rwX,g=rX,o= $synapse_config_path/$app-registration.yaml -#You will then need to restart the synapse server. Remember to restart it every time the registration file is regenerated. -service $synapse_name restart -#Run the bridge with -#service mautrix-whatsapp restart -#./mautrix-whatsapp. #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Configuring log rotation..." --time --weight=1 - -### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app. -### Use this helper only if there is effectively a log file for this app. -### If you're not using this helper: -### - Remove the section "BACKUP LOGROTATE" in the backup script -### - Remove also the section "REMOVE LOGROTATE CONFIGURATION" in the remove script -### - As well as the section "RESTORE THE LOGROTATE CONFIGURATION" in the restore script -### - And the section "SETUP LOGROTATE" in the upgrade script +ynh_script_progression --message="Configuring log rotation..." --time --weight=3 # Use logrotate to manage application logfile(s) ynh_use_logrotate --logfile "/var/log/$app/log.log" @@ -467,62 +380,24 @@ chown $mautrix_whatsapp_user:root -R /var/log/$app #================================================= # ADVERTISE SERVICE IN ADMIN PANEL #================================================= - -### `yunohost service add` is a CLI yunohost command to add a service in the admin panel. -### You'll find the service in the 'services' section of YunoHost admin panel. -### This CLI command would be useless if the app does not have any services (systemd or sysvinit) -### If you're not using these lines: -### - You can remove these files in conf/. -### - Remove the section "REMOVE SERVICE FROM ADMIN PANEL" in the remove script -### - As well as the section "ADVERTISE SERVICE IN ADMIN PANEL" in the restore script - -yunohost service add $app --log "/var/log/$app/log.log" +#yunohost service add $app --log "/var/log/$app/log.log" # if using yunohost version 3.2 or more in the 'manifest.json', a description can be added -#yunohost service add $app --description "$app daemon for XXX" --log "/var/log/$app/$app.log" +yunohost service add $app --description "$app daemon for bridging Whatsapp and Matrix messages" --log "/var/log/$app/log.log" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --time --weight=1 -### `ynh_systemd_action` is used to start a systemd service for an app. -### Only needed if you have configure a systemd service -### If you're not using these lines: -### - Remove the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the backup script -### - As well as the section "START SYSTEMD SERVICE" in the restore script -### - As well as the section"STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the upgrade script -### - And the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the change_url script - # Start a systemd service ynh_systemd_action --service_name=$app --action="start" - -#================================================= -# SETUP FAIL2BAN -#================================================= -#ynh_script_progression --message="Configuring fail2ban..." --time --weight=1 - -# Create a dedicated fail2ban config -#ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" -#ynh_add_fail2ban_config --use_template - -#================================================= -# SETUP SSOWAT -#================================================= -#ynh_script_progression --message="Configuring SSOwat..." --time --weight=1 -# -## Make app public if necessary -#if [ $is_public -eq 1 ] -#then -# # unprotected_uris allows SSO credentials to be passed anyway. -# ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" -#fi -# -#================================================= -# RELOAD NGINX -#================================================= -#ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 - -#ynh_systemd_action --service_name=nginx --action=reload + # (Note that, by default, non-admins might not have your homeserver's permission to create communities.) + if [ "$bot_is_synapse_admin" = "Yes" ] + then + ynh_psql_execute_as_root --database=$synapse_db_name --sql="UPDATE users SET admin = 1 WHERE name = '@$whatsappbot:$server_name';" +# yunohost app action run $synapse_instance set_admin_user -a username=$whatsappbot + fi +ynh_systemd_action --service_name=$app --action="restart" #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 9423376..f35dc8a 100755 --- a/scripts/remove +++ b/scripts/remove @@ -16,8 +16,13 @@ ynh_script_progression --message="Loading installation settings..." --time --wei app=$YNH_APP_INSTANCE_NAME -#domain=$(ynh_app_setting_get --app=$app --key=domain) -#port=$(ynh_app_setting_get --app=$app --key=port) +domain=$(ynh_app_setting_get --app=$app --key=domain) +server_name=$(ynh_app_setting_get --app=$app --key=server_name) +synapse_instance=$(ynh_app_setting_get --app=$app --key=synapse_instance) +app_service_registration_path=$(ynh_app_setting_get --app=$app --key=app_service_registration_path) +whatsappbot=$(ynh_app_setting_get --app=$app --key=whatsappbot) +botadmin=$(ynh_app_setting_get --app=$app --key=botadmin) +port=$(ynh_app_setting_get --app=$app --key=port) #db_name=$(ynh_app_setting_get --app=$app --key=db_name) #db_user=$db_name final_path=$(ynh_app_setting_get --app=$app --key=final_path) @@ -26,9 +31,10 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) # SET CONSTANTS #================================================= +src_path=$final_path"_src" mautrix_whatsapp_user=$app -#mautrix_whatsapp_db_name=$app -#mautrix_whatsapp_db_user=$app +mautrix_whatsapp_db_name=$app +mautrix_whatsapp_db_user=$app #================================================= # STANDARD REMOVE @@ -39,7 +45,7 @@ mautrix_whatsapp_user=$app # Remove a service from the admin panel, added by `yunohost service add` if ynh_exec_warn_less yunohost service status $app >/dev/null then - ynh_script_progression --message="Removing $app service..." --time --weight=1 + ynh_script_progression --message="Removing $app service..." --time --weight=3 yunohost service remove $app fi @@ -52,19 +58,20 @@ ynh_script_progression --message="Stopping and removing the systemd service..." ynh_remove_systemd_config #================================================= -# REMOVE THE MYSQL DATABASE +# REMOVE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Removing the PostgreSQL database..." --time --weight=1 +ynh_script_progression --message="Removing the PostgreSQL database..." --time --weight=3 # Remove a database if it exists, along with the associated user -#ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name -ynh_psql_drop_db $app -ynh_psql_drop_user $app +ynh_psql_remove_db --db_user=$mautrix_whatsapp_db_name --db_name=$mautrix_whatsapp_db_user +ynh_psql_execute_as_root --database=$synapse_db_name --sql="DROP OWNED BY @$whatsappbot:$server_name;" +ynh_psql_execute_as_root --database=$synapse_db_name --sql="DROP USER @$whatsappbot:$server_name;" +#yunohost app action run $synapse_instance drop_user -a username=$whatsappbot #================================================= # REMOVE DEPENDENCIES #================================================= -ynh_script_progression --message="Removing dependencies..." --time --weight=1 +ynh_script_progression --message="Removing dependencies..." --time --weight=4 # Remove metapackage and its dependencies ynh_remove_app_dependencies @@ -72,31 +79,12 @@ ynh_remove_app_dependencies #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_script_progression --message="Removing app main directory..." --time --weight=1 +ynh_script_progression --message="Removing app main directory..." --time --weight=10 # Remove the app directory securely +#ynh_secure_remove --file="/etc/$app/" ynh_secure_remove --file="$final_path" - -ynh_secure_remove --file="/etc/matrix-synapse/$app-registration.yaml" -ynh_replace_string --match_string=" - '/etc/matrix-synapse/$app-registration.yaml'" --replace_string="# - app_service_1.yaml" --target_file="/etc/matrix-synapse/homeserver.yaml" -service matrix-synapse restart - -#================================================= -# REMOVE NGINX CONFIGURATION -#================================================= -#ynh_script_progression --message="Removing nginx web server configuration..." --time --weight=1 - -# Remove the dedicated nginx config -#ynh_remove_nginx_config - -#================================================= -# REMOVE PHP-FPM CONFIGURATION -#================================================= -#ynh_script_progression --message="Removing php-fpm configuration..." --time --weight=1 - -# Remove the dedicated php-fpm config -#ynh_remove_fpm_config - + #================================================= # REMOVE LOGROTATE CONFIGURATION #================================================= @@ -105,45 +93,27 @@ ynh_script_progression --message="Removing logrotate configuration..." --time -- # Remove the app-specific logrotate config ynh_remove_logrotate -#================================================= -# CLOSE A PORT -#================================================= - -#if yunohost firewall list | grep -q "\- $port$" -#then -# ynh_script_progression --message="Closing port $port..." -# ynh_exec_warn_less yunohost firewall disallow TCP $port -#fi - -#================================================= -# REMOVE FAIL2BAN CONFIGURATION -#================================================= -#ynh_script_progression --message="Removing fail2ban configuration..." --time --weight=1 - -# Remove the dedicated fail2ban config -#ynh_remove_fail2ban_config - #================================================= # SPECIFIC REMOVE #================================================= -# REMOVE THE CRON FILE -#================================================= - -# Remove a cron file -#ynh_secure_remove --file="/etc/cron.d/$app" +ynh_script_progression --message="Removing synapse app service..." --time --weight=1 # Remove a directory securely -#ynh_secure_remove --file="/etc/$app/" +ynh_secure_remove --file="$src_path" + +ynh_secure_remove --file="$app_service_registration_path/$app.yaml" +/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh \ + || ynh_die "Synapse can't restart with the appservice configuration" # Remove the log files -#ynh_secure_remove --file="/var/log/$app/" +ynh_secure_remove --file="/var/log/$app" #================================================= # GENERIC FINALIZATION #================================================= # REMOVE DEDICATED USER #================================================= -ynh_script_progression --message="Removing the dedicated system user..." --time --weight=1 +ynh_script_progression --message="Removing the dedicated system user..." --time --weight=5 # Delete a system user ynh_system_user_delete --username=$mautrix_whatsapp_user diff --git a/scripts/restore b/scripts/restore index 9b68d49..b89dba4 100755 --- a/scripts/restore +++ b/scripts/restore @@ -29,29 +29,41 @@ ynh_script_progression --message="Loading settings..." --time --weight=1 app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) -path_url=$(ynh_app_setting_get --app=$app --key=path) +server_name=$(ynh_app_setting_get --app=$app --key=server_name) +whatsappbot=$(ynh_app_setting_get --app=$app --key=whatsappbot) +synapse_instance=$(ynh_app_setting_get --app=$app --key=synapse_instance) +app_service_registration_path=$(ynh_app_setting_get --app=$app --key=app_service_registration_path) +bot_is_synapse_admin=$(ynh_app_setting_get --app=$app --key=bot_is_synapse_admin) +botadmin=$(ynh_app_setting_get --app=$app --key=botadmin) +botusers=$(ynh_app_setting_get --app=$app --key=botusers) final_path=$(ynh_app_setting_get --app=$app --key=final_path) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -db_user=$db_name +mautrix_version=$(ynh_app_setting_get --app=$app --key=mautrix_version) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +ynh_print_OFF +mautrix_whatsapp_db_pwd=$(ynh_app_setting_get --app=$app --key=mautrix_whatsapp_db_pwd) +ynh_print_ON + +#================================================= +# SET CONSTANTS +#================================================= + +synapse_db_name="matrix_$synapse_instance" +mautrix_whatsapp_user=$app +mautrix_whatsapp_db_name=$app +mautrix_whatsapp_db_user=$app #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= ynh_script_progression --message="Validating restoration parameters..." --time --weight=1 -ynh_webpath_available --domain=$domain --path_url=$path_url \ - || ynh_die --message="Path not available: ${domain}${path_url}" +#ynh_webpath_available --domain=$domain --path_url=$path_url \ +# || ynh_die --message="Path not available: ${domain}${path_url}" test ! -d $final_path \ || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= - -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" - #================================================= # RESTORE THE APP MAIN DIR #================================================= @@ -73,21 +85,7 @@ ynh_system_user_create --username=$app # Restore permissions on app files chown -R root: $final_path - -#================================================= -# RESTORE THE PHP-FPM CONFIGURATION -#================================================= - -ynh_restore_file --origin_path="/etc/php/7.0/fpm/pool.d/$app.conf" - -#================================================= -# RESTORE FAIL2BAN CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the fail2ban configuration..." --time --weight=1 - -ynh_restore_file "/etc/fail2ban/jail.d/$app.conf" -ynh_restore_file "/etc/fail2ban/filter.d/$app.conf" -ynh_systemd_action --action=restart --service_name=fail2ban +chown $mautrix_whatsapp_user:root -R $final_path #================================================= # SPECIFIC RESTORATION @@ -96,17 +94,45 @@ ynh_systemd_action --action=restart --service_name=fail2ban #================================================= ynh_script_progression --message="Reinstalling dependencies..." --time --weight=1 +ynh_install_extra_app_dependencies --repo="http://http.debian.net/debian buster-backports main" --package="golang" +ynh_install_extra_app_dependencies --repo="http://http.debian.net/debian buster-backports main" --package="libolm-dev" # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies #================================================= -# RESTORE THE MYSQL DATABASE +# RESTORE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Restoring the MySQL database..." --time --weight=1 +ynh_script_progression --message="Restoring the PostgreSQL database..." --time --weight=1 -db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) -ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd -ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql +ynh_print_OFF +mautrix_whatsapp_db_pwd=$(ynh_string_random --length=30) +ynh_app_setting_set --app=$app --key=mautrix_whatsapp_db_pwd --value=$mautrix_whatsapp_db_pwd +ynh_print_ON + +ynh_psql_test_if_first_run +ynh_print_OFF +ynh_psql_create_user $mautrix_whatsapp_db_user $mautrix_whatsapp_db_pwd +ynh_print_ON +ynh_psql_execute_as_root \ +--sql="CREATE DATABASE $mautrix_whatsapp_db_name + ENCODING 'UTF8' + LC_COLLATE='C' + LC_CTYPE='C' + template=template0 + OWNER $mautrix_whatsapp_db_user;" +ynh_psql_execute_file_as_root --file="${YNH_CWD}/dump.sql" --database="$mautrix_whatsapp_db_name" + +#================================================= +# REGISTER SYNAPSE APP-SERVICE +#================================================= +$final_path/mautrix-whatsapp -g -c $final_path/config.yaml -r $app_service_registration_path/$app.yaml +#$as_token=; +#$hs_token=; +#ynh_replace_string --match_string=__AS_TOKEN__ --replace_string="$as_token" --target_file=$app_service_registration_path/$app.yaml +#ynh_replace_string --match_string=__HS_TOKEN__ --replace_string="$hs_token" --target_file=$app_service_registration_path/$app.yaml +/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh \ + || ynh_die "Synapse can't restart with the appservice configuration" +# Handled by synapse: synapse_ynh adds all registration files added in $app_service_registration_path to the app_service_config_files list #================================================= # RESTORE SYSTEMD @@ -120,36 +146,34 @@ systemctl enable $app.service # ADVERTISE SERVICE IN ADMIN PANEL #================================================= -yunohost service add $app --log "/var/log/$app/$app.log" +yunohost service add $app --log "/var/log/$app/log.log" +# if using yunohost version 3.2 or more in the 'manifest.json', a description can be added +yunohost service add $app --description "$app daemon for bridging Whatsapp and Matrix messages" --log "/var/log/$app/log.log" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --time --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" - -#================================================= -# RESTORE THE CRON FILE -#================================================= - -ynh_restore_file --origin_path="/etc/cron.d/$app" +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/log.log" + # (Note that, by default, non-admins might not have your homeserver's permission to create communities.) + if [ "$bot_is_synapse_admin" = "Yes" ] + then + ynh_psql_execute_as_root --database=$synapse_db_name --sql="UPDATE users SET admin = 1 WHERE name = '@$whatsappbot:$server_name';" +# yunohost app action run $synapse_instance set_admin_user -a username=$whatsappbot + fi +ynh_systemd_action --service_name=$app --action="restart" #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= -ynh_restore_file --origin_path="/etc/logrotate.d/$app" +ynh_use_logrotate --logfile "/var/log/$app/log.log" +chown $mautrix_whatsapp_user:root -R /var/log/$app #================================================= # GENERIC FINALIZATION #================================================= -# RELOAD NGINX AND PHP-FPM -#================================================= -ynh_script_progression --message="Reloading nginx web server and php-fpm..." --time --weight=1 - -ynh_systemd_action --service_name=php7.0-fpm --action=reload -ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/scripts/upgrade b/scripts/upgrade index 243e85b..69479a6 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -17,12 +17,25 @@ ynh_script_progression --message="Loading installation settings..." --time --wei app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) -path_url=$(ynh_app_setting_get --app=$app --key=path) -admin=$(ynh_app_setting_get --app=$app --key=admin) -is_public=$(ynh_app_setting_get --app=$app --key=is_public) +server_name=$(ynh_app_setting_get --app=$app --key=server_name) +whatsappbot=$(ynh_app_setting_get --app=$app --key=whatsappbot) +synapse_instance=$(ynh_app_setting_get --app=$app --key=synapse_instance) +app_service_registration_path=$(ynh_app_setting_get --app=$app --key=app_service_registration_path) +bot_is_synapse_admin=$(ynh_app_setting_get --app=$app --key=bot_is_synapse_admin) +encryption=$(ynh_app_setting_get --app=$app --key=encryption) +botadmin=$(ynh_app_setting_get --app=$app --key=botadmin) +botusers=$(ynh_app_setting_get --app=$app --key=botusers) final_path=$(ynh_app_setting_get --app=$app --key=final_path) -language=$(ynh_app_setting_get --app=$app --key=language) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) +mautrix_version=$(ynh_app_setting_get --app=$app --key=mautrix_version) + +#================================================= +# SET CONSTANTS +#================================================= + +synapse_db_name="matrix_$synapse_instance" +mautrix_whatsapp_user=$app +mautrix_whatsapp_db_name=$app +mautrix_whatsapp_db_user=$app #================================================= # CHECK VERSION @@ -41,24 +54,15 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1 -# Fix is_public as a boolean value -if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set --app=$app --key=is_public --value=1 - is_public=1 -elif [ "$is_public" = "No" ]; then - ynh_app_setting_set --app=$app --key=is_public --value=0 - is_public=0 -fi - # If db_name doesn't exist, create it -if [ -z "$db_name" ]; then - db_name=$(ynh_sanitize_dbid --db_name=$app) - ynh_app_setting_set --app=$app --key=db_name --value=$db_name +if [ -z "$mautrix_whatsapp_db_name" ]; then + mautrix_whatsapp_db_name=$(ynh_sanitize_dbid --db_name=$app) + ynh_app_setting_set --app=$app --key=db_name --value=$mautrix_whatsapp_db_name fi # If final_path doesn't exist, create it if [ -z "$final_path" ]; then - final_path=/var/www/$app + final_path=/opt/yunohost/$app ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi @@ -76,18 +80,6 @@ ynh_clean_setup () { # Exit if an error occurs during the execution of the script ynh_abort_if_errors -#================================================= -# CHECK THE PATH -#================================================= - -# Normalize the URL path syntax -# N.B. : this is for app installations before YunoHost 2.7 -# where this value might be something like /foo/ or foo/ -# instead of /foo .... -# If nobody installed your app before 2.7, then you may -# safely remove this line -path_url=$(ynh_normalize_url_path --path_url=$path_url) - #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -95,7 +87,7 @@ path_url=$(ynh_normalize_url_path --path_url=$path_url) #================================================= ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/log.log" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -109,36 +101,42 @@ then ynh_setup_source --dest_dir="$final_path" fi -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading nginx web server configuration..." --time --weight=1 - -# Create a dedicated nginx config -ynh_add_nginx_config - #================================================= # UPGRADE DEPENDENCIES #================================================= ynh_script_progression --message="Upgrading dependencies..." --time --weight=1 +ynh_install_extra_app_dependencies --repo="http://http.debian.net/debian buster-backports main" --package="golang" +ynh_install_extra_app_dependencies --repo="http://http.debian.net/debian buster-backports main" --package="libolm-dev" ynh_install_app_dependencies $pkg_dependencies +#================================================= +# BUILD GO +#================================================= +# Build mautrix-whatsapp +base_directory=$PWD +export GOPATH="$final_path"_src +export GOCACHE="$GOPATH"/.cache/go-build +cd $final_path +if [ $encryption = true ] +then +# build with libolm3 end-to-bridge encryption +./build.sh +else +# build without end-to-bridge encryption +./build.sh -tags nocrypto +fi +# build with libolm2 encryption +# ./build.sh -tags nosas +cd $base_directory + #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1 # Create a dedicated user (if not existing) -ynh_system_user_create --username=$app - -#================================================= -# PHP-FPM CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading php-fpm configuration..." --time --weight=1 - -# Create a dedicated php-fpm config -ynh_add_fpm_config +ynh_system_user_create --username=$mautrix_whatsapp_user #================================================= # SPECIFIC UPGRADE @@ -152,15 +150,33 @@ ynh_add_fpm_config ### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. ### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. -ynh_backup_if_checksum_is_different --file="$final_path/CONFIG_FILE" +ynh_backup_if_checksum_is_different --file="$final_path/config.yaml" +ynh_backup_if_checksum_is_different --file="$app_service_registration_path/$app.yaml" + +#================================================= +# REGISTER SYNAPSE APP-SERVICE +#================================================= +$final_path/mautrix-whatsapp -g -c $final_path/config.yaml -r $app_service_registration_path/$app.yaml +#$as_token=; +#$hs_token=; +#ynh_replace_string --match_string=__AS_TOKEN__ --replace_string="$as_token" --target_file=$app_service_registration_path/$app.yaml +#ynh_replace_string --match_string=__HS_TOKEN__ --replace_string="$hs_token" --target_file=$app_service_registration_path/$app.yaml +/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh \ + || ynh_die "Synapse can't restart with the appservice configuration" +# Handled by synapse: synapse_ynh adds all registration files added in $app_service_registration_path to the app_service_config_files list + # Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum --file="$final_path/CONFIG_FILE" +ynh_store_file_checksum --file="$final_path/config.yaml" +ynh_store_file_checksum --file="$app_service_registration_path/$app.yaml" #================================================= # SETUP LOGROTATE #================================================= ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1 +# Use logrotate to manage application logfile(s) +#ynh_use_logrotate --logfile "/var/log/$app/log.log" +#chown $mautrix_whatsapp_user:root -R /var/log/$app # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append @@ -175,45 +191,20 @@ ynh_add_systemd_config #================================================= # GENERIC FINALIZATION #================================================= -# UPGRADE FAIL2BAN -#================================================= -ynh_script_progression --message="Reconfiguring fail2ban..." --time --weight=1 - -# Create a dedicated fail2ban config -ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" - #================================================= # SECURE FILES AND DIRECTORIES #================================================= # Set permissions on app files chown -R root: $final_path - -#================================================= -# SETUP SSOWAT -#================================================= -ynh_script_progression --message="Upgrading SSOwat configuration..." --time --weight=1 - -# Make app public if necessary -if [ $is_public -eq 1 ] -then - # unprotected_uris allows SSO credentials to be passed anyway - ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" -fi +chown $mautrix_whatsapp_user:root -R $final_path #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --time --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 - -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/log.log" #================================================= # END OF SCRIPT