1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/borg_ynh.git synced 2024-09-03 18:16:05 +02:00

[enh] Add config panel

This commit is contained in:
ljf 2021-11-30 04:13:07 +01:00
parent 1adfd3205b
commit ef97208252
5 changed files with 137 additions and 2 deletions

View file

@ -22,6 +22,8 @@ filter_hooks() {
fail_if_partially_failed() {
grep Skipped|Error
}
sudo yunohost app setting ${borg_id} last_run -v "${current_date}"
sudo yunohost app setting ${borg_id} state -v "ongoing"
# Backup system part conf
conf=$(sudo yunohost app setting ${borg_id} conf)
@ -74,6 +76,12 @@ fi
domain=$(hostname)
repository="$(sudo yunohost app setting ${borg_id} repository)"
mailalert="$(sudo yunohost app setting ${borg_id} mailalert)"
if [[ ! -z "$errors" ]]; then
sudo yunohost app setting ${borg_id} state -v "failed"
else
sudo yunohost app setting ${borg_id} state -v "successful"
fi
if [[ ! -z "$errors" && $mailalert != "never" ]]; then
cat <(echo -e "$errors\n\n\n") "$log_file" "$err_file" | mail -s "[borg] Backup failed from $domain onto $repository" root
exit 1

78
config_panel.toml Normal file
View file

@ -0,0 +1,78 @@
version = "1.0"
[main]
services = []
[main.settings]
name = ""
visible = "false"
[main.settings.repository]
type = "string"
[main.settings.ssh_public_key]
type = "text"
visible = "false"
bind = "/root/.ssh/id___APP___ed25519.pub"
[main.settings.state]
type = "string"
visible = "false"
[main.settings.last_run]
type = "string"
visible = "false"
[main.general]
[main.general.info]
ask = """\
Repository : `{repository}`\
SSH public key : `{ssh_public_key}`\
Backup state : {state}
Last run: {last_run}
"""
type = "alert"
style = "info"
[main.general.on_calendar]
ask.en = "Frequency"
type = "string"
help = "With which regular time schedule should the backups be performed? (see systemd OnCalendar format)"
bind = "OnCalendar:/etc/systemd/system/__APP__.timer"
[main.general.mailalert]
ask.en = "Mail alert"
type = "select"
choices.always = "Always"
choices.errors_only = "Only if an error occured"
choices.never = "Never alert me"
help = "Alerts are sent to the first user of this server"
[main.content]
name = "What should be backuped ?"
optional = false
[main.content.conf]
ask.en = "Configuration"
type = "boolean"
[main.content.data]
ask.en = "Data"
type = "boolean"
[main.content.apps]
ask.en = "Apps"
type = "tags"
help = "App list separated by comma. You can write 'all' to select all apps, even those installed after this borg app. You can also select all apps but some apps by writing 'exclude:' following by an app list separated by comma."
[advanced]
name = "Advanced"
services = []
[advanced.list]
name = "Last backups list"
[advanced.list.last_backups]
ask.en = """\
{last_backups}\
"""
type = "markdown"

46
scripts/config Normal file
View file

@ -0,0 +1,46 @@
#!/bin/bash
source /usr/share/yunohost/helpers
ynh_abort_if_errors
#=================================================
# SPECIFIC GETTERS FOR TOML SHORT KEY
#=================================================
get__info() {
if [ "$state" == "failed" ]; then
cat << EOF
style: "danger"
EOF
elif [ "$state" == "successful" ]; then
cat << EOF
style: "success"
EOF
else
cat << EOF
style: "info"
EOF
fi
}
get__last_backups() {
cat << EOF
value:
$(borg list --short --last 50 $repository)
EOF
}
#=================================================
# SPECIFIC VALIDATORS FOR TOML SHORT KEYS
#=================================================
validate__on_calendar() {
(! systemd-analyze calendar $on_calendar > /dev/null) &&
echo 'Please follow systemd OnCalendar format: https://man.archlinux.org/man/systemd.time.7#CALENDAR_EVENTS'
}
#=================================================
# GENERIC FINALIZATION
#=================================================
ynh_app_config_run $1

View file

@ -21,7 +21,6 @@ ynh_abort_if_errors
#=================================================
export app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments
ynh_export repository passphrase on_calendar conf data apps mailalert
@ -36,7 +35,9 @@ if [[ $repository == *"@"* ]]; then
fi
ssh_user=$(echo "$repository" | cut -d"@" -f1 | cut -d"/" -f2)
fi
ynh_save_args repository server passphrase on_calendar conf data apps mailalert
state="repository uncreated"
last_run="-"
ynh_save_args repository server passphrase on_calendar conf data apps mailalert state last_run
#=================================================
# INSTALL DEPENDENCIES

View file

@ -28,6 +28,8 @@ if [[ $mailalert != "always" && $mailalert != "errors_only" && $mailalert != "ne
ynh_app_setting_set --app=$app --key="mailalert" --value="errors_only"
export mailalert="errors_only"
fi
ynh_app_setting_set --app=$app --key="state" --value="not run since last update"
ynh_app_setting_set --app=$app --key="last_run" --value="-"
#=================================================
# CHECK IF AN UPGRADE IS NEEDED