mirror of
https://github.com/YunoHost-Apps/mattermost_ynh.git
synced 2024-09-03 19:36:29 +02:00
commit
35da6983d7
12 changed files with 223 additions and 110 deletions
18
README.md
18
README.md
|
@ -2,9 +2,7 @@
|
|||
|
||||
A Yunohost package for [Mattermost](http://www.mattermost.org/), an open-source, self-hosted alternative to Slack.
|
||||
|
||||
## Build status
|
||||
|
||||
See https://ci-apps.yunohost.org/jenkins/job/mattermost%20(Community)/ for checking current build status.
|
||||
[](https://dash.yunohost.org/appci/app/mattermost)
|
||||
|
||||
## Requirements
|
||||
|
||||
|
@ -16,17 +14,13 @@ Mattermost requires:
|
|||
|
||||
## Installing
|
||||
|
||||
[](https://install-app.yunohost.org/?app=mattermost)
|
||||
|
||||
You can either :
|
||||
|
||||
* Install from the Yunohost Admin web interface, by providing this URL: `https://github.com/YunoHost-Apps/mattermost_ynh`
|
||||
* Install from the command-line: `sudo yunohost app install https://github.com/YunoHost-Apps/mattermost_ynh`
|
||||
|
||||
## Upgrading
|
||||
|
||||
Mattermost upgrades tend to work only from one minor version to the other (3.0 to 3.1, 3.1 to 3.2, etc).
|
||||
|
||||
**Important**: to upgrade from Mattermost 2.2, you will need an extra manual step.
|
||||
Run the upgrade from Yunohost, then follow [this guide](https://docs.mattermost.com/administration/upgrade.html).
|
||||
* Install by clicking the button above;
|
||||
* Install from the Yunohost Admin web interface, from the Community Apps list;
|
||||
* Install from the command-line: `sudo yunohost app install https://github.com/YunoHost-Apps/mattermost_ynh`.
|
||||
|
||||
## What works
|
||||
|
||||
|
|
5
Vagrantfile
vendored
5
Vagrantfile
vendored
|
@ -67,11 +67,6 @@ Vagrant.configure("2") do |config|
|
|||
# Install package_check
|
||||
if ! [ -f "$HOME/package_check/package_check.sh" ]; then
|
||||
git clone https://github.com/YunoHost/package_check
|
||||
# Checkout our custom patches (until they get merged upstream)
|
||||
cd package_check
|
||||
git remote add kemenaran https://github.com/kemenaran/package_check.git
|
||||
git fetch kemenaran
|
||||
git checkout --track kemenaran/fixes
|
||||
|
||||
# Fix LXC containers not being able to reach outside internet.
|
||||
# The default configuration is to detect the default gateway used
|
||||
|
|
|
@ -1,21 +1,25 @@
|
|||
;; Mattermost
|
||||
; Manifest
|
||||
domain="ynhtests.local" (DOMAIN)
|
||||
domain="ynhtests.local" (DOMAIN)
|
||||
path="" (PATH)
|
||||
language="fr"
|
||||
admin_email="john@gmail.com"
|
||||
admin_password="mattermost_password"
|
||||
admin_locale="fr"
|
||||
team_display_name="Mon équipe"
|
||||
is_public=1 (PUBLIC|public=1|private=0)
|
||||
password="alpine" (PASSWORD)
|
||||
analytics=0
|
||||
; Checks
|
||||
pkg_linter=1
|
||||
setup_root=1
|
||||
setup_private=0
|
||||
setup_private=1
|
||||
setup_public=1
|
||||
upgrade=1
|
||||
backup_restore=1
|
||||
multi_instance=0
|
||||
port_already_use=0 (XXXX)
|
||||
multi_instance=1
|
||||
port_already_use=1 (8085)
|
||||
# Checks not supported yet
|
||||
change_url=0
|
||||
# Tests not applicable
|
||||
# Checks not applicable
|
||||
setup_sub_dir=0
|
||||
setup_nourl=0
|
||||
incorrect_path=0
|
||||
|
@ -23,7 +27,7 @@
|
|||
Level 1=auto
|
||||
Level 2=auto
|
||||
Level 3=auto
|
||||
Level 4=0
|
||||
Level 4=na
|
||||
Level 5=auto
|
||||
Level 6=auto
|
||||
Level 7=auto
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
SOURCE_URL=https://releases.mattermost.com/4.4.2/mattermost-4.4.2-linux-amd64.tar.gz
|
||||
SOURCE_SUM=ba1648e5806239ce9071f5730eb712a6d0d9077fd9ecad37e85baeb08c1fa170
|
||||
SOURCE_URL=https://releases.mattermost.com/4.8.1/mattermost-4.8.1-linux-amd64.tar.gz
|
||||
SOURCE_SUM=3dac9f9bb4884cd83b8274c2bd7c32418f2535d3f9911cea845ac047ee2c7a82
|
||||
SOURCE_SUM_PRG=sha256sum
|
||||
SOURCE_FORMAT=tar.gz
|
||||
SOURCE_IN_SUBDIR=true
|
||||
SOURCE_FILENAME=mattermost-4.4.2-linux-amd64.tar.gz
|
||||
SOURCE_FILENAME=mattermost-4.8.1-linux-amd64.tar.gz
|
||||
|
|
|
@ -12,16 +12,11 @@ location ~ /api/v[0-9]+/(users/)?websocket$ {
|
|||
proxy_buffers 256 16k;
|
||||
proxy_buffer_size 16k;
|
||||
proxy_read_timeout 600s;
|
||||
proxy_pass http://127.0.0.1:8065;
|
||||
proxy_pass http://127.0.0.1:__PORT__;
|
||||
}
|
||||
|
||||
location / {
|
||||
client_max_body_size 50M;
|
||||
|
||||
if ($scheme = http) {
|
||||
rewrite ^ https://$server_name$request_uri? permanent;
|
||||
}
|
||||
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
|
@ -38,5 +33,9 @@ location / {
|
|||
#proxy_cache_min_uses 2;
|
||||
#proxy_cache_use_stale timeout;
|
||||
#proxy_cache_lock on;
|
||||
proxy_pass http://127.0.0.1:8065;
|
||||
proxy_pass http://127.0.0.1:__PORT__;
|
||||
# Yunohost addition: redirect HTTP to HTTPS
|
||||
if ($scheme = http) {
|
||||
rewrite ^ https://$server_name$request_uri? permanent;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
# This file is managed by the Yunohost Mattermost package,
|
||||
# and will be overwritten on upgrade.
|
||||
|
||||
[Unit]
|
||||
Description=Mattermost
|
||||
After=network.target
|
||||
|
@ -5,14 +8,9 @@ After=mysql.service
|
|||
Requires=mysql.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
Type=notify
|
||||
ExecStart=__FINALPATH__/bin/platform
|
||||
# HACK: Wait for Mattermost port to be open before declaring the service to be launched successfully.
|
||||
# This avoids to report the service as launched even when it crashes a few milliseconds after start.
|
||||
#
|
||||
# TODO: improve mattermost to send a STARTED notification, and
|
||||
# switch the service to 'Type=notify' instead.
|
||||
ExecStartPost=/usr/bin/timeout 10 /bin/sh -c 'while ! nc -z localhost 8065; do sleep 0.2; done'
|
||||
TimeoutStartSec=3600
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
WorkingDirectory=__FINALPATH__
|
||||
|
|
|
@ -7,12 +7,13 @@
|
|||
"fr": "Une alternative open-source et auto-hébergée à Slack"
|
||||
},
|
||||
"url": "http://www.mattermost.org/",
|
||||
"license": "free",
|
||||
"license": "GPL-3.0-only",
|
||||
"version": "4.6.0-1",
|
||||
"maintainer": {
|
||||
"name": "pmorinerie",
|
||||
"email": "kemenaran@gmail.com"
|
||||
},
|
||||
"multi_instance": false,
|
||||
"multi_instance": true,
|
||||
"services": [
|
||||
"nginx"
|
||||
],
|
||||
|
@ -31,19 +32,55 @@
|
|||
"example": "domain.org"
|
||||
},
|
||||
{
|
||||
"name": "public_site",
|
||||
"name": "is_public",
|
||||
"type": "boolean",
|
||||
"ask": {
|
||||
"en": "Can guest users access this chat?",
|
||||
"fr": "Les utilisateurs non-enregistrés peuvent-ils accéder à ce chat ?"
|
||||
},
|
||||
"choices": ["Yes", "No"],
|
||||
"default": "Yes"
|
||||
"default": true
|
||||
},
|
||||
{
|
||||
"name": "admin_email",
|
||||
"ask": {
|
||||
"en": "Login email for the chat admin",
|
||||
"fr": "Adresse email de login pour l’administrateur du chat"
|
||||
},
|
||||
"example": "john@gmail.com",
|
||||
"optional": false
|
||||
},
|
||||
{
|
||||
"name": "admin_password",
|
||||
"type": "password",
|
||||
"ask": {
|
||||
"en": "Password for the chat admin",
|
||||
"fr": "Mot de passe pour l’administrateur du chat"
|
||||
},
|
||||
"optional": false
|
||||
},
|
||||
{
|
||||
"name": "admin_locale",
|
||||
"ask": {
|
||||
"en": "Choose the language of the chat for the admin",
|
||||
"fr": "Choissisez la langue utilisée pour l'administrateur"
|
||||
},
|
||||
"choices": ["en", "fr"],
|
||||
"default": "en"
|
||||
},
|
||||
{
|
||||
"name": "team_display_name",
|
||||
"ask": {
|
||||
"en": "Choose a Team name",
|
||||
"fr": "Choisissez le nom de l’équipe"
|
||||
},
|
||||
"example": "Super Groupe",
|
||||
"optional": false
|
||||
},
|
||||
{
|
||||
"name": "analytics",
|
||||
"type": "boolean",
|
||||
"ask": {
|
||||
"en": "Do you want to allow Mattermost to send some telemetrics about your usage of this app?",
|
||||
"en": "Allow Mattermost to send some telemetrics about your usage of this app?",
|
||||
"fr": "Autorisez-vous Mattermost à envoyer des informations anonymes sur votre usage de l’application ?"
|
||||
},
|
||||
"default": false
|
||||
|
|
|
@ -20,10 +20,9 @@ ynh_abort_if_errors
|
|||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
final_path="/var/www/$app"
|
||||
data_path="/home/yunohost.app/$app"
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
db_name="$app"
|
||||
default_backup_dir="${1}apps/$app"
|
||||
backup_dir=${backup_dir:-"$default_backup_dir"}
|
||||
|
||||
#=================================================
|
||||
# STANDARD BACKUP STEPS
|
||||
|
@ -31,23 +30,29 @@ backup_dir=${backup_dir:-"$default_backup_dir"}
|
|||
# BACKUP THE APP MAIN DIR
|
||||
#=================================================
|
||||
|
||||
ynh_backup "$final_path" "${backup_dir}$final_path"
|
||||
ynh_backup "$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" "${backup_dir}/db.sql"
|
||||
ynh_backup "db.sql"
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "${backup_dir}/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
#=================================================
|
||||
# BACKUP SYSTEMD
|
||||
#=================================================
|
||||
|
||||
ynh_backup "/etc/systemd/system/$app.service" "${backup_dir}/etc/systemd/system/$app.service"
|
||||
ynh_backup "/etc/systemd/system/$app.service"
|
||||
|
|
|
@ -21,7 +21,11 @@ ynh_abort_if_errors
|
|||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
domain=$YNH_APP_ARG_DOMAIN
|
||||
is_public=$YNH_APP_ARG_PUBLIC_SITE
|
||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||
admin_email=$YNH_APP_ARG_ADMIN_EMAIL
|
||||
admin_password=$YNH_APP_ARG_ADMIN_PASSWORD
|
||||
admin_locale=$YNH_APP_ARG_ADMIN_LOCALE
|
||||
team_display_name=$YNH_APP_ARG_TEAM_DISPLAY_NAME
|
||||
analytics=$YNH_APP_ARG_ANALYTICS
|
||||
path_url="/"
|
||||
|
||||
|
@ -55,15 +59,28 @@ 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
|
||||
ynh_webpath_available "$domain" "$path_url"
|
||||
# Register (book) web path
|
||||
ynh_webpath_register $app $domain $path_url
|
||||
ynh_webpath_register "$app" "$domain" "$path_url"
|
||||
# Store setting
|
||||
ynh_app_setting_set "$app" domain "$domain"
|
||||
|
||||
#=================================================
|
||||
# FIND AN AVAILABLE PORT
|
||||
#=================================================
|
||||
|
||||
# Find an available port
|
||||
port=$(ynh_find_port 8065)
|
||||
# Store setting
|
||||
ynh_app_setting_set "$app" port "$port"
|
||||
|
||||
#=================================================
|
||||
# SET UP INSTALLATION VARIABLES
|
||||
#=================================================
|
||||
|
@ -77,19 +94,20 @@ logs_path="/var/log/$app"
|
|||
# CREATE A MYSQL DATABASE
|
||||
#=================================================
|
||||
|
||||
db_name="mattermost"
|
||||
db_name="$app"
|
||||
db_user="mmuser"
|
||||
db_password=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
|
||||
ynh_mysql_create_db $db_name $db_user $db_password
|
||||
ynh_app_setting_set mattermost mysqlpwd "$db_password"
|
||||
ynh_mysql_create_db "$db_name" "$db_user" "$db_password"
|
||||
ynh_app_setting_set "$app" mysqlpwd "$db_password"
|
||||
|
||||
#=================================================
|
||||
# CREATE USER FOR EMAIL NOTIFICATIONS
|
||||
#=================================================
|
||||
|
||||
smtp_password=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
|
||||
sudo useradd -M --shell /bin/false -p $(openssl passwd -1 "$smtp_password") "mattermost"
|
||||
ynh_app_setting_set mattermost smtppwd "$smtp_password"
|
||||
mattermost_user="$app"
|
||||
mattermost_user_password=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
|
||||
sudo useradd -M --shell /bin/false -p $(openssl passwd -1 "$mattermost_user_password") "$mattermost_user"
|
||||
ynh_app_setting_set "$app" smtppwd "$mattermost_user_password"
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
|
@ -106,24 +124,25 @@ sudo mkdir -p "$logs_path"
|
|||
#=================================================
|
||||
|
||||
# Configure Service Settings
|
||||
sudo sed -i "s|\"SiteURL\": \"\"|\"SiteURL\": \"https://${domain}${path_url}\"|g" $final_path/config/config.json
|
||||
sudo sed -i "s|\"SiteURL\": \"\"|\"SiteURL\": \"https://${domain}${path_url}\"|g" $final_path/config/config.json
|
||||
sudo sed -i "s|\"ListenAddress\": \".*\"|\"ListenAddress\": \"127.0.0.1:${port}\"|g" $final_path/config/config.json
|
||||
# Configure the database connection
|
||||
db_connection_url="${db_user}:${db_password}@tcp(127.0.0.1:3306)/${db_name}?charset=utf8mb4,utf8"
|
||||
sudo sed -i "s|\"DataSource\": \".*\"|\"DataSource\": \"${db_connection_url}\"|g" $final_path/config/config.json
|
||||
sudo sed -i "s|\"DataSource\": \".*\"|\"DataSource\": \"${db_connection_url}\"|g" $final_path/config/config.json
|
||||
# Configure uploaded files directory
|
||||
sudo sed -i "s|\"Directory\": \"./data/\"|\"Directory\": \"${data_path}/\"|g" $final_path/config/config.json
|
||||
sudo sed -i "s|\"Directory\": \"./data/\"|\"Directory\": \"${data_path}/\"|g" $final_path/config/config.json
|
||||
# Configure SMTP account for sending email notifications
|
||||
sudo sed -i "s|\"SendEmailNotifications\": false|\"SendEmailNotifications\": true|g" $final_path/config/config.json
|
||||
sudo sed -i "s|\"FeedbackName\": \"\"|\"FeedbackName\": \"Mattermost notification\"|g" $final_path/config/config.json
|
||||
sudo sed -i "s|\"FeedbackEmail\": \"\"|\"FeedbackEmail\": \"no-reply@${domain}\"|g" $final_path/config/config.json
|
||||
sudo sed -i "s|\"SMTPUsername\": \"\"|\"SMTPUsername\": \"mattermost\"|g" $final_path/config/config.json
|
||||
sudo sed -i "s|\"SMTPPassword\": \"\"|\"SMTPPassword\": \"${smtp_password}\"|g" $final_path/config/config.json
|
||||
sudo sed -i "s|\"SMTPServer\": \"\"|\"SMTPServer\": \"localhost\"|g" $final_path/config/config.json
|
||||
sudo sed -i "s|\"SMTPPort\": \"\"|\"SMTPPort\": \"25\"|g" $final_path/config/config.json
|
||||
sudo sed -i "s|\"SendEmailNotifications\": false|\"SendEmailNotifications\": true|g" $final_path/config/config.json
|
||||
sudo sed -i "s|\"FeedbackName\": \"\"|\"FeedbackName\": \"Mattermost notification\"|g" $final_path/config/config.json
|
||||
sudo sed -i "s|\"FeedbackEmail\": \"\"|\"FeedbackEmail\": \"no-reply@${domain}\"|g" $final_path/config/config.json
|
||||
sudo sed -i "s|\"SMTPUsername\": \"\"|\"SMTPUsername\": \"${mattermost_user}\"|g" $final_path/config/config.json
|
||||
sudo sed -i "s|\"SMTPPassword\": \"\"|\"SMTPPassword\": \"${mattermost_user_password}\"|g" $final_path/config/config.json
|
||||
sudo sed -i "s|\"SMTPServer\": \"\"|\"SMTPServer\": \"localhost\"|g" $final_path/config/config.json
|
||||
sudo sed -i "s|\"SMTPPort\": \"\"|\"SMTPPort\": \"25\"|g" $final_path/config/config.json
|
||||
# Disable Mattermost debug console by default
|
||||
sudo sed -i "s|\"EnableConsole\": true|\"EnableConsole\": false|g" $final_path/config/config.json
|
||||
sudo sed -i "s|\"EnableConsole\": true|\"EnableConsole\": false|g" $final_path/config/config.json
|
||||
# Configure log file location
|
||||
sudo sed -i "s|\"FileLocation\": \"\"|\"FileLocation\": \"$logs_path\"|g" $final_path/config/config.json
|
||||
sudo sed -i "s|\"FileLocation\": \"\"|\"FileLocation\": \"$logs_path\"|g" $final_path/config/config.json
|
||||
# Configure analytics according to user choice
|
||||
if [ $analytics -eq 0 ]; then
|
||||
sudo sed -i "s|\"EnableDiagnostics\": true|\"EnableDiagnostics\": false|g" $final_path/config/config.json
|
||||
|
@ -134,22 +153,20 @@ ynh_app_setting_set "$app" analytics "$analytics"
|
|||
# SECURE FILES AND DIRECTORIES
|
||||
#=================================================
|
||||
|
||||
sudo chown -R mattermost:www-data "$final_path"
|
||||
sudo chown -R mattermost:www-data "$data_path"
|
||||
sudo chown -R mattermost:adm "$logs_path"
|
||||
sudo chown -R "$mattermost_user:www-data" "$final_path"
|
||||
sudo chown -R "$mattermost_user:www-data" "$data_path"
|
||||
sudo chown -R "$mattermost_user:adm" "$logs_path"
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Copy conf/nginx.conf to the correct location
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# SYSTEMD CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Create a dedicated systemd config
|
||||
ynh_add_systemd_config
|
||||
|
||||
#=================================================
|
||||
|
@ -163,11 +180,11 @@ sudo yunohost service add "$app" --log "$logs_path/mattermost.log"
|
|||
#=================================================
|
||||
|
||||
ynh_app_setting_set "$app" is_public "$is_public"
|
||||
if [ "$is_public" = "Yes" ];
|
||||
then
|
||||
|
||||
if [[ $is_public == "1" ]]; then
|
||||
# Make the app accessible to the public
|
||||
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||
fi
|
||||
sudo yunohost app ssowatconf
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
|
@ -179,4 +196,21 @@ sudo systemctl reload nginx
|
|||
# START SERVER
|
||||
#=================================================
|
||||
|
||||
sudo systemctl start mattermost
|
||||
sudo systemctl start "$app"
|
||||
|
||||
#=================================================
|
||||
# CREATE ADMIN AND FIRST TEAM
|
||||
#=================================================
|
||||
|
||||
admin_username=$(cut -d @ -f 1 <<< "$admin_email")
|
||||
team_name=$(echo "$team_display_name" | iconv -f utf8 -t ascii//TRANSLIT//IGNORE | sed -e 's/[^[:alnum:]]/-/g' | tr -s '-' | tr A-Z a-z)
|
||||
|
||||
cd "$final_path/bin"
|
||||
sudo ./platform user create --username "$admin_username" --email "$admin_email" --password "$admin_password" --locale "$admin_locale" --system_admin
|
||||
sudo ./platform user verify "$admin_username"
|
||||
sudo ./platform team create --name "$team_name" --display_name "$team_display_name" --email "$admin_email"
|
||||
sudo ./platform team add "$team_name" "$admin_username"
|
||||
|
||||
ynh_app_setting_set "$app" admin_email "$admin_email"
|
||||
ynh_app_setting_set "$app" admin_locale "$admin_locale"
|
||||
ynh_app_setting_set "$app" team_name "$team_name"
|
||||
|
|
|
@ -14,9 +14,10 @@ source /usr/share/yunohost/helpers
|
|||
#=================================================
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
domain=$(ynh_app_setting_get mattermost domain)
|
||||
db_name="mattermost"
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
db_name="$app"
|
||||
db_user="mmuser"
|
||||
mattermost_user="$app"
|
||||
final_path="/var/www/$app"
|
||||
data_path="/home/yunohost.app/$app"
|
||||
logs_path="/var/log/$app"
|
||||
|
@ -76,4 +77,4 @@ sudo rm -rf "$logs_path"
|
|||
# REMOVE DEDICATED USER
|
||||
#=================================================
|
||||
|
||||
ynh_system_user_delete "$app"
|
||||
ynh_system_user_delete "$mattermost_user"
|
||||
|
|
|
@ -27,6 +27,7 @@ data_path="/home/yunohost.app/$app"
|
|||
logs_path="/var/log/$app"
|
||||
db_name="$app"
|
||||
db_user="mmuser"
|
||||
mattermost_user="$app"
|
||||
|
||||
#=================================================
|
||||
# CHECK IF THE APP CAN BE RESTORED
|
||||
|
@ -51,23 +52,29 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
|||
|
||||
ynh_restore_file "$final_path"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE APP DATA
|
||||
#=================================================
|
||||
|
||||
ynh_restore_file "$data_path"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE MYSQL DATABASE
|
||||
#=================================================
|
||||
|
||||
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
|
||||
ynh_mysql_setup_db $db_user $db_name $db_pwd
|
||||
ynh_mysql_connect_as $db_user $db_pwd $db_name < ./db.sql
|
||||
ynh_mysql_setup_db "$db_user" "$db_name" "$db_pwd"
|
||||
ynh_mysql_connect_as "$db_user" "$db_pwd" "$db_name" < ./db.sql
|
||||
|
||||
#=================================================
|
||||
# RECREATE THE DEDICATED USER
|
||||
#=================================================
|
||||
|
||||
# Create the dedicated user (if not existing)
|
||||
smtp_user="$app"
|
||||
if ! ynh_system_user_exists "$smtp_user"; then
|
||||
smtp_password=$(ynh_app_setting_get $app smtp_password)
|
||||
useradd -M --shell /bin/false -p $(openssl passwd -1 "$smtp_password") "$smtp_user"
|
||||
mattermost_user="$app"
|
||||
if ! ynh_system_user_exists "$mattermost_user"; then
|
||||
mattermost_user_password=$(ynh_app_setting_get $app smtppwd)
|
||||
useradd -M --shell /bin/false -p $(openssl passwd -1 "$mattermost_user_password") "$mattermost_user"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
|
@ -75,21 +82,24 @@ fi
|
|||
#=================================================
|
||||
|
||||
# Restore permissions on app files
|
||||
sudo chown -R mattermost:www-data "$final_path"
|
||||
sudo chown -R "$mattermost_user:www-data" "$final_path"
|
||||
|
||||
mkdir -p "$data_path"
|
||||
sudo chown -R mattermost:www-data "$data_path"
|
||||
sudo chown -R "$mattermost_user:www-data" "$data_path"
|
||||
|
||||
mkdir -p "$logs_path"
|
||||
sudo chown -R mattermost:adm "$logs_path"
|
||||
sudo chown -R "$mattermost_user:adm" "$logs_path"
|
||||
|
||||
#=================================================
|
||||
# RESTORE SSOWAT
|
||||
#=================================================
|
||||
|
||||
if [ "$is_public" = "Yes" ];
|
||||
then
|
||||
if [[ $is_public == "1" ]]; then
|
||||
# Make the app accessible to the public
|
||||
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||
else
|
||||
# Remove the public access
|
||||
ynh_app_setting_delete "$app" skipped_uris
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -20,8 +20,10 @@ ynh_abort_if_errors
|
|||
#=================================================
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
domain=$(ynh_app_setting_get mattermost domain)
|
||||
is_public=$(ynh_app_setting_get mattermost is_public)
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
is_public=$(ynh_app_setting_get $app is_public)
|
||||
port=$(ynh_app_setting_get $app port)
|
||||
mattermost_user="$app"
|
||||
|
||||
root_path="$(pwd)/.."
|
||||
final_path="/var/www/$app"
|
||||
|
@ -33,16 +35,32 @@ logs_path="/var/log/$app"
|
|||
#=================================================
|
||||
|
||||
# Backup the current version of the app
|
||||
ynh_backup_before_upgrade
|
||||
# (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 () {
|
||||
# Stop attempting to restart the app
|
||||
if $(sudo systemctl -q is-active "$app"); then
|
||||
sudo systemctl stop "$app"
|
||||
if [ "$can_restore_backup" = true ]; then
|
||||
# Stop attempting to restart the app
|
||||
if $(sudo systemctl -q is-active "$app"); then
|
||||
sudo 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.
|
||||
sudo systemctl start "$app"
|
||||
fi
|
||||
# Restore the backup
|
||||
ynh_restore_upgradebackup
|
||||
}
|
||||
|
||||
# Exit if an error occurs during the execution of the script
|
||||
|
@ -57,7 +75,7 @@ if $(sudo systemctl -q is-active "$app"); then
|
|||
sudo systemctl stop "$app"
|
||||
fi
|
||||
|
||||
# Legacy, for older versions of this app which used supervisor
|
||||
# Legacy, for previous versions of this app which used supervisor
|
||||
if [ -f "/etc/supervisor/conf.d/${app}.conf" ]; then
|
||||
sudo supervisorctl stop "$app"
|
||||
sudo rm -f "/etc/supervisor/conf.d/${app}.conf"
|
||||
|
@ -72,6 +90,24 @@ backup_config_file="/tmp/config.json"
|
|||
|
||||
sudo cp -f "$config_file" "$backup_config_file"
|
||||
|
||||
#=================================================
|
||||
# MIGRATE SETTINGS FROM PREVIOUS VERSIONS
|
||||
#=================================================
|
||||
|
||||
# Convert is_public from "Yes"/"No" to 1 / 0
|
||||
if [[ $is_public == "Yes" ]]; then
|
||||
is_public=1
|
||||
elif [[ $is_public == "No" ]]; then
|
||||
is_public=0
|
||||
fi
|
||||
ynh_app_setting_set "$app" is_public "$is_public"
|
||||
|
||||
# Save the port used if not present
|
||||
if ! [[ "$port" ]]; then
|
||||
port=8065
|
||||
ynh_app_setting_set "$app" port "$port"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
|
@ -123,9 +159,9 @@ fi
|
|||
# RESTORE FILE PERMISSIONS
|
||||
#=================================================
|
||||
|
||||
sudo chown -R mattermost:www-data "$final_path"
|
||||
sudo chown -R mattermost:www-data "$data_path"
|
||||
sudo chown -R mattermost:adm "$logs_path"
|
||||
sudo chown -R "$mattermost_user:www-data" "$final_path"
|
||||
sudo chown -R "$mattermost_user:www-data" "$data_path"
|
||||
sudo chown -R "$mattermost_user:adm" "$logs_path"
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
|
|
Loading…
Add table
Reference in a new issue