1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mattermost_ynh.git synced 2024-09-03 19:36:29 +02:00

repackage

This commit is contained in:
ericgaspar 2021-01-10 16:18:16 +01:00
parent 6aa3905965
commit c6f33cc587
No known key found for this signature in database
GPG key ID: 574F281483054D44
9 changed files with 155 additions and 160 deletions

View file

@ -1,7 +1,7 @@
# Mattermost for YunoHost
[![Integration level](https://dash.yunohost.org/integration/mattermost.svg)](https://dash.yunohost.org/appci/app/mattermost) ![](https://ci-apps.yunohost.org/ci/badges/mattermost.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/mattermost.maintain.svg)
[![Install Mattermost with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=mattermost)
[![Install Mattermost with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=mattermost)
## Overview
A Yunohost package for [Mattermost](http://www.mattermost.org/), an open-source, self-hosted alternative to Slack.

View file

@ -18,12 +18,8 @@
backup_restore=1
multi_instance=1
port_already_use=1 (8085)
# Checks not supported yet
change_url=0
# Checks not applicable
setup_nourl=0
;;; Levels
Level 5=auto
;;; Options
Email=kemenaran@gmail.com
Notification=change

View file

@ -1,14 +1,14 @@
{
"packaging_format": 1,
"name": "Mattermost",
"id": "mattermost",
"packaging_format": 1,
"description": {
"en": "An open-source, self-hosted alternative to Slack",
"fr": "Une alternative open-source et auto-hébergée à Slack"
},
"version": "5.30.1~ynh1",
"url": "http://www.mattermost.org/",
"license": "GPL-3.0-only",
"version": "5.30.1~ynh1",
"maintainer": {
"name": "pmorinerie",
"email": "kemenaran@gmail.com"
@ -18,7 +18,7 @@
"nginx"
],
"requirements": {
"yunohost": ">= 3.0.0"
"yunohost": ">= 3.8.1"
},
"arguments": {
"install" : [

0
scripts/_common.sh Normal file
View file

View file

@ -16,34 +16,32 @@ ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
final_path="/var/www/$app"
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
data_path="/home/yunohost.app/$app"
domain=$(ynh_app_setting_get $app domain)
db_name="$app"
domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#=================================================
# STANDARD BACKUP STEPS
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup "$final_path"
ynh_backup --src_path="$final_path"
#=================================================
# BACKUP THE APP DATA
#=================================================
ynh_backup "$data_path"
#=================================================
# BACKUP THE DATABASE
#=================================================
ynh_mysql_dump_db "$db_name" > db.sql
ynh_backup "db.sql"
ynh_backup --src_path="$data_path"
#=================================================
# BACKUP THE NGINX CONFIGURATION
@ -56,3 +54,16 @@ ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
ynh_backup "/etc/systemd/system/$app.service"
#=================================================
# BACKUP THE POSTGRESQL DATABASE
#=================================================
ynh_print_info --message="Backing up the PostgreSQL database..."
ynh_psql_dump_db --database="$db_name" > db.sql
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -30,77 +30,53 @@ team_display_name=$YNH_APP_ARG_TEAM_DISPLAY_NAME
analytics=$YNH_APP_ARG_ANALYTICS
#=================================================
# CHECK IF THE APP CAN BE INSTALLED
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --time --weight=1
# Allow using the `ynh_die` command without triggering linter warnings
function script_die () {
die_command=$(printf '%s%s' 'ynh_' 'die')
$die_command "$*"
}
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Check for 64 bits support
arch="$(uname -m)"
if [[ "$arch" != "x86_64" ]]; then
script_die "Mattermost requires an x86_64 machine, but this one is '${arch}'."
fi
# Check for MySQL version (without triggering a package_linter warning)
db_command=$(printf '%s%s' 'my' 'sql')
db_version=$($db_command --version)
if [[ "$db_version" == *"Distrib 4."* ]] \
|| [[ "$db_version" == *"Distrib 5.0"* ]] \
|| [[ "$db_version" == *"Distrib 5.1"* ]] \
|| [[ "$db_version" == *"Distrib 5.2"* ]] \
|| [[ "$db_version" == *"Distrib 5.3"* ]] \
|| [[ "$db_version" == *"Distrib 5.4"* ]] \
|| [[ "$db_version" == *"Distrib 5.5"* ]];
then
script_die "Mattermost requires MySQL 5.6 or higher, or MariaDB 10 or higher."
fi
#=================================================
# FIND AN AVAILABLE PATH
#=================================================
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
# Check web path availability
ynh_webpath_available "$domain" "$path_url"
# Register (book) web path
ynh_webpath_register "$app" "$domain" "$path_url"
# Store setting
ynh_app_setting_set "$app" domain "$domain"
ynh_app_setting_set "$app" path "$path_url"
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --time --weight=1
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app=$app --key=admin --value=$admin
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
ynh_app_setting_set --app=$app --key=language --value=$language
#=================================================
# FIND AN AVAILABLE PORT
#=================================================
ynh_script_progression --message="Configuring firewall..." --time --weight=1
# Find an available port
port=$(ynh_find_port 8065)
# Store setting
ynh_app_setting_set "$app" port "$port"
port=$(ynh_find_port --port=8065)
ynh_app_setting_set --app=$app --key=port --value=$port
#=================================================
# SET UP INSTALLATION VARIABLES
#=================================================
root_path="$(pwd)/.."
final_path="/var/www/$app"
data_path="/home/yunohost.app/$app"
logs_path="/var/log/$app"
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
ynh_script_progression --message="Creating a MySQL database..." --time --weight=1
db_name="$app"
db_user="$YNH_APP_INSTANCE_NAME"
db_password=$(ynh_string_random --length=24)
ynh_mysql_create_db "$db_name" "$db_user" "$db_password"
ynh_app_setting_set "$app" mysqluser "$db_user"
ynh_app_setting_set "$app" mysqlpwd "$db_password"
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
#=================================================
# CREATE USER FOR EMAIL NOTIFICATIONS
@ -114,9 +90,11 @@ ynh_app_setting_set "$app" smtppwd "$mattermost_user_password"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --time --weight=1
ynh_app_setting_set "$app" final_path "$final_path"
ynh_setup_source "$final_path"
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"
mkdir -p "$data_path"
mkdir -p "$logs_path"
@ -168,43 +146,50 @@ chown -R "$mattermost_user:adm" "$logs_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --time --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SYSTEMD CONFIGURATION
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --time --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --time --weight=1
yunohost service add "$app" --log "$logs_path/mattermost.log"
yunohost service add $app --description="A short description of the app" --log="/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" #--line_match="HTTP Server listening"
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring SSOwat..." --weight=1
ynh_app_setting_set "$app" is_public "$is_public"
if [[ $is_public == "1" ]]; then
# Make the app accessible to the public
ynh_app_setting_set "$app" unprotected_uris "/"
if [ $is_public -eq 1 ]
then
ynh_permission_update --permission "main" --add "visitors"
fi
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=2
systemctl reload nginx
#=================================================
# START SERVER
#=================================================
systemctl start "$app"
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# CREATE ADMIN AND FIRST TEAM

View file

@ -1,5 +1,4 @@
#!/bin/bash
set -u # treat unset variables as an error
#=================================================
# GENERIC START
@ -7,6 +6,7 @@ set -u # treat unset variables as an error
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================

View file

@ -1,9 +1,12 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================

View file

@ -6,6 +6,7 @@
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
@ -18,8 +19,10 @@ ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=2
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path) # used during nginx configuration
is_public=$(ynh_app_setting_get $app is_public)
@ -32,67 +35,13 @@ data_path="/home/yunohost.app/$app"
logs_path="/var/log/$app"
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
# CHECK VERSION
#=================================================
# Backup the current version of the app
# (NB: `tee` uses process substitution rather than a pipe,
# to avoid spawning a subshell that would not save global
# variables defined by `ynh_backup_before_upgrade`.)
ynh_backup_before_upgrade > >(tee "upgrade.log")
# Ensure the backup can be restored
if grep -q "mattermost: Warning$" "upgrade.log"; then
can_restore_backup=false
else
can_restore_backup=true
fi
# If the upgrade fails…
ynh_clean_setup () {
if [ "$can_restore_backup" = true ]; then
# Stop attempting to restart the app
if $(systemctl -q is-active "$app"); then
systemctl stop "$app"
fi
# Restore the backup
ynh_restore_upgradebackup
else
# Backup restoration is not available:
# let's try at least to restart the server.
systemctl start "$app"
fi
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# STOP SERVER
#=================================================
# Stop the server (if the app is already using systemd)
if $(systemctl -q is-active "$app"); then
systemctl stop "$app"
fi
# Legacy, for previous versions of this app which used supervisor
if [ -f "/etc/supervisor/conf.d/${app}.conf" ]; then
supervisorctl stop "$app"
rm -f "/etc/supervisor/conf.d/${app}.conf"
fi
#=================================================
# BACKUP CONFIGURATION FILE
#=================================================
config_file="$final_path/config/config.json"
backup_config_file="/tmp/config.json"
cp -f "$config_file" "$backup_config_file"
#=================================================
# MIGRATE SETTINGS FROM PREVIOUS VERSIONS
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# Convert is_public from "Yes"/"No" to 1 / 0
@ -109,37 +58,72 @@ if ! [[ "$port" ]]; then
ynh_app_setting_set "$app" port "$port"
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
ynh_clean_setup () {
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# 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"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_app_setting_set "$app" final_path "$final_path"
ynh_setup_source "$final_path"
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --time --weight=1
#=================================================
# RESTORE CONFIGURATION FILE
#=================================================
# Create a temporary directory
tmpdir="$(mktemp -d)"
cp -f "$backup_config_file" "$config_file"
# Backup the config file in the temp dir
cp -a "$final_path/config/config.json" "$tmpdir/config.json"
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
# Copy the admin saved settings from tmp directory to final path
cp -a "$tmpdir/config.json" "$final_path/config/config.json"
# Remove the tmp directory securely
ynh_secure_remove --file="$tmpdir"
fi
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --time --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SYSTEMD CONFIGURATION
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..." --time --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add "$app" --log "$logs_path/mattermost.log"
#=================================================
# SPECIFIC UPGRADE STEPS
#=================================================
@ -164,14 +148,30 @@ chown -R "$mattermost_user:www-data" "$final_path"
chown -R "$mattermost_user:www-data" "$data_path"
chown -R "$mattermost_user:adm" "$logs_path"
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --time --weight=1
yunohost service add $app --description="A short description of the app" --log="/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" #--line_match="HTTP Server listening"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --time --weight=1
service nginx reload
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# START SERVER
# END OF SCRIPT
#=================================================
systemctl start "$app"
ynh_script_progression --message="Upgrade of $app completed" --time --last