mirror of
https://github.com/YunoHost-Apps/agendav_ynh.git
synced 2024-09-03 20:36:12 +02:00
126 lines
3.6 KiB
Bash
126 lines
3.6 KiB
Bash
#!/bin/bash
|
|
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
if [ ! -e _common.sh ]; then
|
|
# Get the _common.sh file if it's not in the current directory
|
|
cp ../settings/scripts/_common.sh ./_common.sh
|
|
chmod a+rx _common.sh
|
|
fi
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# MANAGE SCRIPT FAILURE
|
|
#=================================================
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
|
|
# Set app specific variables
|
|
app="$YNH_APP_INSTANCE_NAME"
|
|
dbname=$app
|
|
dbuser=$app
|
|
|
|
# Retrieve old app settings
|
|
domain=$(ynh_app_setting_get "$app" domain)
|
|
path_url=$(ynh_app_setting_get "$app" path)
|
|
final_path=$(ynh_app_setting_get "$app" final_path)
|
|
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
|
|
|
LOGDIR=/var/log/$app
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
#=================================================
|
|
|
|
ynh_webpath_available "$domain" "$path_url" \
|
|
|| ynh_die "Path not available: ${domain}${path_url}"
|
|
test ! -d "$final_path" \
|
|
|| ynh_die "There is already a directory: $final_path "
|
|
|
|
#=================================================
|
|
# STANDARD RESTORATION STEPS
|
|
#=================================================
|
|
# RESTORE THE NGINX CONFIGURATION
|
|
#=================================================
|
|
|
|
# Restore configuration files
|
|
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
|
|
#=================================================
|
|
|
|
# Create and restore the database
|
|
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
|
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./db.sql
|
|
|
|
#=================================================
|
|
# RECREATE THE DEDICATED USER
|
|
#=================================================
|
|
|
|
ynh_system_user_create "$app" "$final_path"
|
|
|
|
#=================================================
|
|
# RESTORE USER RIGHTS
|
|
#=================================================
|
|
|
|
chown -R root: "$final_path"
|
|
|
|
# Only agendav user should write here
|
|
chown -R "$app" "${final_path}/web/var/cache/"{profiler,twig}
|
|
|
|
# The agendav user should read here, but does not need to write
|
|
chown -R root:"$app" "${final_path}/web/config/"
|
|
chmod -R g+rx "${final_path}/web/config/"
|
|
|
|
# Other users should not be able to read as it stores passwords.
|
|
chmod -R o-rwx "${final_path}/web/config/"
|
|
|
|
#=================================================
|
|
# RESTORE THE PHP-FPM CONFIGURATION
|
|
#=================================================
|
|
|
|
ynh_restore_file "/etc/php5/fpm/pool.d/${app}.conf"
|
|
|
|
#=================================================
|
|
# SPECIFIC RESTORATION
|
|
#=================================================
|
|
# REINSTALL DEPENDENCIES
|
|
#=================================================
|
|
|
|
# Install dependencies
|
|
ynh_install_app_dependencies php5-cli
|
|
|
|
#=================================================
|
|
# SETUP LOG directory
|
|
#=================================================
|
|
|
|
mkdir -p "$LOGDIR"
|
|
chown -R "$app": "$LOGDIR"
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# RELOAD NGINX AND PHP-FPM
|
|
#=================================================
|
|
|
|
service php5-fpm reload
|
|
service nginx reload
|