1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/dont-code_ynh.git synced 2024-09-03 18:26:34 +02:00
dont-code_ynh/scripts/restore

111 lines
4 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_path
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"
# Enable restart of services for the dont-code user
chown "$app:$app" "$install_dir/restart-services.sh"
chmod o-rwx,gu=rwx "$install_dir/restart-services.sh"
# Add sudoers file for this specific command
ynh_restore_file --origin_path="/etc/sudoers.d/$app-sudoers"
chown root:root "/etc/sudoers.d/$app-sudoers"
chmod o-rwx,gu=r "/etc/sudoers.d/$app-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
ynh_mongo_setup_db --db_user=$db_user --db_name=${MONGO_DB_LIST[0]} --db_pwd=$db_pwd
for db_name in "${MONGO_DB_LIST[@]}"; do
ynh_mongo_restore_db --database="$db_name" < "./dump-${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