2017-09-11 12:05:16 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2017-10-10 13:00:33 +02:00
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2017-09-11 12:05:16 +02:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
2017-10-10 12:47:33 +02:00
|
|
|
is_public=$(ynh_app_setting_get $app is_public)
|
2020-02-08 23:33:19 +01:00
|
|
|
path_url=$(ynh_app_setting_get $app path)
|
2017-09-11 12:05:16 +02:00
|
|
|
final_path="/var/www/$app"
|
|
|
|
data_path="/home/yunohost.app/$app"
|
2017-10-17 06:49:29 +02:00
|
|
|
logs_path="/var/log/$app"
|
2017-09-11 12:05:16 +02:00
|
|
|
db_name="$app"
|
|
|
|
db_user="mmuser"
|
2018-01-30 07:49:02 +01:00
|
|
|
mattermost_user="$app"
|
2017-09-11 12:05:16 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
|
|
#=================================================
|
|
|
|
|
2017-10-12 08:09:21 +02:00
|
|
|
ynh_webpath_available $domain $path_url \
|
2017-09-11 12:05:16 +02:00
|
|
|
|| 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"
|
|
|
|
|
|
|
|
#=================================================
|
2018-01-29 06:45:24 +01:00
|
|
|
# RESTORE THE APP DATA
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_restore_file "$data_path"
|
|
|
|
|
|
|
|
#=================================================
|
2017-09-11 12:05:16 +02:00
|
|
|
# RESTORE THE MYSQL DATABASE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
|
2018-01-30 07:42:16 +01:00
|
|
|
ynh_mysql_setup_db "$db_user" "$db_name" "$db_pwd"
|
|
|
|
ynh_mysql_connect_as "$db_user" "$db_pwd" "$db_name" < ./db.sql
|
2017-09-11 12:05:16 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RECREATE THE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Create the dedicated user (if not existing)
|
2018-01-30 07:49:02 +01:00
|
|
|
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"
|
2017-09-11 12:05:16 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE USER RIGHTS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Restore permissions on app files
|
2020-02-09 00:27:51 +01:00
|
|
|
chown -R "$mattermost_user:www-data" "$final_path"
|
2017-10-12 12:47:51 +02:00
|
|
|
|
2017-10-17 06:49:29 +02:00
|
|
|
mkdir -p "$data_path"
|
2020-02-09 00:27:51 +01:00
|
|
|
chown -R "$mattermost_user:www-data" "$data_path"
|
2017-10-17 06:49:29 +02:00
|
|
|
|
|
|
|
mkdir -p "$logs_path"
|
2020-02-09 00:27:51 +01:00
|
|
|
chown -R "$mattermost_user:adm" "$logs_path"
|
2017-09-11 12:05:16 +02:00
|
|
|
|
2017-10-10 12:47:33 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE SSOWAT
|
|
|
|
#=================================================
|
|
|
|
|
2018-01-29 08:19:04 +01:00
|
|
|
if [[ $is_public == "1" ]]; then
|
|
|
|
# Make the app accessible to the public
|
2017-10-10 12:47:33 +02:00
|
|
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
2018-01-29 08:19:04 +01:00
|
|
|
else
|
|
|
|
# Remove the public access
|
|
|
|
ynh_app_setting_delete "$app" skipped_uris
|
2017-10-10 12:47:33 +02:00
|
|
|
fi
|
|
|
|
|
2017-09-11 12:05:16 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC RESTORATION
|
|
|
|
#=================================================
|
2017-10-12 12:47:51 +02:00
|
|
|
# RESTORE SYSTEMD
|
2017-09-11 12:05:16 +02:00
|
|
|
#=================================================
|
|
|
|
|
2017-10-12 12:47:51 +02:00
|
|
|
ynh_restore_file "/etc/systemd/system/$app.service"
|
2020-02-09 00:27:51 +01:00
|
|
|
systemctl enable "$app"
|
2017-09-11 12:05:16 +02:00
|
|
|
|
2017-10-12 14:51:54 +02:00
|
|
|
#=================================================
|
|
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
|
|
|
|
2020-02-09 00:27:51 +01:00
|
|
|
yunohost service add "$app" --log "$logs_path/mattermost.log"
|
2017-10-12 14:51:54 +02:00
|
|
|
|
2017-09-11 12:05:16 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
2017-10-12 08:08:53 +02:00
|
|
|
# RELOAD NGINX
|
2017-09-11 12:05:16 +02:00
|
|
|
#=================================================
|
|
|
|
|
2020-02-09 00:27:51 +01:00
|
|
|
service nginx reload
|
2017-10-12 08:08:53 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SERVER
|
|
|
|
#=================================================
|
|
|
|
|
2020-02-09 00:27:51 +01:00
|
|
|
systemctl start "$app"
|