From 12eaa4986dd304c1591e7d12e1262724e2f3edc0 Mon Sep 17 00:00:00 2001 From: magikcypress Date: Wed, 8 Mar 2017 13:11:33 +0100 Subject: [PATCH] Ajout des script update, restore, backup --- scripts/backup | 27 +++++++++++++++++++++++++++ scripts/restore | 41 +++++++++++++++++++++++++++++++++++++++++ scripts/upgrade | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 scripts/backup create mode 100644 scripts/restore create mode 100644 scripts/upgrade diff --git a/scripts/backup b/scripts/backup new file mode 100644 index 0000000..84dc0dc --- /dev/null +++ b/scripts/backup @@ -0,0 +1,27 @@ +#!/bin/bash + +# Exit on command errors and treat unset variables as an error +set -eu + +# The parameter $1 is the backup directory location dedicated to the app +backup_dir=$1 + +# The parameter $2 is theid of the app instance +app=$YNH_APP_INSTANCE_NAME + +# Source app helpers +source /usr/share/yunohost/helpers + +domain=$(ynh_app_setting_get $app domain) +final_path=$(ynh_app_setting_get $app final_path) + +# Copy the app web files +sudo mkdir -p ${backup_dir}/var/www +sudo cp -a $final_path "${backup_dir}/var/www/$app" +# Copy the music files +sudo mkdir -p ${backup_dir}/var/lib/$app/ +sudo cp -a $final_path "${backup_dir}/var/lib/$app" + +# Copy the conf files +sudo mkdir -p "${backup_dir}/conf" +sudo cp -a /etc/nginx/conf.d/$domain.d/$app.conf "${backup_dir}/conf/nginx.conf" diff --git a/scripts/restore b/scripts/restore new file mode 100644 index 0000000..d2b004f --- /dev/null +++ b/scripts/restore @@ -0,0 +1,41 @@ +#!/bin/bash +# This restore script is adapted to Yunohost >=2.4 + +# Exit on command errors and treat unset variables as an error +set -eu + +# The parameter $1 is the backup directory location dedicated to the app +backup_dir=$1 + +# The parameter $2 is the id of the app instance ex: ynhexample__2 +app=$YNH_APP_INSTANCE_NAME + +# Source app helpers +source /usr/share/yunohost/helpers + +# Get old parameter of the app +domain=$(ynh_app_setting_get $app domain) +path=$(ynh_app_setting_get $app path) +final_path=$(ynh_app_setting_get $app final_path) + +if [ -d $final_path ]; then + ynh_die "There is already a directory: $final_path" +fi + +conf=/etc/nginx/conf.d/$domain.d/$app.conf +if [ -f $conf ]; then + ynh_die "There is already a nginx conf file at this path: $conf" +fi +# Restore conf files +sudo cp -a "${backup_dir}/conf/nginx.conf" $conf + +# Reload Nginx +sudo service nginx reload + +sudo cp -a "${backup_dir}/var/www/$app" $final_path +sudo cp -a "${backup_dir}/var/lib/$app" "/var/lib/$app" + +# Set permissions +sudo chown -R www-data: $final_path + +sudo yunohost app ssowatconf diff --git a/scripts/upgrade b/scripts/upgrade new file mode 100644 index 0000000..e3b75e0 --- /dev/null +++ b/scripts/upgrade @@ -0,0 +1,33 @@ +#!/bin/bash + +# Exit on command errors and treat unset variables as an error +set -eu + +source .fonctions # Loads the generic functions usually used in the script +source /usr/share/yunohost/helpers # Source YunoHost helpers + +# See comments in install script +app=$YNH_APP_INSTANCE_NAME + +# Retrieve app settings +domain=$(ynh_app_setting_get "$app" domain) +path=$(ynh_app_setting_get "$app" path) +admin=$(ynh_app_setting_get "$app" admin) + +CHECK_PATH # Checks and corrects the syntax of the path. + +# Check if admin is not null +if [[ "$admin" = "" ]]; then + echo "Unable to upgrade, please contact support" + ynh_die +fi + +final_path=/var/www/$app + +# Modify Nginx configuration file and copy it to Nginx conf directory +sed -i "s@__PATHTOCHANGE__@$app@g" ../conf/nginx.conf* +sed -i "s@__FINALPATH__@$final_path/@g" ../conf/nginx.conf* +sed -i "s@__DOMAINNAME__@$domain/@g" ../conf/nginx.conf* + +# Reload Nginx +sudo service nginx reload