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

121 lines
3.5 KiB
Text
Raw Normal View History

2017-09-11 12:05:16 +02:00
#!/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
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)
path_url="/"
2017-09-11 12:05:16 +02:00
final_path="/var/www/$app"
data_path="/home/yunohost.app/$app"
db_name="$app"
db_user="mmuser"
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
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"
#=================================================
# 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)
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"
fi
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chown -R mattermost:www-data $final_path
2017-09-11 12:05:16 +02:00
mkdir -p $data_path
chown -R mattermost:www-data $data_path
sudo touch "/var/log/mattermost.log"
sudo chown mattermost:adm "/var/log/mattermost.log"
2017-09-11 12:05:16 +02:00
2017-10-10 12:47:33 +02:00
#=================================================
# RESTORE SSOWAT
#=================================================
if [ "$is_public" = "Yes" ];
then
ynh_app_setting_set "$app" unprotected_uris "/"
fi
2017-09-11 12:05:16 +02:00
#=================================================
# SPECIFIC RESTORATION
#=================================================
# RESTORE SYSTEMD
2017-09-11 12:05:16 +02:00
#=================================================
ynh_restore_file "/etc/systemd/system/$app.service"
sudo systemctl enable "$app"
2017-09-11 12:05:16 +02:00
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
sudo yunohost service add "$app" --log "/var/log/${app}.log"
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
#=================================================
sudo service nginx reload
2017-10-12 08:08:53 +02:00
#=================================================
# START SERVER
#=================================================
sudo systemctl start "$app"