2017-07-18 13:38:42 +02:00
|
|
|
#!/bin/bash
|
2017-07-18 13:46:22 +02:00
|
|
|
set -eu
|
2017-07-18 13:38:42 +02:00
|
|
|
|
2017-07-21 12:11:26 +02:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2017-07-18 13:38:42 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Exit on command errors and treat access to unset variables as an error
|
2017-07-18 13:46:22 +02:00
|
|
|
ynh_abort_if_errors
|
2017-07-18 13:38:42 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
2017-07-21 14:35:08 +02:00
|
|
|
path=$(ynh_app_setting_get $app path)
|
2017-07-18 13:38:42 +02:00
|
|
|
final_path=$(ynh_app_setting_get $app final_path)
|
2017-07-21 14:35:08 +02:00
|
|
|
serviceuser=$(ynh_app_setting_get $app serviceuser)
|
2017-07-18 13:38:42 +02:00
|
|
|
|
2017-07-21 13:12:41 +02:00
|
|
|
# Check domain/path availability
|
2017-07-21 14:35:08 +02:00
|
|
|
sudo yunohost app checkurl "${domain}${path}" -a "$app" || ynh_die
|
2017-07-21 13:12:41 +02:00
|
|
|
|
|
|
|
# Check destination directory
|
2017-07-21 14:35:08 +02:00
|
|
|
[[ -d $final_path ]] && ynh_die \
|
|
|
|
"The destination directory '$final_path' already exists.\
|
|
|
|
You should safely delete it before restoring this app."
|
|
|
|
|
|
|
|
# Create destination
|
|
|
|
sudo mkdir -p $final_path
|
|
|
|
|
|
|
|
# Create user
|
|
|
|
sudo useradd -d "$final_path" -M $serviceuser
|
2017-07-18 13:38:42 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD RESTORATION STEPS
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
2017-07-21 14:35:08 +02:00
|
|
|
sudo cp -a "conf/nginx" "/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
|
|
sudo systemctl reload nginx
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE SYSTEMD CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
sudo cp -a "conf/service" "/etc/systemd/system/rocketchat.service"
|
|
|
|
sudo systemctl daemon-reload
|
|
|
|
sudo systemctl enable rocketchat
|
2017-07-18 13:38:42 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE APP MAIN DIR
|
|
|
|
#=================================================
|
|
|
|
|
2017-07-21 14:35:08 +02:00
|
|
|
sudo tar -xzf ./rocket.chat.gtar -C $final_path
|
|
|
|
sudo chown -R $serviceuser: $final_path
|
2017-07-18 13:38:42 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE MONGODB
|
|
|
|
#=================================================
|
|
|
|
|
2017-07-21 14:35:08 +02:00
|
|
|
sudo mongorestore ./dump
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START APP RELATED SERVICES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
sudo systemctl start rocketchat
|