mirror of
https://github.com/YunoHost-Apps/flarum_ynh.git
synced 2024-09-03 18:36:24 +02:00
Merge pull request #118 from YunoHost-Apps/testing
Upgrade to v0.1.0-beta.9
This commit is contained in:
commit
d5a4f432cb
18 changed files with 1076 additions and 424 deletions
15
README.md
15
README.md
|
@ -1,8 +1,8 @@
|
|||
# Flarum for YunoHost
|
||||
|
||||
[![Install Hubzilla with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=flarum)
|
||||
[![Install Flarum with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=flarum)
|
||||
|
||||
[![Integration level](https://ci-apps.yunohost.org/ci/logs/flarum%20(Community).svg)](https://dash.yunohost.org/appci/app/flarum) [![Flarum version](https://img.shields.io/badge/flarum-0.1.0--beta.7.2-green.svg)](https://github.com/flarum/core/releases/tag/v0.1.0-beta.7.2)
|
||||
[![Integration level](https://ci-apps.yunohost.org/ci/logs/flarum%20%28Apps%29.svg)](https://dash.yunohost.org/appci/app/flarum) [![Flarum version](https://img.shields.io/badge/flarum-0.1.0--beta.9-green.svg)](https://github.com/flarum/flarum/releases/tag/v0.1.0-beta.9) ![PHP version](https://img.shields.io/badge/php-7.3-green.svg)
|
||||
|
||||
[Flarum](http://flarum.org/), an open-source forum software, packaged for [YunoHost](https://yunohost.org/), a self-hosting server operating server.
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
|||
- SSOwat integration through a [dedicated extension](https://github.com/tituspijean/flarum-ext-auth-ssowat).
|
||||
|
||||
## Installation
|
||||
|
||||
This Flarum package can be installed through:
|
||||
- YunoHost's webadmin, in the Community listing
|
||||
- YunoHost's CLI: `yunohost app install https://github.com/YunoHost-Apps/flarum_ynh`.
|
||||
|
@ -24,7 +25,7 @@ Required parameters are:
|
|||
- `admin`, among the YunoHosts users
|
||||
- `public`, *true* by default, for guests to read the forum
|
||||
- `title` of the forum
|
||||
- `language` can be English (by default), French, and German. Other languages installable after installation as any other extensions
|
||||
- `language` can be English `en` (by default), French `fr`, and German `de`. Other languages are installable after installation like any other extensions
|
||||
- `bazaar_extension` to install the extension marketplace (*false* by default), to avoid using the command line to add new extensions.
|
||||
|
||||
After installation, simply open your browser to Flarum's page. First loading may be a bit longer as assets are generated.
|
||||
|
@ -50,13 +51,13 @@ Reboot the system and try the installation again.
|
|||
### `Timeout` errors
|
||||
Some users have reported a successful installation, but get a blank page due to a `timeout` on a PHP script that prepares the forum assests (`Minify.php`, notably).
|
||||
|
||||
In `/etc/php/7.0/fpm/conf.d/20-{APPID}.ini`, you can increase the `max_execution_time` and `max_input_time` limits (both values are in seconds if nothing is specified).
|
||||
In `/etc/php/*php_version*/fpm/pool.d/*app_id*.conf`, you can increase the `max_execution_time` and `max_input_time` limits (both values are in seconds if nothing is specified).
|
||||
|
||||
Reload PHP-FPM with `sudo service php7.0-fpm reload`.
|
||||
Reload PHP-FPM with `sudo service php*php_version*-fpm reload`.
|
||||
|
||||
### Upload limit
|
||||
If you are facing an error while uploading large files into the forum, PHP may be limiting file upload.
|
||||
|
||||
In `/etc/php/7.0/fpm/conf.d/20-{APPID}.ini`, you can uncomment (remove `;` at the beginning of the line) and increase the values of `upload_max_filesize` and `post_max_size` (both values are in bytes).
|
||||
In `/etc/php/*php_version*/fpm/pool.d/*app_id*.conf`, you can uncomment (remove `;` at the beginning of the line) and increase the values of `upload_max_filesize` and `post_max_size` (both values are in bytes).
|
||||
|
||||
Reload PHP-FPM with `sudo service php7.0-fpm reload`.
|
||||
Reload PHP-FPM with `sudo service php*php_version*-fpm reload`.
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
path="/path" (PATH)
|
||||
admin="john" (USER)
|
||||
title="Test flarum"
|
||||
bazaar_extension=0
|
||||
language="en"
|
||||
is_public=1 (PUBLIC|public=1|private=0)
|
||||
; Checks
|
||||
|
@ -17,12 +18,12 @@
|
|||
setup_private=1
|
||||
setup_public=1
|
||||
upgrade=1
|
||||
upgrade=1 from_commit=46ca549825e311f4095b173e79d58a349d70d9a2
|
||||
upgrade=1 from_commit=e9d524d3ede85572e72bf9ac05b224c18b2f1765
|
||||
backup_restore=1
|
||||
multi_instance=1
|
||||
incorrect_path=1
|
||||
port_already_use=0
|
||||
change_url=0
|
||||
change_url=1
|
||||
;;; Levels
|
||||
Level 1=auto
|
||||
Level 2=auto
|
||||
|
|
|
@ -4,23 +4,16 @@ location ^~ __PATH__ {
|
|||
rewrite ^ https://$server_name$request_uri? permanent;
|
||||
}
|
||||
|
||||
alias __FINALPATH__/;
|
||||
try_files $uri $uri/ /index.php?$query_string;
|
||||
index __LOCATION_HACK__/index.php;
|
||||
alias __FINALPATH__/public/;
|
||||
index index.php;
|
||||
|
||||
# Bug in Nginx with locations and aliases (see http://stackoverflow.com/a/35102259 )
|
||||
location __LOCATION_HACK__/ { try_files $uri $uri/ __PATH_HACK__/index.php?$query_string; }
|
||||
location __LOCATION_HACK__/api { try_files $uri $uri/ __PATH_HACK__/api.php?$query_string; }
|
||||
location __LOCATION_HACK__/admin { try_files $uri $uri/ __PATH_HACK__/admin.php?$query_string; }
|
||||
|
||||
location __LOCATION_HACK__/flarum/ {
|
||||
deny all;
|
||||
return 404;
|
||||
}
|
||||
# try_files $uri $uri/ /index.php?$query_string; # will not work for /admin and /api
|
||||
if (!-e $request_filename) { rewrite ^ __PATH_HACK__/index.php last; }
|
||||
|
||||
location ~* \.php$ {
|
||||
fastcgi_split_path_info ^(.+.php)(/.+)$;
|
||||
fastcgi_pass unix:/var/run/php5-fpm-__NAME__.sock;
|
||||
fastcgi_pass unix:/var/run/php-fpm-__NAME__.sock;
|
||||
include fastcgi_params;
|
||||
fastcgi_param SCRIPT_FILENAME $request_filename;
|
||||
fastcgi_param HTTP_PROXY ""; # Fix for https://httpoxy.org/ vulnerability
|
||||
|
@ -28,38 +21,61 @@ location ^~ __PATH__ {
|
|||
fastcgi_read_timeout 600;
|
||||
}
|
||||
|
||||
location ~* \.html$ {
|
||||
expires -1;
|
||||
# Expire rules for static content
|
||||
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
|
||||
add_header Cache-Control "max-age=0";
|
||||
}
|
||||
|
||||
location ~* \.(css|js|gif|jpe?g|png)$ {
|
||||
expires 1M;
|
||||
add_header Pragma public;
|
||||
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
|
||||
location ~* \.(?:rss|atom)$ {
|
||||
add_header Cache-Control "max-age=3600";
|
||||
}
|
||||
|
||||
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|mp4|ogg|ogv|webm|htc)$ {
|
||||
add_header Cache-Control "max-age=2592000";
|
||||
access_log off;
|
||||
}
|
||||
|
||||
location ~* \.(?:css|js)$ {
|
||||
add_header Cache-Control "max-age=31536000";
|
||||
access_log off;
|
||||
}
|
||||
|
||||
location ~* \.(?:ttf|ttc|otf|eot|woff|woff2)$ {
|
||||
add_header Cache-Control "max-age=2592000";
|
||||
access_log off;
|
||||
}
|
||||
|
||||
# Gzip compression
|
||||
gzip on;
|
||||
gzip_http_version 1.1;
|
||||
gzip_vary on;
|
||||
gzip_comp_level 6;
|
||||
gzip_comp_level 5;
|
||||
gzip_min_length 256;
|
||||
gzip_proxied any;
|
||||
gzip_types application/atom+xml
|
||||
gzip_vary on;
|
||||
gzip_types
|
||||
application/atom+xml
|
||||
application/javascript
|
||||
application/json
|
||||
application/ld+json
|
||||
application/manifest+json
|
||||
application/rss+xml
|
||||
application/vnd.geo+json
|
||||
application/vnd.ms-fontobject
|
||||
application/x-font-ttf
|
||||
application/x-web-app-manifest+json
|
||||
application/xhtml+xml
|
||||
application/xml
|
||||
font/opentype
|
||||
image/bmp
|
||||
image/svg+xml
|
||||
image/x-icon
|
||||
text/cache-manifest
|
||||
text/css
|
||||
text/plain
|
||||
text/xml;
|
||||
gzip_buffers 16 8k;
|
||||
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
|
||||
|
||||
text/vcard
|
||||
text/vnd.rim.location.xloc
|
||||
text/vtt
|
||||
text/x-component
|
||||
text/x-cross-domain-policy;
|
||||
|
||||
# Include SSOWAT user panel.
|
||||
# include conf.d/yunohost_panel.conf.inc;
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
; specific port;
|
||||
; '/path/to/unix/socket' - to listen on a unix socket.
|
||||
; Note: This value is mandatory.
|
||||
listen = /var/run/php5-fpm-__USER__.sock
|
||||
listen = /var/run/php-fpm-__USER__.sock
|
||||
|
||||
; Set listen(2) backlog. A value of '-1' means unlimited.
|
||||
; Default Value: 128 (-1 on FreeBSD and OpenBSD)
|
||||
|
@ -246,7 +246,7 @@ catch_workers_output = yes
|
|||
; Other common parameters
|
||||
php_value[max_execution_time] = 600
|
||||
php_value[max_input_time] = 600
|
||||
;php_value[memory_limit] = 256M
|
||||
php_value[memory_limit] = 256M
|
||||
;php_value[short_open_tag] = On
|
||||
|
||||
env[COMPOSER_HOME] = __FINALPATH__/.composer
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
; Common values to change to increase file upload limit
|
||||
; upload_max_filesize = 50M
|
||||
; post_max_size = 50M
|
||||
; mail.add_x_header = Off
|
||||
|
||||
; Other common parameters
|
||||
max_execution_time = 600
|
||||
max_input_time = 300
|
||||
memory_limit = 256M
|
||||
; short_open_tag = On
|
|
@ -3,24 +3,24 @@
|
|||
"id": "flarum",
|
||||
"packaging_format": 1,
|
||||
"description": {
|
||||
"en": "Flarum (open-source forum software) package for YunoHost.",
|
||||
"fr": "Package Flarum (système de forum libre) pour YunoHost.",
|
||||
"de": "Flarum (Open Source) ist ein Programmpaket für Yunohost."
|
||||
"en": "Flarum is the next-generation forum software that makes online discussion fun. It's simple, fast, and free.",
|
||||
"fr": "Flarum est le forum de nouvelle génération qui rend les discussions ligne un plaisir. Il est simple, rapide, et libre.",
|
||||
"de": "Flarum ist die Forensoftware der nächsten Generation, mit der Online-Diskussionen Spaß machen. Es ist einfach, schnell und freie."
|
||||
},
|
||||
"url": "http://flarum.org/",
|
||||
"license": "MIT",
|
||||
"version": "0.1.0-beta.7",
|
||||
"version": "0.1.0-beta.9~ynh1",
|
||||
"maintainer": {
|
||||
"name": "Titus PiJean",
|
||||
"name": "tituspijean",
|
||||
"email": "tituspijean@outlook.com"
|
||||
},
|
||||
"requirements": {
|
||||
"yunohost": ">= 2.4.0"
|
||||
"yunohost": ">= 3.5.0"
|
||||
},
|
||||
"multi_instance": true,
|
||||
"services": [
|
||||
"nginx",
|
||||
"php5-fpm",
|
||||
"php7.3-fpm",
|
||||
"mysql"
|
||||
],
|
||||
"arguments": {
|
||||
|
@ -57,6 +57,7 @@
|
|||
},
|
||||
{
|
||||
"name": "title",
|
||||
"type": "string",
|
||||
"ask": {
|
||||
"en": "Choose a title for your forum",
|
||||
"fr": "Choisissez un titre pour votre forum",
|
||||
|
@ -87,6 +88,7 @@
|
|||
},
|
||||
{
|
||||
"name": "language",
|
||||
"type": "string",
|
||||
"ask": {
|
||||
"en": "Choose the application language",
|
||||
"fr": "Choisissez la langue de l'application",
|
||||
|
|
|
@ -1,77 +1,38 @@
|
|||
#=================================================
|
||||
# COMMON VARIABLES
|
||||
#=================================================
|
||||
|
||||
# dependencies used by the app
|
||||
pkg_dependencies="php7.3-curl php7.3-dom php7.3-gd php7.3-json php7.3-mbstring php7.3-pdo-mysql php7.3-tokenizer php7.3-zip"
|
||||
|
||||
# Version numbers
|
||||
project_version="0.1.0-beta.7"
|
||||
flarum_version="0.1.0-beta.7.2"
|
||||
ssowat_ext_ver="0.6"
|
||||
php_version="7.3"
|
||||
project_version="0.1.0-beta.9"
|
||||
core_version="0.1.0-beta.9"
|
||||
ssowat_version="0.1.0-beta.9-1"
|
||||
|
||||
# Execute a command as another user
|
||||
# usage: exec_as USER COMMAND [ARG ...]
|
||||
exec_as() {
|
||||
local USER=$1
|
||||
shift 1
|
||||
|
||||
if [[ $USER = $(whoami) ]]
|
||||
then
|
||||
eval $@
|
||||
else
|
||||
sudo -u "$USER" $@
|
||||
fi
|
||||
}
|
||||
|
||||
# Execute a composer command from a given directory
|
||||
# usage: composer_exec AS_USER WORKDIR COMMAND [ARG ...]
|
||||
exec_composer() {
|
||||
local AS_USER=$1
|
||||
local WORKDIR=$2
|
||||
shift 2
|
||||
|
||||
# Do not run composer as root
|
||||
if [ $AS_USER = "root" ] ; then ynh_die "Do not run composer as root" ; fi
|
||||
pushd "${WORKDIR}"
|
||||
ynh_exec_warn_less \
|
||||
"exec_as "$AS_USER" COMPOSER_HOME="${WORKDIR}/.composer" \
|
||||
php -d memory_limit=-1 \
|
||||
"${WORKDIR}/composer.phar" $@ \
|
||||
--no-interaction"
|
||||
popd
|
||||
}
|
||||
|
||||
# Install and initialize Composer in the given directory
|
||||
# usage: init_composer destdir
|
||||
init_composer() {
|
||||
local AS_USER=$1
|
||||
local WORKDIR=$2
|
||||
|
||||
# Do not install composer as root
|
||||
if [ $AS_USER = "root" ] ; then ynh_die "Do not install composer as root" ; fi
|
||||
|
||||
# install composer
|
||||
curl -sS https://getcomposer.org/installer \
|
||||
| ynh_exec_warn_less \
|
||||
"COMPOSER_HOME="${WORKDIR}/.composer" php -- --install-dir="$WORKDIR"" \
|
||||
|| ynh_die "Unable to install Composer"
|
||||
chmod +x "${WORKDIR}/composer.phar"
|
||||
# update dependencies to create composer.lock
|
||||
#exec_composer "$AS_USER" "$WORKDIR" install --no-dev \
|
||||
# || ynh_die "Unable to update core dependencies with Composer"
|
||||
}
|
||||
#=================================================
|
||||
# PERSONAL HELPERS
|
||||
#=================================================
|
||||
|
||||
# Install extension, and activate it in database
|
||||
# usage: install_and_activate_extension $user $final_path $db_name $extension $short_extension
|
||||
# usage: install_and_activate_extension $user $php_version $final_path $db_name $extension $short_extension
|
||||
# $extension is the "vendor/extension-name" string from packagist
|
||||
# $short_extension is the extension name written in database, how it is shortened is still a mystery
|
||||
install_and_activate_extension() {
|
||||
local AS_USER=$1
|
||||
local WORKDIR=$2
|
||||
local DB_NAME=$3
|
||||
local EXTENSION=$4
|
||||
local SHORT_EXTENSION=$5
|
||||
local PHP_VERSION=$2
|
||||
local WORKDIR=$3
|
||||
local DB_NAME=$4
|
||||
local EXTENSION=$5
|
||||
local SHORT_EXTENSION=$6
|
||||
local sql_command
|
||||
local old_extensions_enabled
|
||||
local addition
|
||||
local new_extensions_enabled
|
||||
|
||||
# Install extension
|
||||
exec_composer $AS_USER $WORKDIR "require $EXTENSION -n --ansi -d $WORKDIR"
|
||||
ynh_composer_exec $AS_USER $PHP_VERSION $WORKDIR "require $EXTENSION -n --ansi -d $WORKDIR"
|
||||
|
||||
# Retrieve current extensions
|
||||
sql_command="SELECT \`value\` FROM settings WHERE \`key\` = 'extensions_enabled'"
|
||||
|
@ -86,63 +47,8 @@ install_and_activate_extension() {
|
|||
|
||||
}
|
||||
|
||||
# Send an email to inform the administrator
|
||||
#
|
||||
# usage: ynh_send_readme_to_admin app_message [recipients]
|
||||
# | arg: app_message - The message to send to the administrator.
|
||||
# | arg: recipients - The recipients of this email. Use spaces to separate multiples recipients. - default: root
|
||||
# example: "root admin@domain"
|
||||
# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you
|
||||
# example: "root admin@domain user1 user2"
|
||||
ynh_send_readme_to_admin() {
|
||||
local app_message="${1:-...No specific information...}"
|
||||
local recipients="${2:-root}"
|
||||
#=================================================
|
||||
# EXPERIMENTAL HELPERS
|
||||
#=================================================
|
||||
|
||||
# Retrieve the email of users
|
||||
find_mails () {
|
||||
local list_mails="$1"
|
||||
local mail
|
||||
local recipients=" "
|
||||
# Read each mail in argument
|
||||
for mail in $list_mails
|
||||
do
|
||||
# Keep root or a real email address as it is
|
||||
if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@"
|
||||
then
|
||||
recipients="$recipients $mail"
|
||||
else
|
||||
# But replace an user name without a domain after by its email
|
||||
if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null)
|
||||
then
|
||||
recipients="$recipients $mail"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
echo "$recipients"
|
||||
}
|
||||
recipients=$(find_mails "$recipients")
|
||||
|
||||
local mail_subject="☁️🆈🅽🅷☁️: \`$app\` was just installed!"
|
||||
|
||||
local mail_message="This is an automated message from your beloved YunoHost server.
|
||||
|
||||
Specific information for the application $app.
|
||||
|
||||
$app_message
|
||||
|
||||
---
|
||||
Automatic diagnosis data from YunoHost
|
||||
|
||||
$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')"
|
||||
|
||||
# Define binary to use for mail command
|
||||
if [ -e /usr/bin/bsd-mailx ]
|
||||
then
|
||||
local mail_bin=/usr/bin/bsd-mailx
|
||||
else
|
||||
local mail_bin=/usr/bin/mail.mailutils
|
||||
fi
|
||||
|
||||
# Send the email to the recipients
|
||||
echo "$mail_message" | $mail_bin -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients"
|
||||
}
|
||||
# See ynh_* scripts
|
||||
|
|
|
@ -6,62 +6,73 @@
|
|||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
if [ ! -e _common.sh ]; then
|
||||
# Get the _common.sh file if it's not in the current directory
|
||||
cp ../settings/scripts/_common.sh ./_common.sh
|
||||
chmod a+rx _common.sh
|
||||
fi
|
||||
source _common.sh
|
||||
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
||||
source ../settings/scripts/_common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
ynh_clean_setup () {
|
||||
### Remove this function if there's nothing to clean before calling the remove script.
|
||||
true
|
||||
}
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Loading installation settings..." --time --weight=1
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
db_name=$(ynh_app_setting_get $app db_name)
|
||||
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)
|
||||
|
||||
#=================================================
|
||||
# STANDARD BACKUP STEPS
|
||||
#=================================================
|
||||
# BACKUP THE APP MAIN DIR
|
||||
#=================================================
|
||||
ynh_script_progression --message="Backing up the main app directory..." --time --weight=1
|
||||
|
||||
ynh_backup "$final_path"
|
||||
ynh_backup --src_path="$final_path"
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Backing up nginx web server configuration..." --time --weight=1
|
||||
|
||||
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
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 "/etc/php5/fpm/pool.d/$app.conf"
|
||||
ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini"
|
||||
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 "$db_name" > db.sql
|
||||
ynh_mysql_dump_db --database="$db_name" > db.sql
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC BACKUP
|
||||
#=================================================
|
||||
# BACKUP LOGROTATE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Backing up logrotate configuration..." --time --weight=1
|
||||
|
||||
ynh_backup "/etc/logrotate.d/$app"
|
||||
ynh_backup --src_path="/etc/logrotate.d/$app"
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --time --last
|
||||
|
|
|
@ -24,22 +24,15 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Loading installation settings..." --time --weight=1
|
||||
|
||||
# Needed for helper "ynh_add_nginx_config"
|
||||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
|
||||
# Add settings here as needed by your application
|
||||
#db_name=$(ynh_app_setting_get "$app" db_name)
|
||||
#db_pwd=$(ynh_app_setting_get $app db_pwd)
|
||||
|
||||
#=================================================
|
||||
# CHECK THE SYNTAX OF THE PATHS
|
||||
#=================================================
|
||||
|
||||
test -n "$old_path" || old_path="/"
|
||||
test -n "$new_path" || new_path="/"
|
||||
new_path=$(ynh_normalize_url_path $new_path)
|
||||
old_path=$(ynh_normalize_url_path $old_path)
|
||||
#db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
||||
#db_user=$db_name
|
||||
#db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
|
||||
|
||||
#=================================================
|
||||
# CHECK WHICH PARTS SHOULD BE CHANGED
|
||||
|
@ -59,9 +52,17 @@ fi
|
|||
|
||||
#=================================================
|
||||
# STANDARD MODIFICATIONS
|
||||
#=================================================
|
||||
# STOP SYSTEMD SERVICE
|
||||
#=================================================
|
||||
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"
|
||||
|
||||
#=================================================
|
||||
# MODIFY URL IN NGINX CONF
|
||||
#=================================================
|
||||
ynh_script_progression --message="Updating nginx web server configuration..." --time --weight=1
|
||||
|
||||
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
|
||||
|
||||
|
@ -69,17 +70,15 @@ nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
|
|||
if [ $change_path -eq 1 ]
|
||||
then
|
||||
# Make a backup of the original nginx config file if modified
|
||||
ynh_backup_if_checksum_is_different "$nginx_conf_path"
|
||||
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
|
||||
# Set global variables for nginx helper
|
||||
domain="$old_domain"
|
||||
path_url="$new_path"
|
||||
# Bug in Nginx with locations and aliases (see http://stackoverflow.com/a/35102259 )
|
||||
if [ $path_url = "/" ]; then
|
||||
sed -i "s@__LOCATION_HACK__@@g" ../conf/nginx.conf
|
||||
sed -i "s@__PATH_HACK__@/@g" ../conf/nginx.conf
|
||||
ynh_replace_string "__PATH_HACK__" "" "../conf/nginx.conf"
|
||||
else
|
||||
sed -i "s@__LOCATION_HACK__@$path_url@g" ../conf/nginx.conf
|
||||
sed -i "s@__PATH_HACK__@$path_url$path_url@g" ../conf/nginx.conf
|
||||
ynh_replace_string "__PATH_HACK__" "$path_url" "../conf/nginx.conf"
|
||||
fi
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
|
@ -89,32 +88,36 @@ fi
|
|||
if [ $change_domain -eq 1 ]
|
||||
then
|
||||
# Delete file checksum for the old conf file location
|
||||
ynh_delete_file_checksum "$nginx_conf_path"
|
||||
ynh_delete_file_checksum --file="$nginx_conf_path"
|
||||
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
|
||||
# Store file checksum for the new config file location
|
||||
ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf"
|
||||
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC MODIFICATIONS
|
||||
#=================================================
|
||||
# MODIFY URL IN CONFIG.PHP
|
||||
# ...
|
||||
#=================================================
|
||||
|
||||
if [ $change_domain -eq 1 ]
|
||||
then
|
||||
ynh_replace_string $old_domain $new_domain $final_path/config.php
|
||||
fi
|
||||
|
||||
if [ $change_path -eq 1 ]
|
||||
then
|
||||
ynh_replace_string $old_path $new_path $final_path/config.php
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALISATION
|
||||
#=================================================
|
||||
# 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
|
||||
|
||||
systemctl reload nginx
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Change of URL completed for $app" --time --last
|
||||
|
|
101
scripts/install
101
scripts/install
|
@ -7,6 +7,11 @@
|
|||
#=================================================
|
||||
|
||||
source _common.sh
|
||||
source ynh_add_extra_apt_repos__3
|
||||
source ynh_install_php__3
|
||||
source ynh_exec_as
|
||||
source ynh_composer__2
|
||||
source ynh_send_readme_to_admin__2
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
|
@ -69,27 +74,46 @@ ynh_app_setting_set $app admin $admin
|
|||
ynh_app_setting_set $app is_public $is_public
|
||||
ynh_app_setting_set $app language $language
|
||||
ynh_app_setting_set $app final_path $final_path
|
||||
ynh_app_setting_set $app php_version $php_version
|
||||
ynh_app_setting_set $app project_version $project_version
|
||||
ynh_app_setting_set $app flarum_version $flarum_version
|
||||
ynh_app_setting_set $app ssowat_ext_ver $ssowat_ext_ver
|
||||
ynh_app_setting_set $app core_version $core_version
|
||||
ynh_app_setting_set $app ssowat_version $ssowat_version
|
||||
ynh_app_setting_set $app bazaar_extension $bazaar_extension
|
||||
|
||||
#=================================================
|
||||
# STANDARD MODIFICATIONS
|
||||
#=================================================
|
||||
# INSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
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_php --phpversion=7.3 --package="$pkg_dependencies"
|
||||
|
||||
#===================================================
|
||||
# CREATE DEDICATED USER
|
||||
#===================================================
|
||||
|
||||
ynh_system_user_create $app $final_path
|
||||
sudo usermod -a -G www-data $app
|
||||
ynh_system_user_create $app $final_path 1
|
||||
usermod -a -G www-data $app
|
||||
# Create working directory
|
||||
sudo mkdir -p "$final_path/.composer"
|
||||
sudo chown -R $app:www-data $final_path
|
||||
sudo chmod -R 0775 $final_path
|
||||
mkdir -p "$final_path/.composer"
|
||||
chown -R $app:www-data $final_path
|
||||
chmod -R 0775 $final_path
|
||||
|
||||
#=================================================
|
||||
# COMPOSER INSTALLATION
|
||||
#=================================================
|
||||
|
||||
init_composer $app $final_path
|
||||
ynh_script_progression --message="Installing Composer..." --time --weight=1
|
||||
ynh_install_composer $php_version $final_path
|
||||
|
||||
#=================================================
|
||||
# FLARUM INSTALLATION
|
||||
|
@ -97,23 +121,26 @@ init_composer $app $final_path
|
|||
|
||||
# Prepare Flarum temp directory
|
||||
tmp=/tmp/$app
|
||||
sudo mkdir -p $tmp
|
||||
sudo chown -R $app:www-data $tmp
|
||||
sudo chmod -R 0775 $tmp
|
||||
mkdir -p $tmp
|
||||
chown -R $app:www-data $tmp
|
||||
chmod -R 0775 $tmp
|
||||
|
||||
# Install Flarum
|
||||
ynh_print_info "Composer is installing Flarum and its dependencies. It may take a while..."
|
||||
ynh_script_progression --message="Composer is installing Flarum and its dependencies (may take a while)..." --time --weight=3
|
||||
|
||||
# First, create the project with core and all basic extensions
|
||||
exec_composer $app $final_path "create-project flarum/flarum=$project_version $tmp --stability=beta --ansi -d $tmp"
|
||||
ynh_composer_exec $app $php_version $final_path "create-project flarum/flarum=$project_version $tmp --stability=beta --ansi -d $tmp"
|
||||
# Let's fix the core version by explicitely requiring it
|
||||
exec_composer $app $final_path "require flarum/core:$flarum_version -n --ansi -d $tmp"
|
||||
ynh_composer_exec $app $php_version $final_path "require flarum/core:$core_version -n --ansi -d $tmp"
|
||||
|
||||
# Copy Flarum to working directory and clean temp directory
|
||||
sudo cp -Rf $tmp/* $final_path
|
||||
sudo chown -R $app:www-data $final_path
|
||||
sudo chmod -R 0775 $final_path
|
||||
cp -Rf $tmp/* $final_path
|
||||
ynh_secure_remove $tmp
|
||||
ynh_print_info " ... done!"
|
||||
|
||||
# Set right permissions for the post-installation
|
||||
chown -R $app: $final_path
|
||||
chown -R $app:www-data $final_path/storage
|
||||
chmod -R 0775 $final_path
|
||||
|
||||
#=================================================
|
||||
# CREATE A MYSQL DATABASE
|
||||
|
@ -130,12 +157,11 @@ ynh_app_setting_set "$app" db_pwd "$db_pwd"
|
|||
|
||||
# Bug in Nginx with locations and aliases (see http://stackoverflow.com/a/35102259 )
|
||||
if [ $path_url = "/" ]; then
|
||||
ynh_replace_string "__LOCATION_HACK__" "" "../conf/nginx.conf"
|
||||
ynh_replace_string "__PATH_HACK__" "/" "../conf/nginx.conf"
|
||||
ynh_replace_string "__PATH_HACK__" "" "../conf/nginx.conf"
|
||||
else
|
||||
ynh_replace_string "__LOCATION_HACK__" "$path_url" "../conf/nginx.conf"
|
||||
ynh_replace_string "__PATH_HACK__" "$path_url$path_url" "../conf/nginx.conf"
|
||||
ynh_replace_string "__PATH_HACK__" "$path_url" "../conf/nginx.conf"
|
||||
fi
|
||||
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
|
||||
|
@ -144,7 +170,7 @@ ynh_add_nginx_config
|
|||
#=================================================
|
||||
|
||||
# Create a dedicated php-fpm config
|
||||
ynh_add_fpm_config
|
||||
ynh_add_fpm_config $php_version
|
||||
|
||||
#=================================================
|
||||
# SETUP LOGROTATE
|
||||
|
@ -177,8 +203,8 @@ systemctl reload nginx
|
|||
#=================================================
|
||||
# FLARUM POST-INSTALL
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring Flarum..." --time --weight=2
|
||||
|
||||
ynh_print_info "Configuring Flarum..."
|
||||
# Copy the configuration.yml to working directory
|
||||
finalflarumconf="$final_path/configuration.yml"
|
||||
cp ../conf/configuration.yml $finalflarumconf
|
||||
|
@ -197,8 +223,8 @@ ynh_replace_string "__ADMIN_EML__" "$admin_mail" "$finalflarumconf"
|
|||
ynh_replace_string "__FORUM_TITLE__" "$title" "$finalflarumconf"
|
||||
# Execute post-installation
|
||||
pushd $final_path
|
||||
exec_as $app "php -d $final_path -d memory_limit=-1 flarum install -f configuration.yml"
|
||||
# Delete configuration.yml as it sensitive data
|
||||
exec_as $app php$php_version -d $final_path -d memory_limit=-1 flarum install -f configuration.yml
|
||||
# Delete configuration.yml as it contains sensitive data
|
||||
ynh_secure_remove $finalflarumconf
|
||||
popd
|
||||
|
||||
|
@ -210,10 +236,11 @@ sql_command="REPLACE INTO \`settings\` (\`key\`, \`value\`) VALUES
|
|||
('mail_host', 'localhost'),
|
||||
('mail_port', '587');"
|
||||
ynh_mysql_execute_as_root "$sql_command" $db_name
|
||||
ynh_print_info " ... done!"
|
||||
|
||||
|
||||
# Install and activate the SSOwat auth extension
|
||||
install_and_activate_extension $app $final_path $db_name "tituspijean/flarum-ext-auth-ssowat:$ssowat_ext_ver" "tituspijean-auth-ssowat"
|
||||
ynh_script_progression --message="Installing SSOwat extension..." --time --weight=2
|
||||
install_and_activate_extension $app $php_version $final_path $db_name "tituspijean/flarum-ext-auth-ssowat:$ssowat_version" "tituspijean-auth-ssowat"
|
||||
# Configure SSOwat auth extension
|
||||
ssowatdomain=$(</etc/yunohost/current_host)
|
||||
sql_command="INSERT INTO \`settings\` (\`key\`, \`value\`) VALUES ('tituspijean-auth-ssowat.domain', '$ssowatdomain'), ('tituspijean-auth-ssowat.onlyUse', '0');"
|
||||
|
@ -223,25 +250,29 @@ ynh_print_info "SSOwat extension has been installed."
|
|||
# Install, activate and set language extensions
|
||||
case $language in
|
||||
fr)
|
||||
install_and_activate_extension $app $final_path $db_name "milescellar/flarum-ext-french" "milescellar-french"
|
||||
ynh_script_progression --message="Installing French extension..." --time --weight=2
|
||||
install_and_activate_extension $app $php_version $final_path $db_name "milescellar/flarum-ext-french" "milescellar-french"
|
||||
sql_command="UPDATE \`settings\` SET \`value\` = 'fr' WHERE \`settings\`.\`key\` = 'default_locale'"
|
||||
ynh_mysql_execute_as_root "$sql_command" $db_name
|
||||
ynh_print_info "French language has been installed."
|
||||
;;
|
||||
de)
|
||||
install_and_activate_extension $app $final_path $db_name "cbmainz/flarum-de" "cbmainz-de"
|
||||
ynh_script_progression --message="Installing German extension..." --time --weight=2
|
||||
install_and_activate_extension $app $php_version $final_path $db_name "cbmainz/flarum-de" "cbmainz-de"
|
||||
sql_command="UPDATE \`settings\` SET \`value\` = 'de' WHERE \`settings\`.\`key\` = 'default_locale'"
|
||||
ynh_mysql_execute_as_root "$sql_command" $db_name
|
||||
ynh_print_info "German language has been installed."
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $bazaar_extension -eq 1 ]; then
|
||||
exec_composer $app $final_path "require flagrow/bazaar --ansi"
|
||||
ynh_print_info "Bazaar extension has been installed."
|
||||
ynh_script_progression --message="Installing Bazaar extension..." --time --weight=2
|
||||
ynh_composer_exec $app $php_version $final_path "require flagrow/bazaar --ansi"
|
||||
fi
|
||||
|
||||
# Send login credentials to admin
|
||||
#=================================================
|
||||
# SEND CREDENTIALS TO ADMIN
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Sending generated admin credentials by email, but you can log in with your YunoHost credentials!" --time --weight=1
|
||||
app_message="User : $admin, password : $admin_pwd
|
||||
Change your password!
|
||||
Your forum is accessible at https://$domain$path_url"
|
||||
|
|
|
@ -7,37 +7,54 @@
|
|||
#=================================================
|
||||
|
||||
source _common.sh
|
||||
source ynh_add_extra_apt_repos__3
|
||||
source ynh_install_php__3
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Loading installation settings..." --time --weight=1
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
db_name=$(ynh_app_setting_get $app db_name)
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
port=$(ynh_app_setting_get --app=$app --key=port)
|
||||
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
||||
db_user=$db_name
|
||||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
|
||||
#=================================================
|
||||
# STANDARD REMOVE
|
||||
#=================================================
|
||||
# REMOVE THE MYSQL DATABASE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing the MySQL database..." --time --weight=1
|
||||
|
||||
# Remove a database if it exists, along with the associated user
|
||||
ynh_mysql_remove_db $db_user $db_name
|
||||
ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
|
||||
|
||||
#=================================================
|
||||
# REMOVE DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing dependencies..." --time --weight=1
|
||||
|
||||
# Remove metapackage and its dependencies
|
||||
ynh_remove_app_dependencies
|
||||
ynh_remove_php
|
||||
|
||||
#=================================================
|
||||
# REMOVE APP MAIN DIR
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing app main directory..." --time --weight=1
|
||||
|
||||
# Remove the app directory securely
|
||||
ynh_secure_remove "$final_path"
|
||||
ynh_secure_remove "/tmp/$app"
|
||||
ynh_secure_remove --file="$final_path"
|
||||
|
||||
#=================================================
|
||||
# REMOVE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing nginx web server configuration..." --time --weight=1
|
||||
|
||||
# Remove the dedicated nginx config
|
||||
ynh_remove_nginx_config
|
||||
|
@ -45,6 +62,7 @@ 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
|
||||
|
@ -52,15 +70,36 @@ ynh_remove_fpm_config
|
|||
#=================================================
|
||||
# REMOVE LOGROTATE CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing logrotate configuration..." --time --weight=1
|
||||
|
||||
# Remove the app-specific logrotate config
|
||||
ynh_remove_logrotate
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC REMOVE
|
||||
#=================================================
|
||||
# REMOVE THE CRON FILE
|
||||
#=================================================
|
||||
|
||||
# Remove a temp directory securely
|
||||
ynh_secure_remove --file="/tmp/$app/"
|
||||
ynh_secure_remove --file="/tmp/${app}backup"
|
||||
|
||||
# Remove the log files
|
||||
ynh_secure_remove --file="/var/log/$app/"
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# REMOVE DEDICATED USER
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing the dedicated system user..." --time --weight=1
|
||||
|
||||
# Delete a system user
|
||||
ynh_system_user_delete $app
|
||||
ynh_system_user_delete --username=$app
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Removal of $app completed" --time --last
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source _common.sh
|
||||
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
||||
source ../settings/scripts/_common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
|
@ -42,14 +43,40 @@ test ! -d $final_path \
|
|||
# RESTORE THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE APP MAIN DIR
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring the app main directory..." --time --weight=1
|
||||
|
||||
ynh_restore_file "$final_path"
|
||||
ynh_restore_file --origin_path="$final_path"
|
||||
|
||||
#=================================================
|
||||
# RECREATE THE DEDICATED USER
|
||||
#=================================================
|
||||
ynh_script_progression --message="Recreating the dedicated system user..." --time --weight=1
|
||||
|
||||
# Create the dedicated user (if not existing)
|
||||
ynh_system_user_create --username=$app
|
||||
|
||||
#=================================================
|
||||
# RESTORE USER RIGHTS
|
||||
#=================================================
|
||||
|
||||
# Set right permissions
|
||||
chown -R $app: $final_path
|
||||
chown -R $app:www-data $final_path/storage
|
||||
chmod -R 0775 $final_path
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE PHP-FPM CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_restore_file --origin_path="/etc/php/${php_version}/fpm/pool.d/$app.conf"
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC RESTORATION
|
||||
#=================================================
|
||||
# RESTORE THE MYSQL DATABASE
|
||||
#=================================================
|
||||
|
@ -58,28 +85,6 @@ db_pwd=$(ynh_app_setting_get $app mysqlpwd)
|
|||
ynh_mysql_setup_db $db_name $db_name $db_pwd
|
||||
ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
|
||||
|
||||
#=================================================
|
||||
# RECREATE THE DEDICATED USER
|
||||
#=================================================
|
||||
|
||||
# Create the dedicated user (if not existing)
|
||||
ynh_system_user_create $app
|
||||
|
||||
#=================================================
|
||||
# RESTORE USER RIGHTS
|
||||
#=================================================
|
||||
|
||||
# Restore permissions on app files
|
||||
chown -R $app:www-data $final_path
|
||||
chmod -R 0775 $final_path
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE PHP-FPM CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf"
|
||||
ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE LOGROTATE CONFIGURATION
|
||||
#=================================================
|
||||
|
@ -91,6 +96,13 @@ ynh_restore_file "/etc/logrotate.d/$app"
|
|||
#=================================================
|
||||
# RELOAD NGINX AND PHP-FPM
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reloading nginx web server and php-fpm..." --time --weight=1
|
||||
|
||||
systemctl reload php5-fpm
|
||||
systemctl reload nginx
|
||||
ynh_systemd_action --service_name=php${php_version}-fpm --action=reload
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Restoration completed for $app" --time --last
|
||||
|
|
294
scripts/upgrade
294
scripts/upgrade
|
@ -7,72 +7,76 @@
|
|||
#=================================================
|
||||
|
||||
source _common.sh
|
||||
source ynh_add_extra_apt_repos__3
|
||||
source ynh_install_php__3
|
||||
source ynh_exec_as
|
||||
source ynh_composer__2
|
||||
source ynh_send_readme_to_admin__2
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Loading installation settings..." --time --weight=1
|
||||
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#===================================================
|
||||
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
||||
#===================================================
|
||||
|
||||
# This is 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 you are interested the 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
|
||||
|
||||
# Retrieve app settings
|
||||
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)
|
||||
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)
|
||||
db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
|
||||
old_project_version=$(ynh_app_setting_get --app=$app --key=project_version)
|
||||
old_core_version=$(ynh_app_setting_get --app=$app --key=core_version)
|
||||
old_ssowat_version=$(ynh_app_setting_get --app=$app --key=ssowat_version)
|
||||
[ -z "$old_ssowat_version" ] && old_ssowat_version="0.6"
|
||||
bazaar_extension=$(ynh_app_setting_get --app=$app --key=bazaar_extension)
|
||||
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
path_url=$(ynh_app_setting_get "$app" path)
|
||||
admin=$(ynh_app_setting_get "$app" admin)
|
||||
is_public=$(ynh_app_setting_get "$app" is_public)
|
||||
final_path=$(ynh_app_setting_get "$app" final_path)
|
||||
db_name=$(ynh_app_setting_get $app db_name)
|
||||
db_pwd=$(ynh_app_setting_get $app db_pwd)
|
||||
old_flarum_version=$(ynh_app_setting_get "$app" flarum_version)
|
||||
old_ssowat_ext_ver=$(ynh_app_setting_get "$app" ssowat_ext_ver)
|
||||
bazaar_extension=$(ynh_app_setting_get "$app" bazaar_extension)
|
||||
#=================================================
|
||||
# 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)
|
||||
|
||||
#=================================================
|
||||
# ENSURE DOWNWARD COMPATIBILITY
|
||||
#=================================================
|
||||
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 is_public 1
|
||||
ynh_app_setting_set --app=$app --key=is_public --value=1
|
||||
is_public=1
|
||||
elif [ "$is_public" = "No" ]; then
|
||||
ynh_app_setting_set $app is_public 0
|
||||
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 $app)
|
||||
ynh_app_setting_set $app db_name $db_name
|
||||
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
|
||||
fi
|
||||
|
||||
# If final_path doesn't exist, create it
|
||||
if [ -z $final_path ]; then
|
||||
if [ -z "$final_path" ]; then
|
||||
final_path=/var/www/$app
|
||||
ynh_app_setting_set $app final_path $final_path
|
||||
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||
#=================================================
|
||||
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1
|
||||
|
||||
# Backup the current version of the app
|
||||
ynh_backup_before_upgrade
|
||||
|
@ -88,23 +92,61 @@ ynh_abort_if_errors
|
|||
#=================================================
|
||||
|
||||
# Normalize the URL path syntax
|
||||
path_url=$(ynh_normalize_url_path $path_url)
|
||||
# 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
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading nginx web server configuration..." --time --weight=1
|
||||
|
||||
# Bug in Nginx with locations and aliases (see http://stackoverflow.com/a/35102259 )
|
||||
if [ $path_url = "/" ]; then
|
||||
ynh_replace_string "__PATH_HACK__" "" "../conf/nginx.conf"
|
||||
else
|
||||
ynh_replace_string "__PATH_HACK__" "$path_url" "../conf/nginx.conf"
|
||||
fi
|
||||
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# UPGRADE DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading dependencies..." --time --weight=1
|
||||
|
||||
ynh_install_php --phpversion=7.3 --package="$pkg_dependencies"
|
||||
|
||||
#=================================================
|
||||
# CREATE DEDICATED USER
|
||||
#=================================================
|
||||
ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1
|
||||
|
||||
# Create a system user
|
||||
ynh_system_user_create $app
|
||||
# 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 $php_version
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC UPGRADE
|
||||
#=================================================
|
||||
# COMPOSER UPGRADE
|
||||
#=================================================
|
||||
|
||||
if ! type "$final_path/composer.phar" > /dev/null; then
|
||||
init_composer $app $final_path
|
||||
ynh_install_composer $php_version $final_path
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
|
@ -112,81 +154,109 @@ fi
|
|||
#=================================================
|
||||
|
||||
# Downward compatibility: remove the v before version number
|
||||
if [[ $old_flarum_version == "v*" ]]; then $old_flarum_version = ${old_flarum_version:1}; fi
|
||||
if [[ $old_project_version == "v*" ]]; then $old_project_version = ${old_project_version:1}; fi
|
||||
# Check if upgrade of Flarum core is needed
|
||||
if [[ $(dpkg --compare-versions $old_flarum_version lt $flarum_version && echo true) ]]; then
|
||||
# Upgrade Flarum
|
||||
exec_composer $app $final_path "require -n flarum/core:$flarum_version"
|
||||
|
||||
# Database password has to be input on admin page after upgrade to 0.1.0-beta.7.2
|
||||
if [[ $flarum_version == "0.1.0-beta.7.2" ]]; then
|
||||
if [[ $project_version == "0.1.0-beta.7.2" ]]; then
|
||||
curl "https://$domain$path_url/admin" -H "Accept: */*" --compressed -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" --data "databasePassword=$db_pwd" -k
|
||||
fi
|
||||
pushd $final_path
|
||||
exec_as $app php flarum cache:clear
|
||||
popd
|
||||
ynh_print_info "Flarum has been updated to version $flarum_version."
|
||||
upgraded_flarum=true
|
||||
else
|
||||
ynh_print_info "Flarum does not need updating."
|
||||
upgraded_flarum=false
|
||||
#=================================================
|
||||
# UPGRADING TO 0.1.0-beta.8 and above
|
||||
#=================================================
|
||||
if [[ $(dpkg --compare-versions $old_project_version lt "0.1.0-beta.8" && echo true) ]]; then
|
||||
|
||||
# Backing up the app directory
|
||||
tmpbak="/tmp/${app}backup"
|
||||
mkdir -p $tmpbak
|
||||
cp -R $final_path/* $tmpbak
|
||||
|
||||
# Deleting current app directory
|
||||
ynh_secure_remove --file="$final_path"
|
||||
|
||||
# Create working directory
|
||||
mkdir -p "$final_path/.composer"
|
||||
chown -R $app:www-data $final_path
|
||||
chmod -R 0775 $final_path
|
||||
|
||||
#=================================================
|
||||
# COMPOSER INSTALLATION
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Installing Composer..." --time --weight=1
|
||||
ynh_install_composer $php_version $final_path
|
||||
|
||||
#=================================================
|
||||
# FLARUM INSTALLATION
|
||||
#=================================================
|
||||
|
||||
# Prepare Flarum temp directory
|
||||
tmp=/tmp/$app
|
||||
mkdir -p $tmp
|
||||
chown -R $app:www-data $tmp
|
||||
chmod -R 0775 $tmp
|
||||
|
||||
# Install Flarum
|
||||
ynh_script_progression --message="Composer is installing Flarum and its dependencies (may take a while)..." --time --weight=3
|
||||
|
||||
# First, create the project with core and all basic extensions
|
||||
ynh_composer_exec $app $php_version $final_path "create-project flarum/flarum=$project_version $tmp --stability=beta --ansi -d $tmp"
|
||||
# Let's fix the core version by explicitely requiring it
|
||||
ynh_composer_exec $app $php_version $final_path "require flarum/core:$core_version -n --ansi -d $tmp"
|
||||
|
||||
# Copy Flarum to working directory
|
||||
cp -Rf $tmp/* $final_path
|
||||
# Copy config.php and assets from old app versions
|
||||
cp -Rf $tmpbak/config.php $final_path
|
||||
cp -Rf $tmpbak/assets $final_path/public
|
||||
# Clean temp directory
|
||||
ynh_secure_remove $tmp
|
||||
ynh_secure_remove $tmpbak
|
||||
|
||||
# Set right permissions for the post-installation
|
||||
chown -R $app: $final_path
|
||||
chown -R $app:www-data $final_path/storage
|
||||
chmod -R 0775 $final_path
|
||||
fi
|
||||
|
||||
# Check if upgrade of SSOwat extension is needed
|
||||
if [[ $(dpkg --compare-versions $old_ssowat_ext_ver lt $ssowat_ext_ver && echo true) || -z $old_ssowat_ext_ver ]]; then
|
||||
pushd $final_path
|
||||
ynh_composer_exec $app $php_version $final_path "update --prefer-dist --no-dev -o --with-all-dependencies"
|
||||
exec_as $app php$php_version flarum migrate
|
||||
exec_as $app php$php_version flarum cache:clear
|
||||
popd
|
||||
|
||||
# Install and activate the SSOwat auth extension
|
||||
install_and_activate_extension $app $final_path $db_name "tituspijean/flarum-ext-auth-ssowat:$ssowat_ext_ver" "tituspijean-auth-ssowat"
|
||||
install_and_activate_extension $app $php_version $final_path $db_name "tituspijean/flarum-ext-auth-ssowat:$ssowat_version" "tituspijean-auth-ssowat"
|
||||
# Configure SSOwat auth extension
|
||||
ssowatdomain=$(</etc/yunohost/current_host)
|
||||
sql_command="INSERT IGNORE INTO \`settings\` (\`key\`, \`value\`) VALUES ('tituspijean-auth-ssowat.domain', '$ssowatdomain'), ('tituspijean-auth-ssowat.onlyUse', '0');"
|
||||
ynh_mysql_execute_as_root "$sql_command" $db_name
|
||||
ynh_print_info "SSOwat extension has been updated and configured."
|
||||
upgraded_ssowat=true
|
||||
else
|
||||
ynh_print_info "SSOwat extension does not need updating."
|
||||
upgraded_ssowat=false
|
||||
fi
|
||||
|
||||
# Install, activate and set language extensions
|
||||
case $language in
|
||||
fr)
|
||||
ynh_script_progression --message="Installing French extension..." --time --weight=2
|
||||
install_and_activate_extension $app $php_version $final_path $db_name "milescellar/flarum-ext-french" "milescellar-french"
|
||||
sql_command="UPDATE \`settings\` SET \`value\` = 'fr' WHERE \`settings\`.\`key\` = 'default_locale'"
|
||||
ynh_mysql_execute_as_root "$sql_command" $db_name
|
||||
;;
|
||||
de)
|
||||
ynh_script_progression --message="Installing German extension..." --time --weight=2
|
||||
install_and_activate_extension $app $php_version $final_path $db_name "cbmainz/flarum-de" "cbmainz-de"
|
||||
sql_command="UPDATE \`settings\` SET \`value\` = 'de' WHERE \`settings\`.\`key\` = 'default_locale'"
|
||||
ynh_mysql_execute_as_root "$sql_command" $db_name
|
||||
;;
|
||||
esac
|
||||
ynh_print_info "You may need to manually enable your language extension in Flarum's admin panel."
|
||||
|
||||
if [ $bazaar_extension -eq 1 ]; then
|
||||
install_and_activate_extension $app $final_path $db_name "flagrow/bazaar" "flagrow-bazaar"
|
||||
ynh_print_info "Bazaar extension has been installed."
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Bug in Nginx with locations and aliases (see http://stackoverflow.com/a/35102259 )
|
||||
if [ $path_url = "/" ]; then
|
||||
ynh_replace_string "__LOCATION_HACK__" "" "../conf/nginx.conf"
|
||||
ynh_replace_string "__PATH_HACK__" "/" "../conf/nginx.conf"
|
||||
else
|
||||
ynh_replace_string "__LOCATION_HACK__" "$path_url" "../conf/nginx.conf"
|
||||
ynh_replace_string "__PATH_HACK__" "$path_url$path_url" "../conf/nginx.conf"
|
||||
fi
|
||||
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# PHP-FPM CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Create a dedicated php-fpm config
|
||||
ynh_add_fpm_config
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC UPGRADE
|
||||
#=================================================
|
||||
|
||||
# If app is public, add url to SSOWat conf as skipped_uris
|
||||
if [[ $is_public -eq 1 ]]; then
|
||||
# See install script
|
||||
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||
install_and_activate_extension $app $php_version $final_path $db_name "flagrow/bazaar" "flagrow-bazaar"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# SETUP LOGROTATE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1
|
||||
|
||||
# Use logrotate to manage app-specific logfile(s)
|
||||
ynh_use_logrotate --non-append
|
||||
|
@ -197,38 +267,32 @@ ynh_use_logrotate --non-append
|
|||
# SECURE FILES AND DIRECTORIES
|
||||
#=================================================
|
||||
|
||||
# Set right permissions
|
||||
chown -R $app:www-data $final_path
|
||||
sudo chmod -R 0775 $final_path
|
||||
# Set permissions on app files
|
||||
chown -R $app: $final_path
|
||||
chown -R $app:www-data $final_path/storage
|
||||
chmod -R 0775 $final_path
|
||||
|
||||
#=================================================
|
||||
# SETUP SSOWAT
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading SSOwat configuration..." --time --weight=1
|
||||
|
||||
if [ $is_public -eq 0 ]
|
||||
then # Remove the public access
|
||||
ynh_app_setting_delete $app skipped_uris
|
||||
fi
|
||||
# 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 unprotected_uris "/"
|
||||
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
|
||||
|
||||
systemctl reload nginx
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
#===================================================
|
||||
# STORE SETTINGS
|
||||
#===================================================
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
||||
if [ $upgraded_flarum ]; then
|
||||
ynh_app_setting_set $app flarum_version $flarum_version
|
||||
fi
|
||||
if [ $upgraded_ssowat ]; then
|
||||
ynh_app_setting_set $app ssowat_ext_ver $ssowat_ext_ver
|
||||
fi
|
||||
ynh_script_progression --message="Upgrade of $app completed" --time --last
|
||||
|
|
295
scripts/ynh_add_extra_apt_repos__3
Normal file
295
scripts/ynh_add_extra_apt_repos__3
Normal file
|
@ -0,0 +1,295 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Pin a repository.
|
||||
#
|
||||
# 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"
|
||||
}
|
||||
|
||||
# Add a repository.
|
||||
#
|
||||
# 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"
|
||||
}
|
||||
|
||||
# Add an extra repository correctly, pin it and get the key.
|
||||
#
|
||||
# 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:-0}
|
||||
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.
|
||||
#
|
||||
# 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
|
||||
}
|
||||
|
||||
# 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:-0}
|
||||
|
||||
# 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
|
||||
}
|
||||
|
||||
#=================================================
|
||||
|
||||
# patched version of ynh_install_app_dependencies to be used with ynh_add_app_dependencies
|
||||
|
||||
# Define and install dependencies with a equivs control file
|
||||
# This helper can/should only be called once per app
|
||||
#
|
||||
# usage: ynh_install_app_dependencies dep [dep [...]]
|
||||
# | arg: dep - the package name to install in dependence
|
||||
# You can give a choice between some package with this syntax : "dep1|dep2"
|
||||
# Example : ynh_install_app_dependencies dep1 dep2 "dep3|dep4|dep5"
|
||||
# This mean in the dependence tree : dep1 & dep2 & (dep3 | dep4 | dep5)
|
||||
#
|
||||
# Requires YunoHost version 2.6.4 or higher.
|
||||
ynh_install_app_dependencies () {
|
||||
local dependencies=$@
|
||||
dependencies="$(echo "$dependencies" | sed 's/\([^\<=\>]\)\ \([^(]\)/\1, \2/g')"
|
||||
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
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
ynh_install_app_dependencies "${current_dependencies}${package}"
|
||||
}
|
||||
|
49
scripts/ynh_composer__2
Normal file
49
scripts/ynh_composer__2
Normal file
|
@ -0,0 +1,49 @@
|
|||
#!/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=uvwc
|
||||
declare -Ar args_array=( [u]=user [v]=phpversion= [w]=workdir= [c]=commands= )
|
||||
local user
|
||||
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" \
|
||||
exec_as $user 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" \
|
||||
exec_as $app 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."
|
||||
}
|
14
scripts/ynh_exec_as
Normal file
14
scripts/ynh_exec_as
Normal file
|
@ -0,0 +1,14 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Execute a command as another user
|
||||
# usage: exec_as USER COMMAND [ARG ...]
|
||||
exec_as() {
|
||||
local USER=$1
|
||||
shift 1
|
||||
|
||||
if [[ $USER = $(whoami) ]]; then
|
||||
eval "$@"
|
||||
else
|
||||
sudo -u "$USER" "$@"
|
||||
fi
|
||||
}
|
78
scripts/ynh_install_php__3
Normal file
78
scripts/ynh_install_php__3
Normal file
|
@ -0,0 +1,78 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Install another version of php.
|
||||
#
|
||||
# usage: ynh_install_php --phpversion=phpversion [--package=packages]
|
||||
# | arg: -v, --phpversion - Version of php to install. Can be one of 7.1, 7.2 or 7.3
|
||||
# | arg: -p, --package - Additionnal php packages to install
|
||||
ynh_install_php () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=vp
|
||||
declare -Ar args_array=( [v]=phpversion= [p]=package= )
|
||||
local phpversion
|
||||
local package
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
package=${package:-}
|
||||
|
||||
# Store php_version into the config of this app
|
||||
ynh_app_setting_set $app php_version $phpversion
|
||||
|
||||
if [ "$phpversion" == "7.0" ]
|
||||
then
|
||||
ynh_die "Do not use ynh_install_php to install php7.0"
|
||||
fi
|
||||
|
||||
# Store the ID of this app and the version of php requested for it
|
||||
echo "$YNH_APP_INSTANCE_NAME:$phpversion" | tee --append "/etc/php/ynh_app_version"
|
||||
|
||||
# Add an extra repository for those packages
|
||||
ynh_install_extra_repo --repo="https://packages.sury.org/php/ $(lsb_release -sc) main" --key="https://packages.sury.org/php/apt.gpg" --priority=995 --name=extra_php_version
|
||||
|
||||
# Install requested dependencies from this extra repository.
|
||||
# Install php-fpm first, otherwise php will install apache as a dependency.
|
||||
ynh_add_app_dependencies --package="php${phpversion}-fpm"
|
||||
ynh_add_app_dependencies --package="php$phpversion php${phpversion}-common $package"
|
||||
|
||||
# Set php7.0 back as the default version for php-cli.
|
||||
update-alternatives --set php /usr/bin/php7.0
|
||||
|
||||
# Remove this extra repository after packages are installed
|
||||
ynh_remove_extra_repo --name=extra_php_version
|
||||
|
||||
# Advertise service in admin panel
|
||||
yunohost service add php${phpversion}-fpm --log "/var/log/php${phpversion}-fpm.log"
|
||||
}
|
||||
|
||||
ynh_remove_php () {
|
||||
# Get the version of php used by this app
|
||||
local phpversion=$(ynh_app_setting_get $app php_version)
|
||||
|
||||
if [ "$phpversion" == "7.0" ] || [ -z "$phpversion" ]
|
||||
then
|
||||
if [ "$phpversion" == "7.0" ]
|
||||
then
|
||||
ynh_print_err "Do not use ynh_remove_php to install php7.0"
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Remove the line for this app
|
||||
sed --in-place "/$YNH_APP_INSTANCE_NAME:$phpversion/d" "/etc/php/ynh_app_version"
|
||||
|
||||
# If no other app uses this version of php, remove it.
|
||||
if ! grep --quiet "$phpversion" "/etc/php/ynh_app_version"
|
||||
then
|
||||
# Purge php dependences for this version.
|
||||
ynh_package_autopurge "php$phpversion php${phpversion}-fpm php${phpversion}-common"
|
||||
# Remove the service from the admin panel
|
||||
yunohost service remove php${phpversion}-fpm
|
||||
fi
|
||||
|
||||
# If no other app uses alternate php versions, remove the extra repo for php
|
||||
if [ ! -s "/etc/php/ynh_app_version" ]
|
||||
then
|
||||
ynh_secure_remove /etc/php/ynh_app_version
|
||||
fi
|
||||
}
|
||||
|
140
scripts/ynh_send_readme_to_admin__2
Normal file
140
scripts/ynh_send_readme_to_admin__2
Normal file
|
@ -0,0 +1,140 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Send an email to inform the administrator
|
||||
#
|
||||
# usage: ynh_send_readme_to_admin --app_message=app_message [--recipients=recipients] [--type=type]
|
||||
# | arg: -m --app_message= - The file with the content to send to the administrator.
|
||||
# | arg: -r, --recipients= - The recipients of this email. Use spaces to separate multiples recipients. - default: root
|
||||
# example: "root admin@domain"
|
||||
# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you
|
||||
# example: "root admin@domain user1 user2"
|
||||
# | arg: -t, --type= - Type of mail, could be 'backup', 'change_url', 'install', 'remove', 'restore', 'upgrade'
|
||||
ynh_send_readme_to_admin() {
|
||||
# Declare an array to define the options of this helper.
|
||||
declare -Ar args_array=( [m]=app_message= [r]=recipients= [t]=type= )
|
||||
local app_message
|
||||
local recipients
|
||||
local type
|
||||
# Manage arguments with getopts
|
||||
|
||||
ynh_handle_getopts_args "$@"
|
||||
app_message="${app_message:-}"
|
||||
recipients="${recipients:-root}"
|
||||
type="${type:-install}"
|
||||
|
||||
# Get the value of admin_mail_html
|
||||
admin_mail_html=$(ynh_app_setting_get $app admin_mail_html)
|
||||
admin_mail_html="${admin_mail_html:-0}"
|
||||
|
||||
# Retrieve the email of users
|
||||
find_mails () {
|
||||
local list_mails="$1"
|
||||
local mail
|
||||
local recipients=" "
|
||||
# Read each mail in argument
|
||||
for mail in $list_mails
|
||||
do
|
||||
# Keep root or a real email address as it is
|
||||
if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@"
|
||||
then
|
||||
recipients="$recipients $mail"
|
||||
else
|
||||
# But replace an user name without a domain after by its email
|
||||
if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null)
|
||||
then
|
||||
recipients="$recipients $mail"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
echo "$recipients"
|
||||
}
|
||||
recipients=$(find_mails "$recipients")
|
||||
|
||||
# Subject base
|
||||
local mail_subject="☁️🆈🅽🅷☁️: \`$app\`"
|
||||
|
||||
# Adapt the subject according to the type of mail required.
|
||||
if [ "$type" = "backup" ]; then
|
||||
mail_subject="$mail_subject has just been backup."
|
||||
elif [ "$type" = "change_url" ]; then
|
||||
mail_subject="$mail_subject has just been moved to a new URL!"
|
||||
elif [ "$type" = "remove" ]; then
|
||||
mail_subject="$mail_subject has just been removed!"
|
||||
elif [ "$type" = "restore" ]; then
|
||||
mail_subject="$mail_subject has just been restored!"
|
||||
elif [ "$type" = "upgrade" ]; then
|
||||
mail_subject="$mail_subject has just been upgraded!"
|
||||
else # install
|
||||
mail_subject="$mail_subject has just been installed!"
|
||||
fi
|
||||
|
||||
local mail_message="This is an automated message from your beloved YunoHost server.
|
||||
|
||||
Specific information for the application $app.
|
||||
|
||||
$(if [ -n "$app_message" ]
|
||||
then
|
||||
cat "$app_message"
|
||||
else
|
||||
echo "...No specific information..."
|
||||
fi)
|
||||
|
||||
---
|
||||
Automatic diagnosis data from YunoHost
|
||||
|
||||
__PRE_TAG1__$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')__PRE_TAG2__"
|
||||
|
||||
# Store the message into a file for further modifications.
|
||||
echo "$mail_message" > mail_to_send
|
||||
|
||||
# If a html email is required. Apply html tags to the message.
|
||||
if [ "$admin_mail_html" -eq 1 ]
|
||||
then
|
||||
# Insert 'br' tags at each ending of lines.
|
||||
ynh_replace_string "$" "<br>" mail_to_send
|
||||
|
||||
# Insert starting HTML tags
|
||||
sed --in-place '1s@^@<!DOCTYPE html>\n<html>\n<head></head>\n<body>\n@' mail_to_send
|
||||
|
||||
# Keep tabulations
|
||||
ynh_replace_string " " "\ \ " mail_to_send
|
||||
ynh_replace_string "\t" "\ \ " mail_to_send
|
||||
|
||||
# Insert url links tags
|
||||
ynh_replace_string "__URL_TAG1__\(.*\)__URL_TAG2__\(.*\)__URL_TAG3__" "<a href=\"\2\">\1</a>" mail_to_send
|
||||
|
||||
# Insert pre tags
|
||||
ynh_replace_string "__PRE_TAG1__" "<pre>" mail_to_send
|
||||
ynh_replace_string "__PRE_TAG2__" "<\pre>" mail_to_send
|
||||
|
||||
# Insert finishing HTML tags
|
||||
echo -e "\n</body>\n</html>" >> mail_to_send
|
||||
|
||||
# Otherwise, remove tags to keep a plain text.
|
||||
else
|
||||
# Remove URL tags
|
||||
ynh_replace_string "__URL_TAG[1,3]__" "" mail_to_send
|
||||
ynh_replace_string "__URL_TAG2__" ": " mail_to_send
|
||||
|
||||
# Remove PRE tags
|
||||
ynh_replace_string "__PRE_TAG[1-2]__" "" mail_to_send
|
||||
fi
|
||||
|
||||
# Define binary to use for mail command
|
||||
if [ -e /usr/bin/bsd-mailx ]
|
||||
then
|
||||
local mail_bin=/usr/bin/bsd-mailx
|
||||
else
|
||||
local mail_bin=/usr/bin/mail.mailutils
|
||||
fi
|
||||
|
||||
if [ "$admin_mail_html" -eq 1 ]
|
||||
then
|
||||
content_type="text/html"
|
||||
else
|
||||
content_type="text/plain"
|
||||
fi
|
||||
|
||||
# Send the email to the recipients
|
||||
cat mail_to_send | $mail_bin -a "Content-Type: $content_type; charset=UTF-8" -s "$mail_subject" "$recipients"
|
||||
}
|
Loading…
Reference in a new issue