manifestv2

This commit is contained in:
Salamandar 2024-01-09 17:31:18 +01:00
parent 3ffbf915d0
commit 4de2b22738
16 changed files with 282 additions and 711 deletions

View file

@ -2,51 +2,55 @@ Changelog
=========
## Unreleased
- Nothing for now...
## [1.0~ynh5](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13) - 2019-04-24
#### Added
* [Add a changelog](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13/commits/054a7f4e0c98e2ade70779a9f470ef1d0d50413e)
- [New badges](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13/commits/477f7f3f178336ec03882fe3ec4e718c745ecda2)
#### Fixed
- [Fix Buster](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13/commits/fa7afd13e1657948a07a3f05227e5b6d26bdd9de)
#### Changed
- [Update to last standard](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13/commits/f7ad5779f7074bfaafd1bf4653bfeaf2ddc0880d)
- [Update helpers](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13/commits/02e6b338b17ddd468875865edc8bd9c5ad741381)
- [Update config-panel and actions](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13/commits/f37594eb5df701e70ce884354e4f5ad3371b3d8b)
- [Global upgrade](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/13/commits/74210eea818d76a35f1f9872029b267300ff5c46)
## [1.0~ynh4](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/9) - 2019-02-03
#### Added
- [Add progression bar](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/9/commits/51a015f726f852bbb0dc8ceb4c463657803b1b8b)
- [Changelog & html email](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/9/commits/f5c468947230dd2bcf8a82a0552548c6f6f61877)
## [1.0~ynh3](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/8) - 2019-01-21
#### Changed
- [Update to last standart](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/8/commits/2093bcf70e8527066eb8e0750c17cc361dd9a408)
- [Advertise config-panel and actions](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/8/commits/53132454227b9b972357ee694f79748f6a6bab93)
## [1.0~ynh2](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/6) - 2018-09-30
#### Added
- [Panel-config + actions fully tested](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/6/commits/eb48bf36a6a792d80b553624f5a221495c0d29a5)
- [Panel-config + actions fully tested](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/6/commits/eb48bf36a6a792d80b553624f5a221495c0d29a5)
## [1.0~ynh2](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/5) - 2018-07-16
#### Changed
- [Upgrade helpers](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/5/commits/d7d56c2d88aeb2817b509dbd9aa23434a1480148)
- [Upgrade helpers](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/5/commits/d7d56c2d88aeb2817b509dbd9aa23434a1480148)
## [1.0~ynh1](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/1) - 2018-03-14
#### Changed
- [Update helpers](https://github.com/YunoHost-Apps/unattended_upgrades_ynh/pull/1/commits/5a359c6833a5415932ab427a80dbbdc6ca3c8e23)

View file

@ -1,69 +0,0 @@
;; Test complet 1/3
; Manifest
upgrade_level="Security only"
ynh_update=1
previous_apticron=1
after_apticron=1
unattended_mail="If an upgrade has been done"
unattended_verbosity="1"
; Actions
; Config_panel
main.unattended_configuration.upgrade_level=Security only|Security and updates
main.unattended_configuration.ynh_update=0|1
main.unattended_configuration.unattended_mail=If an upgrade has been done|Only if there was an error|Never
main.apticron_configuration.previous_apticron=0|1
main.apticron_configuration.previous_apticron_hour=21
main.apticron_configuration.after_apticron=0|1
main.apticron_configuration.after_apticron_hour=5
main.periodic_configuration.unattended_verbosity=1|2|3
main.overwrite_files.overwrite_periodic=0|1
main.global_config.email_type=0|1
; Checks
pkg_linter=1
setup_sub_dir=0
setup_root=0
setup_nourl=1
setup_private=0
setup_public=0
upgrade=1
upgrade=1 from_commit=4e342d41ea448c4a9de2bbbc6b6cffe92320ef71
backup_restore=1
multi_instance=0
port_already_use=0
change_url=0
actions=0
config_panel=0
;; Test complet 2/3
; Manifest
upgrade_level="Security and updates"
ynh_update=0
previous_apticron=0
after_apticron=1
unattended_mail="Only if there was an error"
unattended_verbosity="2"
; Checks
setup_sub_dir=0
setup_root=0
setup_nourl=1
upgrade=1
backup_restore=1
;; Test complet 3/3
; Manifest
upgrade_level="Security only"
ynh_update=0
previous_apticron=1
after_apticron=0
unattended_mail="Never"
unattended_verbosity="3"
; Checks
setup_sub_dir=0
setup_root=0
setup_nourl=1
upgrade=1
backup_restore=1
;;; Options
Email=
Notification=change
;;; Upgrade options
; commit=4e342d41ea448c4a9de2bbbc6b6cffe92320ef71
name=Merge pull request #16 from YunoHost-Apps/testing

14
doc/ADMIN.md Normal file
View file

@ -0,0 +1,14 @@
## Configuration
Have a look to the following config files for Unattended-upgrades:
* /etc/apt/apt.conf.d/50unattended-upgrades
* /etc/apt/apt.conf.d/02periodic
And this one for Apticron:
* /etc/apticron/apticron.conf
With its cron file:
* /etc/cron.d/apticron

14
doc/ADMIN_fr.md Normal file
View file

@ -0,0 +1,14 @@
## Configuration
Regardez les fichiers de configuration suivant pour Unattended-upgrades:
* /etc/apt/apt.conf.d/50unattended-upgrades
* /etc/apt/apt.conf.d/02periodic
Et celui-ci pour Apticron
* /etc/apticron/apticron.conf
Avec son cron:
* /etc/cron.d/apticron

View file

@ -1,10 +0,0 @@
## Configuration
Have a look to the following config files for Unattended-upgrades
* /etc/apt/apt.conf.d/50unattended-upgrades
* /etc/apt/apt.conf.d/02periodic
And this one for Apticron
* /etc/apticron/apticron.conf
With its cron file
* /etc/cron.d/apticron

View file

@ -1,10 +0,0 @@
## Configuration
Regardez les fichiers de configuration suivant pour Unattended-upgrades
* /etc/apt/apt.conf.d/50unattended-upgrades
* /etc/apt/apt.conf.d/02periodic
Et celui-ci pour Apticron
* /etc/apticron/apticron.conf
Avec son cron
* /etc/cron.d/apticron

10
doc/POST_INSTALL.md Normal file
View file

@ -0,0 +1,10 @@
To modify any option of unattended-upgrades, please have a look to `/etc/apt/apt.conf.d/50unattended-upgrades` and `/etc/apt/apt.conf.d/02periodic`.
Unattended-upgrades will be executed every day at midnight.
To modify the configuration of apticron, please have a look to `/etc/apticron/apticron.conf`.
Apticron will be executed, depending of the requested configuration at 8 p.m. and 2 a.m. If you want to change this schedule, please have a look to the cron file /etc/cron.d/apticron.
You can configure this app easily by using the experimental [config-panel feature](__ADMIN_PANEL__/config-panel).
You can also find some specific actions for this app by using the experimental [action feature](__ADMIN_PANEL__/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/unattended_upgrades_ynh).

View file

@ -1,96 +0,0 @@
{
"name": "Unattended-upgrades",
"id": "unattended_upgrades",
"packaging_format": 1,
"description": {
"en": "Daily automatic upgrades",
"fr": "Mise à jour automatique quotidienne"
},
"version": "1.0~ynh6",
"url": "https://wiki.debian.org/UnattendedUpgrades",
"upstream": {
"license": "GPL-2.0-or-later",
"website": "https://wiki.debian.org/UnattendedUpgrades",
"admindoc": "https://wiki.debian.org/UnattendedUpgrades",
"userdoc": "https://manpages.debian.org/stretch/apticron/apticron.1.en.html"
},
"license": "GPL-2.0-or-later",
"maintainer": {
"name": "",
"email": ""
},
"previous_maintainers": [{
"name": "Maniack Crudelis",
"email": "maniackc_dev@crudelis.fr"
}],
"requirements": {
"yunohost": ">= 4.3.0"
},
"multi_instance": false,
"services": [],
"arguments": {
"install" : [
{
"name": "upgrade_level",
"type": "string",
"ask": {
"en": "Choose the sources of packages to automatically upgrade",
"fr": "Choisissez les sources des paquets à mettre à jour automatiquement"
},
"choices": ["Security only", "Security and updates"],
"default": "Security only"
},
{
"name": "ynh_update",
"type": "boolean",
"ask": {
"en": "Would you like to update YunoHost packages automatically?",
"fr": "Souhaitez-vous mettre à jour les paquets YunoHost automatiquement ?"
},
"default": true
},
{
"name": "previous_apticron",
"type": "boolean",
"ask": {
"en": "Would you like to receive an email to inform which upgrades need to be done?",
"fr": "Souhaitez-vous recevoir un email pour vous informer des mises à jour nécessaires ?"
},
"default": true
},
{
"name": "after_apticron",
"type": "boolean",
"ask": {
"en": "Would you like to receive an email to verify if there any upgrades left after each auto upgrade?",
"fr": "Souhaitez-vous recevoir un email pour vérifier s'il reste des mises à jour après chaque mise à niveau automatique ?"
},
"default": true
},
{
"name": "unattended_mail",
"type": "string",
"ask": {
"en": "Would you like to receive an email from Unattended-Upgrades?",
"fr": "Souhaitez-vous recevoir un email de Unattended-Upgrades ?"
},
"choices": ["If an upgrade has been done", "Only if there was an error", "Never"],
"default": "If an upgrade has been done"
},
{
"name": "unattended_verbosity",
"type": "string",
"ask": {
"en": "Choose the level of verbosity of Unattended-Upgrades mail",
"fr": "Choisir le niveau de verbosité du mail de Unattended-Upgrades"
},
"help": {
"en": "1: Progress report only.<br>2: Progress report and command outputs.<br>3: Progress report and command outputs and trace.<br>",
"fr": "1: Rapport d'avancement seulement.<br>2: Rapport d'avancement et sortie de commandes.<br>3: Rapport d'avancement, sortie de commandes et trace."
},
"choices": ["1", "2", "3"],
"default": "1"
}
]
}
}

88
manifest.toml Normal file
View file

@ -0,0 +1,88 @@
#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json
packaging_format = 2
id = "unattended_upgrades"
name = "Unattended-upgrades"
description.en = "Daily automatic upgrades"
description.fr = "Mise à jour automatique quotidienne"
version = "1.0~ynh6"
maintainers = []
[upstream]
license = "GPL-2.0-or-later"
website = "https://wiki.debian.org/UnattendedUpgrades"
admindoc = "https://wiki.debian.org/UnattendedUpgrades"
userdoc = "https://manpages.debian.org/stretch/apticron/apticron.1.en.html"
[integration]
yunohost = ">= 4.3.0"
architectures = "all"
multi_instance = false
ldap = "not_relevant"
sso = "not_relevant"
disk = "50M"
ram.build = "5M"
ram.runtime = "50M"
[install]
[install.upgrade_level]
ask.en = "Choose the sources of packages to automatically upgrade"
ask.fr = "Choisissez les sources des paquets à mettre à jour automatiquement"
type = "string"
choices.security_only = "Security only"
choices.security_and_updates = "Security and updates"
default = "security_only"
[install.ynh_update]
ask.en = "Would you like to update YunoHost packages automatically?"
ask.fr = "Souhaitez-vous mettre à jour les paquets YunoHost automatiquement ?"
type = "boolean"
default = true
[install.previous_apticron]
ask.en = "Would you like to receive an email to inform which upgrades need to be done?"
ask.fr = "Souhaitez-vous recevoir un email pour vous informer des mises à jour nécessaires ?"
type = "boolean"
default = true
[install.after_apticron]
ask.en = "Would you like to receive an email to verify if there any upgrades left after each auto upgrade?"
ask.fr = "Souhaitez-vous recevoir un email pour vérifier s'il reste des mises à jour après chaque mise à niveau automatique ?"
type = "boolean"
default = true
[install.unattended_mail]
ask.en = "Would you like to receive an email from Unattended-Upgrades?"
ask.fr = "Souhaitez-vous recevoir un email de Unattended-Upgrades ?"
type = "select"
choices.on_upgrade = "If an upgrade has been done"
choices.on_error = "Only if there was an error"
choices.never = "Never"
default = "on_upgrade"
[install.unattended_verbosity]
ask.en = "Choose the level of verbosity of Unattended-Upgrades mail"
ask.fr = "Choisir le niveau de verbosité du mail de Unattended-Upgrades"
type = "select"
choices.v1 = "Progress report only"
choices.v2 = "Progress report and command outputs"
choices.v3 = "Progress report and command outputs and trace"
# help.fr = "1: Rapport d'avancement seulement.<br>2: Rapport d'avancement et sortie de commandes.<br>3: Rapport d'avancement, sortie de commandes et trace."
default = "v1"
[resources]
[resources.system_user]
[resources.install_dir]
[resources.permissions]
[resources.apt]
packages = [
"apticron",
"unattended-upgrades",
"apt-listchanges",
]

View file

@ -4,48 +4,110 @@
# COMMON VARIABLES
#=================================================
# dependencies used by the app
pkg_dependencies="apticron unattended-upgrades apt-listchanges"
#=================================================
# PERSONAL HELPERS
#=================================================
apticron_config="/etc/apticron/apticron.conf"
apticron_cron="/etc/cron.d/apticron"
_apticron_set_config() {
# If the config file doesn't exist, copy the model
if [ ! -e "$apticron_config" ]; then
cp "/usr/lib/apticron/apticron.conf" "$apticron_config"
fi
# Create a backup of the config file for the reset action
cp "$apticron_config" "/etc/yunohost/apps/$app/conf/apticron.conf.backup"
ynh_replace_string --match_string="# CUSTOM_SUBJECT=.*" \
--replace_string="&\nCUSTOM_SUBJECT=\'[apticron] \$SYSTEM: \$NUM_PACKAGES package update(s)\'" --target_file="$apticron_config"
ynh_replace_string --match_string="# CUSTOM_NO_UPDATES_SUBJECT=.*" \
--replace_string="&\nCUSTOM_NO_UPDATES_SUBJECT=\'[apticron] \$SYSTEM: Up to date \\\\o/\'" --target_file="$apticron_config"
# Create a backup of the cron file for the reset action
cp "$apticron_cron" "/etc/yunohost/apps/$app/conf/apticron.crond.backup"
# Copy and comment the current cron
ynh_replace_string --match_string="^.* root if.*" --replace_string="#&\n&" --target_file="$apticron_cron"
# Modify the time to set at 20:00 every day
ynh_replace_string --match_string="^[[:digit:]].*\( root if.*\)" --replace_string="0 20 * * *\1" --target_file="$apticron_cron"
# Copy the new cron and set the time to 2:00 every night
ynh_replace_string --match_string="^0 20\(.*\)" --replace_string="&\n0 2\1" --target_file="$apticron_cron"
if [ "$previous_apticron" -eq 0 ]; then
# Comment the first cron
ynh_replace_string --match_string="^0 20 .*" --replace_string="#&" --target_file="$apticron_cron"
fi
if [ "$after_apticron" -eq 0 ]; then
# Comment the second cron
ynh_replace_string --match_string="^0 2 .*" --replace_string="#&" --target_file="$apticron_cron"
fi
}
_apticron_restore_config() {
mv "/etc/yunohost/apps/$app/conf/apticron.conf.backup" "$apticron_config"
mv "/etc/yunohost/apps/$app/conf/apticron.crond.backup" "$apticron_cron"
}
unattended_upgrades_config="/etc/apt/apt.conf.d/50unattended-upgrades"
_unattended_upgrades_set_config() {
# Make a backup of 50unattended-upgrades
cp "$unattended_upgrades_config" "/etc/yunohost/apps/$app/conf/50unattended-upgrades.backup"
# Configure upgrade sources
# Allow other updates
if [ "$upgrade_level" = "security_and_updates" ]; then
ynh_replace_string --match_string="//\(.*\"o=Debian,a=stable\)" --replace_string="\1" --target_file="$unattended_upgrades_config"
ynh_replace_string --match_string="//\(.*\"o=Debian,a=stable-updates\)" --replace_string="\1" --target_file="$unattended_upgrades_config"
fi
# Add YunoHost upgrade source
if [ $ynh_update -eq 1 ]; then
ynh_replace_string --match_string="origin=Debian,codename=\${distro_codename},label=Debian-Security\";" \
--replace_string="&\n\n //YunoHost upgrade\n \"o=YunoHost,a=stable\";" --target_file="$unattended_upgrades_config"
fi
# Allow MinimalSteps upgrading to reduce risk in case of reboot
ynh_replace_string --match_string="//\(Unattended-Upgrade::MinimalSteps\).*" --replace_string="\1 \"true\";" --target_file="$unattended_upgrades_config"
# Configure Unattended Upgrades mailing
if [ "$unattended_mail" = "on_upgrade" ]; then
# Allow mail to root
ynh_replace_string --match_string="//\(Unattended-Upgrade::Mail \)" --replace_string="\1" --target_file="$unattended_upgrades_config"
# Send mail even if there's no errors
ynh_replace_string --match_string="//\(Unattended-Upgrade::MailOnlyOnError \).*" --replace_string="\1\"false\";" --target_file="$unattended_upgrades_config"
elif [ "$unattended_mail" = "on_error" ]; then
# Allow mail to root
ynh_replace_string --match_string="//\(Unattended-Upgrade::Mail \)" --replace_string="\1" --target_file="$unattended_upgrades_config"
# Send mail only if there's an error
ynh_replace_string --match_string="//\(Unattended-Upgrade::MailOnlyOnError \).*" --replace_string="\1\"true\";" --target_file="$unattended_upgrades_config"
else # "Never"
# Comment "Unattended-Upgrade::Mail" if it isn't already commented
ynh_replace_string --match_string="^\(Unattended-Upgrade::Mail \)" --replace_string="//\1" --target_file="$unattended_upgrades_config"
fi
}
_unattended_upgrades_restore_config() {
mv "/etc/yunohost/apps/$app/conf/50unattended-upgrades.backup" "$unattended_upgrades_config"
}
#=================================================
# BACKUP
#=================================================
HUMAN_SIZE () { # Transforme une taille en Ko en une taille lisible pour un humain
human=$(numfmt --to=iec --from-unit=1K $1)
echo $human
}
CHECK_SIZE () { # Vérifie avant chaque backup que l'espace est suffisant
file_to_analyse=$1
backup_size=$(du --summarize "$file_to_analyse" | cut -f1)
free_space=$(df --output=avail "/home/yunohost.backup" | sed 1d)
if [ $free_space -le $backup_size ]
then
ynh_print_err "Espace insuffisant pour sauvegarder $file_to_analyse."
ynh_print_err "Espace disponible: $(HUMAN_SIZE $free_space)"
ynh_die "Espace nécessaire: $(HUMAN_SIZE $backup_size)"
fi
}
#=================================================
# PACKAGE CHECK BYPASSING...
#=================================================
IS_PACKAGE_CHECK () {
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]
then
return 0
else
return 1
fi
}
#=================================================
# FUTUR OFFICIAL HELPERS
#=================================================
@ -54,228 +116,6 @@ IS_PACKAGE_CHECK () {
# 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
}
#=================================================
# 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]
@ -311,7 +151,7 @@ ynh_app_changelog () {
return 0
fi
local current_version=$(ynh_read_manifest --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" --manifest_key="version")
#REMOVEME? 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
@ -411,76 +251,3 @@ ynh_app_changelog () {
echo "No significative changes from the changelog..." > "${final_changelog}_lite"
fi
}
#=================================================
# Check the amount of available RAM
#
# usage: ynh_check_ram [--required=RAM required in Mb] [--no_swap|--only_swap] [--free_ram]
# | arg: -r, --required= - Amount of RAM required in Mb. The helper will return 0 is there's enough RAM, or 1 otherwise.
# If --required isn't set, the helper will print the amount of RAM, in Mb.
# | arg: -s, --no_swap - Ignore swap
# | arg: -o, --only_swap - Ignore real RAM, consider only swap.
# | arg: -f, --free_ram - Count only free RAM, not the total amount of RAM available.
ynh_check_ram () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [r]=required= [s]=no_swap [o]=only_swap [f]=free_ram )
local required
local no_swap
local only_swap
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
required=${required:-}
no_swap=${no_swap:-0}
only_swap=${only_swap:-0}
local total_ram=$(vmstat --stats --unit M | grep "total memory" | awk '{print $1}')
local total_swap=$(vmstat --stats --unit M | grep "total swap" | awk '{print $1}')
local total_ram_swap=$(( total_ram + total_swap ))
local free_ram=$(vmstat --stats --unit M | grep "free memory" | awk '{print $1}')
local free_swap=$(vmstat --stats --unit M | grep "free swap" | awk '{print $1}')
local free_ram_swap=$(( free_ram + free_swap ))
# Use the total amount of ram
local ram=$total_ram_swap
if [ $free_ram -eq 1 ]
then
# Use the total amount of free ram
ram=$free_ram_swap
if [ $no_swap -eq 1 ]
then
# Use only the amount of free ram
ram=$free_ram
elif [ $only_swap -eq 1 ]
then
# Use only the amount of free swap
ram=$free_swap
fi
else
if [ $no_swap -eq 1 ]
then
# Use only the amount of free ram
ram=$total_ram
elif [ $only_swap -eq 1 ]
then
# Use only the amount of free swap
ram=$total_swap
fi
fi
if [ -n "$required" ]
then
# Return 1 if the amount of ram isn't enough.
if [ $ram -lt $required ]
then
return 1
else
return 0
fi
# If no RAM is required, return the amount of available ram.
else
echo $ram
fi
}

