diff --git a/scripts/backup b/scripts/backup new file mode 100644 index 0000000..2020d37 --- /dev/null +++ b/scripts/backup @@ -0,0 +1,34 @@ +#!/bin/bash + +# causes the shell to exit if any subcommand or pipeline returns a non-zero status +set -e + +# Source YNH helpers +. /usr/share/yunohost/helpers + +# This is a multi-instance app, meaning it can be installed several times independently +# The id of the app as stated in the manifest is available as $YNH_APP_ID +# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) +# The app instance name is available as $YNH_APP_INSTANCE_NAME +# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample +# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 +# - ynhexample__{N} for the subsequent installations, with N=3,4, ... +# The app instance name is probably what you are interested the most, since this is +# guaranteed to be unique. This is a good unique identifier to define installation path, +# db names, ... +app=$YNH_APP_INSTANCE_NAME + +# Retrieve arguments +domain=$(sudo yunohost app setting $app domain) + +# Backup directory location for the app from where the script is executed and +# which will be compressed afterward +backup_dir=$YNH_APP_BACKUP_DIR + +# Backup sources & data +ynh_backup "/home/yunohost.app/$app" "data" +ynh_backup "/var/www/$app" "sources" + +# Copy configuration files +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx.conf" +ynh_backup "/etc/php5/fpm/pool.d/$app.conf" "conf/php-fpm.conf" diff --git a/scripts/restore b/scripts/restore new file mode 100644 index 0000000..45312c9 --- /dev/null +++ b/scripts/restore @@ -0,0 +1,85 @@ +#!/bin/bash + +# causes the shell to exit if any subcommand or pipeline returns a non-zero status +set -e + +# Source YNH helpers +. /usr/share/yunohost/helpers + +# This is a multi-instance app, meaning it can be installed several times independently +# The id of the app as stated in the manifest is available as $YNH_APP_ID +# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) +# The app instance name is available as $YNH_APP_INSTANCE_NAME +# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample +# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 +# - ynhexample__{N} for the subsequent installations, with N=3,4, ... +# The app instance name is probably what you are interested the most, since this is +# guaranteed to be unique. This is a good unique identifier to define installation path, +# db names, ... +app=$YNH_APP_INSTANCE_NAME + +# Retrieve arguments +domain=$(sudo yunohost app setting $app domain) + +# Get old parameter of the app +domain=$(sudo yunohost app setting $app domain) +path=$(sudo yunohost app setting $app path) +admin_user=$(sudo yunohost app setting $app admin_user) +upload_password=$(sudo yunohost app setting $app upload_password) +is_public=$(sudo yunohost app setting $app is_public) + +# Check domain/path availability +sudo yunohost app checkurl $domain$path -a $app +if [[ ! $? -eq 0 ]]; then + echo "There is already an app on this URL : $domain$path" | sudo tee /dev/stderr + exit 1 +fi + +# Check that admin user is an existing account +sudo yunohost user list --json | grep -q "\"username\": \"$admin_user\"" +if [[ ! $? -eq 0 ]]; then + echo "Error : the chosen admin user does not exist" + exit 1 +fi + +sources_path=/var/www/$app +if [ -d $sources_path ]; then + echo "There is already a directory: $sources_path " | sudo tee /dev/stderr + exit 1 +fi + +data_path=/home/yunohost.app/$app +if [ -d $data_path ]; then + echo "There is already a directory: $data_path " | sudo tee /dev/stderr + exit 1 +fi + +nginx_conf=/etc/nginx/conf.d/$domain.d/$app.conf +if [ -f $nginx_conf ]; then + echo "There is already a nginx conf file at this path: $nginx_conf " | sudo tee /dev/stderr + exit 1 +fi + +phpfpm_conf=/etc/php5/fpm/pool.d/$app.conf +if [ -f $phpfpm_conf ]; then + echo "There is already a PHP-FPM conf file at this path: $phpfpm_conf " | sudo tee /dev/stderr + exit 1 +fi + +# Restore sources & data +sudo cp -a "./sources" $sources_path +sudo cp -a "./data" $data_path + +# Restore conf files +sudo cp -a "./conf/nginx.conf" $nginx_conf +sudo cp -a "./conf/php-fpm.conf" $phpfpm_conf + +# Reload PHP & Nginx +sudo service php5-fpm restart +sudo service nginx reload + +# Set ssowat config +if [ "$is_public" = "Yes" ]; +then + sudo yunohost app setting $app unprotected_uris -v "/" +fi