1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/archivist_ynh.git synced 2024-09-03 18:15:55 +02:00

Manifest v2

This commit is contained in:
Salamandar 2024-03-29 12:47:49 +01:00
parent ab8914fbc6
commit e7741dddfb
14 changed files with 239 additions and 890 deletions

View file

@ -1,5 +0,0 @@
SOURCE_URL=https://github.com/maniackcrudelis/archivist/archive/refs/tags/v1.3.4.tar.gz
SOURCE_SUM=97df967d79ee2acd0bfae929a9feccea4df0f5943f14101a20a066470142fe89
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true

1
conf/archivist.cron Normal file
View file

@ -0,0 +1 @@
__CRON_FREQUENCY__ root nice -n10 __INSTALL_DIR__/archivist.sh | tee -a /var/log/__APP__/__APP__.log 2>&1

View file

@ -1 +0,0 @@
__FREQUENCY__ root nice -n10 __FINALPATH__/archivist.sh | tee -a /var/log/__APP__/__APP__.log 2>&1

View file

@ -7,4 +7,3 @@ Please read the [documentation](https://github.com/maniackcrudelis/archivist/blo
* Encfs, which be used to encrypt the data, is not fully secured.
Have a look to the [security audit](https://defuse.ca/audits/encfs.htm) to have more informations.

14
doc/POST_INSTALL.md Normal file
View file

@ -0,0 +1,14 @@
If encryption is enabled, your password for encryption is '__ENCRYPTION_PWD__'
Archivist is going to run __FREQUENCY_HUMAN__.
If you want to change the frequency, have a look to the file `/etc/cron.d/__APP__`.
To add recipients or to modify the files or apps to backup,please have a look to the config file `__INSTALL_DIR__/Backup_list.conf`.
Please read the [documentation](https://github.com/maniackcrudelis/archivist/blob/master/Configuration.md) about the configuration of archivist for more information.
You can configure this app easily by using the experimental [config-panel feature](https://__DOMAIN__/yunohost/admin/#/apps/__APP__/config-panel).
You can also find some specific actions for this app by using the experimental [action feature](https://__DOMAIN__/yunohost/admin/#/apps/__APP__/actions).
If you're facing an issue or want to improve this app, please open a new issue in this [project](https://github.com/YunoHost-Apps/archivist_ynh).

View file

@ -1,83 +0,0 @@
{
"name": "Archivist",
"id": "archivist",
"packaging_format": 1,
"description": {
"en": "Automatic backups",
"fr": "Sauvegardes automatiques"
},
"version": "1.3.4~ynh1",
"url": "https://github.com/maniackcrudelis/archivist",
"upstream": {
"license": "GPL-3.0",
"code": "https://github.com/maniackcrudelis/archivist"
},
"license": "GPL-3.0",
"maintainer": {
"name": "",
"email": ""
},
"previous_maintainers": [{
"name": "Maniack Crudelis",
"email": "maniackc_dev@crudelis.fr"
}],
"requirements": {
"yunohost": ">= 11.2.9"
},
"multi_instance": true,
"services": [],
"arguments": {
"install": [
{
"name": "encrypt",
"type": "boolean",
"ask": {
"en": "Do you want to encrypt your backups?",
"fr": "Voulez-vous chiffrer vos sauvegardes ?"
},
"default": true
},
{
"name": "encryption_pwd",
"type": "password",
"ask": {
"en": "Set the password for encryption.",
"fr": "Définissez le mot de passe de chiffrement."
},
"help": {
"en": "It's needed if you use backup encryption.",
"fr": "C'est nécessaire si vous utilisez le chiffrement."
},
"optional": true
},
{
"name": "core_backup",
"type": "boolean",
"ask": {
"en": "Would you like to backup your YunoHost core?",
"fr": "Souhaitez-vous effectuer des sauvegardes du système YunoHost ?"
},
"default": true
},
{
"name": "apps_backup",
"type": "boolean",
"ask": {
"en": "Would you like to backup your apps?",
"fr": "Souhaitez-vous effectuer des sauvegardes de vos applications ?"
},
"default": true
},
{
"name": "frequency",
"type": "select",
"ask": {
"en": "Choose the frequency of your backups?",
"fr": "Choississez la fréquence de votre backup ?"
},
"choices" : ["Daily", "Each 3 days", "Weekly", "Biweekly", "Monthly"],
"default" : "Weekly"
}
]
}
}

92
manifest.toml Normal file
View file

@ -0,0 +1,92 @@
#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json
packaging_format = 2
id = "archivist"
name = "Archivist"
description.en = "Automatic backups"
description.fr = "Sauvegardes automatiques"
version = "1.3.4~ynh2"
maintainers = []
[upstream]
license = "GPL-3.0"
code = "https://github.com/maniackcrudelis/archivist"
website = "https://github.com/maniackcrudelis/archivist"
[integration]
yunohost = ">= 11.2.9"
architectures = "all"
multi_instance = true
ldap = "not_relevant"
sso = "not_relevant"
disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ...
ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ...
ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ...
[install]
[install.encrypt]
ask.en = "Do you want to encrypt your backups?"
ask.fr = "Voulez-vous chiffrer vos sauvegardes ?"
type = "boolean"
default = true
[install.encryption_pwd]
ask.en = "Set the password for encryption."
ask.fr = "Définissez le mot de passe de chiffrement."
help.en = "It's needed if you use backup encryption."
help.fr = "C'est nécessaire si vous utilisez le chiffrement."
type = "password"
optional = true
[install.core_backup]
ask.en = "Would you like to backup your YunoHost core?"
ask.fr = "Souhaitez-vous effectuer des sauvegardes du système YunoHost ?"
type = "boolean"
default = true
[install.apps_backup]
ask.en = "Would you like to backup your apps?"
ask.fr = "Souhaitez-vous effectuer des sauvegardes de vos applications ?"
type = "boolean"
default = true
[install.frequency]
ask.en = "Choose the frequency of your backups?"
ask.fr = "Choississez la fréquence de votre backup ?"
type = "select"
choices.daily = "Daily"
choices.days_3 = "Each 3 days"
choices.weekly = "Weekly"
choices.weeks_2 = "Biweekly"
choices.monthly = "Monthly"
default = "Weekly"
[resources]
[resources.sources.main]
url = "https://github.com/maniackcrudelis/archivist/archive/refs/tags/v1.3.4.tar.gz"
sha256 = "97df967d79ee2acd0bfae929a9feccea4df0f5943f14101a20a066470142fe89"
autoupdate.strategy = "latest_github_tag"
[resources.system_user]
[resources.install_dir]
[resources.data_dir]
subdirs = ["backup", "encrypted_backup"]
[resources.permissions]
[resources.apt]
packages = [
"rsync",
"encfs",
"sshpass",
"ccrypt",
"lzop",
"zstd",
"lzip",
]

View file

@ -4,371 +4,44 @@
# COMMON VARIABLES
#=================================================
# dependencies used by the app
pkg_dependencies="rsync encfs sshpass ccrypt lzop zstd lzip"
#=================================================
# PERSONAL HELPERS
#=================================================
_set_frequencies() {
case "$frequency" in
daily)
frequency_cron="0 2 * * *"
frequency_human="every day"
;;
days_3)
frequency_cron="0 2 */3 * *"
frequency_human="each 3 days"
;;
weekly)
frequency_cron="0 2 * * 0"
frequency_human="once a week on sunday"
;;
weeks_2)
frequency_cron="0 2 * * 0/2"
frequency_human="one sunday out of two"
;;
monthly)
frequency_cron="0 2 1 * *"
frequency_human="once a month on the first sunday"
;;
*)
ynh_die --message="Unsupported frequency $frequency" ;;
esac
# For POST_INSTALL.md
ynh_app_setting_set --app="$app" --key=frequency_human --value="$frequency_human"
}
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
# Send an email to inform the administrator
#
# usage: ynh_send_readme_to_admin --app_message=app_message [--recipients=recipients] [--type=type]
# | arg: -m --app_message= - The file with the content to send to the administrator.
# | arg: -r, --recipients= - The recipients of this email. Use spaces to separate multiples recipients. - default: root
# example: "root admin@domain"
# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you
# example: "root admin@domain user1 user2"
# | arg: -t, --type= - Type of mail, could be 'backup', 'change_url', 'install', 'remove', 'restore', 'upgrade'
ynh_send_readme_to_admin() {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [m]=app_message= [r]=recipients= [t]=type= )
local app_message
local recipients
local type
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
app_message="${app_message:-}"
recipients="${recipients:-root}"
type="${type:-install}"
# Get the value of admin_mail_html
admin_mail_html=$(ynh_app_setting_get $app admin_mail_html)
admin_mail_html="${admin_mail_html:-0}"
# Retrieve the email of users
find_mails () {
local list_mails="$1"
local mail
local recipients=" "
# Read each mail in argument
for mail in $list_mails
do
# Keep root or a real email address as it is
if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@"
then
recipients="$recipients $mail"
else
# But replace an user name without a domain after by its email
if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null)
then
recipients="$recipients $mail"
fi
fi
done
echo "$recipients"
}
recipients=$(find_mails "$recipients")
# Subject base
local mail_subject="☁️🆈🅽🅷☁️: \`$app\`"
# Adapt the subject according to the type of mail required.
if [ "$type" = "backup" ]; then
mail_subject="$mail_subject has just been backup."
elif [ "$type" = "change_url" ]; then
mail_subject="$mail_subject has just been moved to a new URL!"
elif [ "$type" = "remove" ]; then
mail_subject="$mail_subject has just been removed!"
elif [ "$type" = "restore" ]; then
mail_subject="$mail_subject has just been restored!"
elif [ "$type" = "upgrade" ]; then
mail_subject="$mail_subject has just been upgraded!"
else # install
mail_subject="$mail_subject has just been installed!"
fi
local mail_message="This is an automated message from your beloved YunoHost server.
Specific information for the application $app.
$(if [ -n "$app_message" ]
then
cat "$app_message"
else
echo "...No specific information..."
fi)
---
Automatic diagnosis data from YunoHost
__PRE_TAG1__$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')__PRE_TAG2__"
# Store the message into a file for further modifications.
echo "$mail_message" > mail_to_send
# If a html email is required. Apply html tags to the message.
if [ "$admin_mail_html" -eq 1 ]
then
# Insert 'br' tags at each ending of lines.
ynh_replace_string "$" "<br>" mail_to_send
# Insert starting HTML tags
sed --in-place '1s@^@<!DOCTYPE html>\n<html>\n<head></head>\n<body>\n@' mail_to_send
# Keep tabulations
ynh_replace_string " " "\&#160;\&#160;" mail_to_send
ynh_replace_string "\t" "\&#160;\&#160;" mail_to_send
# Insert url links tags
ynh_replace_string "__URL_TAG1__\(.*\)__URL_TAG2__\(.*\)__URL_TAG3__" "<a href=\"\2\">\1</a>" mail_to_send
# Insert pre tags
ynh_replace_string "__PRE_TAG1__" "<pre>" mail_to_send
ynh_replace_string "__PRE_TAG2__" "<\pre>" mail_to_send
# Insert finishing HTML tags
echo -e "\n</body>\n</html>" >> mail_to_send
# Otherwise, remove tags to keep a plain text.
else
# Remove URL tags
ynh_replace_string "__URL_TAG[1,3]__" "" mail_to_send
ynh_replace_string "__URL_TAG2__" ": " mail_to_send
# Remove PRE tags
ynh_replace_string "__PRE_TAG[1-2]__" "" mail_to_send
fi
# Define binary to use for mail command
if [ -e /usr/bin/bsd-mailx ]
then
local mail_bin=/usr/bin/bsd-mailx
else
local mail_bin=/usr/bin/mail.mailutils
fi
if [ "$admin_mail_html" -eq 1 ]
then
content_type="text/html"
else
content_type="text/plain"
fi
# Send the email to the recipients
cat mail_to_send | $mail_bin -a "Content-Type: $content_type; charset=UTF-8" -s "$mail_subject" "$recipients"
}
#=================================================
ynh_maintenance_mode_ON () {
# Load value of $path_url and $domain from the config if their not set
if [ -z $path_url ]; then
path_url=$(ynh_app_setting_get $app path)
fi
if [ -z $domain ]; then
domain=$(ynh_app_setting_get $app domain)
fi
mkdir -p /var/www/html/
# Create an html to serve as maintenance notice
echo "<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="3">
<title>Your app $app is currently under maintenance!</title>
<style>
body {
width: 70em;
margin: 0 auto;
}
</style>
</head>
<body>
<h1>Your app $app is currently under maintenance!</h1>
<p>This app has been put under maintenance by your administrator at $(date)</p>
<p>Please wait until the maintenance operation is done. This page will be reloaded as soon as your app will be back.</p>
</body>
</html>" > "/var/www/html/maintenance.$app.html"
# Create a new nginx config file to redirect all access to the app to the maintenance notice instead.
echo "# All request to the app will be redirected to ${path_url}_maintenance and fall on the maintenance notice
rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/? redirect;
# Use another location, to not be in conflict with the original config file
location ${path_url}_maintenance/ {
alias /var/www/html/ ;
try_files maintenance.$app.html =503;
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
}" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf"
# The current config file will redirect all requests to the root of the app.
# To keep the full path, we can use the following rewrite rule:
# rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/\$1? redirect;
# The difference will be in the $1 at the end, which keep the following queries.
# But, if it works perfectly for a html request, there's an issue with any php files.
# This files are treated as simple files, and will be downloaded by the browser.
# Would be really be nice to be able to fix that issue. So that, when the page is reloaded after the maintenance, the user will be redirected to the real page he was.
systemctl reload nginx
}
ynh_maintenance_mode_OFF () {
# Load value of $path_url and $domain from the config if their not set
if [ -z $path_url ]; then
path_url=$(ynh_app_setting_get $app path)
fi
if [ -z $domain ]; then
domain=$(ynh_app_setting_get $app domain)
fi
# Rewrite the nginx config file to redirect from ${path_url}_maintenance to the real url of the app.
echo "rewrite ^${path_url}_maintenance/(.*)$ ${path_url}/\$1 redirect;" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf"
systemctl reload nginx
# Sleep 4 seconds to let the browser reload the pages and redirect the user to the app.
sleep 4
# Then remove the temporary files used for the maintenance.
rm "/var/www/html/maintenance.$app.html"
rm "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf"
systemctl reload nginx
}
# FUTURE OFFICIAL HELPERS
#=================================================
# Create a changelog for an app after an upgrade from the file CHANGELOG.md.
#
# usage: ynh_app_changelog [--format=markdown/html/plain] [--output=changelog_file] --changelog=changelog_source]
# | arg: -f --format= - Format in which the changelog will be printed
# markdown: Default format.
# html: Turn urls into html format.
# plain: Plain text changelog
# | arg: -o --output= - Output file for the changelog file (Default ./changelog)
# | arg: -c --changelog= - CHANGELOG.md source (Default ../CHANGELOG.md)
#
# The changelog is printed into the file ./changelog and ./changelog_lite
ynh_app_changelog () {
# Declare an array to define the options of this helper.
local legacy_args=foc
declare -Ar args_array=( [f]=format= [o]=output= [c]=changelog= )
local format
local output
local changelog
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
format=${format:-markdown}
output=${output:-changelog}
changelog=${changelog:-../CHANGELOG.md}
local original_changelog="$changelog"
local temp_changelog="changelog_temp"
local final_changelog="$output"
if [ ! -n "$original_changelog" ]
then
echo "No changelog available..." > "$final_changelog"
echo "No changelog available..." > "${final_changelog}_lite"
return 0
fi
local current_version=$(ynh_read_manifest --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" --manifest_key="version")
local update_version=$(ynh_read_manifest --manifest="../manifest.json" --manifest_key="version")
# Get the line of the version to update to into the changelog
local update_version_line=$(grep --max-count=1 --line-number "^## \[$update_version" "$original_changelog" | cut -d':' -f1)
# If there's no entry for this version yet into the changelog
# Get the first available version
if [ -z "$update_version_line" ]
then
update_version_line=$(grep --max-count=1 --line-number "^##" "$original_changelog" | cut -d':' -f1)
fi
# Get the length of the complete changelog.
local changelog_length=$(wc --lines "$original_changelog" | awk '{print $1}')
# Cut the file before the version to update to.
tail --lines=$(( $changelog_length - $update_version_line + 1 )) "$original_changelog" > "$temp_changelog"
# Get the length of the troncated changelog.
changelog_length=$(wc --lines "$temp_changelog" | awk '{print $1}')
# Get the line of the current version into the changelog
# Keep only the last line found
local current_version_line=$(grep --line-number "^## \[$current_version" "$temp_changelog" | cut -d':' -f1 | tail --lines=1)
# If there's no entry for this version into the changelog
# Get the last available version
if [ -z "$current_version_line" ]
then
current_version_line=$(grep --line-number "^##" "$original_changelog" | cut -d':' -f1 | tail --lines=1)
fi
# Cut the file before the current version.
# Then grep the previous version into the changelog to get the line number of the previous version
local previous_version_line=$(tail --lines=$(( $changelog_length - $current_version_line )) \
"$temp_changelog" | grep --max-count=1 --line-number "^## " | cut -d':' -f1)
# If there's no previous version into the changelog
# Go until the end of the changelog
if [ -z "$previous_version_line" ]
then
previous_version_line=$changelog_length
fi
# Cut the file after the previous version to keep only the changelog between the current version and the version to update to.
head --lines=$(( $current_version_line + $previous_version_line - 1 )) "$temp_changelog" | tee "$final_changelog"
if [ "$format" = "html" ]
then
# Replace markdown links by html links
ynh_replace_string --match_string="\[\(.*\)\](\(.*\)))" --replace_string="<a href=\"\2\">\1</a>)" --target_file="$final_changelog"
ynh_replace_string --match_string="\[\(.*\)\](\(.*\))" --replace_string="<a href=\"\2\">\1</a>" --target_file="$final_changelog"
elif [ "$format" = "plain" ]
then
# Change title format.
ynh_replace_string --match_string="^##.*\[\(.*\)\](\(.*\)) - \(.*\)$" --replace_string="## \1 (\3) - \2" --target_file="$final_changelog"
# Change modifications lines format.
ynh_replace_string --match_string="^\([-*]\).*\[\(.*\)\]\(.*\)" --replace_string="\1 \2 \3" --target_file="$final_changelog"
fi
# else markdown. As the file is already in markdown, nothing to do.
# Keep only important changes into the changelog
# Remove all minor changes
sed '/^-/d' "$final_changelog" > "${final_changelog}_lite"
# Remove all blank lines (to keep a clear workspace)
sed --in-place '/^$/d' "${final_changelog}_lite"
# Add a blank line at the end
echo "" >> "${final_changelog}_lite"
# Clean titles if there's no significative changes
local line
local previous_line=""
while read line <&3
do
if [ -n "$previous_line" ]
then
# Remove the line if it's a title or a blank line, and the previous one was a title as well.
if ( [ "${line:0:1}" = "#" ] || [ ${#line} -eq 0 ] ) && [ "${previous_line:0:1}" = "#" ]
then
ynh_replace_special_string --match_string="${previous_line//[/.}" --replace_string="" --target_file="${final_changelog}_lite"
fi
fi
previous_line="$line"
done 3< "${final_changelog}_lite"
# Remove all blank lines again
sed --in-place '/^$/d' "${final_changelog}_lite"
# Restore changelog format with blank lines
ynh_replace_string --match_string="^##.*" --replace_string="\n\n&\n" --target_file="${final_changelog}_lite"
# Remove the 2 first blank lines
sed --in-place '1,2d' "${final_changelog}_lite"
# Add a blank line at the end
echo "" >> "${final_changelog}_lite"
# If changelog are empty, add an info
if [ $(wc --words "$final_changelog" | awk '{print $1}') -eq 0 ]
then
echo "No changes from the changelog..." > "$final_changelog"
fi
if [ $(wc --words "${final_changelog}_lite" | awk '{print $1}') -eq 0 ]
then
echo "No significative changes from the changelog..." > "${final_changelog}_lite"
fi
}

View file

@ -1,7 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
@ -10,22 +8,6 @@
source ../settings/scripts/_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
#=================================================
ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
@ -35,21 +17,21 @@ ynh_print_info --message="Declaring files to be backed up..."
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup --src_path="$final_path"
ynh_backup --src_path="$install_dir"
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
# BACKUP SYSTEM
#=================================================
ynh_backup --src_path="/etc/logrotate.d/$app"
ynh_backup --src_path="/etc/cron.d/$app"
#=================================================
# BACKUP VARIOUS FILES
#=================================================
ynh_backup --src_path="/etc/cron.d/$app"
ynh_backup --src_path="/var/log/$app/"
#=================================================
# END OF SCRIPT

View file

@ -1,7 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
@ -10,205 +8,84 @@ source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
# INITIALIZE AND STORE SETTINGS
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
encrypt=$YNH_APP_ARG_ENCRYPT
encryption_pwd=$YNH_APP_ARG_ENCRYPTION_PWD
core_backup=$YNH_APP_ARG_CORE_BACKUP
apps_backup=$YNH_APP_ARG_APPS_BACKUP
frequency="$YNH_APP_ARG_FREQUENCY"
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..."
final_path=/opt/yunohost/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
if [ $encrypt -eq 1 ]; then
test -n "$encryption_pwd" || ynh_die --message="encryption_pwd can't be empty if you choose to enable encryption."
if [ "$encrypt" -eq 1 ] && [ -z "$encryption_pwd" ]; then
ynh_die --message="encryption_pwd can't be empty if you choose to enable encryption."
fi
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --weight=3
_set_frequencies
ynh_app_setting_set --app=$app --key=frequency --value="$frequency"
ynh_app_setting_set --app=$app --key=encrypt --value="$encrypt"
ynh_app_setting_set --app=$app --key=core_backup --value="$core_backup"
ynh_app_setting_set --app=$app --key=apps_backup --value="$apps_backup"
ynh_app_setting_set --app="$app" --key=overwrite_cron --value=1
ynh_app_setting_set --app=$app --key=overwrite_cron --value=1
ynh_app_setting_set --app=$app --key=admin_mail_html --value=1
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=15
# Valid the fucking debconf message
# To find this, install the package, install also debconf-utils
# Then use `debconf-get-selections | grep package`
echo "encfs encfs/security-information boolean true" | debconf-set-selections
ynh_install_app_dependencies $pkg_dependencies
# echo "encfs encfs/security-information boolean true" | debconf-set-selections
#REMOVEME? ynh_install_app_dependencies $pkg_dependencies
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=3
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
ynh_setup_source --dest_dir="$install_dir"
#=================================================
# SPECIFIC SETUP
#=================================================
# CREATE THE BACKUP DIRECTORY
#=================================================
chown -R "root:root" "$install_dir"
backup_dir="/home/yunohost.app/${app}/backup"
enc_backup_dir="/home/yunohost.app/${app}/encrypted_backup"
mkdir -p "$backup_dir"
chown -R "root:root" "$data_dir"
#=================================================
# CONFIGURE ARCHIVIST
#=================================================
ynh_script_progression --message="Configuring Archivist..." --weight=2
config_file="$final_path/Backup_list.conf"
cp "$final_path/Backup_list.conf.default" "$config_file"
ynh_replace_string --match_string="^backup_dir=.*" --replace_string="backup_dir=$backup_dir" --target_file="$config_file"
ynh_replace_string --match_string="^enc_backup_dir=.*" --replace_string="enc_backup_dir=$enc_backup_dir" --target_file="$config_file"
if [ $encrypt -eq 1 ]
then
encrypt=true
passkey="$final_path/passkey"
echo "$encryption_pwd" > "$passkey"
chmod 400 "$passkey"
if [ "$encrypt" -eq 1 ]; then
encrypt=true
passkey="$install_dir/passkey"
echo "$encryption_pwd" > "$passkey"
chmod 400 "$passkey"
else
encrypt=false
passkey=na
encrypt=false
passkey=na
fi
ynh_replace_string --match_string="^encrypt=.*" --replace_string="encrypt=$encrypt" --target_file="$config_file"
ynh_replace_string --match_string="^cryptpass=.*" --replace_string="cryptpass=$passkey" --target_file="$config_file"
if [ $core_backup -eq 1 ]
then
core_backup=true
if [ "$core_backup" -eq 1 ]; then
core_backup=true
else
core_backup=false
core_backup=false
fi
ynh_replace_string --match_string="^ynh_core_backup=.*" --replace_string="ynh_core_backup=$core_backup" --target_file="$config_file"
if [ $apps_backup -eq 1 ]
then
# Add all current applications to the backup
while read backup_app
do
ynh_replace_string --match_string="^ynh_app_backup=$" --replace_string="ynh_app_backup=$backup_app\n&" --target_file="$config_file"
done <<< "$(yunohost app list | grep 'id:' | sed 's/.*id: //')"
config_file="$install_dir/Backup_list.conf"
cp "$install_dir/Backup_list.conf.default" "$config_file"
ynh_replace_string --target_file="$config_file" --match_string="^backup_dir=.*" --replace_string="backup_dir=$data_dir/backup"
ynh_replace_string --target_file="$config_file" --match_string="^enc_backup_dir=.*" --replace_string="enc_backup_dir=$data_dir/encrypted_backup"
ynh_replace_string --target_file="$config_file" --match_string="^encrypt=.*" --replace_string="encrypt=$encrypt"
ynh_replace_string --target_file="$config_file" --match_string="^cryptpass=.*" --replace_string="cryptpass=$passkey"
ynh_replace_string --target_file="$config_file" --match_string="^ynh_core_backup=.*" --replace_string="ynh_core_backup=$core_backup"
if [ $apps_backup -eq 1 ]; then
# Add all current applications to the backup
while read -r backup_app; do
ynh_replace_string --target_file="$config_file" --match_string="^ynh_app_backup=$" --replace_string="ynh_app_backup=$backup_app\n&"
done <<< "$(yunohost app list | grep 'id:' | sed 's/.*id: //')"
fi
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$config_file"
#=================================================
# SET THE CRON FILE
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring the cron file..."
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
cp ../conf/cron /etc/cron.d/$app
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file=/etc/cron.d/$app
ynh_replace_string --match_string="__APP__" --replace_string=$app --target_file=/etc/cron.d/$app
if [ "$frequency" = "Daily" ]; then
cron_freq="0 2 * * *"
run_freq="every day"
elif [ "$frequency" = "Each 3 days" ]; then
cron_freq="0 2 */3 * *"
run_freq="each 3 days"
elif [ "$frequency" = "Weekly" ]; then
cron_freq="0 2 * * 0"
run_freq="once a week on sunday"
elif [ "$frequency" = "Biweekly" ]; then
cron_freq="0 2 * * 0/2"
run_freq="one sunday out of two"
else # Monthly
cron_freq="0 2 1 * *"
run_freq="once a month on the first sunday"
fi
ynh_replace_string --match_string="__FREQUENCY__" --replace_string="$cron_freq" --target_file=/etc/cron.d/$app
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="/etc/cron.d/$app"
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions to app files
chown -R root: $final_path
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..."
mkdir -p /var/log/$app
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
# PRINT INFORMATION
#=================================================
Informations="To add recipients or to modify the files or apps to backup,please have a look to the config file $config_file"
ynh_print_info --message="$Informations"
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
if [ "$encrypt" = "true" ]
then
encrypt_message="Your password for encryption is '$encryption_pwd'"
else
encrypt_message=""
fi
# Get main domain and buid the url of the admin panel of the app.
admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
echo "${encrypt_message}Archivist is going to run $run_freq.
If you want to change the frequency, have a look to the file /etc/cron.d/$app.
$Informations
Please read the __URL_TAG1__documentation__URL_TAG2__https://github.com/maniackcrudelis/archivist/blob/master/Configuration.md__URL_TAG3__ about the configuration of archivist for more information.
You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__.
You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__.
If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/archivist_ynh__URL_TAG3__." > mail_to_send
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=install
# Add Cron configuration file
ynh_add_config --template="archivist.cron" --destination="/etc/cron.d/$app"
#=================================================
# END OF SCRIPT

View file

@ -1,7 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
@ -10,54 +8,17 @@ source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
# REMOVE SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=2
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Removing logrotate configuration..."
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1
# Remove the app-specific logrotate config
ynh_remove_logrotate
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing app main directory..."
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=7
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE VARIOUS FILES
#=================================================
ynh_script_progression --message="Removing various files..."
# Remove a cron file
ynh_secure_remove --file="/etc/cron.d/$app"
ynh_script_progression --message="Removing backup directory..." --weight=5
# Remove the backup directory
ynh_secure_remove --file="/home/yunohost.app/$app/backup"
ynh_secure_remove --file="/var/log/$app"
#=================================================
# END OF SCRIPT

View file

@ -1,7 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
@ -10,87 +8,38 @@
source ../settings/scripts/_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
#=================================================
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..."
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..."
ynh_script_progression --message="Restoring the app main directory..." --weight=1
ynh_restore_file --origin_path="$final_path"
ynh_restore_file --origin_path="$install_dir"
chown -R "root:root" "$install_dir"
#=================================================
# SPECIFIC RESTORATION
# RESTORE THE DATA DIRECTORY
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=17
ynh_script_progression --message="Restoring the data directory..." --weight=1
# Valid the fucking debconf message
# To find this, install the package, install also debconf-utils
# Then use `debconf-get-selections | grep package`
echo "encfs encfs/security-information boolean true" | debconf-set-selections
ynh_install_app_dependencies $pkg_dependencies
ynh_restore_file --origin_path="$data_dir" --not_mandatory
chown -R "root:root" "$data_dir"
#=================================================
# RESTORE SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
ynh_restore_file --origin_path="/etc/cron.d/$app"
#=================================================
# RESTORE VARIOUS FILES
#=================================================
ynh_script_progression --message="Restoring various files..."
ynh_restore_file --origin_path="/etc/cron.d/$app"
mkdir -p "/home/yunohost.app/${app}/backup"
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the logrotate configuration..."
mkdir -p /var/log/$app
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
# Get main domain and buid the url of the admin panel of the app.
admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
echo "If you want to change the frequency of Archivist, have a look to the file /etc/cron.d/$app.
The configuration file of Archivist has been restored at $final_path/Backup_list.conf
Please read the __URL_TAG1__documentation__URL_TAG2__https://github.com/maniackcrudelis/archivist/blob/master/Configuration.md__URL_TAG3__ about the configuration of archivist for more information.
You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__.
You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__.
If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/archivist_ynh__URL_TAG3__." > mail_to_send
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=restore
ynh_restore_file --origin_path="/var/log/$app/"
#=================================================
# END OF SCRIPT

View file

@ -1,7 +1,5 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
@ -9,184 +7,76 @@
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=3
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
frequency="$(ynh_app_setting_get --app=$app --key=frequency)"
encrypt=$(ynh_app_setting_get --app=$app --key=encrypt)
core_backup=$(ynh_app_setting_get --app=$app --key=core_backup)
apps_backup=$(ynh_app_setting_get --app=$app --key=apps_backup)
overwrite_cron=$(ynh_app_setting_get --app=$app --key=overwrite_cron)
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=2
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
_set_frequencies
# If encrypt doesn't exist, create it
if [ -z "$encrypt" ]; then
encrypt="$(grep "^encrypt=" "$final_path/Backup_list.conf" | cut -d= -f2)"
if [ "$encrypt" = true ]; then
encrypt=1
else
encrypt=0
fi
ynh_app_setting_set --app=$app --key=encrypt --value=$encrypt
if [ -z "${encrypt:-}" ]; then
encrypt="$(grep "^encrypt=" "$install_dir/Backup_list.conf" | cut -d= -f2)"
if [ "$encrypt" = true ]; then
encrypt=1
else
encrypt=0
fi
ynh_app_setting_set --app="$app" --key="encrypt" --value="$encrypt"
fi
# If core_backup doesn't exist, create it
if [ -z "$core_backup" ]; then
core_backup="$(grep "^ynh_core_backup=" "$final_path/Backup_list.conf" | cut -d= -f2)"
ynh_app_setting_set --app=$app --key=core_backup --value=$core_backup
if [ -z "${core_backup:-}" ]; then
core_backup="$(grep "^ynh_core_backup=" "$install_dir/Backup_list.conf" | cut -d= -f2)"
ynh_app_setting_set --app="$app" --key="core_backup" --value="$core_backup"
fi
# If apps_backup doesn't exist, create it
if [ -z "$apps_backup" ]; then
apps_backup="$(grep --count --max-count=1 "^ynh_app_backup=" "$final_path/Backup_list.conf")"
ynh_app_setting_set --app=$app --key=apps_backup --value=$apps_backup
if [ -z "${apps_backup:-}" ]; then
apps_backup="$(grep --count --max-count=1 "^ynh_app_backup=" "$install_dir/Backup_list.conf")"
ynh_app_setting_set --app="$app" --key="apps_backup" --value="$apps_backup"
fi
# If overwrite_cron doesn't exist, create it
if [ -z "$overwrite_cron" ]; then
overwrite_cron=1
ynh_app_setting_set --app=$app --key=overwrite_cron --value=$overwrite_cron
if [ -z "${overwrite_cron:-}" ]; then
overwrite_cron=1
ynh_app_setting_set --app="$app" --key="overwrite_cron" --value="$overwrite_cron"
fi
admin_mail_html=$(ynh_app_setting_get --app=$app --key=admin_mail_html)
# If admin_mail_html doesn't exist, create it
if [ -z "$admin_mail_html" ]; then
admin_mail_html=1
ynh_app_setting_set --app=$app --key=admin_mail_html --value=$admin_mail_html
if [ -z "${admin_mail_html:-}" ]; then
admin_mail_html=1
ynh_app_setting_set --app="$app" --key="admin_mail_html" --value="$admin_mail_html"
fi
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Upgrading source files..." --weight=2
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --weight=2
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
fi
chown -R "root:root" "$install_dir"
#=================================================
# UPGRADE DEPENDENCIES
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=8
ynh_install_app_dependencies $pkg_dependencies
ynh_script_progression --message="Updating $app's configuration files..." --weight=1
#=================================================
# SPECIFIC UPGRADE
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
# UPDATE THE CRON FILE
#=================================================
ynh_script_progression --message="Updating the cron file..."
# Overwrite the cron file only if it's allowed
if [ $overwrite_cron -eq 1 ]
then
# Verify the checksum and backup the file if it's different
ynh_backup_if_checksum_is_different --file="/etc/cron.d/$app"
cp ../conf/cron /etc/cron.d/$app
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file=/etc/cron.d/$app
ynh_replace_string --match_string="__APP__" --replace_string=$app --target_file=/etc/cron.d/$app
if [ "$frequency" = "Daily" ]; then
cron_freq="0 2 * * *"
run_freq="every day"
elif [ "$frequency" = "Each 3 days" ]; then
cron_freq="0 2 */3 * *"
run_freq="each 3 days"
elif [ "$frequency" = "Weekly" ]; then
cron_freq="0 2 * * 0"
run_freq="once a week on sunday"
elif [ "$frequency" = "Biweekly" ]; then
cron_freq="0 2 * * 0/2"
run_freq="one sunday out of two"
else # Monthly
cron_freq="0 2 1 * *"
run_freq="once a month on the first sunday"
fi
ynh_replace_string --match_string="__FREQUENCY__" --replace_string="$cron_freq" --target_file=/etc/cron.d/$app
# Recalculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="/etc/cron.d/$app"
fi
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions on app files
chown -R root: $final_path
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..."
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
if (( overwrite_cron == 1 )); then
# Add Cron configuration file
ynh_add_config --template="archivist.cron" --destination="/etc/cron.d/$app"
fi
# Get main domain and buid the url of the admin panel of the app.
admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
# Build the changelog
ynh_app_changelog || true
echo "Archivist is going to run $run_freq.
If you want to change the frequency, have a look to the file /etc/cron.d/$app.
Please read the __URL_TAG1__documentation__URL_TAG2__https://github.com/maniackcrudelis/archivist/blob/master/Configuration.md__URL_TAG3__ about the configuration of archivist for more information.
You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__.
You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__.
If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/archivist_ynh__URL_TAG3__.
---
Changelog since your last upgrade:
$(cat changelog)" > mail_to_send
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=upgrade
#=================================================
# END OF SCRIPT