View file

@ -14,14 +14,14 @@ source /usr/share/yunohost/helpers
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#REMOVEME? ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info --message="Loading installation settings..."
#REMOVEME? ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP

View file

@ -10,119 +10,29 @@ source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE FAILURE OF THE SCRIPT
# STORE VARIABLES FOR POST_INSTALL.md
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
# 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"
ynh_app_setting_set --app="$app" --key=admin_panel --value="$admin_panel"
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
# ynh_app_setting_set --app=$app --key=overwrite_periodic --value=1
# ynh_app_setting_set --app=$app --key=admin_mail_html --value=1
upgrade_level="$YNH_APP_ARG_UPGRADE_LEVEL"
ynh_update=$YNH_APP_ARG_YNH_UPDATE
previous_apticron=$YNH_APP_ARG_PREVIOUS_APTICRON
after_apticron=$YNH_APP_ARG_AFTER_APTICRON
unattended_mail="$YNH_APP_ARG_UNATTENDED_MAIL"
unattended_verbosity=$YNH_APP_ARG_UNATTENDED_VERBOSITY
app=$YNH_APP_INSTANCE_NAME
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --weight=3
ynh_app_setting_set --app=$app --key=upgrade_level --value="$upgrade_level"
ynh_app_setting_set --app=$app --key=ynh_update --value=$ynh_update
ynh_app_setting_set --app=$app --key=previous_apticron --value=$previous_apticron
ynh_app_setting_set --app=$app --key=after_apticron --value=$after_apticron
ynh_app_setting_set --app=$app --key=unattended_mail --value="$unattended_mail"
ynh_app_setting_set --app=$app --key=unattended_verbosity --value=$unattended_verbosity
ynh_app_setting_set --app=$app --key=overwrite_periodic --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=10
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# SPECIFIC SETUP
#=================================================
# CONFIGURE APTICRON
#=================================================
ynh_script_progression --message="Configuring Apticron..."
apticron_config="/etc/apticron/apticron.conf"
# If the config file doesn't exist, copy the model
if [ ! -e "$apticron_config" ]
then
cp "/usr/lib/apticron/apticron.conf" "$apticron_config"
fi
# Create a backup of the config file for the reset action
cp "$apticron_config" "/etc/yunohost/apps/$app/conf/apticron.conf.backup"
ynh_replace_string --match_string="# CUSTOM_SUBJECT=.*" \
--replace_string="&\nCUSTOM_SUBJECT=\'[apticron] \$SYSTEM: \$NUM_PACKAGES package update(s)\'" --target_file="$apticron_config"
ynh_replace_string --match_string="# CUSTOM_NO_UPDATES_SUBJECT=.*" \
--replace_string="&\nCUSTOM_NO_UPDATES_SUBJECT=\'[apticron] \$SYSTEM: Up to date \\\\o/\'" --target_file="$apticron_config"
_apticron_set_config
#=================================================
# CONFIGURE UNATTENDED-UPGRADES
#=================================================
ynh_script_progression --message="Configuring Unattended-Upgrades..."
unattended_upgrades_config="/etc/apt/apt.conf.d/50unattended-upgrades"
# Make a backup of 50unattended-upgrades
cp "$unattended_upgrades_config" "/etc/apt/50unattended-upgrades.backup"
# Configure upgrade sources
# Allow other updates
if [ "$upgrade_level" = "Security and updates" ]
then
ynh_replace_string --match_string="//\(.*\"o=Debian,a=stable\)" --replace_string="\1" --target_file="$unattended_upgrades_config"
ynh_replace_string --match_string="//\(.*\"o=Debian,a=stable-updates\)" --replace_string="\1" --target_file="$unattended_upgrades_config"
fi
# Add YunoHost upgrade source
if [ $ynh_update -eq 1 ]
then
ynh_replace_string --match_string="origin=Debian,codename=\${distro_codename},label=Debian-Security\";" \
--replace_string="&\n\n //YunoHost upgrade\n \"o=YunoHost,a=stable\";" --target_file="$unattended_upgrades_config"
fi
# Allow MinimalSteps upgrading to reduce risk in case of reboot
ynh_replace_string --match_string="//\(Unattended-Upgrade::MinimalSteps\).*" --replace_string="\1 \"true\";" --target_file="$unattended_upgrades_config"
# Configure Unattended Upgrades mailing
if [ "$unattended_mail" = "If an upgrade has been done" ]
then
# Allow mail to root
ynh_replace_string --match_string="//\(Unattended-Upgrade::Mail \)" --replace_string="\1" --target_file="$unattended_upgrades_config"
# Send mail even if there's no errors
ynh_replace_string --match_string="//\(Unattended-Upgrade::MailOnlyOnError \).*" --replace_string="\1\"false\";" --target_file="$unattended_upgrades_config"
elif [ "$unattended_mail" = "Only if there was an error" ]
then
# Allow mail to root
ynh_replace_string --match_string="//\(Unattended-Upgrade::Mail \)" --replace_string="\1" --target_file="$unattended_upgrades_config"
# Send mail only if there's an error
ynh_replace_string --match_string="//\(Unattended-Upgrade::MailOnlyOnError \).*" --replace_string="\1\"true\";" --target_file="$unattended_upgrades_config"
else # "Never"
# Comment "Unattended-Upgrade::Mail" if it isn't already commented
ynh_replace_string --match_string="^\(Unattended-Upgrade::Mail \)" --replace_string="//\1" --target_file="$unattended_upgrades_config"
fi
_unattended_upgrades_set_config
#=================================================
# CONFIGURE APT PERIODIC FOR UNATTENDED
@ -131,56 +41,6 @@ ynh_script_progression --message="Configure APT Periodic for Unattended" --weigh
ynh_add_config --template="../conf/02periodic" --destination="/etc/apt/apt.conf.d/02periodic"
#=================================================
# MODIFY ORIGINAL APTICRON CRON FILE
#=================================================
ynh_script_progression --message="Modify original Apticron cron file" --weight=3
apticron_cron="/etc/cron.d/apticron"
# Create a backup of the cron file for the reset action
cp "$apticron_cron" "/etc/yunohost/apps/$app/conf/apticron.crond.backup"
# Copy and comment the current cron
ynh_replace_string --match_string="^.* root if.*" --replace_string="#&\n&" --target_file="$apticron_cron"
# Modify the time to set at 20:00 every day
ynh_replace_string --match_string="^[[:digit:]].*\( root if.*\)" --replace_string="0 20 * * *\1" --target_file="$apticron_cron"
# Copy the new cron and set the time to 2:00 every night
ynh_replace_string --match_string="^0 20\(.*\)" --replace_string="&\n0 2\1" --target_file="$apticron_cron"
if [ $previous_apticron -eq 0 ]
then
# Comment the first cron
ynh_replace_string --match_string="^0 20 .*" --replace_string="#&" --target_file="$apticron_cron"
fi
if [ $after_apticron -eq 0 ]
then
# Comment the second cron
ynh_replace_string --match_string="^0 2 .*" --replace_string="#&" --target_file="$apticron_cron"
fi
#=================================================
# GENERIC FINALISATION
#=================================================
# 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 "To modify any option of unattended-upgrades, please have a look to $unattended_upgrades_config and
/etc/apt/apt.conf.d/02periodic
Unattended-upgrades will be executed every day at midnight.
To modify the configuration of apticron, please have a look to $apticron_config.
Apticron will be executed, depending of the requested configuration at 8 p.m. and 2 a.m. If you want to change this schedule, please have a look to the cron file $apticron_cron.
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/unattended_upgrades_ynh__URL_TAG3__." > mail_to_send
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients=root --type=install
#=================================================
# END OF SCRIPT

