1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mattermost_ynh.git synced 2024-09-03 19:36:29 +02:00
mattermost_ynh/scripts/restore
Pierre de La Morinerie 6826e253b4 scripts: use a per-instance db username
The scripts still uses "mmuser" by default, for retro-compatibility.
2020-02-18 22:31:15 +01:00

133 lines
3.9 KiB
Bash

#!/bin/bash
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
is_public=$(ynh_app_setting_get $app is_public)
path_url=$(ynh_app_setting_get $app path)
final_path="/var/www/$app"
data_path="/home/yunohost.app/$app"
logs_path="/var/log/$app"
db_name="$app"
db_user=$(ynh_app_setting_get $app mysqluser)
db_user=${db_user:-"mmuser"}
mattermost_user="$app"
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
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
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
# Create the dedicated user (if not existing)
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
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chown -R "$mattermost_user:www-data" "$final_path"
mkdir -p "$data_path"
chown -R "$mattermost_user:www-data" "$data_path"
mkdir -p "$logs_path"
chown -R "$mattermost_user:adm" "$logs_path"
#=================================================
# RESTORE SSOWAT
#=================================================
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
#=================================================
# SPECIFIC RESTORATION
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_restore_file "/etc/systemd/system/$app.service"
systemctl enable "$app"
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add "$app" --log "$logs_path/mattermost.log"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
#=================================================
service nginx reload
#=================================================
# START SERVER
#=================================================
systemctl start "$app"