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
|
|
|
|
#=================================================
|
2019-02-03 11:14:23 +01:00
|
|
|
if [ ! -e _common.sh ]; then
|
|
|
|
# Fetch helpers file if not in current directory
|
2019-02-10 21:21:55 +01:00
|
|
|
cp ../settings/scripts/_common.sh ./_common.sh
|
|
|
|
chmod a+rx _common.sh
|
2019-02-03 11:14:23 +01:00
|
|
|
fi
|
2017-07-21 12:11:26 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
2019-02-03 11:14:23 +01:00
|
|
|
source _common.sh
|
2017-07-21 12:11:26 +02:00
|
|
|
|
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-09-27 19:52:56 +02:00
|
|
|
port=$(ynh_app_setting_get $app port)
|
2017-07-18 13:38:42 +02:00
|
|
|
|
2017-07-21 13:12:41 +02:00
|
|
|
# Check domain/path availability
|
2017-10-31 22:29:52 +01:00
|
|
|
ynh_webpath_available $domain $path
|
|
|
|
if [[ ! $? -eq 0 ]]; then
|
|
|
|
ynh_die "domain not available"
|
|
|
|
fi
|
|
|
|
|
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
|
2019-02-10 21:21:55 +01:00
|
|
|
mkdir -p $final_path
|
2017-07-21 14:35:08 +02:00
|
|
|
|
|
|
|
# Create user
|
2019-02-10 21:21:55 +01:00
|
|
|
id -u $serviceuser || useradd -d "$final_path" -M $serviceuser
|
2017-07-18 13:38:42 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD RESTORATION STEPS
|
|
|
|
#=================================================
|
2018-10-20 00:35:40 +02:00
|
|
|
|
|
|
|
ynh_restore
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD THE NGINX CONFIGURATION
|
2017-07-18 13:38:42 +02:00
|
|
|
#=================================================
|
|
|
|
|
2019-02-10 21:21:55 +01:00
|
|
|
systemctl reload nginx
|
2017-07-21 14:35:08 +02:00
|
|
|
|
|
|
|
#=================================================
|
2018-10-20 00:35:40 +02:00
|
|
|
# RELOAD AND ENABLE THE SYSTEMD CONFIGURATION
|
2017-07-21 14:35:08 +02:00
|
|
|
#=================================================
|
2019-02-10 21:21:55 +01:00
|
|
|
systemctl daemon-reload
|
|
|
|
systemctl enable rocketchat
|
2017-07-18 13:38:42 +02:00
|
|
|
|
|
|
|
#=================================================
|
2018-10-20 00:35:40 +02:00
|
|
|
# RESTORE PERMISSIONS IN THE APP MAIN DIR
|
2017-07-18 13:38:42 +02:00
|
|
|
#=================================================
|
|
|
|
|
2019-02-10 21:21:55 +01:00
|
|
|
chown -R $serviceuser: $final_path
|
2017-07-18 13:38:42 +02:00
|
|
|
|
2017-09-04 22:24:56 +02:00
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
installdeps
|
|
|
|
|
2017-07-18 13:38:42 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE THE MONGODB
|
|
|
|
#=================================================
|
|
|
|
|
2019-02-10 21:21:55 +01:00
|
|
|
mongorestore ./dump
|
2017-07-21 14:35:08 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START APP RELATED SERVICES
|
|
|
|
#=================================================
|
|
|
|
|
2019-02-10 21:21:55 +01:00
|
|
|
systemctl start rocketchat
|
2017-09-19 23:23:23 +02:00
|
|
|
waitforservice
|