View file

@ -9,22 +9,6 @@
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=5
ynh_remove_app_dependencies
#=================================================
# SPECIFIC REMOVE
#=================================================

View file

@ -14,23 +14,23 @@ source /usr/share/yunohost/helpers
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#REMOVEME? ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading settings..."
app=$YNH_APP_INSTANCE_NAME
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
#=================================================
# SPECIFIC RESTORE
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=10
#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." --weight=10
ynh_install_app_dependencies $pkg_dependencies
#REMOVEME? ynh_install_app_dependencies $pkg_dependencies
#=================================================
# RESTORE UNATTENDED-UPGRADES CONFIG

View file

@ -9,20 +9,6 @@
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
unattended_verbosity=$(ynh_app_setting_get --app=$app --key=unattended_verbosity)
overwrite_periodic=$(ynh_app_setting_get --app=$app --key=overwrite_periodic)
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
@ -39,7 +25,7 @@ fi
# 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
#REMOVEME? ynh_app_setting_set --app=$app --key=admin_mail_html --value=$admin_mail_html
fi
# Make a non perfect backup for apticron.conf if non existent
@ -61,25 +47,25 @@ fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=3
#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=3
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
#REMOVEME? ynh_backup_before_upgrade
#REMOVEME? ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
#REMOVEME? ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#REMOVEME? ynh_abort_if_errors
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=5
#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." --weight=5
ynh_install_app_dependencies $pkg_dependencies
#REMOVEME? ynh_install_app_dependencies $pkg_dependencies
#=================================================
# SPECIFIC UPGRADE

29
tests.toml Normal file
View file

@ -0,0 +1,29 @@
#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json
test_format = 1.0
[default]
args.upgrade_level = "security_only"
args.ynh_update = true
args.previous_apticron = true
args.after_apticron = true
args.unattended_mail = "on_upgrade"
args.unattended_verbosity = "v1"
test_upgrade_from.4e342d41.name = "Merge pull request #16 from YunoHost-Apps/testing"
[suite_2]
args.upgrade_level = "security_and_updates"
args.ynh_update = false
args.previous_apticron = false
args.after_apticron = true
args.unattended_mail = "on_error"
args.unattended_verbosity = "v2"
[suite_3]
args.upgrade_level = "security_only"
args.ynh_update = false
args.previous_apticron = true
args.after_apticron = false
args.unattended_mail = "never"
args.unattended_verbosity = "v3"