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

Use toml for config-panel and actions

This commit is contained in:
maniack 2019-10-25 18:29:31 +02:00
parent 536e472ada
commit 21b7e74609
5 changed files with 120 additions and 115 deletions

View file

@ -1,33 +0,0 @@
[{
"id": "force_backup",
"name": "Create a new backup",
"command": "/bin/bash scripts/actions/force_backup",
"user": "root",
"accepted_return_codes": [0],
"description": {
"en": "Run Archivist to create a new backup.",
"fr": "Lance Archivist pour créer un nouveau backup."
}
},
{
"id": "clean_backups",
"name": "Clean all previous backup files",
"command": "/bin/bash scripts/actions/clean_backups",
"user": "root",
"accepted_return_codes": [0],
"description": {
"en": "Remove all previous backup files made by Archivist.",
"fr": "Supprime tout les précédents backups créés par Archivist."
}
},
{
"id": "reset_default_config",
"name": "Reset the config file and restore a default one.",
"command": "/bin/bash scripts/actions/reset_default_config \"Backup_list.conf\"",
"user": "root",
"accepted_return_codes": [0],
"description": {
"en": "Reset the config file Backup_list.conf.",
"fr": "Réinitialise le fichier de configuration Backup_list.conf."
}
}]

26
actions.toml Normal file
View file

@ -0,0 +1,26 @@
[force_backup]
name = "Create a new backup"
command = "/bin/bash scripts/actions/force_backup"
# user = "root" # optional
# cwd = "/" # optional
# accepted_return_codes = [0, 1, 2, 3] # optional
accepted_return_codes = [0]
description = "Run Archivist to create a new backup."
[clean_backups]
name = "Clean all previous backup files"
command = "/bin/bash scripts/actions/clean_backups"
# user = "root" # optional
# cwd = "/" # optional
# accepted_return_codes = [0, 1, 2, 3] # optional
accepted_return_codes = [0]
description = "Remove all previous backup files made by Archivist."
[reset_default_config]
name = "Reset the config file and restore a default one."
command = "/bin/bash scripts/actions/reset_default_config \"Backup_list.conf\""
# user = "root" # optional
# cwd = "/" # optional
# accepted_return_codes = [0, 1, 2, 3] # optional
accepted_return_codes = [0]
description = "Reset the config file Backup_list.conf."

View file

@ -1,81 +0,0 @@
{
"name": "Archivist configuration panel",
"version": "0.1",
"panel": [{
"name": "Archivist configuration",
"id": "main",
"sections": [{
"name": "Encryption",
"id": "encryption",
"options": [{
"name": "Do you want to encrypt your backups ?",
"id": "encrypt",
"type": "bool",
"default": true
}, {
"name": "Set the password for encryption",
"help": "A password is needed if encryption is activated.",
"id": "encryption_pwd",
"type": "password",
"optional": true
}]
},
{
"name": "Backup",
"id": "backup_types",
"options": [{
"name": "Would you like to backup your YunoHost core ?",
"id": "core_backup",
"type": "bool",
"default": true
}, {
"name": "Would you like to backup your apps ?",
"help": "WARNING: Changing this value will either remove backup for all apps or add all current apps to the backup.",
"id": "apps_backup",
"type": "bool",
"default": true
}]
},
{
"name": "Backup options",
"id": "backup_options",
"options": [{
"name": "Choose the frequency of your backups ?",
"help": "We can't use a choices field for now. In the meantime please choose between one of this values:<br>Daily, Each 3 days, Weekly, Biweekly, Monthly.",
"id": "frequency",
"type": "text",
"//": "\"choices\" : [\"Daily\", \"Each 3 days\", \"Weekly\", \"Biweekly\", \"Monthly\"]",
"default" : "Weekly"
}, {
"name": "Max size for each backup in Mb",
"help": "Specify the max size of each backup for the following option file_to_backup.</br>This option is a soft limit, that means the script will try to limit each backup to this max size if it can.</br>But there's 2 limitations, for a single directory, it can't makes more than one backup file, even if the files in this directory exceed this maximum size.</br>And, if there's some files in a directory, next to subdirectories, it'll make only one backup for this files.</br>So this limit will be applied to split the backup by its subdirectories to avoid to have only one big backup.",
"id": "max_size",
"type": "number",
"default": 500
}]
},
{
"name": "Overwriting config files",
"id": "overwrite_files",
"options": [{
"name": "Overwrite the cron file during the upgrade ?",
"help": "If the file is overwritten, a backup will be created.",
"id": "overwrite_cron",
"type": "bool",
"default": true
}]
},
{
"name": "Global configuration",
"id": "global_config",
"options": [{
"name": "Send HTML email to admin ?",
"help": "Allow app scripts to send HTML mails instead of plain text.",
"id": "email_type",
"type": "bool",
"default": true
}]
}]
}
]
}

65
config_panel.toml Normal file
View file

