From 51e6e1d31755aae22fadd7513f8674158a884780 Mon Sep 17 00:00:00 2001 From: opi Date: Sat, 7 May 2016 02:14:57 +0200 Subject: [PATCH] [enh] Use latest backup specification. --- manifest.json | 3 +++ scripts/backup | 33 ++++++++++++++++++++++++ scripts/restore | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100755 scripts/backup create mode 100755 scripts/restore diff --git a/manifest.json b/manifest.json index 6c4d008..6471874 100644 --- a/manifest.json +++ b/manifest.json @@ -2,6 +2,9 @@ "name": "Zerobin", "id": "zerobin", "packaging_format": 1, + "requirements": { + "yunohost": ">> 2.3.15" + }, "description": { "en": "A minimalist, opensource online pastebin where the server has zero knowledge of pasted data", "fr": "Un pastebin minimaliste, libre et où le serveur n'a aucune connaissance des données copiées" diff --git a/scripts/backup b/scripts/backup new file mode 100755 index 0000000..d8dc4cc --- /dev/null +++ b/scripts/backup @@ -0,0 +1,33 @@ +#!/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 "/var/www/$app" "sources" + +# Copy Nginx conf +sudo mkdir -p ./conf +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "conf/nginx.conf" diff --git a/scripts/restore b/scripts/restore new file mode 100755 index 0000000..281984c --- /dev/null +++ b/scripts/restore @@ -0,0 +1,67 @@ +#!/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) +user=$(sudo yunohost app setting $app allowed_users) +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 + +final_path=/var/www/$app + +if [ -d $final_path ]; then + echo "There is already a directory: $final_path " | sudo tee /dev/stderr + exit 1 +fi + +conf=/etc/nginx/conf.d/$domain.d/$app.conf +if [ -f $conf ]; then + echo "There is already a nginx conf file at this path: $conf " | sudo tee /dev/stderr + exit 1 +fi + +# Restore sources & data +sudo cp -a "./sources" $final_path + +# Set permissions +sudo chown -R www-data:root $final_path/{conf,data,data/attic,data/cache,data/index,data/locks,data/media*,data/meta,data/pages,data/tmp,lib/plugins} +sudo chmod -R 700 $final_path/{conf,data,data/attic,data/cache,data/index,data/locks,data/media*,data/meta,data/pages,data/tmp,lib/plugins} + +# Restore conf files +sudo cp -a "./conf/nginx.conf" $conf + +# Reload Nginx +sudo service nginx reload + +# Set ssowat config +if [ "$is_public" = "Yes" ]; +then + sudo yunohost app setting $app unprotected_uris -v "/" +fi