mirror of
https://github.com/YunoHost-Apps/dont-code_ynh.git
synced 2024-09-03 18:26:34 +02:00
104 lines
3.7 KiB
Bash
Executable file
104 lines
3.7 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
|
source ../settings/scripts/_common.sh
|
|
source ../settings/scripts/ynh_mongo_db__2
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# RESTORE THE APP MAIN DIR
|
|
#=================================================
|
|
ynh_script_progression --message="Restoring the app main directory..." --weight=1
|
|
|
|
ynh_restore_file --origin_path="$install_dir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
chown -R $app:$app "$install_dir"
|
|
|
|
mkdir /var/log/$app
|
|
chown "$app:$app" /var/log/$app
|
|
|
|
#=================================================
|
|
# RESTORE THE DOCUMENTS DIRECTORY
|
|
#=================================================
|
|
ynh_script_progression --message="Restoring the document storage..." --weight=1
|
|
|
|
ynh_restore_file --origin_path="$data_dir" --not_mandatory
|
|
|
|
mkdir -p $document_dir
|
|
|
|
chmod -R o-rwx "$data_dir"
|
|
chown -R $app:www-data "$data_dir"
|
|
|
|
#=================================================
|
|
# ADD SSH ACCESS
|
|
#=================================================
|
|
|
|
# Make sure the .ssh and files have the correct access rights
|
|
if [ -n "$public_key" ]; then
|
|
ynh_script_progression --message="Restoring ssh access for dev..." --weight=1
|
|
|
|
chown -R "$app:$app" "$install_dir/.ssh"
|
|
chmod 700 "$install_dir/.ssh"
|
|
chmod 600 "$install_dir/.ssh/authorized_keys"
|
|
|
|
_install_restart_script_and_sudoers
|
|
fi
|
|
|
|
#=================================================
|
|
# INSTALL MONGO
|
|
#=================================================
|
|
ynh_script_progression --message="Reinstalling MongoDB..." --weight=1
|
|
|
|
# Install the required version of Mongo
|
|
ynh_install_mongo --mongo_version=$mongo_version
|
|
|
|
#=================================================
|
|
# RESTORE THE MONGO DATABASES
|
|
#=================================================
|
|
ynh_script_progression --message="Restoring the Mongo databases..." --weight=1
|
|
|
|
for db_name in "${MONGO_DB_LIST[@]}"; do
|
|
ynh_mongo_setup_db --db_user="$db_user" --db_pwd="$db_pwd" --db_name="dontCode$tenant${db_name}"
|
|
ynh_mongo_restore_db --database="dontCode$tenant$db_name" < "./dump-${tenant}${db_name}.bson"
|
|
done
|
|
|
|
#=================================================
|
|
# RESTORE SYSTEM CONFIGURATIONS
|
|
#=================================================
|
|
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
|
|
|
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
|
|
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
|
|
|
for service_name in "${SERVICES_LIST[@]}"; do
|
|
ynh_restore_file --origin_path="/etc/systemd/system/${app}-${service_name}.service"
|
|
systemctl enable "${app}-${service_name}.service" --quiet
|
|
yunohost service add "${app}-${service_name}" --description="Dont-code platform ${service_name} service" --log="/var/log/${app}/${service_name}-${app}.log"
|
|
done
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Reloading NGINX web server and $app's services..." --weight=1
|
|
|
|
for service_name in "${SERVICES_LIST[@]}"; do
|
|
ynh_systemd_action --service_name="${app}-${service_name}" --action="start" --log_path="/var/log/$app/$app.log"
|
|
done
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Restoration completed for $app" --last
|