@ -0,0 +1,65 @@
version = "0.1"
name = "Archivist configuration panel"
[main]
name = "Archivist configuration"
[main.encryption]
name = "Encryption"
[main.encryption.encrypt]
ask = "Do you want to encrypt your backups ?"
type = "boolean"
default = true
[main.encryption.encryption_pwd]
ask = "Set the password for encryption"
type = "password"
optional = true
help = "A password is needed if encryption is activated."
[main.backup_types]
name = "Backup"
[main.backup_types.core_backup]
ask = "Would you like to backup your YunoHost core ?"
type = "boolean"
default = true
[main.backup_types.apps_backup]
ask = "Would you like to backup your apps ?"
type = "boolean"
default = true
help = "WARNING: Changing this value will either remove backup for all apps or add all current apps to the backup."
[main.backup_options]
name = "Backup options"
[main.backup_options.frequency]
ask = "Choose the frequency of your backups ?"
choices = ["Daily", "Each 3 days", "Weekly", "Biweekly", "Monthly"]
default = "Weekly"
[main.backup_options.max_size]
ask = "Max size for each backup in Mb"
type = "number"
default = 500
help = "Specify the max size of each backup for the following option file_to_backup.</br>This option is a soft limit, that means the script will try to limit each backup to this max size if it can.</br>But there's 2 limitations, for a single directory, it can't makes more than one backup file, even if the files in this directory exceed this maximum size.</br>And, if there's some files in a directory, next to subdirectories, it'll make only one backup for this files.</br>So this limit will be applied to split the backup by its subdirectories to avoid to have only one big backup."
[main.overwrite_files]
name = "Overwriting config files"
[main.overwrite_files.overwrite_cron]
ask = "Overwrite the cron file during the upgrade ?"
type = "boolean"
default = true
help = "If the file is overwritten, a backup will be created."
[main.global_config]
name = "Global configuration"
[main.global_config.email_type]
ask = "Send HTML email to admin ?"
type = "boolean"
default = true
help = "Allow app scripts to send HTML mails instead of plain text."

View file

@ -44,14 +44,17 @@ get_config_value() {
# Encryption
old_encrypt="$(get_config_value encrypt)"
encrypt="${YNH_CONFIG_MAIN_ENCRYPTION_ENCRYPT:-$old_encrypt}"
# Encryption password
ynh_print_OFF
old_encrypt_password="$(cat $passkey)"
encrypt_password="${YNH_CONFIG_MAIN_ENCRYPTION_ENCRYPTION_PWD:-$old_encrypt_password}"
ynh_print_ON
# ynh_core_backup
old_ynh_core_backup="$(get_config_value ynh_core_backup)"
ynh_core_backup="${YNH_CONFIG_MAIN_BACKUP_TYPES_CORE_BACKUP:-$old_ynh_core_backup}"
# ynh_app_backup
if [ -n "$(get_config_value ynh_app_backup)" ]
then
@ -60,9 +63,11 @@ else
old_ynh_app_backup="false"
fi
ynh_app_backup="${YNH_CONFIG_MAIN_BACKUP_TYPES_APPS_BACKUP:-$old_ynh_app_backup}"
# Frequency
old_frequency="$(grep "^frequency: " "/etc/yunohost/apps/$app/settings.yml" | cut -d' ' -f2)"
frequency="${YNH_CONFIG_MAIN_BACKUP_OPTIONS_FREQUENCY:-$old_frequency}"
# Max size
old_max_size="$(get_config_value max_size)"
max_size="${YNH_CONFIG_MAIN_BACKUP_OPTIONS_MAX_SIZE:-$old_max_size}"
@ -84,6 +89,7 @@ admin_mail_html="${YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE:-$old_admin_mail_htm
show_config() {
# here you are supposed to read some config file/database/other then print the values
# echo "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value"
echo "YNH_CONFIG_MAIN_ENCRYPTION_ENCRYPT=$encrypt"
echo "YNH_CONFIG_MAIN_ENCRYPTION_ENCRYPTION_PWD="
@ -103,8 +109,14 @@ show_config() {
#=================================================
apply_config() {
#=================================================
# MODIFY THE PASSWORD
#=================================================
# Change the password if needed
if [ "$encrypt" = "true" ]; then
if [ "$encrypt" = "true" ]
then
ynh_print_OFF
test -n "$encrypt_password" || ynh_die --message="The password for encryption can't be empty if you choose to enable encryption."
ynh_print_ON
@ -115,9 +127,17 @@ apply_config() {
ynh_replace_string --match_string="^cryptpass=.*" --replace_string="cryptpass=$passkey" --target_file="$config_file"
fi
#=================================================
# MODIFY ENCRYPT SETTING
#=================================================
# Change encrypt in the config file
ynh_replace_string --match_string="^encrypt=.*" --replace_string="encrypt=$encrypt" --target_file="$config_file"
#=================================================
# MODIFY SETTINGS
#=================================================
# Change ynh_core_backup in the config file
ynh_replace_string --match_string="^ynh_core_backup=.*" --replace_string="ynh_core_backup=$ynh_core_backup" --target_file="$config_file"
@ -161,10 +181,18 @@ apply_config() {
# Change max_size in the config file
ynh_replace_string --match_string="^max_size=.*" --replace_string="max_size=$max_size" --target_file="$config_file"
#=================================================
# MODIFY OVERWRITTING SETTINGS
#=================================================
# Set overwrite_cron
overwrite_cron=$(bool_to_01 $overwrite_cron)
ynh_app_setting_set --app=$app --key=overwrite_cron --value="$overwrite_cron"
#=================================================
# MODIFY EMAIL SETTING
#=================================================
# Set admin_mail_html
admin_mail_html=$(bool_to_01 $admin_mail_html)
ynh_app_setting_set --app=$app --key=admin_mail_html --value="$admin_mail_html"