diff --git a/README.md b/README.md index 072513d..9d34213 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,19 @@ # Friendica social network for YunoHost -[![Integration level](https://dash.yunohost.org/integration/friendica.svg)](https://ci-apps.yunohost.org/jenkins/job/friendica%20%28Community%29/lastBuild/consoleFull) - +[![Integration level](https://dash.yunohost.org/integration/friendica.svg)](https://dash.yunohost.org/appci/app/friendica) [![Install Friendica with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=friendica) +> *This package allow you to install Friendica quickly and simply on a YunoHost server. +If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.* + +## Overview +Friendica (formerly Friendika, originally Mistpark) is an open, free, distributed social network. It forms one part of the Fediverse, an interconnected and decentralized network of independently operated servers. -[Friendica](http://friendi.ca/) integration for YunoHost
**Version:2020.03**

-Current snapshot in *sources*: +## Screenshots -* https://github.com/friendica/friendica: 2020.03 -* https://github.com/friendica/friendica-addons: 2020.03 +![](https://en.wikipedia.org/wiki/Friendica#/media/File:Screenshot_of_Friendica.jpg) ## Important Notes @@ -42,3 +44,30 @@ Make sure to select your domain from the previous section as the application dom After the installation,login with the username provided at the time of the installaion with your SSO password.You can then create your profile and access the admin panel from the button in the center of the top nav bar, just adjecent to the search bar.(The admin panel don't have text,so don't get confuse with it) Public users can register and use the instance as normal users. SSO users can login with there username and password as normal users too. + +#### Supported architectures + +* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/friendica%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/friendica/) +* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/friendica%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/friendica/) + +## Links + + * Report a bug: https://github.com/YunoHost-Apps/friendica_ynh/issues + * App website: https://friendi.ca/ + * Upstream app repository: https://github.com/friendica/friendica + * YunoHost website: https://yunohost.org/ + +--- + +Developers info +---------------- + +**Only if you want to use a testing branch for coding, instead of merging directly into master.** +Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/friendica_ynh/tree/testing). + +To try the testing branch, please proceed like that. +``` +sudo yunohost app install https://github.com/YunoHost-Apps/friendica_ynh/tree/testing --debug +or +sudo yunohost app upgrade friendica -u https://github.com/YunoHost-Apps/friendica_ynh/tree/testing --debug +``` diff --git a/check_process b/check_process index 0726b57..2258bb0 100644 --- a/check_process +++ b/check_process @@ -10,7 +10,6 @@ setup_private=0 setup_public=1 upgrade=1 - upgrade=1 from_commit=1c018b9ed379e25d5bcab4bd27e9833feee9da68 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. diff --git a/conf/app.src b/conf/app.src index 968419c..f12e4c7 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://friendi.ca/wp-content/uploads/2020/03/friendica-full-2020.03.tar.gz -SOURCE_SUM=dbfb001a90533e57fc453ff8d8d5c017236251aef78e5feb9902744d8b8dc1bd +SOURCE_URL=https://github.com/friendica/friendica/archive/2020.03.tar.gz +SOURCE_SUM=24aa577b6ef4d98aa3681df07ddd709ea201df9d8b8ded357fa03db3198ccfc5 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true diff --git a/conf/nginx.conf b/conf/nginx.conf index 5bb7945..d179139 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -29,34 +29,31 @@ # You have Friendica installed in /var/www/friendica ## location __PATH__ { - alias __FINALPATH__/; + alias __FINALPATH__/; - if ($scheme = http) { - rewrite ^ https://$server_name$request_uri? permanent; - } + # Force usage of https + if ($scheme = http) { + rewrite ^ https://$server_name$request_uri? permanent; + } - if (!-e $request_filename) { - rewrite ^(.*)$ /index.php?pagename=$1; - } - - - - #allow uploads up to 20MB in size - client_max_body_size 20m; - client_body_buffer_size 128k; - - - #Default indexes and catch-all - index index.php; + if (!-e $request_filename) { + rewrite ^(.*)$ /index.php?pagename=$1; + } + #allow uploads up to 20MB in size + client_max_body_size 20m; + client_body_buffer_size 128k; + #Default indexes and catch-all + index index.php; + # make sure webfinger and other well known services aren't blocked # by denying dot files and rewrite request to the front controller location ^~ /.well-known/ { allow all; - if (!-e $request_filename) { - rewrite ^(.*)$ /index.php?pagename=$1; - } + if (!-e $request_filename) { + rewrite ^(.*)$ /index.php?pagename=$1; + } } include mime.types; @@ -67,21 +64,23 @@ location __PATH__ { } - #Execute and serve PHP files - location ~* \.php$ { - fastcgi_split_path_info ^(.+?\.php)(/.*)$; - try_files $uri =404; - fastcgi_pass unix:/var/run/php5-fpm-__NAME__.sock; - fastcgi_index index.php; - include fastcgi_params; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - } + #Execute and serve PHP files + location ~* \.php$ { + fastcgi_split_path_info ^(.+?\.php)(/.*)$; + try_files $uri =404; + fastcgi_pass unix:/var/run/php/php7.0-fpm-__NAME__.sock; + + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + } # deny access to all dot files location ~ /\. { deny all; } - #Include SSOWAT user panel. - include conf.d/yunohost_panel.conf.inc; + + #Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; } diff --git a/conf/php-fpm.conf b/conf/php-fpm.conf index 57affa6..5c98f03 100644 --- a/conf/php-fpm.conf +++ b/conf/php-fpm.conf @@ -1,10 +1,11 @@ ; Start a new pool named 'www'. -; the variable $pool can we used in any directive and will be replaced by the +; 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' @@ -24,17 +25,19 @@ 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 +; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on ; a specific port; -; 'port' - to listen on a TCP socket to all addresses 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/php5-fpm-__NAMETOCHANGE__.sock +listen = /var/run/php/php7.0-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 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 @@ -44,8 +47,13 @@ listen = /var/run/php5-fpm-__NAMETOCHANGE__.sock 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 ipv4 addresses of FastCGI clients which are allowed to connect. +; 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 @@ -59,7 +67,13 @@ listen.group = www-data ; - The pool processes will inherit the master process priority ; unless it specified otherwise ; Default Value: no set -; priority = -19 +; 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: @@ -215,7 +229,7 @@ pm.max_requests = 500 ; 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 +; 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 @@ -275,7 +289,7 @@ pm.max_requests = 500 ; - %{megabytes}M ; - %{mega}M ; %n: pool name -; %o: ouput header +; %o: output header ; it must be associated with embraces to specify the name of the header: ; - %{Content-Type}o ; - %{X-Powered-By}o @@ -291,9 +305,13 @@ pm.max_requests = 500 ; %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" @@ -349,13 +367,22 @@ chdir = __FINALPATH__ ; 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 -; exectute php code. +; execute php code. ; Note: set an empty value to allow all extensions. ; Default Value: .php -;security.limit_extensions = .php .php3 .php4 .php5 +;security.limit_extensions = .php .php3 .php4 .php5 .php7 ; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from ; the current environment. @@ -392,13 +419,12 @@ catch_workers_output = yes ;php_admin_value[memory_limit] = 32M ; Common values to change to increase file upload limit -; upload_max_filesize = 50M -; post_max_size = 50M -; mail.add_x_header = Off +; 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 -; max_execution_time = 600 -; max_input_time = 300 -; memory_limit = 256M -; short_open_tag = On - +; 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 af61b28..3ccded7 100644 --- a/manifest.json +++ b/manifest.json @@ -6,15 +6,15 @@ "en": "Social Communication Server", "fr": "Serveur de Communication Social" }, + "version": "2020.03~ynh1", "url": "http://friendi.ca", "license": "free", - "version": "2020.03", "maintainer": { "name": "Anmol Sharma", "email": "anmol@datamol.org" }, "requirements": { - "yunohost": ">= 2.7.2" + "yunohost": ">= 3.5" }, "previous_maintainers": { "name": "aymhce", @@ -23,7 +23,7 @@ "multi_instance": true, "services": [ "nginx", - "php5-fpm", + "php7.0-fpm", "mysql" ], "arguments": { @@ -46,7 +46,6 @@ }, "example": "homer" } - ] } } diff --git a/scripts/_common.sh b/scripts/_common.sh index 37d0f4f..2186500 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -7,36 +7,14 @@ # dependencies used by the app pkg_dependencies="php-mbstring php-cli php-imagick php-gd php-xml" -# ============================================================================= -# COMMON ROUNDCUBE FUNCTIONS -# ============================================================================= +#================================================= +# PERSONAL HELPERS +#================================================= -# Execute a composer command from a given directory -# usage: composer_exec workdir COMMAND [ARG ...] -exec_composer() { - local workdir=$1 - shift 1 +#================================================= +# EXPERIMENTAL HELPERS +#================================================= - COMPOSER_HOME="${workdir}/.composer" \ - php "${workdir}/composer.phar" $@ \ - -d "${workdir}" --quiet --no-interaction -} - -# Install and initialize Composer in the given directory -# usage: init_composer destdir -init_composer() { - local destdir=$1 - - # install composer - curl -sS https://getcomposer.org/installer \ - | COMPOSER_HOME="${destdir}/.composer" \ - php -- --quiet --install-dir="$destdir" \ - || ynh_die "Unable to install Composer" - - # install composer.json - cp "${destdir}/composer.json-dist" "${destdir}/composer.json" - - # update dependencies to create composer.lock - exec_composer "$destdir" install --no-dev \ - || ynh_die "Unable to update Roundcube core dependencies" -} +#================================================= +# FUTURE OFFICIAL HELPERS +#================================================= diff --git a/scripts/backup b/scripts/backup index bea7d44..4fea4c6 100644 --- a/scripts/backup +++ b/scripts/backup @@ -15,7 +15,6 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ### Remove this function if there's nothing to clean before calling the remove script. true } # Exit if an error occurs during the execution of the script @@ -64,7 +63,13 @@ ynh_script_progression --message="Backing up the MySQL database..." --time --wei ynh_mysql_dump_db --database="$db_name" > db.sql -# Backup cron job +#================================================= +# SPECIFIC BACKUP +#================================================= +# BACKUP A CRON FILE +#================================================= +ynh_script_progression --message="Backing up a cron file..." --time --weight=1 + ynh_backup --src_path="/etc/cron.d/$app" #================================================= diff --git a/scripts/install b/scripts/install index 700fc87..176dabe 100644 --- a/scripts/install +++ b/scripts/install @@ -7,6 +7,7 @@ #================================================= source _common.sh +source ynh_composer__2 source /usr/share/yunohost/helpers #================================================= @@ -14,7 +15,6 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ### Remove this function if there's nothing to clean before calling the remove script. true } # Exit if an error occurs during the execution of the script @@ -24,7 +24,6 @@ ynh_abort_if_errors # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -# Retrieve arguments domain=$YNH_APP_ARG_DOMAIN path_url='/' admin=$YNH_APP_ARG_ADMIN @@ -32,34 +31,13 @@ admin_mail=$(yunohost user info $admin | grep "mail:" | cut -d' ' -f2) is_public=1 database="1" - -### 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 #================================================= # 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 -### 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=/var/www/$app test ! -e "$final_path" || ynh_die --message="This path already contains a folder" @@ -83,14 +61,6 @@ ynh_app_setting_set --app=$app --key=database --value=$database #================================================= ynh_script_progression --message="Installing dependencies..." --time --weight=1 -### `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. -### If you're not using this helper: -### - Remove the section "REMOVE DEPENDENCIES" in the remove script -### - Remove the variable "pkg_dependencies" in _common.sh -### - As well as the section "REINSTALL DEPENDENCIES" in the restore script -### - And the section "UPGRADE DEPENDENCIES" in the upgrade script - ynh_install_app_dependencies $pkg_dependencies #================================================= @@ -98,15 +68,6 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= ynh_script_progression --message="Creating a MySQL database..." --time --weight=1 -### Use these lines if you need a database for the application. -### `ynh_mysql_setup_db` will create a database, an associated user and a ramdom password. -### The password will be stored as 'mysqlpwd' into the app settings, -### and will be available as $db_pwd -### If you're not using these lines: -### - Remove the section "BACKUP THE MYSQL DATABASE" in the backup script -### - Remove also the section "REMOVE THE MYSQL DATABASE" in the remove script -### - As well as the section "RESTORE THE MYSQL DATABASE" in the restore script - db_name=$(ynh_sanitize_dbid --db_name=$app) db_user=$db_name ynh_app_setting_set --app=$app --key=db_name --value=$db_name @@ -117,10 +78,6 @@ ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name #================================================= ynh_script_progression --message="Setting up source files..." --time --weight=1 -### `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. -### `ynh_setup_source` use the file conf/app.src - ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$final_path" @@ -128,7 +85,7 @@ ynh_setup_source --dest_dir="$final_path" cp -f "$final_path/.htaccess-dist" "$final_path/.htaccess" # 2 - Addons -sudo mkdir $final_path/addon +sudo mkdir -p $final_path/addon ynh_setup_source --dest_dir="$final_path/addon" --source_id="addons" #================================================= @@ -136,28 +93,9 @@ ynh_setup_source --dest_dir="$final_path/addon" --source_id="addons" #================================================= ynh_script_progression --message="Configuring nginx web server..." --time --weight=1 -### `ynh_add_nginx_config` will use the file conf/nginx.conf - # Create a dedicated nginx config ynh_add_nginx_config - -# configure friendica -sudo cp -f "/var/www/$app/config/local-sample.config.php" "/var/www/$app/config/local.config.php" -ynh_replace_string --match_string="your.mysqlhost.com" --replace_string="localhost" --target_file="$final_path/config/local.config.php" -ynh_replace_string --match_string="mysqlusername" --replace_string="$db_name" --target_file="$final_path/config/local.config.php" -ynh_replace_string --match_string="mysqldatabasename" --replace_string="$db_name" --target_file="$final_path/config/local.config.php" -ynh_replace_string --match_string="mysqlpassword" --replace_string="$db_pwd" --target_file="$final_path/config/local.config.php" -ynh_replace_string --match_string="'admin_email' => ''," --replace_string="'admin_email' => '$admin_mail'," --target_file="$final_path/config/local.config.php" -ynh_replace_string --match_string="REGISTER_OPEN" --replace_string="REGISTER_CLOSED" --target_file="$final_path/config/local.config.php" - - -# init db -ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < "$final_path/database.sql" - -# addon config -cp "../conf/addon.config.php" "$final_path/config/." - #================================================= # CREATE DEDICATED USER #================================================= @@ -171,57 +109,79 @@ ynh_system_user_create --username=$app #================================================= ynh_script_progression --message="Configuring php-fpm..." --time --weight=1 -### `ynh_add_fpm_config` is used to set up a PHP config. -### You can remove it if your app doesn't use PHP. -### `ynh_add_fpm_config` will use the files conf/php-fpm.conf -### If you're not using these lines: -### - You can remove these files in conf/. -### - Remove the section "BACKUP THE PHP-FPM CONFIGURATION" in the backup script -### - Remove also the section "REMOVE PHP-FPM CONFIGURATION" in the remove script -### - As well as the section "RESTORE THE PHP-FPM CONFIGURATION" in the restore script -### With the reload at the end of the script. -### - And the section "PHP-FPM CONFIGURATION" in the upgrade script - # Create a dedicated php-fpm config ynh_add_fpm_config +#================================================= +# SPECIFIC SETUP +#================================================= +# CONFIGURE FRIENDICA +#================================================= + +cp -f "/var/www/$app/config/local-sample.config.php" "/var/www/$app/config/local.config.php" +ynh_replace_string --match_string="your.mysqlhost.com" --replace_string="localhost" --target_file="$final_path/config/local.config.php" +ynh_replace_string --match_string="mysqlusername" --replace_string="$db_name" --target_file="$final_path/config/local.config.php" +ynh_replace_string --match_string="mysqldatabasename" --replace_string="$db_name" --target_file="$final_path/config/local.config.php" +ynh_replace_string --match_string="mysqlpassword" --replace_string="$db_pwd" --target_file="$final_path/config/local.config.php" +ynh_replace_string --match_string="'admin_email' => ''," --replace_string="'admin_email' => '$admin_mail'," --target_file="$final_path/config/local.config.php" +ynh_replace_string --match_string="REGISTER_OPEN" --replace_string="REGISTER_CLOSED" --target_file="$final_path/config/local.config.php" + +#================================================= +# INIT DB +#================================================= + +ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < "$final_path/database.sql" + +#================================================= +# ADDON CONFIG +#================================================= + +cp "../conf/addon.config.php" "$final_path/config/." chown -R www-data:www-data $final_path # 3 - some extra folders sudo mkdir -p "${final_path}/view/smarty3" sudo chmod -R 775 $final_path/view/smarty3 -# Set up poller +#================================================= +# SETUP A CRON JOB +#================================================= + ynh_replace_string --match_string="__YNH_WWW_PATH__" --replace_string="$final_path" --target_file="../conf/poller-cron" ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="../conf/poller-cron" cp ../conf/poller-cron /etc/cron.d/$app #================================================= -# STORE THE CONFIG FILE CHECKSUM +# INSTALL THE APPLICATION #================================================= -### `ynh_store_file_checksum` is used to store the checksum of a file. -### That way, during the upgrade script, by using `ynh_backup_if_checksum_is_different`, -### you can make a backup of this file before modifying it again if the admin had modified it. +ynh_install_composer +(cd $final_path && sudo bin/console config system addon ldapauth) + +#================================================= +# STORE THE CONFIG FILE CHECKSUM +#================================================= # Calculate and store the config file checksum into the app settings ynh_store_file_checksum --file="$final_path/config/local.config.php" -# Run composer -(cd $final_path && sudo php bin/composer.phar install) -(cd $final_path && sudo bin/console config system addon ldapauth) +#================================================= +# GENERIC FINALIZATION +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= +ynh_print_info --message="Securing files and directories..." +# Set permissions to app files chown -R $app: $final_path #================================================= # SETUP SSOWAT #================================================= - # unprotected_uris allows SSO credentials to be passed anyway. ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" - #================================================= # RELOAD NGINX #================================================= diff --git a/scripts/remove b/scripts/remove index a807cca..3e00c1c 100644 --- a/scripts/remove +++ b/scripts/remove @@ -62,12 +62,11 @@ ynh_script_progression --message="Removing php-fpm configuration..." --time --we ynh_remove_fpm_config #================================================= -# REMOVE LOGROTATE CONFIGURATION +# SPECIFIC REMOVE #================================================= -ynh_script_progression --message="Removing logrotate configuration..." --time --weight=1 - -# Remove the app-specific logrotate config -ynh_remove_logrotate +# REMOVE THE CRON FILE +#================================================= +ynh_script_progression --message="Removing the cron file..." --time --weight=1 # Remove a cron file ynh_secure_remove --file="/etc/cron.d/$app" @@ -86,4 +85,4 @@ ynh_system_user_delete --username=$app # END OF SCRIPT #================================================= -ynh_print_info "Removal of $app completed" +ynh_script_progression --message="Removal of $app completed" --time --last diff --git a/scripts/restore b/scripts/restore index a4af90e..1ee79f8 100644 --- a/scripts/restore +++ b/scripts/restore @@ -15,14 +15,11 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - #### Remove this function if there's nothing to clean before calling the remove script. true } # Exit if an error occurs during the execution of the script ynh_abort_if_errors - - #================================================= # LOAD SETTINGS #================================================= @@ -34,7 +31,7 @@ domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) - +db_user=$db_name #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -54,13 +51,6 @@ test ! -d $final_path \ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# 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 - #================================================= # RESTORE THE APP MAIN DIR #================================================= @@ -71,16 +61,26 @@ ynh_restore_file --origin_path="$final_path" #================================================= # RECREATE THE DEDICATED USER #================================================= -ynh_print_info "Recreating the dedicated system user..." +ynh_script_progression --message="Recreating the dedicated system user..." --time --weight=1 # Create the dedicated user (if not existing) -ynh_system_user_create $app +ynh_system_user_create --username=$app + +#================================================= +# RESTORE USER RIGHTS +#================================================= +ynh_script_progression --message="Restoring user rights..." --time --weight=1 + +# Restore permissions on app files +chown -R $app: $final_path +# set permission +chmod -R 775 $final_path/view/smarty3 #================================================= # RESTORE THE PHP-FPM CONFIGURATION #================================================= -ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf" +ynh_restore_file --origin_path="/etc/php/7.0/fpm/pool.d/$app.conf" #================================================= # SPECIFIC RESTORATION @@ -92,29 +92,19 @@ ynh_script_progression --message="Reinstalling dependencies..." --time --weight= # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies -# set permission -chmod -R 775 $final_path/view/smarty3 +#================================================= +# RESTORE THE MYSQL DATABASE +#================================================= + +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 #================================================= # RESTORE THE CRON FILE #================================================= ynh_restore_file "/etc/cron.d/$app" -# Run composer -(cd $final_path && sudo php bin/composer.phar install) -(cd $final_path && sudo bin/console config system addon ldapauth) - -chown -R $app: $final_path - -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= - -ynh_restore_file --origin_path="/etc/logrotate.d/$app" - -# unprotected_uris allows SSO credentials to be passed anyway. -ynh_app_setting_set $app unprotected_uris "/" - #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index f4a7511..303d7e9 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,6 +7,7 @@ #================================================= source _common.sh +source ynh_composer__2 source /usr/share/yunohost/helpers #================================================= @@ -28,12 +29,6 @@ admin=$(ynh_app_setting_get --app=$app --key=admin) # CHECK VERSION #================================================= -### This helper will compare the version of the currently installed app and the version of the upstream package. -### $upgrade_type can have 2 different values -### - UPGRADE_APP if the upstream app version has changed -### - UPGRADE_PACKAGE if only the YunoHost package has changed -### ynh_check_app_version_changed will stop the upgrade if the app is up to date. -### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do. upgrade_type=$(ynh_check_app_version_changed) #================================================= @@ -61,7 +56,6 @@ ynh_clean_setup () { # Exit if an error occurs during the execution of the script ynh_abort_if_errors - #================================================= # CHECK THE PATH #================================================= @@ -96,6 +90,8 @@ if [ -z $admin_mail ]; then ynh_app_setting_set --app=$app --key=email --value=$admin_mail fi +#================================================= +# STANDARD UPGRADE STEPS #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -106,28 +102,14 @@ then # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$final_path" + + #Copy Addons + rm -Rf "$final_path/addon" + ynh_setup_source --dest_dir="$final_path/addon" --source_id="addons" + # 3 - some extra folders + chmod -R 775 $final_path/view/smarty3 fi -# Copy config file for correct place -cp -f "/var/www/$app/config/local-sample.config.php" "/var/www/$app/config/local.config.php" - -# Replace strings in config file -ynh_replace_string --match_string="your.mysqlhost.com" --replace_string="localhost" --target_file="$final_path/config/local.config.php" -ynh_replace_string --match_string="mysqlusername" --replace_string="$db_name" --target_file="$final_path/config/local.config.php" -ynh_replace_string --match_string="mysqldatabasename" --replace_string="$db_name" --target_file="$final_path/config/local.config.php" -ynh_replace_string --match_string="mysqlpassword" --replace_string="$db_pwd" --target_file= "$final_path/config/local.config.php" -ynh_replace_string --match_string="'admin_email' => ''," --replace_string="'admin_email' => '$admin_mail'," --target_file="$final_path/config/local.config.php" -ynh_replace_string --match_string="REGISTER_OPEN" --replace_string="REGISTER_CLOSED" --target_file="$final_path/config/local.config.php" - - -#Copy Addons -rm -Rf "$final_path/addon" -ynh_setup_source --dest_dir="$final_path/addon" --source_id="addons" - -# 3 - some extra folders -chmod -R 775 $final_path/view/smarty3 - - #================================================= # NGINX CONFIGURATION #================================================= @@ -159,28 +141,56 @@ ynh_script_progression --message="Upgrading php-fpm configuration..." --time --w # Create a dedicated php-fpm config ynh_add_fpm_config +#================================================= +# SPECIFIC UPGRADE +#================================================= +# UPGRADE CONFIGURATION +#================================================= + +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_backup_if_checksum_is_different --file="$final_path/config/local.config.php" + # Copy config file for correct place + cp -f "/var/www/$app/config/local-sample.config.php" "$final_path/config/local.config.php" + + # Replace strings in config file + ynh_replace_string --match_string="your.mysqlhost.com" --replace_string="localhost" --target_file="$final_path/config/local.config.php" + ynh_replace_string --match_string="mysqlusername" --replace_string="$db_name" --target_file="$final_path/config/local.config.php" + ynh_replace_string --match_string="mysqldatabasename" --replace_string="$db_name" --target_file="$final_path/config/local.config.php" + ynh_replace_string --match_string="mysqlpassword" --replace_string="$db_pwd" --target_file= "$final_path/config/local.config.php" + ynh_replace_string --match_string="'admin_email' => ''," --replace_string="'admin_email' => '$admin_mail'," --target_file="$final_path/config/local.config.php" + ynh_replace_string --match_string="REGISTER_OPEN" --replace_string="REGISTER_CLOSED" --target_file="$final_path/config/local.config.php" + + ynh_store_file_checksum --file="$final_path/config/local.config.php" +fi #================================================= -# STORE THE CONFIG FILE CHECKSUM +# SETUP CRON JOB #================================================= -### 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/local.config.php" -# Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum --file="$final_path/config/local.config.php" +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_replace_string --match_string="__YNH_WWW_PATH__" --replace_string="$final_path" --target_file="../conf/poller-cron" + ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="../conf/poller-cron" + cp "../conf/poller-cron" "/etc/cron.d/$app" +fi -# Set up cron job -ynh_replace_string --match_string="__YNH_WWW_PATH__" --replace_string="$final_path" --target_file="../conf/poller-cron" -ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="../conf/poller-cron" -cp "../conf/poller-cron" "/etc/cron.d/$app" +#================================================= +# INSTALL THE APPLICATION +#================================================= -# Run composer -(cd $final_path && sudo php bin/composer.phar install) -(cd $final_path && sudo bin/console config system addon ldapauth) +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_install_composer + (cd $final_path && sudo bin/console config system addon ldapauth) +fi -# Set app as owner +#================================================= +# SECURE FILES AND DIRECTORIES +#================================================= + +# Set permissions on app files chown -R $app: $final_path #================================================= @@ -203,4 +213,3 @@ ynh_systemd_action --service_name=nginx --action=reload #================================================= ynh_script_progression --message="Upgrade of $app completed" --time --last - diff --git a/scripts/ynh_composer__2 b/scripts/ynh_composer__2 new file mode 100644 index 0000000..1b6aa80 --- /dev/null +++ b/scripts/ynh_composer__2 @@ -0,0 +1,48 @@ +#!/bin/bash + +# Execute a command with Composer +# +# usage: ynh_composer_exec --phpversion=phpversion [--workdir=$final_path] --commands="commands" +# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path. +# | arg: -c, --commands - Commands to execute. +ynh_composer_exec () { + # Declare an array to define the options of this helper. + local legacy_args=vwc + declare -Ar args_array=( [v]=phpversion= [w]=workdir= [c]=commands= ) + local phpversion + local workdir + local commands + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + workdir="${workdir:-$final_path}" + phpversion="${phpversion:-7.0}" + + COMPOSER_HOME="$workdir/.composer" \ + php${phpversion} "$workdir/composer.phar" $commands \ + -d "$workdir" --quiet --no-interaction +} + +# Install and initialize Composer in the given directory +# +# usage: ynh_install_composer --phpversion=phpversion [--workdir=$final_path] +# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path. +ynh_install_composer () { + # Declare an array to define the options of this helper. + local legacy_args=vw + declare -Ar args_array=( [v]=phpversion= [w]=workdir= ) + local phpversion + local workdir + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + workdir="${workdir:-$final_path}" + phpversion="${phpversion:-7.0}" + + curl -sS https://getcomposer.org/installer \ + | COMPOSER_HOME="$workdir/.composer" \ + php${phpversion} -- --quiet --install-dir="$workdir" \ + || ynh_die "Unable to install Composer." + + # update dependencies to create composer.lock + ynh_composer_exec --phpversion="${phpversion}" --workdir="$workdir" --commands="install --no-dev" \ + || ynh_die "Unable to update core dependencies with Composer." +}